mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
|
|
import {
|
|
operationsStandardsService,
|
|
type OperationsStandardsPatch,
|
|
} from "@/services/operationsStandards.service";
|
|
import { useErrorHandler } from "@/shared/hooks/useErrorHandler";
|
|
|
|
const QUERY_KEY = ["operationsStandards"];
|
|
|
|
export const useOperationsStandardsQuery = () =>
|
|
useQuery({
|
|
queryKey: QUERY_KEY,
|
|
queryFn: () => operationsStandardsService.get(),
|
|
});
|
|
|
|
export const useUpdateOperationsStandards = () => {
|
|
const queryClient = useQueryClient();
|
|
const { t } = useTranslation();
|
|
const { handleError } = useErrorHandler(t);
|
|
|
|
return useMutation({
|
|
mutationFn: (patch: OperationsStandardsPatch) =>
|
|
operationsStandardsService.update(patch),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
|
toast.success(
|
|
t("operationsStandards.updated", "Operating standards updated"),
|
|
);
|
|
},
|
|
onError: handleError,
|
|
});
|
|
};
|