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

99 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import {
Box,
Typography,
RadioGroup,
FormControlLabel,
Radio,
useTheme,
} from "@mui/material";
import { useQuizViewStore, updateAnswer } from "@root/quizView";
import RadioCheck from "@ui_kit/RadioCheck";
import RadioIcon from "@ui_kit/RadioIcon";
import type { QuizQuestionVariant } from "../../../model/questionTypes/variant";
type VariantProps = {
stepNumber: number;
currentQuestion: QuizQuestionVariant;
2023-11-30 17:39:57 +00:00
};
export const Variant = ({ currentQuestion }: VariantProps) => {
2023-11-30 17:39:57 +00:00
const { answers } = useQuizViewStore();
const theme = useTheme();
2023-12-11 13:07:41 +00:00
const { answer } =
answers.find(
({ questionId }) => questionId === currentQuestion.content.id
) ?? {};
2023-11-30 17:39:57 +00:00
return (
<Box>
<Typography variant="h5">{currentQuestion.title}</Typography>
2023-11-30 17:39:57 +00:00
<Box sx={{ display: "flex" }}>
<RadioGroup
name={currentQuestion.id}
2023-12-11 13:07:41 +00:00
value={currentQuestion.content.variants.findIndex(
({ id }) => answer === id
)}
2023-11-30 17:39:57 +00:00
onChange={({ target }) =>
updateAnswer(
currentQuestion.content.id,
currentQuestion.content.variants[Number(target.value)].id
2023-11-30 17:39:57 +00:00
)
}
sx={{
display: "flex",
flexWrap: "wrap",
flexDirection: "row",
justifyContent: "space-between",
flexBasis: "100%",
marginTop: "20px",
}}
>
2023-12-11 13:07:41 +00:00
<Box
sx={{
display: "flex",
flexDirection: "row",
flexWrap: "wrap",
width: "100%",
gap: "20px",
}}
>
{currentQuestion.content.variants.map(({ id, answer }, index) => (
2023-11-30 17:39:57 +00:00
<FormControlLabel
key={id}
sx={{
margin: "0",
borderRadius: "12px",
2023-11-30 17:39:57 +00:00
padding: "15px",
border: `1px solid ${theme.palette.grey2.main}`,
display: "flex",
maxWidth: "685px",
justifyContent: "space-between",
2023-12-11 13:07:41 +00:00
width: "100%",
2023-11-30 17:39:57 +00:00
}}
value={index}
labelPlacement="start"
2023-11-30 17:39:57 +00:00
control={
<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />
}
label={answer}
/>
))}
</Box>
</RadioGroup>
{currentQuestion.content.back && (
2023-11-30 17:39:57 +00:00
<Box sx={{ maxWidth: "400px", width: "100%", height: "300px" }}>
<img
src={currentQuestion.content.back}
2023-11-30 17:39:57 +00:00
style={{ width: "100%", height: "100%", objectFit: "cover" }}
alt=""
/>
</Box>
)}
</Box>
</Box>
);
};