251209:1453 Frontend: progress nest = UAT & Bug Fixing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { masterDataService } from '@/lib/services/master-data.service';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export const masterDataKeys = {
|
||||
all: ['masterData'] as const,
|
||||
@@ -15,6 +16,54 @@ export function useOrganizations() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateOrganization() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: any) => masterDataService.createOrganization(data),
|
||||
onSuccess: () => {
|
||||
toast.success("Organization created successfully");
|
||||
queryClient.invalidateQueries({ queryKey: masterDataKeys.organizations() });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error("Failed to create organization", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateOrganization() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: any }) => masterDataService.updateOrganization(id, data),
|
||||
onSuccess: () => {
|
||||
toast.success("Organization updated successfully");
|
||||
queryClient.invalidateQueries({ queryKey: masterDataKeys.organizations() });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error("Failed to update organization", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteOrganization() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => masterDataService.deleteOrganization(id),
|
||||
onSuccess: () => {
|
||||
toast.success("Organization deleted successfully");
|
||||
queryClient.invalidateQueries({ queryKey: masterDataKeys.organizations() });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error("Failed to delete organization", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useDisciplines(contractId?: number) {
|
||||
return useQuery({
|
||||
queryKey: masterDataKeys.disciplines(contractId),
|
||||
|
||||
Reference in New Issue
Block a user