update: index lazy for submit option on assessment
This commit is contained in:
parent
49b6fac174
commit
2e9156a30b
|
|
@ -14,11 +14,10 @@ import {
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
getAnswersQueryOptions,
|
submitOptionMutationOptions,
|
||||||
getAverageScoreSubAspectQueryOptions,
|
getAverageScoreSubAspectQueryOptions,
|
||||||
getAverageScoreQueryOptions,
|
getAverageScoreQueryOptions,
|
||||||
fetchAspects,
|
fetchAspects,
|
||||||
submitAnswerMutationOptions,
|
|
||||||
getQuestionsAllQueryOptions,
|
getQuestionsAllQueryOptions,
|
||||||
toggleFlagAnswer,
|
toggleFlagAnswer,
|
||||||
} from "@/modules/assessmentManagement/queries/assessmentQueries";
|
} from "@/modules/assessmentManagement/queries/assessmentQueries";
|
||||||
|
|
@ -163,8 +162,8 @@ export default function AssessmentPage() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Inside the AssessmentPage function:
|
// Mutation function to submit answer
|
||||||
const submitAnswerMutation = useMutation(submitAnswerMutationOptions());
|
const submitOptionMutation = useMutation(submitOptionMutationOptions());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const savedAnswers = localStorage.getItem("assessmentAnswers");
|
const savedAnswers = localStorage.getItem("assessmentAnswers");
|
||||||
|
|
@ -174,7 +173,7 @@ export default function AssessmentPage() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleAnswerChange = (questionId: string, optionId: string) => {
|
const handleAnswerChange = (questionId: string, optionId: string) => {
|
||||||
const assessmentId = getQueryParam("id"); // Mengambil assessmentId otomatis dari URL
|
const assessmentId = getQueryParam("id");
|
||||||
|
|
||||||
if (!assessmentId) {
|
if (!assessmentId) {
|
||||||
console.error("Assessment ID tidak ditemukan");
|
console.error("Assessment ID tidak ditemukan");
|
||||||
|
|
@ -188,13 +187,12 @@ export default function AssessmentPage() {
|
||||||
// Update state
|
// Update state
|
||||||
setAnswers(updatedAnswers);
|
setAnswers(updatedAnswers);
|
||||||
|
|
||||||
// Kirim jawaban ke backend
|
submitOptionMutation.mutate({
|
||||||
submitAnswerMutation.mutate({
|
|
||||||
optionId,
|
optionId,
|
||||||
assessmentId, // Menggunakan assessmentId dari URL
|
assessmentId,
|
||||||
validationInformation: JSON.stringify({
|
|
||||||
questionId,
|
questionId,
|
||||||
}),
|
isFlagged: false,
|
||||||
|
filename: undefined,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -261,9 +259,6 @@ export default function AssessmentPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalQuestions = data?.data?.length || 0;
|
const totalQuestions = data?.data?.length || 0;
|
||||||
const totalPages = Math.ceil(totalQuestions / limit);
|
|
||||||
const averageScores = averageScoreQuery.data?.aspects;
|
|
||||||
const averageScoresSubAspect = averageScoreSubAspectQuery.data?.subAspects;
|
|
||||||
|
|
||||||
if (!assessmentId) {
|
if (!assessmentId) {
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user