251225:1703 On going update to 1.7.0: Refoctory drawing Module not finish
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { contractDrawingService } from '@/lib/services/contract-drawing.service';
|
||||
import { shopDrawingService } from '@/lib/services/shop-drawing.service';
|
||||
import { asBuiltDrawingService } from '@/lib/services/asbuilt-drawing.service'; // Added
|
||||
import { asBuiltDrawingService } from '@/lib/services/asbuilt-drawing.service';
|
||||
import { SearchContractDrawingDto, CreateContractDrawingDto } from '@/types/dto/drawing/contract-drawing.dto';
|
||||
import { SearchShopDrawingDto, CreateShopDrawingDto } from '@/types/dto/drawing/shop-drawing.dto';
|
||||
import { SearchAsBuiltDrawingDto, CreateAsBuiltDrawingDto } from '@/types/dto/drawing/asbuilt-drawing.dto'; // Added
|
||||
import { SearchAsBuiltDrawingDto, CreateAsBuiltDrawingDto } from '@/types/dto/drawing/asbuilt-drawing.dto';
|
||||
import { toast } from 'sonner';
|
||||
import { ContractDrawing, ShopDrawing, AsBuiltDrawing } from "@/types/drawing";
|
||||
|
||||
type DrawingType = 'CONTRACT' | 'SHOP' | 'AS_BUILT'; // Added AS_BUILT
|
||||
type DrawingType = 'CONTRACT' | 'SHOP' | 'AS_BUILT';
|
||||
type DrawingSearchParams = SearchContractDrawingDto | SearchShopDrawingDto | SearchAsBuiltDrawingDto;
|
||||
type CreateDrawingData = CreateContractDrawingDto | CreateShopDrawingDto | CreateAsBuiltDrawingDto;
|
||||
|
||||
@@ -25,13 +26,45 @@ export function useDrawings(type: DrawingType, params: DrawingSearchParams) {
|
||||
return useQuery({
|
||||
queryKey: drawingKeys.list(type, params),
|
||||
queryFn: async () => {
|
||||
let response;
|
||||
if (type === 'CONTRACT') {
|
||||
return contractDrawingService.getAll(params as SearchContractDrawingDto);
|
||||
response = await contractDrawingService.getAll(params as SearchContractDrawingDto);
|
||||
// Map ContractDrawing to Drawing
|
||||
if (response && response.data) {
|
||||
response.data = response.data.map((d: ContractDrawing) => ({
|
||||
...d,
|
||||
drawingId: d.id,
|
||||
drawingNumber: d.contractDrawingNo,
|
||||
type: 'CONTRACT',
|
||||
}));
|
||||
}
|
||||
} else if (type === 'SHOP') {
|
||||
return shopDrawingService.getAll(params as SearchShopDrawingDto);
|
||||
response = await shopDrawingService.getAll(params as SearchShopDrawingDto);
|
||||
// Map ShopDrawing to Drawing
|
||||
if (response && response.data) {
|
||||
response.data = response.data.map((d: ShopDrawing) => ({
|
||||
...d,
|
||||
drawingId: d.id,
|
||||
type: 'SHOP',
|
||||
title: d.currentRevision?.title || "Untitled",
|
||||
revision: d.currentRevision?.revisionNumber,
|
||||
legacyDrawingNumber: d.currentRevision?.legacyDrawingNumber,
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
return asBuiltDrawingService.getAll(params as SearchAsBuiltDrawingDto);
|
||||
response = await asBuiltDrawingService.getAll(params as SearchAsBuiltDrawingDto);
|
||||
// Map AsBuiltDrawing to Drawing
|
||||
if (response && response.data) {
|
||||
response.data = response.data.map((d: AsBuiltDrawing) => ({
|
||||
...d,
|
||||
drawingId: d.id,
|
||||
type: 'AS_BUILT',
|
||||
title: d.currentRevision?.title || "Untitled",
|
||||
revision: d.currentRevision?.revisionNumber,
|
||||
}));
|
||||
}
|
||||
}
|
||||
return response;
|
||||
},
|
||||
placeholderData: (previousData) => previousData,
|
||||
});
|
||||
@@ -69,7 +102,8 @@ export function useCreateDrawing(type: DrawingType) {
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success(`${type === 'CONTRACT' ? 'Contract' : 'Shop'} Drawing uploaded successfully`);
|
||||
const typeName = type === 'CONTRACT' ? 'Contract' : type === 'SHOP' ? 'Shop' : 'As Built';
|
||||
toast.success(`${typeName} Drawing uploaded successfully`);
|
||||
queryClient.invalidateQueries({ queryKey: drawingKeys.lists() });
|
||||
},
|
||||
onError: (error: Error & { response?: { data?: { message?: string } } }) => {
|
||||
@@ -79,5 +113,3 @@ export function useCreateDrawing(type: DrawingType) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// You can add useCreateShopDrawingRevision logic here if needed separate
|
||||
|
||||
Reference in New Issue
Block a user