Initial commit: Horux Despachos project
This commit is contained in:
42
apps/web/lib/hooks/use-tenants.ts
Normal file
42
apps/web/lib/hooks/use-tenants.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { getTenants, createTenant, updateTenant, deleteTenant, type CreateTenantData, type UpdateTenantData } from '@/lib/api/tenants';
|
||||
|
||||
export function useTenants() {
|
||||
return useQuery({
|
||||
queryKey: ['tenants'],
|
||||
queryFn: getTenants,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateTenant() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: CreateTenantData) => createTenant(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['tenants'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateTenant() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: UpdateTenantData }) => updateTenant(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['tenants'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteTenant() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => deleteTenant(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['tenants'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user