fix: organization form fields.

This commit is contained in:
a.bouhuolia
2021-09-09 21:04:52 +02:00
parent 7b968a43ef
commit 4b5aa3d898
3 changed files with 21 additions and 7 deletions

View File

@@ -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 }) {
</FastField>
{/* ---------- Base currency ---------- */}
<FastField name={'base_currency'}>
<FastField
name={'base_currency'}
baseCurrencyDisabled={baseCurrencyDisabled}
shouldUpdate={shouldBaseCurrencyUpdate}
>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'base_currency'} />}
@@ -115,7 +123,7 @@ export default function PreferencesGeneralForm({ isSubmitting }) {
<ListSelect
items={Currencies}
onItemSelect={(currency) => {
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}
/>
</FormGroup>
)}
@@ -141,9 +150,9 @@ export default function PreferencesGeneralForm({ isSubmitting }) {
>
<ListSelect
items={FiscalYear}
onItemSelect={({ value }) =>
form.setFieldValue('fiscal_year', value)
}
onItemSelect={(option) => {
form.setFieldValue('fiscal_year', option.key)
}}
selectedItem={value}
selectedItemProp={'key'}
defaultText={<T id={'select_fiscal_year'} />}

View File

@@ -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();
}
};

View File

@@ -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,
};