251210:1709 Frontend: reeactor organization and run build
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { masterDataService } from '@/lib/services/master-data.service';
|
||||
import { toast } from 'sonner';
|
||||
import {
|
||||
CreateOrganizationDto,
|
||||
UpdateOrganizationDto,
|
||||
SearchOrganizationDto,
|
||||
} from '@/types/dto/organization.dto';
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
export const masterDataKeys = {
|
||||
all: ['masterData'] as const,
|
||||
@@ -9,22 +15,22 @@ export const masterDataKeys = {
|
||||
disciplines: (contractId?: number) => [...masterDataKeys.all, 'disciplines', contractId] as const,
|
||||
};
|
||||
|
||||
export function useOrganizations() {
|
||||
export function useOrganizations(params?: SearchOrganizationDto) {
|
||||
return useQuery({
|
||||
queryKey: masterDataKeys.organizations(),
|
||||
queryFn: () => masterDataService.getOrganizations(),
|
||||
queryKey: [...masterDataKeys.organizations(), params],
|
||||
queryFn: () => masterDataService.getOrganizations(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateOrganization() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: any) => masterDataService.createOrganization(data),
|
||||
mutationFn: (data: CreateOrganizationDto) => masterDataService.createOrganization(data),
|
||||
onSuccess: () => {
|
||||
toast.success("Organization created successfully");
|
||||
queryClient.invalidateQueries({ queryKey: masterDataKeys.organizations() });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
onError: (error: AxiosError<{ message?: string }>) => {
|
||||
toast.error("Failed to create organization", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
@@ -35,12 +41,12 @@ export function useCreateOrganization() {
|
||||
export function useUpdateOrganization() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: any }) => masterDataService.updateOrganization(id, data),
|
||||
mutationFn: ({ id, data }: { id: number; data: UpdateOrganizationDto }) => masterDataService.updateOrganization(id, data),
|
||||
onSuccess: () => {
|
||||
toast.success("Organization updated successfully");
|
||||
queryClient.invalidateQueries({ queryKey: masterDataKeys.organizations() });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
onError: (error: AxiosError<{ message?: string }>) => {
|
||||
toast.error("Failed to update organization", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
@@ -56,7 +62,7 @@ export function useDeleteOrganization() {
|
||||
toast.success("Organization deleted successfully");
|
||||
queryClient.invalidateQueries({ queryKey: masterDataKeys.organizations() });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
onError: (error: AxiosError<{ message?: string }>) => {
|
||||
toast.error("Failed to delete organization", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user