모달 무한 호출 해결
This commit is contained in:
parent
f3da984a18
commit
25d0376c1a
|
|
@ -11,7 +11,8 @@ import { Label } from "@/components/ui/label";
|
|||
import { Switch } from "@/components/ui/switch";
|
||||
import { LoadingSpinner } from "@/components/common/LoadingSpinner";
|
||||
import { ValidationMessage } from "@/components/common/ValidationMessage";
|
||||
import { useCategories, useCreateCategory, useUpdateCategory } from "@/hooks/queries/useCategories";
|
||||
import { useCreateCategory, useUpdateCategory } from "@/hooks/queries/useCategories";
|
||||
import type { CodeCategory } from "@/types/commonCode";
|
||||
import { useCheckCategoryDuplicate } from "@/hooks/queries/useValidation";
|
||||
import { useFormValidation } from "@/hooks/useFormValidation";
|
||||
import {
|
||||
|
|
@ -25,10 +26,15 @@ interface CodeCategoryFormModalProps {
|
|||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
editingCategoryCode?: string;
|
||||
categories: CodeCategory[];
|
||||
}
|
||||
|
||||
export function CodeCategoryFormModal({ isOpen, onClose, editingCategoryCode }: CodeCategoryFormModalProps) {
|
||||
const { data: categories = [] } = useCategories();
|
||||
export function CodeCategoryFormModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
editingCategoryCode,
|
||||
categories,
|
||||
}: CodeCategoryFormModalProps) {
|
||||
const createCategoryMutation = useCreateCategory();
|
||||
const updateCategoryMutation = useUpdateCategory();
|
||||
|
||||
|
|
@ -126,7 +132,7 @@ export function CodeCategoryFormModal({ isOpen, onClose, editingCategoryCode }:
|
|||
});
|
||||
}
|
||||
}
|
||||
}, [isOpen, isEditing, editingCategory, categories, createForm, updateForm]);
|
||||
}, [isOpen, isEditing, editingCategory, categories]);
|
||||
|
||||
const handleSubmit = isEditing
|
||||
? updateForm.handleSubmit(async (data) => {
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ export function CodeCategoryPanel({ selectedCategoryCode, onSelectCategory }: Co
|
|||
isOpen={showFormModal}
|
||||
onClose={() => setShowFormModal(false)}
|
||||
editingCategoryCode={editingCategory}
|
||||
categories={categories}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@ export function CodeDetailPanel({ categoryCode }: CodeDetailPanelProps) {
|
|||
}}
|
||||
categoryCode={categoryCode}
|
||||
editingCode={editingCode}
|
||||
codes={codes}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import { Switch } from "@/components/ui/switch";
|
|||
|
||||
import { LoadingSpinner } from "@/components/common/LoadingSpinner";
|
||||
import { ValidationMessage } from "@/components/common/ValidationMessage";
|
||||
import { useCodes, useCreateCode, useUpdateCode } from "@/hooks/queries/useCodes";
|
||||
import { useCreateCode, useUpdateCode } from "@/hooks/queries/useCodes";
|
||||
import { useCheckCodeDuplicate } from "@/hooks/queries/useValidation";
|
||||
import { createCodeSchema, updateCodeSchema, type CreateCodeData, type UpdateCodeData } from "@/lib/schemas/commonCode";
|
||||
import type { CodeInfo } from "@/types/commonCode";
|
||||
|
|
@ -23,6 +23,7 @@ interface CodeFormModalProps {
|
|||
onClose: () => void;
|
||||
categoryCode: string;
|
||||
editingCode?: CodeInfo | null;
|
||||
codes: CodeInfo[];
|
||||
}
|
||||
|
||||
// 에러 메시지를 안전하게 문자열로 변환하는 헬퍼 함수
|
||||
|
|
@ -32,8 +33,7 @@ const getErrorMessage = (error: FieldError | undefined): string => {
|
|||
return error.message || "";
|
||||
};
|
||||
|
||||
export function CodeFormModal({ isOpen, onClose, categoryCode, editingCode }: CodeFormModalProps) {
|
||||
const { data: codes = [] } = useCodes(categoryCode);
|
||||
export function CodeFormModal({ isOpen, onClose, categoryCode, editingCode, codes }: CodeFormModalProps) {
|
||||
const createCodeMutation = useCreateCode();
|
||||
const updateCodeMutation = useUpdateCode();
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ export function CodeFormModal({ isOpen, onClose, categoryCode, editingCode }: Co
|
|||
});
|
||||
}
|
||||
}
|
||||
}, [isOpen, isEditing, editingCode, codes, form]);
|
||||
}, [isOpen, isEditing, editingCode, codes]);
|
||||
|
||||
const handleSubmit = form.handleSubmit(async (data) => {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue