mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-02 02:23:25 +00:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
|
|
import {
|
|
manualPaymentSettingsService,
|
|
type ManualPaymentSettings,
|
|
} from "@/services/manualPaymentSettings.service";
|
|
import { useErrorHandler } from "@/shared/hooks/useErrorHandler";
|
|
|
|
export const MANUAL_PAYMENT_SETTINGS_KEY = ["manualPaymentSettings"];
|
|
|
|
export const useManualPaymentSettingsQuery = () =>
|
|
useQuery({
|
|
queryKey: MANUAL_PAYMENT_SETTINGS_KEY,
|
|
queryFn: () => manualPaymentSettingsService.get(),
|
|
staleTime: 60_000,
|
|
});
|
|
|
|
export const useUpdateManualPaymentSettings = () => {
|
|
const queryClient = useQueryClient();
|
|
const { t } = useTranslation();
|
|
const { handleError } = useErrorHandler(t);
|
|
|
|
return useMutation({
|
|
mutationFn: (
|
|
patch: Partial<Pick<ManualPaymentSettings, "etbEnabled" | "usdEnabled">>,
|
|
) => manualPaymentSettingsService.update(patch),
|
|
onSuccess: (data) => {
|
|
queryClient.setQueryData(MANUAL_PAYMENT_SETTINGS_KEY, data);
|
|
// The Manual Payments worklist only lists enabled currencies.
|
|
queryClient.invalidateQueries({ queryKey: ["invoices"] });
|
|
toast.success(
|
|
t("manualPaymentSettings.updated", "Manual payment settings updated"),
|
|
);
|
|
},
|
|
onError: handleError,
|
|
});
|
|
};
|