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";
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import {
|
||||
getAnswersQueryOptions,
|
||||
submitOptionMutationOptions,
|
||||
getAverageScoreSubAspectQueryOptions,
|
||||
getAverageScoreQueryOptions,
|
||||
fetchAspects,
|
||||
submitAnswerMutationOptions,
|
||||
getQuestionsAllQueryOptions,
|
||||
toggleFlagAnswer,
|
||||
} from "@/modules/assessmentManagement/queries/assessmentQueries";
|
||||
|
|
@ -163,8 +162,8 @@ export default function AssessmentPage() {
|
|||
},
|
||||
});
|
||||
|
||||
// Inside the AssessmentPage function:
|
||||
const submitAnswerMutation = useMutation(submitAnswerMutationOptions());
|
||||
// Mutation function to submit answer
|
||||
const submitOptionMutation = useMutation(submitOptionMutationOptions());
|
||||
|
||||
useEffect(() => {
|
||||
const savedAnswers = localStorage.getItem("assessmentAnswers");
|
||||
|
|
@ -174,7 +173,7 @@ export default function AssessmentPage() {
|
|||
}, []);
|
||||
|
||||
const handleAnswerChange = (questionId: string, optionId: string) => {
|
||||
const assessmentId = getQueryParam("id"); // Mengambil assessmentId otomatis dari URL
|
||||
const assessmentId = getQueryParam("id");
|
||||
|
||||
if (!assessmentId) {
|
||||
console.error("Assessment ID tidak ditemukan");
|
||||
|
|
@ -188,13 +187,12 @@ export default function AssessmentPage() {
|
|||
// Update state
|
||||
setAnswers(updatedAnswers);
|
||||
|
||||
// Kirim jawaban ke backend
|
||||
submitAnswerMutation.mutate({
|
||||
submitOptionMutation.mutate({
|
||||
optionId,
|
||||
assessmentId, // Menggunakan assessmentId dari URL
|
||||
validationInformation: JSON.stringify({
|
||||
questionId,
|
||||
}),
|
||||
assessmentId,
|
||||
questionId,
|
||||
isFlagged: false,
|
||||
filename: undefined,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -261,9 +259,6 @@ export default function AssessmentPage() {
|
|||
}
|
||||
|
||||
const totalQuestions = data?.data?.length || 0;
|
||||
const totalPages = Math.ceil(totalQuestions / limit);
|
||||
const averageScores = averageScoreQuery.data?.aspects;
|
||||
const averageScoresSubAspect = averageScoreSubAspectQuery.data?.subAspects;
|
||||
|
||||
if (!assessmentId) {
|
||||
return (
|
||||
|
|
@ -555,7 +550,7 @@ export default function AssessmentPage() {
|
|||
|
||||
{/* Skor Sub-Aspek */}
|
||||
<div>
|
||||
{averageScoresForSelectedSubAspect?.length ? (
|
||||
{averageScoresForSelectedSubAspect?.length ? (
|
||||
averageScoresForSelectedSubAspect.map((subAspect) => (
|
||||
<div key={subAspect.aspectId} className="flex justify-between items-center">
|
||||
<Text className="text-lg text-gray-400">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user