diff --git a/client/src/containers/Preferences/General/GeneralForm.js b/client/src/containers/Preferences/General/GeneralForm.js index 9e0ad0f49..2fc72621d 100644 --- a/client/src/containers/Preferences/General/GeneralForm.js +++ b/client/src/containers/Preferences/General/GeneralForm.js @@ -16,6 +16,8 @@ import { getFiscalYear } from 'common/fiscalYearOptions'; import { getLanguages } from 'common/languagesOptions'; import { useGeneralFormContext } from './GeneralFormProvider'; +import { shouldBaseCurrencyUpdate } from './utils'; + /** * Preferences general form. */ @@ -27,7 +29,9 @@ export default function PreferencesGeneralForm({ isSubmitting }) { const Languages = getLanguages(); const Currencies = getAllCurrenciesOptions(); - const { dateFormats } = useGeneralFormContext(); + const { dateFormats, baseCurrencyMutateAbility } = useGeneralFormContext(); + + const baseCurrencyDisabled = baseCurrencyMutateAbility.length > 0; // Handle close click. const handleCloseClick = () => { @@ -96,7 +100,11 @@ export default function PreferencesGeneralForm({ isSubmitting }) { {/* ---------- Base currency ---------- */} - + {({ form, field: { value }, meta: { error, touched } }) => ( } @@ -115,7 +123,7 @@ export default function PreferencesGeneralForm({ isSubmitting }) { { - form.setFieldValue('base_currency', currency.code); + form.setFieldValue('base_currency', currency.key); }} selectedItem={value} selectedItemProp={'key'} @@ -123,6 +131,7 @@ export default function PreferencesGeneralForm({ isSubmitting }) { textProp={'name'} labelProp={'key'} popoverProps={{ minimal: true }} + disabled={baseCurrencyDisabled} /> )} @@ -141,9 +150,9 @@ export default function PreferencesGeneralForm({ isSubmitting }) { > - form.setFieldValue('fiscal_year', value) - } + onItemSelect={(option) => { + form.setFieldValue('fiscal_year', option.key) + }} selectedItem={value} selectedItemProp={'key'} defaultText={} diff --git a/client/src/containers/Preferences/General/GeneralFormPage.js b/client/src/containers/Preferences/General/GeneralFormPage.js index da5125bef..ae0bdf605 100644 --- a/client/src/containers/Preferences/General/GeneralFormPage.js +++ b/client/src/containers/Preferences/General/GeneralFormPage.js @@ -53,7 +53,7 @@ function GeneralFormPage({ setSubmitting(false); // Reboot the application if the application's language is mutated. - if (organization.language !== values.language) { + if (organization.metadata?.language !== values.language) { window.location.reload(); } }; diff --git a/client/src/containers/Preferences/General/GeneralFormProvider.js b/client/src/containers/Preferences/General/GeneralFormProvider.js index d7ae3ce51..e51da73cd 100644 --- a/client/src/containers/Preferences/General/GeneralFormProvider.js +++ b/client/src/containers/Preferences/General/GeneralFormProvider.js @@ -5,6 +5,7 @@ import { useCurrentOrganization, useUpdateOrganization, useDateFormats, + useOrgBaseCurrencyMutateAbilities, } from 'hooks/query'; import PreferencesPageLoader from '../PreferencesPageLoader'; @@ -21,6 +22,9 @@ function GeneralFormProvider({ ...props }) { const { data: dateFormats, isLoading: isDateFormatsLoading } = useDateFormats(); + const { data: baseCurrencyMutateAbility } = + useOrgBaseCurrencyMutateAbilities(); + // Mutate organization information. const { mutateAsync: updateOrganization } = useUpdateOrganization(); @@ -29,6 +33,7 @@ function GeneralFormProvider({ ...props }) { isOrganizationLoading, isDateFormatsLoading, updateOrganization, + baseCurrencyMutateAbility, organization, dateFormats, };