mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-06 13:35:03 +00:00
exchangeSettings.service/hook/card follow the backend's new shape: a single ExchangeSettings object becomes a list, get() becomes list(), and setFallbackRate(rate) becomes setFallbackRate(currency, rate). ExchangeRateSettingsCard now renders one row per currency instead of one hardcoded USD->ETB form. manualPaymentSettings.service/hook/card add djfEnabled alongside etb/usdEnabled, matching the backend's new column. InvoicesPage's collected-summary KPI strip adds a DJF tile and folds its ETB-equivalent into the existing 'Total collected' conversion, reading each currency's rate from the now-list-shaped settings query. Claude-Session: https://claude.ai/code/session_01CZy77vCWhka3pnmVF9NDkL
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
|
|
import { exchangeSettingsService } from "@/services/exchangeSettings.service";
|
|
import { useErrorHandler } from "@/shared/hooks/useErrorHandler";
|
|
|
|
const QUERY_KEY = ["exchangeSettings"];
|
|
|
|
/** One row per foreign currency (USD, DJF, …) — see `exchangeSettingsService.list`. */
|
|
export const useExchangeSettingsQuery = () =>
|
|
useQuery({
|
|
queryKey: QUERY_KEY,
|
|
queryFn: () => exchangeSettingsService.list(),
|
|
// Feed health is only interesting while it is being looked at.
|
|
staleTime: 30_000,
|
|
refetchOnWindowFocus: true,
|
|
});
|
|
|
|
export const useSetExchangeFallbackRate = () => {
|
|
const queryClient = useQueryClient();
|
|
const { t } = useTranslation();
|
|
const { handleError } = useErrorHandler(t);
|
|
|
|
return useMutation({
|
|
mutationFn: ({ currency, rate }: { currency: string; rate: number }) =>
|
|
exchangeSettingsService.setFallbackRate(currency, rate),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
|
toast.success(
|
|
t("exchangeSettings.updated", "Fallback exchange rate updated"),
|
|
);
|
|
},
|
|
onError: handleError,
|
|
});
|
|
};
|