From 4b76297a7b9f36fdbffe58b152e5ba418b0e6237 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 12 May 2025 11:32:59 +0000 Subject: (대표님) S-EDP 관련 components/form-data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/form-data/update-form-sheet.tsx | 82 ++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 16 deletions(-) (limited to 'components/form-data/update-form-sheet.tsx') diff --git a/components/form-data/update-form-sheet.tsx b/components/form-data/update-form-sheet.tsx index 27f426c1..6f2a4722 100644 --- a/components/form-data/update-form-sheet.tsx +++ b/components/form-data/update-form-sheet.tsx @@ -4,9 +4,9 @@ import * as React from "react"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; -import { Check, ChevronsUpDown, Loader } from "lucide-react"; +import { Check, ChevronsUpDown, Loader, LockIcon } from "lucide-react"; import { toast } from "sonner"; -import { useRouter } from "next/navigation"; // Add this import +import { useRouter } from "next/navigation"; import { Sheet, @@ -26,6 +26,7 @@ import { FormLabel, FormControl, FormMessage, + FormDescription, } from "@/components/ui/form"; import { Popover, @@ -68,7 +69,7 @@ export function UpdateTagSheet({ ...props }: UpdateTagSheetProps) { const [isPending, startTransition] = React.useTransition(); - const router = useRouter(); // Add router hook + const router = useRouter(); // 1) zod 스키마 const dynamicSchema = React.useMemo(() => { @@ -114,10 +115,19 @@ export function UpdateTagSheet({ async function onSubmit(values: Record) { startTransition(async () => { try { + // 제출 전에 읽기 전용 필드를 원본 값으로 복원 + const finalValues = { ...values }; + for (const col of columns) { + if (col.shi || col.key === "TAG_NO" || col.key === "TAG_DESC") { + // 읽기 전용 필드는 원본 값으로 복원 + finalValues[col.key] = rowData?.[col.key] ?? ""; + } + } + const { success, message } = await updateFormDataInDB( formCode, contractItemId, - values + finalValues ); if (!success) { @@ -131,7 +141,7 @@ export function UpdateTagSheet({ // Create a merged object of original rowData and new values const updatedData = { ...rowData, - ...values, + ...finalValues, TAG_NO: rowData?.TAG_NO, }; @@ -157,7 +167,7 @@ export function UpdateTagSheet({ Update Row - Modify the fields below and save changes + Modify the fields below and save changes. Fields with are read-only. @@ -169,8 +179,11 @@ export function UpdateTagSheet({
{columns.map((col) => { - const isTagNumberField = - col.key === "TAG_NO" || col.key === "TAG_DESC"; + // 읽기 전용 조건 업데이트: shi가 true이거나 TAG_NO/TAG_DESC인 경우 + const isReadOnly = col.shi === true || + col.key === "TAG_NO" || + col.key === "TAG_DESC"; + return ( - {col.displayLabel} + + {col.displayLabel || col.label} + {isReadOnly && ( + + )} + { const num = parseFloat(e.target.value); field.onChange(isNaN(num) ? "" : num); }} value={field.value ?? ""} + className={cn( + isReadOnly && "bg-gray-100 text-gray-600 cursor-not-allowed border-gray-300" + )} /> + {isReadOnly && col.shi && ( + + This field is read-only + + )} ); @@ -200,16 +226,22 @@ export function UpdateTagSheet({ case "LIST": return ( - {col.label} + + {col.label} + {isReadOnly && ( + + )} +