From 356929b399ef31a4de82906267df438cf29ea59d Mon Sep 17 00:00:00 2001 From: 0-Zz-ang Date: Thu, 10 Jul 2025 15:56:13 +0900 Subject: 인터페이스 관련 파일 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/integration/table/integration-edit-dialog.tsx | 274 ++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 lib/integration/table/integration-edit-dialog.tsx (limited to 'lib/integration/table/integration-edit-dialog.tsx') diff --git a/lib/integration/table/integration-edit-dialog.tsx b/lib/integration/table/integration-edit-dialog.tsx new file mode 100644 index 00000000..8ded0ee9 --- /dev/null +++ b/lib/integration/table/integration-edit-dialog.tsx @@ -0,0 +1,274 @@ +"use client"; + +import * as React from "react"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { Edit, Loader2 } from "lucide-react"; + +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Textarea } from "@/components/ui/textarea"; +import { updateIntegration } from "../service"; +import { toast } from "sonner"; +import type { Integration } from "../validations"; + +const updateIntegrationSchema = z.object({ + code: z.string().min(1, "코드는 필수입니다."), + name: z.string().min(1, "이름은 필수입니다."), + type: z.enum(["rest_api", "soap", "db_to_db"], { required_error: "타입은 필수입니다." }), + description: z.string().optional(), + sourceSystem: z.string().min(1, "소스 시스템은 필수입니다."), + targetSystem: z.string().min(1, "타겟 시스템은 필수입니다."), + status: z.enum(["active", "inactive", "deprecated"]), + metadata: z.any().optional(), +}); + +type UpdateIntegrationFormValues = z.infer; + +interface IntegrationEditDialogProps { + integration: Integration; + onSuccess?: () => void; +} + +export function IntegrationEditDialog({ integration, onSuccess }: IntegrationEditDialogProps) { + const [open, setOpen] = React.useState(false); + const [isLoading, setIsLoading] = React.useState(false); + + const form = useForm({ + resolver: zodResolver(updateIntegrationSchema), + defaultValues: { + code: integration.code || "", + name: integration.name || "", + type: integration.type || "rest_api", + description: integration.description || "", + sourceSystem: integration.sourceSystem || "", + targetSystem: integration.targetSystem || "", + status: integration.status || "active", + metadata: integration.metadata || {}, + }, + }); + + const handleOpenChange = (newOpen: boolean) => { + setOpen(newOpen); + if (!newOpen) { + form.reset(); + } + }; + + const handleCancel = () => { + form.reset(); + setOpen(false); + }; + + const onSubmit = async (data: UpdateIntegrationFormValues) => { + setIsLoading(true); + try { + const result = await updateIntegration(integration.id, data); + if (result.data) { + toast.success("인터페이스가 성공적으로 수정되었습니다."); + form.reset(); + setOpen(false); + if (onSuccess) { + onSuccess(); + } + } else { + toast.error(result.error || "수정 중 오류가 발생했습니다."); + } + } catch (error) { + console.error("인터페이스 수정 오류:", error); + toast.error("인터페이스 수정에 실패했습니다."); + } finally { + setIsLoading(false); + } + }; + + return ( + + + + + + + 인터페이스 수정 + + 인터페이스 정보를 수정합니다. 필수 정보를 입력해주세요. + * 표시된 항목은 필수 입력사항입니다. + + + +
+ + ( + + + 코드 * + + + + + + + )} + /> + + ( + + + 이름 * + + + + + + + )} + /> + + ( + + + 타입 * + + + + + )} + /> + + ( + + + 소스 시스템 * + + + + ㄹ + + + )} + /> + + ( + + + 타겟 시스템 * + + + + + + + )} + /> + + ( + + + 상태 * + + + + + )} + /> + + ( + + 설명 + +