Merge branch 'master' of http://114.203.209.83:3000/SamProject/sam-react-prod
This commit is contained in:
@@ -113,8 +113,7 @@ function formatDepartmentName(name: string, depth: number): string {
|
||||
|
||||
interface EmployeeFormProps {
|
||||
mode: 'create' | 'edit' | 'view';
|
||||
employee?: Employee;
|
||||
onSave?: (data: EmployeeFormData) => void;
|
||||
employee?: Employee;onSave?: (data: EmployeeFormData) => Promise<{ success: boolean; error?: string }>;
|
||||
onEdit?: () => void;
|
||||
onDelete?: () => void;
|
||||
fieldSettings?: FieldSettings;
|
||||
@@ -428,8 +427,14 @@ export function EmployeeForm({
|
||||
|
||||
// onSave 호출 (페이지에서 처리)
|
||||
if (onSave) {
|
||||
onSave(formData);
|
||||
return { success: true };
|
||||
const result = await onSave(formData);
|
||||
if (result.success && mode === 'edit') {
|
||||
// 수정 모드: 저장 성공 시 view 모드로 전환 (리스트 이동 방지)
|
||||
toast.success('저장되었습니다.');
|
||||
router.push(`/${locale}/hr/employee-management/${employee?.id}?mode=view`);
|
||||
return { success: false, error: '' }; // navigateToList 방지 + 에러 메시지 숨김
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return { success: false, error: '저장 핸들러가 설정되지 않았습니다.' };
|
||||
@@ -571,13 +576,21 @@ export function EmployeeForm({
|
||||
value={formData.profileImage}
|
||||
onChange={async (file) => {
|
||||
// 미리보기 즉시 표시
|
||||
handleChange('profileImage', URL.createObjectURL(file));
|
||||
const previewUrl = URL.createObjectURL(file);
|
||||
handleChange('profileImage', previewUrl);
|
||||
// 서버에 업로드 (FormData로 감싸서 전송)
|
||||
const uploadFormData = new FormData();
|
||||
uploadFormData.append('file', file);
|
||||
const result = await uploadProfileImage(uploadFormData);
|
||||
if (result.success && result.data?.url) {
|
||||
// 업로드 성공 시 서버 URL로 업데이트
|
||||
URL.revokeObjectURL(previewUrl);
|
||||
handleChange('profileImage', result.data.url);
|
||||
} else {
|
||||
// 업로드 실패 시 미리보기 제거 및 에러 표시
|
||||
URL.revokeObjectURL(previewUrl);
|
||||
handleChange('profileImage', '');
|
||||
toast.error(result.error || '이미지 업로드에 실패했습니다.');
|
||||
}
|
||||
}}
|
||||
onRemove={() => handleChange('profileImage', '')}
|
||||
|
||||
@@ -514,11 +514,23 @@ export async function uploadProfileImage(inputFormData: FormData): Promise<{
|
||||
return { success: false, error: result.message || '파일 업로드에 실패했습니다.' };
|
||||
}
|
||||
|
||||
// 업로드된 파일 경로 추출 (API 응답: file_path 필드)
|
||||
const uploadedPath = result.data?.file_path || result.data?.path || result.data?.url;
|
||||
|
||||
if (!uploadedPath) {
|
||||
return { success: false, error: '업로드된 파일 경로를 가져올 수 없습니다.' };
|
||||
}
|
||||
|
||||
// /storage/tenants/ 경로로 변환 (tenant disk 파일 접근 경로)
|
||||
const storagePath = uploadedPath.startsWith('/storage/')
|
||||
? uploadedPath
|
||||
: `/storage/tenants/${uploadedPath}`;
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
url: result.data?.url || result.data?.path,
|
||||
path: result.data?.path,
|
||||
url: `${process.env.NEXT_PUBLIC_API_URL}${storagePath}`,
|
||||
path: uploadedPath,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@@ -61,6 +61,11 @@ export function extractRelativePath(path: string | null | undefined): string | n
|
||||
return null;
|
||||
}
|
||||
|
||||
// blob URL인 경우 (미리보기) - 저장하지 않음
|
||||
if (path.startsWith('blob:')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 전체 URL인 경우 상대 경로 추출
|
||||
if (path.startsWith('http://') || path.startsWith('https://')) {
|
||||
// /storage/tenants/ 이후의 경로 추출
|
||||
|
||||
@@ -1214,6 +1214,50 @@ export async function revertOrderConfirmation(orderId: string): Promise<{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수주 변환용 단일 견적 조회 (ID로 조회)
|
||||
* 견적 상세페이지에서 수주등록 버튼 클릭 시 사용
|
||||
*/
|
||||
export async function getQuoteByIdForSelect(id: string): Promise<{
|
||||
success: boolean;
|
||||
data?: QuotationForSelect;
|
||||
error?: string;
|
||||
__authError?: boolean;
|
||||
}> {
|
||||
try {
|
||||
const searchParams = new URLSearchParams();
|
||||
// 품목 포함
|
||||
searchParams.set('with_items', 'true');
|
||||
|
||||
const { response, error } = await serverFetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/quotes/${id}?${searchParams.toString()}`,
|
||||
{ method: 'GET', cache: 'no-store' }
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return { success: false, error: error.message, __authError: error.code === 'UNAUTHORIZED' };
|
||||
}
|
||||
|
||||
if (!response) {
|
||||
return { success: false, error: '견적 조회에 실패했습니다.' };
|
||||
}
|
||||
|
||||
const result: ApiResponse<ApiQuoteForSelect> = await response.json();
|
||||
|
||||
if (!response.ok || !result.success) {
|
||||
return { success: false, error: result.message || '견적 조회에 실패했습니다.' };
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: transformQuoteForSelect(result.data),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[getQuoteByIdForSelect] Error:', error);
|
||||
return { success: false, error: '서버 오류가 발생했습니다.' };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 수주 변환용 확정 견적 목록 조회
|
||||
* QuotationSelectDialog에서 사용
|
||||
|
||||
@@ -14,17 +14,20 @@ export {
|
||||
getOrderStats,
|
||||
revertProductionOrder,
|
||||
revertOrderConfirmation,
|
||||
getQuoteByIdForSelect,
|
||||
type Order,
|
||||
type OrderItem as OrderItemApi,
|
||||
type OrderFormData as OrderApiFormData,
|
||||
type OrderItemFormData,
|
||||
type OrderStats,
|
||||
type OrderStatus,
|
||||
type QuotationForSelect,
|
||||
type QuotationItem,
|
||||
} from "./actions";
|
||||
|
||||
// Components
|
||||
export { OrderRegistration, type OrderFormData } from "./OrderRegistration";
|
||||
export { QuotationSelectDialog, type QuotationForSelect, type QuotationItem } from "./QuotationSelectDialog";
|
||||
export { QuotationSelectDialog } from "./QuotationSelectDialog";
|
||||
export { ItemAddDialog, type OrderItem } from "./ItemAddDialog";
|
||||
|
||||
// 문서 컴포넌트
|
||||
|
||||
@@ -1161,7 +1161,10 @@ export async function getItemCategoryTree(): Promise<{
|
||||
}
|
||||
|
||||
if (!response || !response.ok) {
|
||||
return { success: false, data: [], error: '카테고리 조회 실패' };
|
||||
console.error('[getItemCategoryTree] response status:', response?.status, response?.statusText);
|
||||
const errorBody = response ? await response.text().catch(() => '') : '';
|
||||
console.error('[getItemCategoryTree] response body:', errorBody);
|
||||
return { success: false, data: [], error: `카테고리 조회 실패 (${response?.status || 'no response'})` };
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
@@ -257,7 +257,8 @@ function IntegratedDetailTemplateInner<T extends Record<string, unknown>>(
|
||||
if (result?.success) {
|
||||
toast.success(isCreateMode ? '등록되었습니다.' : '저장되었습니다.');
|
||||
navigateToList();
|
||||
} else {
|
||||
} else if (result?.error !== '') {
|
||||
// error가 빈 문자열이면 토스트 표시 안 함 (커스텀 네비게이션 처리용)
|
||||
toast.error(result?.error || '저장에 실패했습니다.');
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user