This commit is contained in:
hagiye
2026-06-25 11:00:40 +03:00
parent 503878110f
commit f4a90755c2
42 changed files with 2100 additions and 98 deletions

View File

@@ -0,0 +1,76 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { interchangeDocumentsService } from '@/services/interchange-documents.service';
import type {
GenerateInterchangeDocumentPayload,
InterchangeDocumentFilter,
} from '@/types/interchangeDocument';
export const interchangeDocumentKeys = {
all: ['interchange-documents'] as const,
list: (filter?: InterchangeDocumentFilter) =>
['interchange-documents', 'list', filter ?? {}] as const,
detail: (id?: string) => ['interchange-documents', 'detail', id ?? ''] as const,
};
export function useInterchangeDocuments(filter?: InterchangeDocumentFilter, enabled = true) {
return useQuery({
queryKey: interchangeDocumentKeys.list(filter),
queryFn: () => interchangeDocumentsService.list(filter).then((r) => r.data),
enabled,
});
}
export function useInterchangeDocument(id?: string) {
return useQuery({
queryKey: interchangeDocumentKeys.detail(id),
queryFn: () => interchangeDocumentsService.getById(id as string).then((r) => r.data),
enabled: Boolean(id),
});
}
function useInterchangeInvalidation() {
const qc = useQueryClient();
return () => {
qc.invalidateQueries({ queryKey: interchangeDocumentKeys.all });
qc.invalidateQueries({ queryKey: ['warehouse-inventory', 'export-djibouti-arrival-queue'] });
};
}
export function useGenerateInterchangeDocument() {
const onSuccess = useInterchangeInvalidation();
return useMutation({
mutationFn: (payload: GenerateInterchangeDocumentPayload) =>
interchangeDocumentsService.generateFromSchedule(payload),
onSuccess,
});
}
export function useAcknowledgeInterchangeDocument() {
const onSuccess = useInterchangeInvalidation();
return useMutation({
mutationFn: (args: { id: string; acknowledgedBy: string; remarks?: string }) =>
interchangeDocumentsService.acknowledge(args.id, {
acknowledgedBy: args.acknowledgedBy,
remarks: args.remarks,
}),
onSuccess,
});
}
export function useDisputeInterchangeDocument() {
const onSuccess = useInterchangeInvalidation();
return useMutation({
mutationFn: (args: { id: string; remarks: string }) =>
interchangeDocumentsService.dispute(args.id, { remarks: args.remarks }),
onSuccess,
});
}
export function useCancelInterchangeDocument() {
const onSuccess = useInterchangeInvalidation();
return useMutation({
mutationFn: (id: string) => interchangeDocumentsService.cancel(id),
onSuccess,
});
}

View File

@@ -301,8 +301,18 @@ export function useExportDjiboutiTrainItems(scheduleId?: string) {
}
/** Unload eligible export items assigned to an arrived Djibouti-side train. */
export const useAutoUnloadExportAtDjibouti = () =>
useInventoryMutation((scheduleId: string) => warehouseService.autoUnloadExportAtDjibouti(scheduleId));
export const useAutoUnloadExportAtDjibouti = () => {
const qc = useQueryClient();
return useMutation({
mutationFn: (scheduleId: string) => warehouseService.autoUnloadExportAtDjibouti(scheduleId),
onSuccess: () => {
qc.invalidateQueries({ queryKey: ['warehouse-inventory'] });
qc.invalidateQueries({ queryKey: ['warehouse-loadings'] });
qc.invalidateQueries({ queryKey: warehouseKeys.all });
qc.invalidateQueries({ queryKey: ['interchange-documents'] });
},
});
};
/** IMPORT inventory in the Unloaded Queue (UNLOADED / destination inspection). Read-only. */
export function useImportUnloadedQueue(enabled = true) {
@@ -490,10 +500,10 @@ export const useUpdateFeeRule = () =>
export const useDeleteFeeRule = () =>
useRuleMutation((id: string) => warehouseService.deleteFeeRule(id), ['warehouse-fee-rules']);
export function useFeePreview(inventoryId?: string) {
export function useFeePreview(inventoryId?: string, billingCurrency: 'ETB' | 'USD' = 'USD') {
return useQuery({
queryKey: ['warehouse-inventory', inventoryId, 'fee-preview'],
queryFn: () => warehouseService.feePreview(inventoryId as string).then((r) => r.data),
queryKey: ['warehouse-inventory', inventoryId, 'fee-preview', billingCurrency],
queryFn: () => warehouseService.feePreview(inventoryId as string, billingCurrency).then((r) => r.data),
enabled: Boolean(inventoryId),
});
}
@@ -534,8 +544,15 @@ function useInvoiceInvalidation() {
export function useGenerateInvoice() {
const onSuccess = useInvoiceInvalidation();
return useMutation({
mutationFn: ({ inventoryId, confirmZero }: { inventoryId: string; confirmZero?: boolean }) =>
warehouseService.generateInvoice(inventoryId, confirmZero).then((r) => r.data),
mutationFn: ({
inventoryId,
confirmZero,
billingCurrency,
}: {
inventoryId: string;
confirmZero?: boolean;
billingCurrency?: 'ETB' | 'USD';
}) => warehouseService.generateInvoice(inventoryId, confirmZero, billingCurrency).then((r) => r.data),
onSuccess,
});
}