[st] feat: 검증 항목 등록 기능 추가
This commit is contained in:
@@ -108,6 +108,30 @@ function VerificationArticleManagement() {
|
||||
});
|
||||
}
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: (data: VerificationTargetManagementResponse) =>
|
||||
verificationTargetManagementApi.saveVerificationTargetManagement({
|
||||
vrfcMthdCd: data.vrfcMthdCd || activeTab,
|
||||
statsCd: data.statsCd,
|
||||
schmNm: data.schmNm,
|
||||
tblNm: data.tblNm,
|
||||
colNm: data.colNm,
|
||||
pkColNm: data.pkColNm,
|
||||
ipcrCntVl: data.ipcrCntVl,
|
||||
pctlCrtrVl: data.pctlCrtrVl,
|
||||
scopCntCntVl: data.scopCntCntVl,
|
||||
thrsCntVl: data.thrsCntVl,
|
||||
useYn: data.useYn,
|
||||
vrfcTrgtNm: data.vrfcTrgtNm,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [ENDPOINT.STATVERIFY_SERVICE.VRFCTGT_MNG],
|
||||
});
|
||||
setDialogOpen(false);
|
||||
},
|
||||
});
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: (data: VerificationTargetManagementResponse) =>
|
||||
verificationTargetManagementApi.updateVerificationTargetManagement(
|
||||
@@ -155,6 +179,11 @@ function VerificationArticleManagement() {
|
||||
setDialogOpen(true);
|
||||
}
|
||||
|
||||
function handleRegister() {
|
||||
setSelectedData(null);
|
||||
setDialogOpen(true);
|
||||
}
|
||||
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
handleSearch();
|
||||
@@ -162,7 +191,11 @@ function VerificationArticleManagement() {
|
||||
|
||||
async function handleSave(data: VerificationTargetManagementResponse) {
|
||||
if (await confirm("저장하시겠습니까?")) {
|
||||
updateMutation.mutate(data);
|
||||
if (data.vrfcTrgtSn) {
|
||||
updateMutation.mutate(data);
|
||||
} else {
|
||||
saveMutation.mutate(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +252,13 @@ function VerificationArticleManagement() {
|
||||
</div>
|
||||
|
||||
<div className="ml-auto flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
className="h-[3.6rem] w-[80px]"
|
||||
onClick={handleRegister}
|
||||
>
|
||||
등록
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
color="green"
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user