251209:1453 Frontend: progress nest = UAT & Bug Fixing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { auditLogService } from '@/lib/services/audit-log.service';
|
||||
import { auditLogService, AuditLog } from '@/lib/services/audit-log.service';
|
||||
|
||||
export const auditLogKeys = {
|
||||
all: ['audit-logs'] as const,
|
||||
@@ -7,7 +7,7 @@ export const auditLogKeys = {
|
||||
};
|
||||
|
||||
export function useAuditLogs(params?: any) {
|
||||
return useQuery({
|
||||
return useQuery<AuditLog[]>({
|
||||
queryKey: auditLogKeys.list(params),
|
||||
queryFn: () => auditLogService.getLogs(params),
|
||||
});
|
||||
|
||||
@@ -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),
|
||||
|
||||
65
frontend/hooks/use-projects.ts
Normal file
65
frontend/hooks/use-projects.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { projectService } from '@/lib/services/project.service';
|
||||
import { CreateProjectDto, UpdateProjectDto, SearchProjectDto } from '@/types/dto/project/project.dto';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export const projectKeys = {
|
||||
all: ['projects'] as const,
|
||||
list: (params: SearchProjectDto) => [...projectKeys.all, 'list', params] as const,
|
||||
detail: (id: number) => [...projectKeys.all, 'detail', id] as const,
|
||||
};
|
||||
|
||||
export function useProjects(params?: SearchProjectDto) {
|
||||
return useQuery({
|
||||
queryKey: projectKeys.list(params || {}),
|
||||
queryFn: () => projectService.getAll(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateProject() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: CreateProjectDto) => projectService.create(data),
|
||||
onSuccess: () => {
|
||||
toast.success("Project created successfully");
|
||||
queryClient.invalidateQueries({ queryKey: projectKeys.all });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error("Failed to create project", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateProject() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: UpdateProjectDto }) => projectService.update(id, data),
|
||||
onSuccess: () => {
|
||||
toast.success("Project updated successfully");
|
||||
queryClient.invalidateQueries({ queryKey: projectKeys.all });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error("Failed to update project", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteProject() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => projectService.delete(id),
|
||||
onSuccess: () => {
|
||||
toast.success("Project deleted successfully");
|
||||
queryClient.invalidateQueries({ queryKey: projectKeys.all });
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error("Failed to delete project", {
|
||||
description: error.response?.data?.message || "Unknown error"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -16,6 +16,13 @@ export function useUsers(params?: SearchUserDto) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useRoles() {
|
||||
return useQuery({
|
||||
queryKey: ['roles'],
|
||||
queryFn: () => userService.getRoles(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateUser() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
Reference in New Issue
Block a user