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

40 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import { Box, Typography } from "@mui/material";
import { Select as SelectComponent } from "../../../pages/Questions/Select";
2023-12-01 13:48:25 +00:00
import { useQuizViewStore, updateAnswer } from "@root/quizView";
2023-11-30 17:39:57 +00:00
import type { QuizQuestionSelect } from "../../../model/questionTypes/select";
type SelectProps = {
2023-12-01 13:48:25 +00:00
stepNumber: number;
2023-11-30 17:39:57 +00:00
question: QuizQuestionSelect;
};
2023-12-01 13:48:25 +00:00
export const Select = ({ stepNumber, question }: SelectProps) => {
const { answers } = useQuizViewStore();
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",
}}
>
<SelectComponent
2023-12-01 13:48:25 +00:00
activeItemIndex={Number(answer) || 0}
2023-11-30 17:39:57 +00:00
items={question.content.variants.map(({ answer }) => answer)}
2023-12-01 13:48:25 +00:00
onChange={(_, value) => {
updateAnswer(stepNumber, String(value));
2023-11-30 17:39:57 +00:00
}}
/>
</Box>
</Box>
);
};