fix: 품목기준관리 실시간 동기화 수정
- BOM 항목 추가/수정/삭제 시 섹션탭 즉시 반영 - 섹션 복제 시 UI 즉시 업데이트 (null vs undefined 이슈 해결) - 항목 수정 기능 추가 (useTemplateManagement) - 실시간 동기화 문서 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
77
src/components/items/ItemForm/context/ItemFormContext.tsx
Normal file
77
src/components/items/ItemForm/context/ItemFormContext.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* ItemFormContext - 품목 폼 상태 컨텍스트
|
||||
*
|
||||
* 하위 컴포넌트에서 공유되는 폼 상태 관리
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { createContext, useContext, ReactNode } from 'react';
|
||||
import type { UseFormReturn } from 'react-hook-form';
|
||||
import type { CreateItemFormData } from '@/lib/utils/validation';
|
||||
import type { ItemType } from '@/types/item';
|
||||
import type { UseItemFormStateReturn } from '../hooks/useItemFormState';
|
||||
import type { UseBOMManagementReturn } from '../hooks/useBOMManagement';
|
||||
import type { UseBendingDetailsReturn } from '../hooks/useBendingDetails';
|
||||
|
||||
export interface ItemFormContextType {
|
||||
// React Hook Form
|
||||
form: UseFormReturn<CreateItemFormData>;
|
||||
|
||||
// 모드
|
||||
mode: 'create' | 'edit';
|
||||
|
||||
// 품목 유형
|
||||
selectedItemType: ItemType | '';
|
||||
setSelectedItemType: (type: ItemType | '') => void;
|
||||
|
||||
// 부품 유형
|
||||
selectedPartType: string;
|
||||
setSelectedPartType: (type: string) => void;
|
||||
|
||||
// 상태 훅
|
||||
formState: UseItemFormStateReturn;
|
||||
bomManagement: UseBOMManagementReturn;
|
||||
bendingDetails: UseBendingDetailsReturn;
|
||||
|
||||
// 품목코드 생성
|
||||
generateItemCode: () => string;
|
||||
|
||||
// 품목 유형 변경 핸들러
|
||||
handleItemTypeChange: (type: ItemType) => void;
|
||||
|
||||
// 제출 상태
|
||||
isSubmitting: boolean;
|
||||
}
|
||||
|
||||
const ItemFormContext = createContext<ItemFormContextType | null>(null);
|
||||
|
||||
export interface ItemFormProviderProps {
|
||||
children: ReactNode;
|
||||
value: ItemFormContextType;
|
||||
}
|
||||
|
||||
export function ItemFormProvider({ children, value }: ItemFormProviderProps) {
|
||||
return (
|
||||
<ItemFormContext.Provider value={value}>
|
||||
{children}
|
||||
</ItemFormContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useItemFormContext(): ItemFormContextType {
|
||||
const context = useContext(ItemFormContext);
|
||||
if (!context) {
|
||||
throw new Error('useItemFormContext must be used within an ItemFormProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 선택적으로 컨텍스트 사용 (컨텍스트가 없어도 에러 안 남)
|
||||
*/
|
||||
export function useOptionalItemFormContext(): ItemFormContextType | null {
|
||||
return useContext(ItemFormContext);
|
||||
}
|
||||
|
||||
export default ItemFormContext;
|
||||
12
src/components/items/ItemForm/context/index.ts
Normal file
12
src/components/items/ItemForm/context/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 품목 폼 컨텍스트 export
|
||||
*/
|
||||
|
||||
export {
|
||||
ItemFormProvider,
|
||||
useItemFormContext,
|
||||
useOptionalItemFormContext,
|
||||
default as ItemFormContext,
|
||||
} from './ItemFormContext';
|
||||
|
||||
export type { ItemFormContextType, ItemFormProviderProps } from './ItemFormContext';
|
||||
Reference in New Issue
Block a user