diff --git a/client/src/common/currencies.js b/client/src/common/currencies.js index c0c390bf2..8e9ffd911 100644 --- a/client/src/common/currencies.js +++ b/client/src/common/currencies.js @@ -1,5 +1,5 @@ export default [ - { label: 'US Dollar', code: 'USD' }, - { label: 'Euro', code: 'EUR' }, - { label: 'Libyan Dinar ', code: 'LYD' }, + { name: 'US Dollar', code: 'USD' }, + { name: 'Euro', code: 'EUR' }, + { name: 'Libyan Dinar ', code: 'LYD' }, ] \ No newline at end of file diff --git a/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryForm.js b/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryForm.js index bcb8981be..e406dc359 100644 --- a/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryForm.js +++ b/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryForm.js @@ -9,7 +9,7 @@ import { transformToForm } from 'utils'; import { CreateItemCategoryFormSchema, EditItemCategoryFormSchema, -} from './ItemCategoryForm.schema'; +} from './itemCategoryForm.schema'; import withDialogActions from 'containers/Dialog/withDialogActions'; import ItemCategoryFormContent from './ItemCategoryFormContent' diff --git a/client/src/containers/Preferences/General/General.js b/client/src/containers/Preferences/General/General.js index 7a5840fa4..666fc21bf 100644 --- a/client/src/containers/Preferences/General/General.js +++ b/client/src/containers/Preferences/General/General.js @@ -1,98 +1,15 @@ -import React, { useEffect } 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 React from 'react'; -import { compose, optionsMapToArray } from 'utils'; - -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'; +import GeneralFormPage from './GeneralFormPage'; +import { GeneralFormProvider } from './GeneralFormProvider'; /** * Preferences - General form. */ -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); - }); - }; - +export default function GeneralPreferences() { return ( -
-
- - - -
-
+ + + ); } - -export default compose( - withSettings(({ organizationSettings }) => ({ organizationSettings })), - withSettingsActions, - withDashboardActions, -)(GeneralPreferences); diff --git a/client/src/containers/Preferences/General/GeneralForm.js b/client/src/containers/Preferences/General/GeneralForm.js index 46a711c8a..f799ff848 100644 --- a/client/src/containers/Preferences/General/GeneralForm.js +++ b/client/src/containers/Preferences/General/GeneralForm.js @@ -36,215 +36,220 @@ export default function PreferencesGeneralForm({}) { return (
- - {({ field, meta: { error, touched } }) => ( - } - labelInfo={} - inline={true} - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--org-name'} - > - - - )} - - - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - inline={true} - intent={inputIntent({ error, touched })} - helperText={} - className={classNames('form-group--select-list', CLASSES.FILL)} - > - { - form.setFieldValue('financial_date_start', formattedDate); - })} - popoverProps={{ position: Position.BOTTOM, minimal: true }} - /> - - )} - - - - {({ field, meta: { error, touched } }) => ( - } - inline={true} - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--org-industry'} - > - - - )} - - - - {({ field: { value }, meta: { error, touched } }) => ( - } - className={classNames( - 'form-group--business-location', - CLASSES.FILL, - )} - inline={true} - helperText={} - intent={inputIntent({ error, touched })} - > - {}} - selectedItem={value} - selectedItemProp={'value'} - defaultText={} - textProp={'name'} - popoverProps={{ minimal: true }} - /> - - )} - - - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - className={classNames('form-group--base-currency', CLASSES.FILL)} - inline={true} - helperText={} - intent={inputIntent({ error, touched })} - > - { - form.setFieldValue('base_currency', currency.code); - }} - selectedItem={value} - selectedItemProp={'code'} - defaultText={} - textProp={'label'} - popoverProps={{ minimal: true }} - /> - - )} - - - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - className={classNames('form-group--fiscal-year', CLASSES.FILL)} - inline={true} - helperText={} - intent={inputIntent({ error, touched })} - > - } - selectedItem={value} - onItemSelect={(item) => {}} - popoverProps={{ minimal: true }} - /> - - )} - - - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - inline={true} - className={classNames('form-group--language', CLASSES.FILL)} - intent={inputIntent({ error, touched })} - helperText={} - > - } - selectedItem={value} - onItemSelect={(item) => {}} - popoverProps={{ minimal: true }} - /> - - )} - - - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - inline={true} - className={classNames( - 'form-group--time-zone', - CLASSES.FORM_GROUP_LIST_SELECT, - CLASSES.FILL, - )} - intent={inputIntent({ error, touched })} - helperText={} - > - { - form.setFieldValue('time_zone', timezone); - }} - valueDisplayFormat="composite" - placeholder={} - /> - - )} - - - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - inline={true} - className={classNames('form-group--date-format', CLASSES.FILL)} - intent={inputIntent({ error, touched })} - helperText={} - > - { - form.setFieldValue('date_format', dateFormat); - }} - selectedItem={value} - selectedItemProp={'value'} - defaultText={} - textProp={'name'} - popoverProps={{ minimal: true }} - /> - - )} - - -
- - -
-
+ + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + inline={true} + intent={inputIntent({ error, touched })} + helperText={} + className={classNames('form-group--select-list', CLASSES.FILL)} + > + { + form.setFieldValue('financial_date_start', formattedDate); + })} + popoverProps={{ position: Position.BOTTOM, minimal: true }} + /> + + )} + + + + {({ field, meta: { error, touched } }) => ( + } + inline={true} + intent={inputIntent({ error, touched })} + helperText={} + className={'form-group--org-industry'} + > + + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + className={classNames( + 'form-group--business-location', + CLASSES.FILL, + )} + inline={true} + helperText={} + intent={inputIntent({ error, touched })} + > + { + form.setFieldValue('location', value); + }} + selectedItem={value} + selectedItemProp={'value'} + defaultText={} + textProp={'name'} + popoverProps={{ minimal: true }} + /> + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + className={classNames('form-group--base-currency', CLASSES.FILL)} + inline={true} + helperText={} + intent={inputIntent({ error, touched })} + > + { + form.setFieldValue('base_currency', currency.code); + }} + selectedItem={value} + selectedItemProp={'code'} + defaultText={} + textProp={'name'} + labelProp={'code'} + popoverProps={{ minimal: true }} + /> + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + className={classNames('form-group--fiscal-year', CLASSES.FILL)} + inline={true} + helperText={} + intent={inputIntent({ error, touched })} + > + + form.setFieldValue('fiscal_year', value) + } + selectedItem={value} + selectedItemProp={'value'} + defaultText={} + textProp={'name'} + popoverProps={{ minimal: true }} + /> + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + inline={true} + className={classNames('form-group--language', CLASSES.FILL)} + intent={inputIntent({ error, touched })} + helperText={} + > + } + selectedItem={value} + onItemSelect={(item) => + form.setFieldValue('language', item.value) + } + popoverProps={{ minimal: true }} + /> + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + inline={true} + className={classNames( + 'form-group--time-zone', + CLASSES.FORM_GROUP_LIST_SELECT, + CLASSES.FILL, + )} + intent={inputIntent({ error, touched })} + helperText={} + > + { + form.setFieldValue('time_zone', timezone); + }} + valueDisplayFormat="composite" + placeholder={} + /> + + )} + + + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + labelInfo={} + inline={true} + className={classNames('form-group--date-format', CLASSES.FILL)} + intent={inputIntent({ error, touched })} + helperText={} + > + { + form.setFieldValue('date_format', dateFormat.value); + }} + selectedItem={value} + selectedItemProp={'value'} + defaultText={} + textProp={'name'} + labelProp={'label'} + popoverProps={{ minimal: true }} + /> + + )} + + +
+ + +
+ ); } diff --git a/client/src/containers/Preferences/General/GeneralFormPage.js b/client/src/containers/Preferences/General/GeneralFormPage.js new file mode 100644 index 000000000..34dcbe3d2 --- /dev/null +++ b/client/src/containers/Preferences/General/GeneralFormPage.js @@ -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 ( +
+
+ +
+
+ ); +} + +export default compose( + withSettings(({ organizationSettings }) => ({ organizationSettings })), + withDashboardActions, +)(GeneralFormPage); diff --git a/client/src/containers/Preferences/General/GeneralFormProvider.js b/client/src/containers/Preferences/General/GeneralFormProvider.js new file mode 100644 index 000000000..03b01c69d --- /dev/null +++ b/client/src/containers/Preferences/General/GeneralFormProvider.js @@ -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 ( + + + + ); +} + +const useGeneralFormContext = () => React.useContext(GeneralFormContext); + +export { GeneralFormProvider, useGeneralFormContext }; diff --git a/client/src/containers/Subscriptions/BillingPlansForm.js b/client/src/containers/Subscriptions/BillingPlansForm.js index 789bba008..ac9038c5e 100644 --- a/client/src/containers/Subscriptions/BillingPlansForm.js +++ b/client/src/containers/Subscriptions/BillingPlansForm.js @@ -5,7 +5,7 @@ import 'style/pages/Subscription/BillingPlans.scss' import BillingPlansInput from 'containers/Subscriptions/BillingPlansInput'; import BillingPeriodsInput from 'containers/Subscriptions/BillingPeriodsInput'; -import BillingPaymentMethod from 'containers/Subscriptions/BillingPaymentMethod'; +import BillingPaymentMethod from 'containers/Subscriptions/BillingPaymentmethod'; /** * Billing plans form.