refactor: VehicleDispatch actions 불필요 코드 제거
This commit is contained in:
@@ -22,93 +22,6 @@ interface PaginationMeta {
|
||||
total: number;
|
||||
}
|
||||
|
||||
// ===== 목데이터 (API 미응답 시 fallback) =====
|
||||
const MOCK_LIST: VehicleDispatchItem[] = [
|
||||
{
|
||||
id: 'mock-1',
|
||||
dispatchNo: 'DC-20260301-001',
|
||||
shipmentNo: 'SH-20260228-012',
|
||||
lotNo: 'LOT-260228-01',
|
||||
siteName: '삼성전자 평택캠퍼스',
|
||||
orderCustomer: '삼성전자(주)',
|
||||
logisticsCompany: '한진택배',
|
||||
tonnage: '5톤',
|
||||
supplyAmount: 350000,
|
||||
vat: 35000,
|
||||
totalAmount: 385000,
|
||||
freightCostType: 'prepaid',
|
||||
vehicleNo: '경기12가3456',
|
||||
driverContact: '010-1234-5678',
|
||||
writer: '홍길동',
|
||||
arrivalDateTime: '2026-03-05T09:00:00',
|
||||
status: 'draft',
|
||||
remarks: '오전 입차 요청',
|
||||
},
|
||||
{
|
||||
id: 'mock-2',
|
||||
dispatchNo: 'DC-20260301-002',
|
||||
shipmentNo: 'SH-20260227-008',
|
||||
lotNo: 'LOT-260227-03',
|
||||
siteName: 'LG디스플레이 파주공장',
|
||||
orderCustomer: 'LG디스플레이(주)',
|
||||
logisticsCompany: '대한통운',
|
||||
tonnage: '3.5톤',
|
||||
supplyAmount: 220000,
|
||||
vat: 22000,
|
||||
totalAmount: 242000,
|
||||
freightCostType: 'collect',
|
||||
vehicleNo: '서울34나7890',
|
||||
driverContact: '010-9876-5432',
|
||||
writer: '김철수',
|
||||
arrivalDateTime: '2026-03-04T14:30:00',
|
||||
status: 'completed',
|
||||
remarks: '',
|
||||
},
|
||||
];
|
||||
|
||||
const MOCK_DETAIL: Record<string, VehicleDispatchDetail> = {
|
||||
'mock-1': {
|
||||
id: 'mock-1',
|
||||
dispatchNo: 'DC-20260301-001',
|
||||
shipmentNo: 'SH-20260228-012',
|
||||
lotNo: 'LOT-260228-01',
|
||||
siteName: '삼성전자 평택캠퍼스',
|
||||
orderCustomer: '삼성전자(주)',
|
||||
freightCostType: 'prepaid',
|
||||
status: 'draft',
|
||||
writer: '홍길동',
|
||||
logisticsCompany: '한진택배',
|
||||
arrivalDateTime: '2026-03-05T09:00:00',
|
||||
tonnage: '5톤',
|
||||
vehicleNo: '경기12가3456',
|
||||
driverContact: '010-1234-5678',
|
||||
remarks: '오전 입차 요청',
|
||||
supplyAmount: 350000,
|
||||
vat: 35000,
|
||||
totalAmount: 385000,
|
||||
},
|
||||
'mock-2': {
|
||||
id: 'mock-2',
|
||||
dispatchNo: 'DC-20260301-002',
|
||||
shipmentNo: 'SH-20260227-008',
|
||||
lotNo: 'LOT-260227-03',
|
||||
siteName: 'LG디스플레이 파주공장',
|
||||
orderCustomer: 'LG디스플레이(주)',
|
||||
freightCostType: 'collect',
|
||||
status: 'completed',
|
||||
writer: '김철수',
|
||||
logisticsCompany: '대한통운',
|
||||
arrivalDateTime: '2026-03-04T14:30:00',
|
||||
tonnage: '3.5톤',
|
||||
vehicleNo: '서울34나7890',
|
||||
driverContact: '010-9876-5432',
|
||||
remarks: '',
|
||||
supplyAmount: 220000,
|
||||
vat: 22000,
|
||||
totalAmount: 242000,
|
||||
},
|
||||
};
|
||||
|
||||
// ===== API 응답 → 프론트 타입 변환 =====
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function transformToListItem(data: any): VehicleDispatchItem {
|
||||
@@ -176,7 +89,7 @@ export async function getVehicleDispatches(params?: {
|
||||
pagination: PaginationMeta;
|
||||
error?: string;
|
||||
}> {
|
||||
const result = await executePaginatedAction({
|
||||
return executePaginatedAction({
|
||||
url: buildApiUrl('/api/v1/vehicle-dispatches', {
|
||||
search: params?.search,
|
||||
status: params?.status !== 'all' ? params?.status : undefined,
|
||||
@@ -188,30 +101,6 @@ export async function getVehicleDispatches(params?: {
|
||||
transform: transformToListItem,
|
||||
errorMessage: '배차차량 목록 조회에 실패했습니다.',
|
||||
});
|
||||
|
||||
// API 데이터가 없으면 목데이터 합산
|
||||
if (result.success && result.data.length === 0) {
|
||||
let mockFiltered = [...MOCK_LIST];
|
||||
if (params?.status && params.status !== 'all') {
|
||||
mockFiltered = mockFiltered.filter((m) => m.status === params.status);
|
||||
}
|
||||
if (params?.search) {
|
||||
const q = params.search.toLowerCase();
|
||||
mockFiltered = mockFiltered.filter((m) =>
|
||||
m.dispatchNo.toLowerCase().includes(q) ||
|
||||
m.lotNo?.toLowerCase().includes(q) ||
|
||||
m.siteName.toLowerCase().includes(q) ||
|
||||
m.orderCustomer.toLowerCase().includes(q)
|
||||
);
|
||||
}
|
||||
return {
|
||||
...result,
|
||||
data: mockFiltered,
|
||||
pagination: { ...result.pagination, total: mockFiltered.length, lastPage: 1 },
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===== 배차차량 통계 조회 =====
|
||||
@@ -220,7 +109,7 @@ export async function getVehicleDispatchStats(): Promise<{
|
||||
data?: VehicleDispatchStats;
|
||||
error?: string;
|
||||
}> {
|
||||
const result = await executeServerAction<
|
||||
return executeServerAction<
|
||||
{ prepaid_amount: number; collect_amount: number; total_amount: number },
|
||||
VehicleDispatchStats
|
||||
>({
|
||||
@@ -232,15 +121,6 @@ export async function getVehicleDispatchStats(): Promise<{
|
||||
}),
|
||||
errorMessage: '배차차량 통계 조회에 실패했습니다.',
|
||||
});
|
||||
|
||||
// API 통계가 모두 0이면 목데이터 기반 통계
|
||||
if (result.success && result.data && result.data.totalAmount === 0) {
|
||||
const prepaid = MOCK_LIST.filter((m) => m.freightCostType === 'prepaid').reduce((s, m) => s + m.totalAmount, 0);
|
||||
const collect = MOCK_LIST.filter((m) => m.freightCostType === 'collect').reduce((s, m) => s + m.totalAmount, 0);
|
||||
return { ...result, data: { prepaidAmount: prepaid, collectAmount: collect, totalAmount: prepaid + collect } };
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===== 배차차량 상세 조회 =====
|
||||
@@ -249,11 +129,6 @@ export async function getVehicleDispatchById(id: string): Promise<{
|
||||
data?: VehicleDispatchDetail;
|
||||
error?: string;
|
||||
}> {
|
||||
// 목데이터 ID인 경우 바로 반환
|
||||
if (id.startsWith('mock-') && MOCK_DETAIL[id]) {
|
||||
return { success: true, data: MOCK_DETAIL[id] };
|
||||
}
|
||||
|
||||
return executeServerAction({
|
||||
url: buildApiUrl(`/api/v1/vehicle-dispatches/${id}`),
|
||||
transform: transformToDetail,
|
||||
|
||||
Reference in New Issue
Block a user