[st] feat: 검증 항목 등록 기능 추가

This commit is contained in:
2026-03-12 16:56:39 +09:00
parent 7662e80eba
commit 5446a8a656
2 changed files with 115 additions and 41 deletions
@@ -1,5 +1,16 @@
"use client";
import { useEffect } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { CodeSelect } from "@/entities/code/ui/code-select";
import type { VerificationTargetManagementResponse } from "@/entities/statistics/model/verification-target-management-interface";
import {
type VerificationTargetManagementFormData,
verificationTargetManagementSchema,
} from "@/entities/statistics/model/verification-target-management-schema";
import {
Button,
Dialog,
@@ -14,15 +25,7 @@ import {
TableHead,
TableRow,
} from "@common/components";
import { CodeSelect } from "@/entities/code/ui/code-select";
import type { VerificationTargetManagementResponse } from "@/entities/statistics/model/verification-target-management-interface";
import {
verificationTargetManagementSchema,
type VerificationTargetManagementFormData,
} from "@/entities/statistics/model/verification-target-management-schema";
import { useEffect } from "react";
import { useForm, Controller } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import type { TabValue } from "./VerificationArticleManagement";
interface VerificationTargetDialogProps {
@@ -42,24 +45,41 @@ export function VerificationTargetDialog({
onSave,
onDelete,
}: VerificationTargetDialogProps) {
const {
control,
handleSubmit,
reset,
formState: { errors },
} = useForm<VerificationTargetManagementFormData>({
resolver: zodResolver(verificationTargetManagementSchema),
defaultValues: data || undefined,
});
const { control, handleSubmit, reset } =
useForm<VerificationTargetManagementFormData>({
resolver: zodResolver(verificationTargetManagementSchema),
defaultValues: data || {
vrfcMthdCd: tabValue,
statsCd: "",
vrfcTrgtNm: "",
schmNm: "",
tblNm: "",
colNm: "",
pkColNm: "",
useYn: "Y",
},
});
useEffect(() => {
if (data && open) reset(data);
}, [data, open, reset]);
if (open) {
reset(
data || {
vrfcMthdCd: tabValue,
statsCd: "",
vrfcTrgtNm: "",
schmNm: "",
tblNm: "",
colNm: "",
pkColNm: "",
useYn: "Y",
},
);
}
}, [data, open, reset, tabValue]);
function onSubmit(formData: VerificationTargetManagementFormData) {
if (!data) return;
onSave({
...data,
...(data || {}),
...formData,
} as VerificationTargetManagementResponse);
}
@@ -70,13 +90,13 @@ export function VerificationTargetDialog({
}
}
if (!data) return null;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-[800px]">
<DialogHeader>
<DialogTitle>검증 항목 상세</DialogTitle>
<DialogTitle>
{data ? "검증 항목 상세" : "검증 항목 등록"}
</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)}>
@@ -230,12 +250,15 @@ export function VerificationTargetDialog({
min="0"
max="1"
step="0.1"
value={field.value ?? ""}
value={
field.value ?? ""
}
onChange={(e) =>
field.onChange(
e.target.value
? Number(
e.target
e
.target
.value,
)
: null,
@@ -261,12 +284,15 @@ export function VerificationTargetDialog({
min="0"
max="0.5"
step="0.1"
value={field.value ?? ""}
value={
field.value ?? ""
}
onChange={(e) =>
field.onChange(
e.target.value
? Number(
e.target
e
.target
.value,
)
: null,
@@ -297,12 +323,15 @@ export function VerificationTargetDialog({
min="0"
max="1"
step="0.01"
value={field.value ?? ""}
value={
field.value ?? ""
}
onChange={(e) =>
field.onChange(
e.target.value
? Number(
e.target
e
.target
.value,
)
: null,
@@ -328,12 +357,15 @@ export function VerificationTargetDialog({
min="0"
max="100"
step="1"
value={field.value ?? ""}
value={
field.value ?? ""
}
onChange={(e) =>
field.onChange(
e.target.value
? Number(
e.target
e
.target
.value,
)
: null,
@@ -358,13 +390,15 @@ export function VerificationTargetDialog({
>
취소
</Button>
<Button
type="button"
color="red"
onClick={handleDelete}
>
삭제
</Button>
{data && (
<Button
type="button"
color="red"
onClick={handleDelete}
>
삭제
</Button>
)}
<Button type="submit" color="green">
저장
</Button>