From fe6fe48d7ed54cf903a2c20610c3c027fde9fb2d Mon Sep 17 00:00:00 2001 From: abiyasa05 Date: Fri, 1 Nov 2024 13:13:26 +0700 Subject: [PATCH] update: change form modal aspect using component dialog from shadcn --- .../modals/AspectFormModal.tsx | 199 ++++++++++-------- 1 file changed, 114 insertions(+), 85 deletions(-) diff --git a/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx b/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx index 101b17f..db4b420 100644 --- a/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx +++ b/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx @@ -1,9 +1,20 @@ -import { Button, Flex, Modal, ScrollArea, TextInput, Group, Text } from "@mantine/core"; +import { + AlertDialog, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from "@/shadcn/components/ui/alert-dialog"; +import { ScrollArea } from "@/shadcn/components/ui/scroll-area"; +import { Button } from "@/shadcn/components/ui/button"; +import { TextInput } from "@mantine/core"; +import { Label } from "@/shadcn/components/ui/label"; import { useForm } from "@mantine/form"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { getRouteApi } from "@tanstack/react-router"; import { createAspect, updateAspect, getAspectByIdQueryOptions } from "../queries/aspectQueries"; -import { TbDeviceFloppy } from "react-icons/tb"; import { useEffect, useState } from "react"; import { notifications } from "@mantine/notifications"; import FormResponseError from "@/errors/FormResponseError"; @@ -17,7 +28,7 @@ export default function AspectFormModal() { const navigate = routeApi.useNavigate(); const searchParams = routeApi.useSearch(); const dataId = searchParams.detail || searchParams.edit; - const isModalOpen = Boolean(dataId || searchParams.create); + const isDialogOpen = Boolean(dataId || searchParams.create); const formType = searchParams.detail ? "detail" : searchParams.edit ? "edit" : "create"; // Fetch aspect data if editing or viewing details @@ -93,7 +104,11 @@ export default function AspectFormModal() { const [isSubmitting, setIsSubmitting] = useState(false); - const handleSubmit = async (values: typeof form.values) => { + const handleSubmit = async (event: React.FormEvent) => { + event.preventDefault(); + + const values = form.values; + try { // Start submit process setIsSubmitting(true); @@ -165,89 +180,103 @@ export default function AspectFormModal() { }; return ( - navigate({ search: {} })} - title={modalTitle} - scrollAreaComponent={ScrollArea.Autosize} - size="md" - > -
- + !isOpen && navigate({ search: {} })}> + + + {modalTitle} + + {formType === "detail" ? "Detail dari aspek." : "Silakan isi data aspek di bawah ini."} + + - {form.values.subAspects.map((field, index) => ( - - { - const newSubAspects = [...form.values.subAspects]; - newSubAspects[index] = { ...newSubAspects[index], name: event.target.value }; - form.setValues({ subAspects: newSubAspects }); - }} - disabled={formType === "detail" || isSubmitting} - style={{ flex: 1 }} - /> - {formType === "detail" ? ( - Jumlah Soal: {field.questionCount} - ) : ( - - )} - - ))} + + +
+
+ + +
- {formType !== "detail" && ( - - )} + {form.values.subAspects.map((subAspect, index) => ( +
+
+ + { + if (formType !== "detail" && !mutation.isPending) { + const newSubAspects = [...form.values.subAspects]; + newSubAspects[index] = { ...newSubAspects[index], name: event.target.value }; + form.setValues({ subAspects: newSubAspects }); + } + }} + disabled={formType === "detail" || isSubmitting} + /> +
+ {formType === "detail" && ( +
+ + +
+ )} + {formType !== "detail" && ( + + )} +
+ ))} - {/* Buttons */} - - - {formType !== "detail" && ( - - )} - - - + {formType !== "detail" && ( + + )} +
+ + Tutup + {formType !== "detail" && ( + + )} + + +
+
+
); } \ No newline at end of file