frontPanel/src/pages/ViewPublicationPage/questions/Rating.tsx

70 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import {
Box,
Typography,
Rating as RatingComponent,
useTheme,
} from "@mui/material";
2023-12-01 13:48:25 +00:00
import { useQuizViewStore, updateAnswer } from "@root/quizView";
2023-11-30 17:39:57 +00:00
import StarIconMini from "@icons/questionsPage/StarIconMini";
import type { QuizQuestionRating } from "../../../model/questionTypes/rating";
type RatingProps = {
2023-12-01 13:48:25 +00:00
stepNumber: number;
2023-11-30 17:39:57 +00:00
question: QuizQuestionRating;
};
2023-12-01 13:48:25 +00:00
export const Rating = ({ stepNumber, question }: RatingProps) => {
const { answers } = useQuizViewStore();
2023-11-30 17:39:57 +00:00
const theme = useTheme();
2023-12-01 13:48:25 +00:00
const { answer } = answers.find(({ step }) => step === stepNumber) ?? {};
2023-11-30 17:39:57 +00:00
return (
<Box>
<Typography variant="h5">{question.title}</Typography>
<Box
sx={{
display: "flex",
flexDirection: "column",
width: "100%",
marginTop: "20px",
}}
>
<RatingComponent
2023-12-01 13:48:25 +00:00
value={Number(answer || 0)}
onChange={(_, value) => updateAnswer(stepNumber, String(value))}
2023-11-30 17:39:57 +00:00
sx={{ height: "50px" }}
max={question.content.steps}
icon={
<StarIconMini
color={theme.palette.brightPurple.main}
width={50}
sx={{ transform: "scale(0.8)" }}
/>
}
emptyIcon={
<StarIconMini
color={theme.palette.grey2.main}
width={50}
sx={{ transform: "scale(0.8)" }}
/>
}
/>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
maxWidth: `${question.content.steps * 50}px`,
color: theme.palette.grey2.main,
}}
>
<Typography>{question.content.ratingNegativeDescription}</Typography>
<Typography>{question.content.ratingPositiveDescription}</Typography>
</Box>
</Box>
</Box>
);
};