251211:1314 Frontend: reeactor Admin panel
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-11 13:14:15 +07:00
parent c8a0f281ef
commit 3fa28bd14f
79 changed files with 6571 additions and 206 deletions

View File

@@ -6,18 +6,20 @@ import { SearchShopDrawingDto, CreateShopDrawingDto } from '@/types/dto/drawing/
import { toast } from 'sonner';
type DrawingType = 'CONTRACT' | 'SHOP';
type DrawingSearchParams = SearchContractDrawingDto | SearchShopDrawingDto;
type CreateDrawingData = CreateContractDrawingDto | CreateShopDrawingDto;
export const drawingKeys = {
all: ['drawings'] as const,
lists: () => [...drawingKeys.all, 'list'] as const,
list: (type: DrawingType, params: any) => [...drawingKeys.lists(), type, params] as const,
list: (type: DrawingType, params: DrawingSearchParams) => [...drawingKeys.lists(), type, params] as const,
details: () => [...drawingKeys.all, 'detail'] as const,
detail: (type: DrawingType, id: number | string) => [...drawingKeys.details(), type, id] as const,
};
// --- Queries ---
export function useDrawings(type: DrawingType, params: any) {
export function useDrawings(type: DrawingType, params: DrawingSearchParams) {
return useQuery({
queryKey: drawingKeys.list(type, params),
queryFn: async () => {
@@ -51,7 +53,7 @@ export function useCreateDrawing(type: DrawingType) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (data: any) => {
mutationFn: async (data: CreateDrawingData) => {
if (type === 'CONTRACT') {
return contractDrawingService.create(data as CreateContractDrawingDto);
} else {
@@ -62,7 +64,7 @@ export function useCreateDrawing(type: DrawingType) {
toast.success(`${type === 'CONTRACT' ? 'Contract' : 'Shop'} Drawing uploaded successfully`);
queryClient.invalidateQueries({ queryKey: drawingKeys.lists() });
},
onError: (error: any) => {
onError: (error: Error & { response?: { data?: { message?: string } } }) => {
toast.error('Failed to upload drawing', {
description: error.response?.data?.message || 'Something went wrong',
});