mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Merge remote-tracking branch 'origin/feature/react-query' into feature/react-query
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
export default [
|
export default [
|
||||||
{ label: 'US Dollar', code: 'USD' },
|
{ name: 'US Dollar', code: 'USD' },
|
||||||
{ label: 'Euro', code: 'EUR' },
|
{ name: 'Euro', code: 'EUR' },
|
||||||
{ label: 'Libyan Dinar ', code: 'LYD' },
|
{ name: 'Libyan Dinar ', code: 'LYD' },
|
||||||
]
|
]
|
||||||
@@ -9,7 +9,7 @@ import { transformToForm } from 'utils';
|
|||||||
import {
|
import {
|
||||||
CreateItemCategoryFormSchema,
|
CreateItemCategoryFormSchema,
|
||||||
EditItemCategoryFormSchema,
|
EditItemCategoryFormSchema,
|
||||||
} from './ItemCategoryForm.schema';
|
} from './itemCategoryForm.schema';
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import ItemCategoryFormContent from './ItemCategoryFormContent'
|
import ItemCategoryFormContent from './ItemCategoryFormContent'
|
||||||
|
|||||||
@@ -1,98 +1,15 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import { Formik } from 'formik';
|
|
||||||
import { mapKeys, snakeCase } from 'lodash';
|
|
||||||
import { Intent } from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
|
||||||
import { useQuery, queryCache } from 'react-query';
|
|
||||||
import { useIntl } from 'react-intl';
|
|
||||||
import { CLASSES } from 'common/classes';
|
|
||||||
|
|
||||||
import { compose, optionsMapToArray } from 'utils';
|
import GeneralFormPage from './GeneralFormPage';
|
||||||
|
import { GeneralFormProvider } from './GeneralFormProvider';
|
||||||
import { AppToaster, LoadingIndicator } from 'components';
|
|
||||||
import GeneralForm from './GeneralForm';
|
|
||||||
import { PreferencesGeneralSchema } from './General.schema';
|
|
||||||
|
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
|
||||||
import withSettings from 'containers/Settings/withSettings';
|
|
||||||
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
|
||||||
|
|
||||||
import 'style/pages/Preferences/GeneralForm.scss';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences - General form.
|
* Preferences - General form.
|
||||||
*/
|
*/
|
||||||
function GeneralPreferences({
|
export default function GeneralPreferences() {
|
||||||
// #withSettings
|
|
||||||
organizationSettings,
|
|
||||||
|
|
||||||
//# withDashboardActions
|
|
||||||
changePreferencesPageTitle,
|
|
||||||
|
|
||||||
// #withSettingsActions
|
|
||||||
requestSubmitOptions,
|
|
||||||
requestFetchOptions,
|
|
||||||
}) {
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
const fetchSettings = useQuery(['settings'], () => requestFetchOptions());
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
changePreferencesPageTitle(formatMessage({ id: 'general' }));
|
|
||||||
}, [changePreferencesPageTitle, formatMessage]);
|
|
||||||
|
|
||||||
function transformGeneralSettings(data) {
|
|
||||||
return mapKeys(data, (value, key) => snakeCase(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialValues = {
|
|
||||||
...transformGeneralSettings(organizationSettings),
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFormSubmit = (values, { setSubmitting, resetForm }) => {
|
|
||||||
const options = optionsMapToArray(values).map((option) => {
|
|
||||||
return { key: option.key, ...option, group: 'organization' };
|
|
||||||
});
|
|
||||||
requestSubmitOptions({ options })
|
|
||||||
.then((response) => {
|
|
||||||
AppToaster.show({
|
|
||||||
message: formatMessage({
|
|
||||||
id: 'the_options_has_been_created_successfully',
|
|
||||||
}),
|
|
||||||
intent: Intent.SUCCESS,
|
|
||||||
});
|
|
||||||
setSubmitting(false);
|
|
||||||
resetForm();
|
|
||||||
queryCache.invalidateQueries('settings');
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
setSubmitting(false);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<GeneralFormProvider>
|
||||||
className={classNames(
|
<GeneralFormPage />
|
||||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
</GeneralFormProvider>
|
||||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_GENERAL,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className={classNames(CLASSES.CARD)}>
|
|
||||||
<LoadingIndicator loading={fetchSettings.isFetching} spinnerSize={28}>
|
|
||||||
<Formik
|
|
||||||
initialValues={initialValues}
|
|
||||||
validationSchema={PreferencesGeneralSchema}
|
|
||||||
onSubmit={handleFormSubmit}
|
|
||||||
component={GeneralForm}
|
|
||||||
/>
|
|
||||||
</LoadingIndicator>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withSettings(({ organizationSettings }) => ({ organizationSettings })),
|
|
||||||
withSettingsActions,
|
|
||||||
withDashboardActions,
|
|
||||||
)(GeneralPreferences);
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
<FastField name={'location'}>
|
<FastField name={'location'}>
|
||||||
{({ field: { value }, meta: { error, touched } }) => (
|
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'business_location'} />}
|
label={<T id={'business_location'} />}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@@ -101,7 +101,9 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
>
|
>
|
||||||
<ListSelect
|
<ListSelect
|
||||||
items={countriesOptions}
|
items={countriesOptions}
|
||||||
onItemSelect={(item) => {}}
|
onItemSelect={({ value }) => {
|
||||||
|
form.setFieldValue('location', value);
|
||||||
|
}}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
selectedItemProp={'value'}
|
selectedItemProp={'value'}
|
||||||
defaultText={<T id={'select_business_location'} />}
|
defaultText={<T id={'select_business_location'} />}
|
||||||
@@ -130,7 +132,8 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
selectedItemProp={'code'}
|
selectedItemProp={'code'}
|
||||||
defaultText={<T id={'select_base_currency'} />}
|
defaultText={<T id={'select_base_currency'} />}
|
||||||
textProp={'label'}
|
textProp={'name'}
|
||||||
|
labelProp={'code'}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
@@ -149,11 +152,13 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
>
|
>
|
||||||
<ListSelect
|
<ListSelect
|
||||||
items={fiscalYearOptions}
|
items={fiscalYearOptions}
|
||||||
selectedItemProp={'value'}
|
onItemSelect={({ value }) =>
|
||||||
textProp={'name'}
|
form.setFieldValue('fiscal_year', value)
|
||||||
defaultText={<T id={'select_fiscal_year'} />}
|
}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
onItemSelect={(item) => {}}
|
selectedItemProp={'value'}
|
||||||
|
defaultText={<T id={'select_fiscal_year'} />}
|
||||||
|
textProp={'name'}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
@@ -176,7 +181,9 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
textProp={'name'}
|
textProp={'name'}
|
||||||
defaultText={<T id={'select_language'} />}
|
defaultText={<T id={'select_language'} />}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
onItemSelect={(item) => {}}
|
onItemSelect={(item) =>
|
||||||
|
form.setFieldValue('language', item.value)
|
||||||
|
}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
@@ -222,12 +229,13 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
<ListSelect
|
<ListSelect
|
||||||
items={dateFormatsOptions}
|
items={dateFormatsOptions}
|
||||||
onItemSelect={(dateFormat) => {
|
onItemSelect={(dateFormat) => {
|
||||||
form.setFieldValue('date_format', dateFormat);
|
form.setFieldValue('date_format', dateFormat.value);
|
||||||
}}
|
}}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
selectedItemProp={'value'}
|
selectedItemProp={'value'}
|
||||||
defaultText={<T id={'select_date_format'} />}
|
defaultText={<T id={'select_date_format'} />}
|
||||||
textProp={'name'}
|
textProp={'name'}
|
||||||
|
labelProp={'label'}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
@@ -235,10 +243,7 @@ export default function PreferencesGeneralForm({}) {
|
|||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
<div className={'card__footer'}>
|
<div className={'card__footer'}>
|
||||||
<Button
|
<Button intent={Intent.PRIMARY} type="submit">
|
||||||
intent={Intent.PRIMARY}
|
|
||||||
type="submit"
|
|
||||||
>
|
|
||||||
<T id={'save'} />
|
<T id={'save'} />
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleCloseClick}>
|
<Button onClick={handleCloseClick}>
|
||||||
|
|||||||
87
client/src/containers/Preferences/General/GeneralFormPage.js
Normal file
87
client/src/containers/Preferences/General/GeneralFormPage.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { Formik } from 'formik';
|
||||||
|
import { mapKeys, snakeCase } from 'lodash';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { useIntl } from 'react-intl';
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
import GeneralForm from './GeneralForm';
|
||||||
|
import { PreferencesGeneralSchema } from './General.schema';
|
||||||
|
import { useGeneralFormContext } from './GeneralFormProvider';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
|
||||||
|
import { compose, optionsMapToArray } from 'utils';
|
||||||
|
|
||||||
|
import 'style/pages/Preferences/GeneralForm.scss';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preferences - General form Page.
|
||||||
|
*/
|
||||||
|
function GeneralFormPage({
|
||||||
|
// #withSettings
|
||||||
|
organizationSettings,
|
||||||
|
|
||||||
|
//# withDashboardActions
|
||||||
|
changePreferencesPageTitle,
|
||||||
|
}) {
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
const { saveSettingMutate } = useGeneralFormContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changePreferencesPageTitle(formatMessage({ id: 'general' }));
|
||||||
|
}, [changePreferencesPageTitle, formatMessage]);
|
||||||
|
|
||||||
|
function transformGeneralSettings(data) {
|
||||||
|
return mapKeys(data, (value, key) => snakeCase(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
...transformGeneralSettings(organizationSettings),
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFormSubmit = (values, { setSubmitting, resetForm }) => {
|
||||||
|
const options = optionsMapToArray(values).map((option) => {
|
||||||
|
return { key: option.key, ...option, group: 'organization' };
|
||||||
|
});
|
||||||
|
const onSuccess = (response) => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_options_has_been_created_successfully',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
resetForm();
|
||||||
|
};
|
||||||
|
const onError = (errors) => {
|
||||||
|
setSubmitting(false);
|
||||||
|
};
|
||||||
|
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
||||||
|
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_GENERAL,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className={classNames(CLASSES.CARD)}>
|
||||||
|
<Formik
|
||||||
|
initialValues={initialValues}
|
||||||
|
validationSchema={PreferencesGeneralSchema}
|
||||||
|
onSubmit={handleFormSubmit}
|
||||||
|
component={GeneralForm}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withSettings(({ organizationSettings }) => ({ organizationSettings })),
|
||||||
|
withDashboardActions,
|
||||||
|
)(GeneralFormPage);
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React, { createContext } from 'react';
|
||||||
|
import { LoadingIndicator } from 'components';
|
||||||
|
import { useSaveSettings, useSettings } from 'hooks/query';
|
||||||
|
|
||||||
|
const GeneralFormContext = createContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General form provider.
|
||||||
|
*/
|
||||||
|
function GeneralFormProvider({ ...props }) {
|
||||||
|
//Fetches Organization Settings.
|
||||||
|
const { isFetching: isSettingsLoading } = useSettings();
|
||||||
|
|
||||||
|
// Save Organization Settings.
|
||||||
|
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||||
|
|
||||||
|
// Provider state.
|
||||||
|
const provider = {
|
||||||
|
isSettingsLoading,
|
||||||
|
saveSettingMutate,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LoadingIndicator loading={isSettingsLoading} spinnerSize={28}>
|
||||||
|
<GeneralFormContext.Provider value={provider} {...props} />
|
||||||
|
</LoadingIndicator>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const useGeneralFormContext = () => React.useContext(GeneralFormContext);
|
||||||
|
|
||||||
|
export { GeneralFormProvider, useGeneralFormContext };
|
||||||
@@ -5,7 +5,7 @@ import 'style/pages/Subscription/BillingPlans.scss'
|
|||||||
|
|
||||||
import BillingPlansInput from 'containers/Subscriptions/BillingPlansInput';
|
import BillingPlansInput from 'containers/Subscriptions/BillingPlansInput';
|
||||||
import BillingPeriodsInput from 'containers/Subscriptions/BillingPeriodsInput';
|
import BillingPeriodsInput from 'containers/Subscriptions/BillingPeriodsInput';
|
||||||
import BillingPaymentMethod from 'containers/Subscriptions/BillingPaymentMethod';
|
import BillingPaymentMethod from 'containers/Subscriptions/BillingPaymentmethod';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Billing plans form.
|
* Billing plans form.
|
||||||
|
|||||||
Reference in New Issue
Block a user