update: index lazy for submit validation information
This commit is contained in:
parent
66f29aed8f
commit
d2a0ea97ca
|
|
@ -14,8 +14,8 @@ import {
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
|
submitValidationMutationOptions,
|
||||||
submitOptionMutationOptions,
|
submitOptionMutationOptions,
|
||||||
getAverageScoreSubAspectQueryOptions,
|
|
||||||
getAverageScoreQueryOptions,
|
getAverageScoreQueryOptions,
|
||||||
fetchAspects,
|
fetchAspects,
|
||||||
getQuestionsAllQueryOptions,
|
getQuestionsAllQueryOptions,
|
||||||
|
|
@ -59,10 +59,10 @@ export default function AssessmentPage() {
|
||||||
}>({});
|
}>({});
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const [selectedAspectId, setSelectedAspectId] = useState<string | null>(null);
|
|
||||||
const [selectedSubAspectId, setSelectedSubAspectId] = useState<string | null>(null);
|
const [selectedSubAspectId, setSelectedSubAspectId] = useState<string | null>(null);
|
||||||
const [assessmentId, setAssessmentId] = useState<string | null>(null);
|
const [assessmentId, setAssessmentId] = useState<string | null>(null);
|
||||||
const [answers, setAnswers] = useState<{ [key: string]: string }>({});
|
const [answers, setAnswers] = useState<{ [key: string]: string }>({});
|
||||||
|
const [validationInformation, setValidationInformation] = useState<{ [key: string]: string }>({});
|
||||||
|
|
||||||
// Fetch aspects and sub-aspects
|
// Fetch aspects and sub-aspects
|
||||||
const aspectsQuery = useQuery({
|
const aspectsQuery = useQuery({
|
||||||
|
|
@ -192,6 +192,47 @@ export default function AssessmentPage() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Mutation untuk mengirim data ke backend
|
||||||
|
const { mutate: submitValidation } = useMutation(submitValidationMutationOptions());
|
||||||
|
|
||||||
|
// Mengambil data dari localStorage saat komponen dimuat
|
||||||
|
useEffect(() => {
|
||||||
|
const storedValidationInfo = localStorage.getItem(`validationInfo_${assessmentId}`);
|
||||||
|
if (storedValidationInfo) {
|
||||||
|
try {
|
||||||
|
const parsedValidationInfo = JSON.parse(storedValidationInfo);
|
||||||
|
setValidationInformation(parsedValidationInfo);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error parsing validation information:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [assessmentId]);
|
||||||
|
|
||||||
|
// Handle perubahan di Textarea
|
||||||
|
const handleTextareaChange = (questionId: string, value: string) => {
|
||||||
|
setValidationInformation((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[questionId]: value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Update the localStorage with the new validation information as JSON
|
||||||
|
const updatedValidationInformation = {
|
||||||
|
...validationInformation,
|
||||||
|
[questionId]: value,
|
||||||
|
};
|
||||||
|
localStorage.setItem(`validationInfo_${assessmentId}`, JSON.stringify(updatedValidationInformation));
|
||||||
|
|
||||||
|
// Ensure assessmentId and questionId are not null before submitting
|
||||||
|
if (assessmentId && questionId) {
|
||||||
|
// Send the validation data to the server
|
||||||
|
submitValidation({
|
||||||
|
assessmentId,
|
||||||
|
questionId,
|
||||||
|
validationInformation: value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Drag and Drop handlers
|
// Drag and Drop handlers
|
||||||
const handleDragOver = (event: React.DragEvent<HTMLDivElement>) => {
|
const handleDragOver = (event: React.DragEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
@ -429,6 +470,8 @@ export default function AssessmentPage() {
|
||||||
|
|
||||||
<Textarea
|
<Textarea
|
||||||
placeholder="Berikan keterangan terkait jawaban di atas"
|
placeholder="Berikan keterangan terkait jawaban di atas"
|
||||||
|
value={validationInformation[question.questionId] || ""}
|
||||||
|
onChange={(event) => handleTextareaChange(question.questionId, event.currentTarget.value)}
|
||||||
disabled={!answers[question.questionId]}
|
disabled={!answers[question.questionId]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user