feat: 422 ValidationException 에러 AlertDialog 팝업 추가
- ErrorAlertContext 생성 (전역 에러 알림 상태 관리) - useFieldManagement, useMasterFieldManagement, useTemplateManagement에 적용 - 중복 이름, 예약어 사용 시 디자인된 AlertDialog 팝업 표시 - toast 대신 모달 위에 표시되는 팝업으로 변경 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { useItemMaster } from '@/contexts/ItemMasterContext';
|
||||
import { useErrorAlert } from '../contexts';
|
||||
import type { ItemPage, SectionTemplate, TemplateField, BOMItem, ItemMasterField } from '@/contexts/ItemMasterContext';
|
||||
import { templateService } from '../services';
|
||||
import { ApiError } from '@/lib/api/error-handler';
|
||||
|
||||
export interface UseTemplateManagementReturn {
|
||||
// 섹션 템플릿 다이얼로그 상태
|
||||
@@ -112,6 +114,9 @@ export function useTemplateManagement(): UseTemplateManagementReturn {
|
||||
deleteBOMItem,
|
||||
} = useItemMaster();
|
||||
|
||||
// 에러 알림 (AlertDialog로 표시)
|
||||
const { showErrorAlert } = useErrorAlert();
|
||||
|
||||
// 섹션 템플릿 다이얼로그 상태
|
||||
const [isSectionTemplateDialogOpen, setIsSectionTemplateDialogOpen] = useState(false);
|
||||
const [editingSectionTemplateId, setEditingSectionTemplateId] = useState<number | null>(null);
|
||||
@@ -348,7 +353,23 @@ export function useTemplateManagement(): UseTemplateManagementReturn {
|
||||
resetTemplateFieldForm();
|
||||
} catch (error) {
|
||||
console.error('항목 처리 실패:', error);
|
||||
toast.error('항목 처리에 실패했습니다');
|
||||
|
||||
// 422 ValidationException 상세 메시지 처리 (field_key 중복/예약어, field_name 중복 등) → AlertDialog로 표시
|
||||
if (error instanceof ApiError) {
|
||||
console.log('🔍 ApiError.errors:', error.errors); // 디버깅용
|
||||
|
||||
// errors 객체에서 첫 번째 에러 메시지 추출
|
||||
if (error.errors && Object.keys(error.errors).length > 0) {
|
||||
const firstKey = Object.keys(error.errors)[0];
|
||||
const firstError = error.errors[firstKey];
|
||||
const errorMessage = Array.isArray(firstError) ? firstError[0] : firstError;
|
||||
showErrorAlert(errorMessage, '항목 저장 실패');
|
||||
} else {
|
||||
showErrorAlert(error.message, '항목 저장 실패');
|
||||
}
|
||||
} else {
|
||||
showErrorAlert('항목 처리에 실패했습니다', '오류');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user