mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 14:15:44 +00:00
59 lines
1.9 KiB
TypeScript
59 lines
1.9 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 PAYMENT_CURRENCIES_KEY = ["paymentCurrencies"];
|
|
|
|
/**
|
|
* Currencies a booking may be billed in right now. Open read, so forms can
|
|
* hide a switched-off currency without needing the settings permission.
|
|
*/
|
|
export const usePaymentCurrenciesQuery = () =>
|
|
useQuery({
|
|
queryKey: PAYMENT_CURRENCIES_KEY,
|
|
queryFn: () => manualPaymentSettingsService.currencies(),
|
|
staleTime: 60_000,
|
|
});
|
|
|
|
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" | "djfEnabled" | "djfPaymentsEnabled"
|
|
>
|
|
>,
|
|
) => manualPaymentSettingsService.update(patch),
|
|
onSuccess: (data) => {
|
|
queryClient.setQueryData(MANUAL_PAYMENT_SETTINGS_KEY, data);
|
|
// The Manual Payments worklist only lists enabled currencies, and the
|
|
// booking forms only offer currencies that are switched on.
|
|
queryClient.invalidateQueries({ queryKey: ["invoices"] });
|
|
queryClient.invalidateQueries({ queryKey: PAYMENT_CURRENCIES_KEY });
|
|
toast.success(
|
|
t("manualPaymentSettings.updated", "Manual payment settings updated"),
|
|
);
|
|
},
|
|
onError: handleError,
|
|
});
|
|
};
|