Pull Request branch dev-clone to main #1
|
|
@ -150,11 +150,35 @@ export default function AssessmentPage() {
|
||||||
// Inside the AssessmentPage function:
|
// Inside the AssessmentPage function:
|
||||||
const submitAnswerMutation = useMutation(submitAnswerMutationOptions());
|
const submitAnswerMutation = useMutation(submitAnswerMutationOptions());
|
||||||
|
|
||||||
const handleAnswerChange = (optionId: string) => {
|
useEffect(() => {
|
||||||
|
const savedAnswers = localStorage.getItem("assessmentAnswers");
|
||||||
|
if (savedAnswers) {
|
||||||
|
setAnswers(JSON.parse(savedAnswers));
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleAnswerChange = (questionId: string, optionId: string) => {
|
||||||
|
const assessmentId = getQueryParam("id"); // Mengambil assessmentId otomatis dari URL
|
||||||
|
|
||||||
|
if (!assessmentId) {
|
||||||
|
console.error("Assessment ID tidak ditemukan");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simpan jawaban ke localStorage
|
||||||
|
const updatedAnswers = { ...answers, [questionId]: optionId };
|
||||||
|
localStorage.setItem("assessmentAnswers", JSON.stringify(updatedAnswers));
|
||||||
|
|
||||||
|
// Update state
|
||||||
|
setAnswers(updatedAnswers);
|
||||||
|
|
||||||
|
// Kirim jawaban ke backend
|
||||||
submitAnswerMutation.mutate({
|
submitAnswerMutation.mutate({
|
||||||
optionId: optionId,
|
optionId,
|
||||||
assessmentId: assessmentId || "",
|
assessmentId, // Menggunakan assessmentId dari URL
|
||||||
validationInformation: "someValidationInfo", // Sesuaikan validasi yang relevan
|
validationInformation: JSON.stringify({
|
||||||
|
questionId,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -364,7 +388,7 @@ export default function AssessmentPage() {
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{question.options?.length > 0 ? (
|
{question.options?.length > 0 ? (
|
||||||
<Radio.Group>
|
<Radio.Group value={answers[question.questionId] || ""}>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{question.options.map((option: any) => (
|
{question.options.map((option: any) => (
|
||||||
<label
|
<label
|
||||||
|
|
@ -380,16 +404,8 @@ export default function AssessmentPage() {
|
||||||
size="md"
|
size="md"
|
||||||
radius="xl"
|
radius="xl"
|
||||||
style={{ pointerEvents: "none" }}
|
style={{ pointerEvents: "none" }}
|
||||||
onChange={() => {
|
checked={answers[question.questionId] === option.optionId} // Untuk menampilkan jawaban yang sudah dipilih
|
||||||
submitAnswerMutation.mutate({
|
onChange={() => handleAnswerChange(question.questionId, option.optionId)} // Memanggil handleAnswerChange dengan questionId dan optionId
|
||||||
optionId: option.optionId,
|
|
||||||
assessmentId: assessmentId || "",
|
|
||||||
validationInformation: JSON.stringify({
|
|
||||||
info: "jfjforjfocn",
|
|
||||||
questionId: question.questionId,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user