Pull Request branch dev-clone to main #1
|
|
@ -25,9 +25,6 @@ import {
|
||||||
fetchSubAspects,
|
fetchSubAspects,
|
||||||
} from "../queries/questionQueries";
|
} from "../queries/questionQueries";
|
||||||
|
|
||||||
/**
|
|
||||||
* Change this
|
|
||||||
*/
|
|
||||||
const routeApi = getRouteApi("/_dashboardLayout/questions/");
|
const routeApi = getRouteApi("/_dashboardLayout/questions/");
|
||||||
|
|
||||||
interface Option {
|
interface Option {
|
||||||
|
|
@ -41,15 +38,15 @@ interface CreateQuestionPayload {
|
||||||
subAspectId: string;
|
subAspectId: string;
|
||||||
question: string;
|
question: string;
|
||||||
needFile: boolean;
|
needFile: boolean;
|
||||||
options: Option[]; // Array of options (text and score)
|
options: Option[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UpdateQuestionPayload {
|
interface UpdateQuestionPayload {
|
||||||
id: string; // The ID of the question to update
|
id: string;
|
||||||
subAspectId: string;
|
subAspectId: string;
|
||||||
question: string;
|
question: string;
|
||||||
needFile: boolean;
|
needFile: boolean;
|
||||||
options?: Option[]; // Optional array of options (text and score)
|
options?: Option[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function QuestionFormModal() {
|
export default function QuestionFormModal() {
|
||||||
|
|
@ -71,6 +68,15 @@ export default function QuestionFormModal() {
|
||||||
subAspectId: "",
|
subAspectId: "",
|
||||||
options: [] as { id: string; text: string; score: number; questionId: string }[],
|
options: [] as { id: string; text: string; score: number; questionId: string }[],
|
||||||
},
|
},
|
||||||
|
validate: {
|
||||||
|
aspectId: (value) => (value ? null : "Nama Aspek harus dipilih."),
|
||||||
|
subAspectId: (value) => (value ? null : "Nama Sub Aspek harus dipilih."),
|
||||||
|
question: (value) => (value ? null : "Pertanyaan tidak boleh kosong."),
|
||||||
|
options: {
|
||||||
|
text: (value) => (value ? null : "Jawaban tidak boleh kosong."),
|
||||||
|
score: (value) => (value >= 0 ? null : "Skor harus diisi dengan angka."),
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch aspects and sub-aspects
|
// Fetch aspects and sub-aspects
|
||||||
|
|
@ -148,7 +154,7 @@ export default function QuestionFormModal() {
|
||||||
needFile: values.needFile,
|
needFile: values.needFile,
|
||||||
subAspectId: values.subAspectId,
|
subAspectId: values.subAspectId,
|
||||||
options: values.options.map((option) => ({
|
options: values.options.map((option) => ({
|
||||||
questionId: values.id || "", // Ensure questionId is included
|
questionId: values.id || "",
|
||||||
text: option.text,
|
text: option.text,
|
||||||
score: option.score,
|
score: option.score,
|
||||||
})),
|
})),
|
||||||
|
|
@ -214,12 +220,14 @@ export default function QuestionFormModal() {
|
||||||
: {
|
: {
|
||||||
type: "select",
|
type: "select",
|
||||||
label: "Nama Aspek",
|
label: "Nama Aspek",
|
||||||
|
placeholder: "Pilih Aspek",
|
||||||
data: aspectsQuery.data?.map((aspect) => ({
|
data: aspectsQuery.data?.map((aspect) => ({
|
||||||
value: aspect.id,
|
value: aspect.id,
|
||||||
label: aspect.name,
|
label: aspect.name,
|
||||||
})) || [],
|
})) || [],
|
||||||
disabled: mutation.isPending,
|
disabled: mutation.isPending,
|
||||||
...form.getInputProps("aspectId"),
|
...form.getInputProps("aspectId"),
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
formType === "detail"
|
formType === "detail"
|
||||||
? {
|
? {
|
||||||
|
|
@ -231,16 +239,19 @@ export default function QuestionFormModal() {
|
||||||
: {
|
: {
|
||||||
type: "select",
|
type: "select",
|
||||||
label: "Nama Sub Aspek",
|
label: "Nama Sub Aspek",
|
||||||
|
placeholder: "Pilih Sub Aspek",
|
||||||
data: filteredSubAspects.map((subAspect) => ({
|
data: filteredSubAspects.map((subAspect) => ({
|
||||||
value: subAspect.id,
|
value: subAspect.id,
|
||||||
label: subAspect.name,
|
label: subAspect.name,
|
||||||
})),
|
})),
|
||||||
disabled: mutation.isPending,
|
disabled: mutation.isPending,
|
||||||
...form.getInputProps("subAspectId"),
|
...form.getInputProps("subAspectId"),
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "textarea",
|
type: "textarea",
|
||||||
label: "Pertanyaan",
|
label: "Pertanyaan",
|
||||||
|
placeholder: "Tulis Pertanyaan",
|
||||||
...form.getInputProps("question"),
|
...form.getInputProps("question"),
|
||||||
},
|
},
|
||||||
formType === "detail"
|
formType === "detail"
|
||||||
|
|
@ -251,10 +262,17 @@ export default function QuestionFormModal() {
|
||||||
value: form.values.needFile ? "Ya" : "Tidak",
|
value: form.values.needFile ? "Ya" : "Tidak",
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
type: "checkbox",
|
type: "select",
|
||||||
label: "Dibutuhkan Upload File?",
|
label: "Dibutuhkan Upload File?",
|
||||||
checked: form.values.needFile,
|
placeholder: "Pilih opsi",
|
||||||
...form.getInputProps("needFile"),
|
data: [
|
||||||
|
{ value: "true", label: "Ya" },
|
||||||
|
{ value: "false", label: "Tidak" },
|
||||||
|
],
|
||||||
|
value: form.values.needFile ? "true" : "false",
|
||||||
|
onChange: (value) => form.setFieldValue("needFile", value === "true"),
|
||||||
|
disabled: mutation.isPending,
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})}
|
})}
|
||||||
|
|
@ -274,6 +292,10 @@ export default function QuestionFormModal() {
|
||||||
label="Skor"
|
label="Skor"
|
||||||
placeholder="Skor"
|
placeholder="Skor"
|
||||||
readOnly={formType === "detail"}
|
readOnly={formType === "detail"}
|
||||||
|
min={0}
|
||||||
|
max={999}
|
||||||
|
allowDecimal={false}
|
||||||
|
allowNegative={false}
|
||||||
{...form.getInputProps(`options.${index}.score`)}
|
{...form.getInputProps(`options.${index}.score`)}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user