mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat(webapp): add default exchange rate value to 1 in cause the ex. rate service returned error or failed.
This commit is contained in:
@@ -98,24 +98,30 @@ interface UseSyncExRateToFormProps {
|
|||||||
*/
|
*/
|
||||||
export const useSyncExRateToForm = ({ onSynced }: UseSyncExRateToFormProps) => {
|
export const useSyncExRateToForm = ({ onSynced }: UseSyncExRateToFormProps) => {
|
||||||
const { setFieldValue, values } = useFormikContext();
|
const { setFieldValue, values } = useFormikContext();
|
||||||
const { autoExRateCurrency, autoExchangeRate } = useAutoExRateContext();
|
const { autoExRateCurrency, autoExchangeRate, isAutoExchangeRateLoading } =
|
||||||
|
useAutoExRateContext();
|
||||||
const updateEntriesOnExChange = useUpdateEntriesOnExchangeRateChange();
|
const updateEntriesOnExChange = useUpdateEntriesOnExchangeRateChange();
|
||||||
|
|
||||||
// Sync the fetched real-time exchanage rate to the form.
|
// Sync the fetched real-time exchanage rate to the form.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (autoExchangeRate?.exchange_rate && autoExRateCurrency) {
|
if (!isAutoExchangeRateLoading && autoExRateCurrency) {
|
||||||
setFieldValue('exchange_rate', autoExchangeRate?.exchange_rate + '');
|
// Sets a default ex. rate to 1 in case the exchange rate service wasn't configured.
|
||||||
|
// or returned an error from the server-side.
|
||||||
|
const exchangeRate = autoExchangeRate?.exchange_rate || 1;
|
||||||
|
|
||||||
|
setFieldValue('exchange_rate', exchangeRate + '');
|
||||||
setFieldValue(
|
setFieldValue(
|
||||||
'entries',
|
'entries',
|
||||||
updateEntriesOnExChange(
|
updateEntriesOnExChange(values.exchange_rate, exchangeRate),
|
||||||
values.exchange_rate,
|
|
||||||
autoExchangeRate?.exchange_rate,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
onSynced?.();
|
onSynced?.();
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [autoExchangeRate?.exchange_rate, autoExRateCurrency]);
|
}, [
|
||||||
|
autoExchangeRate?.exchange_rate,
|
||||||
|
autoExRateCurrency,
|
||||||
|
isAutoExchangeRateLoading,
|
||||||
|
]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user