first commit
This commit is contained in:
commit
c9fb67e751
423 files changed
+53287
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import axios from "axios";
|
||||
|
||||
export function useAudiencias(processoId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const addAudiencia = useMutation(
|
||||
async (data: any) => {
|
||||
if (!data.tipo || !data.data || !data.local) {
|
||||
throw new Error("Campos obrigatórios não preenchidos");
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`/api/processos/${processoId}/audiencias`,
|
||||
data,
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(["processo", processoId]);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const updateAudiencia = useMutation(
|
||||
async ({ id, data }: { id: string; data: any }) => {
|
||||
const response = await axios.put(
|
||||
`/api/processos/${processoId}/audiencias/${id}`,
|
||||
data,
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(["processo", processoId]);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const deleteAudiencia = useMutation(
|
||||
async (id: string) => {
|
||||
await axios.delete(`/api/processos/${processoId}/audiencias/${id}`);
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(["processo", processoId]);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
addAudiencia: addAudiencia.mutateAsync,
|
||||
updateAudiencia: updateAudiencia.mutateAsync,
|
||||
deleteAudiencia: deleteAudiencia.mutateAsync,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user