Pull Request branch dev-clone to main #1

Merged
gitea merged 429 commits from dev-clone into main 2024-12-23 09:31:34 +00:00
2 changed files with 19 additions and 9 deletions
Showing only changes of commit a0707d67a9 - Show all commits

View File

@ -94,13 +94,13 @@ export const submitOption = async (form: {
);
};
export const submitOptionMutationOptions: () => UseMutationOptions<
export const submitOptionMutationOptions: UseMutationOptions<
SubmitOptionResponse,
Error,
Parameters<typeof submitOption>[0]
> = () => ({
> = {
mutationFn: submitOption,
});
};
export const submitValidation = async (
form: {

View File

@ -180,8 +180,17 @@ export default function AssessmentPage() {
},
});
// Mutation function to submit answer
const submitOptionMutation = useMutation(submitOptionMutationOptions());
// Usage of the mutation in your component
const submitOptionMutation = useMutation({
...submitOptionMutationOptions, // Spread the mutation options here
onSuccess: () => {
// Refetch the average scores after a successful submission
averageScoreQuery.refetch();
},
onError: (error) => {
console.error("Error submitting option:", error);
},
});
useEffect(() => {
const assessmentId = getQueryParam("id");
@ -200,19 +209,20 @@ export default function AssessmentPage() {
const handleAnswerChange = (questionId: string, optionId: string) => {
const assessmentId = getQueryParam("id");
if (!assessmentId) {
console.error("Assessment ID tidak ditemukan");
return;
}
// Simpan jawaban ke localStorage dengan ID assessment
const updatedAnswers = { ...answers, [questionId]: optionId };
localStorage.setItem(`assessmentAnswers_${assessmentId}`, JSON.stringify(updatedAnswers));
// Update state
setAnswers(updatedAnswers);
// Call the mutation to submit the option
submitOptionMutation.mutate({
optionId,
assessmentId,