From 11df54d4ed5f09d97b47cff79b381dba3d56706d Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sat, 4 Sep 2021 18:49:01 +0200 Subject: [PATCH] BC-5 fix: general tab of preferences form submitting. --- .../components/Dashboard/DashboardTopbar.js | 7 -- client/src/components/Sidebar/SidebarHead.js | 16 ++-- client/src/containers/Homepage/Homepage.js | 23 ++++-- .../Organization/withCurrentOrganization.js | 8 +- .../Preferences/General/General.schema.js | 5 +- .../Preferences/General/GeneralForm.js | 80 ++++++------------- .../Preferences/General/GeneralFormPage.js | 47 ++++++----- .../General/GeneralFormProvider.js | 29 ++++--- .../Setup/SetupOrganization.schema.js | 2 +- .../containers/Setup/SetupOrganizationForm.js | 4 +- .../containers/Setup/SetupOrganizationPage.js | 2 +- client/src/hooks/query/index.js | 1 + client/src/hooks/query/misc.js | 16 ++++ client/src/hooks/query/organization.js | 19 +++++ client/src/lang/en/index.json | 3 +- .../authentication.selectors.js | 24 ++++++ .../organizations/organizations.reducers.js | 4 +- .../api/controllers/Miscellaneous/index.ts | 41 ++++++++++ server/src/api/controllers/Organization.ts | 4 +- server/src/api/index.ts | 3 + .../Miscellaneous/DateFormats/constants.ts | 11 +++ .../Miscellaneous/DateFormats/index.ts | 15 ++++ .../src/services/Miscellaneous/MiscService.ts | 8 ++ server/src/services/Organization/index.ts | 6 +- ...823235340_create_tenants_metadata_table.js | 4 +- 25 files changed, 251 insertions(+), 131 deletions(-) create mode 100644 client/src/hooks/query/misc.js create mode 100644 client/src/store/authentication/authentication.selectors.js create mode 100644 server/src/api/controllers/Miscellaneous/index.ts create mode 100644 server/src/services/Miscellaneous/DateFormats/constants.ts create mode 100644 server/src/services/Miscellaneous/DateFormats/index.ts create mode 100644 server/src/services/Miscellaneous/MiscService.ts diff --git a/client/src/components/Dashboard/DashboardTopbar.js b/client/src/components/Dashboard/DashboardTopbar.js index 2a4535e6a..075d2fe01 100644 --- a/client/src/components/Dashboard/DashboardTopbar.js +++ b/client/src/components/Dashboard/DashboardTopbar.js @@ -19,7 +19,6 @@ import { Icon, Hint, If } from 'components'; import withUniversalSearchActions from 'containers/UniversalSearch/withUniversalSearchActions'; import withDashboardActions from 'containers/Dashboard/withDashboardActions'; import withDashboard from 'containers/Dashboard/withDashboard'; -import withSettings from 'containers/Settings/withSettings'; import QuickNewDropdown from 'containers/QuickNewDropdown/QuickNewDropdown'; import { compose } from 'utils'; @@ -76,9 +75,6 @@ function DashboardTopbar({ // #withDashboard sidebarExpended, - // #withSettings - organizationName, - // #withGlobalSearch openGlobalSearch, @@ -190,9 +186,6 @@ export default compose( sidebarExpended, pageHint, })), - withSettings(({ organizationSettings }) => ({ - organizationName: organizationSettings.name, - })), withDashboardActions, withSubscriptions( ({ isSubscriptionActive, isSubscriptionInactive }) => ({ diff --git a/client/src/components/Sidebar/SidebarHead.js b/client/src/components/Sidebar/SidebarHead.js index 820deb7c9..3955c9c40 100644 --- a/client/src/components/Sidebar/SidebarHead.js +++ b/client/src/components/Sidebar/SidebarHead.js @@ -2,8 +2,8 @@ import React from 'react'; import { Button, Popover, Menu, Position } from '@blueprintjs/core'; import Icon from 'components/Icon'; import { useAuthUser } from 'hooks/state'; -import withSettings from 'containers/Settings/withSettings'; import { compose, firstLettersArgs } from 'utils'; +import withCurrentOrganization from '../../containers/Organization/withCurrentOrganization'; // Popover modifiers. const POPOVER_MODIFIERS = { @@ -14,8 +14,8 @@ const POPOVER_MODIFIERS = { * Sideabr head. */ function SidebarHead({ - // #withSettings - organizationName, + // #withCurrentOrganization + organization, }) { const user = useAuthUser(); @@ -29,9 +29,9 @@ function SidebarHead({
-
{organizationName}
+
{organization.name}
} @@ -42,7 +42,7 @@ function SidebarHead({ className="title" rightIcon={} > - {organizationName} + {organization.name} {user.full_name} @@ -61,7 +61,5 @@ function SidebarHead({ } export default compose( - withSettings(({ organizationSettings }) => ({ - organizationName: organizationSettings.name, - })), + withCurrentOrganization(({ organization }) => ({ organization })), )(SidebarHead); diff --git a/client/src/containers/Homepage/Homepage.js b/client/src/containers/Homepage/Homepage.js index 22e5d1990..ea1edef1a 100644 --- a/client/src/containers/Homepage/Homepage.js +++ b/client/src/containers/Homepage/Homepage.js @@ -2,14 +2,25 @@ import React, { useEffect } from 'react'; import DashboardInsider from 'components/Dashboard/DashboardInsider'; import HomepageContent from './HomepageContent'; + import withDashboardActions from 'containers/Dashboard/withDashboardActions'; -import withSettings from 'containers/Settings/withSettings'; +import withCurrentOrganization from '../Organization/withCurrentOrganization'; + import { compose } from 'utils'; -function DashboardHomepage({ changePageTitle, name }) { +/** + * Dashboard homepage. + */ +function DashboardHomepage({ + // #withDashboardActions + changePageTitle, + + // #withCurrentOrganization + organization, +}) { useEffect(() => { - changePageTitle(name); - }, [name, changePageTitle]); + changePageTitle(organization.name); + }, [organization.name, changePageTitle]); return ( @@ -20,7 +31,5 @@ function DashboardHomepage({ changePageTitle, name }) { export default compose( withDashboardActions, - withSettings(({ organizationSettings }) => ({ - name: organizationSettings.name, - })), + withCurrentOrganization(({ organization }) => ({ organization })), )(DashboardHomepage); diff --git a/client/src/containers/Organization/withCurrentOrganization.js b/client/src/containers/Organization/withCurrentOrganization.js index b1d1a391f..12b3ae31f 100644 --- a/client/src/containers/Organization/withCurrentOrganization.js +++ b/client/src/containers/Organization/withCurrentOrganization.js @@ -1,12 +1,16 @@ import { connect } from 'react-redux'; +import { getCurrentOrganizationFactory } from '../../store/authentication/authentication.selectors'; export default (mapState) => { + const getCurrentOrganization = getCurrentOrganizationFactory(); + const mapStateToProps = (state, props) => { const mapped = { organizationTenantId: state.authentication.organizationId, organizationId: state.authentication.organization, + organization: getCurrentOrganization(state, props), }; - return (mapState) ? mapState(mapped, state, props) : mapped; + return mapState ? mapState(mapped, state, props) : mapped; }; return connect(mapStateToProps); -}; \ No newline at end of file +}; diff --git a/client/src/containers/Preferences/General/General.schema.js b/client/src/containers/Preferences/General/General.schema.js index 6ac713d1b..f6647c471 100644 --- a/client/src/containers/Preferences/General/General.schema.js +++ b/client/src/containers/Preferences/General/General.schema.js @@ -5,9 +5,6 @@ const Schema = Yup.object().shape({ name: Yup.string() .required() .label(intl.get('organization_name_')), - financial_date_start: Yup.date() - .required() - .label(intl.get('date_start_')), industry: Yup.string() .nullable() .label(intl.get('organization_industry_')), @@ -23,7 +20,7 @@ const Schema = Yup.object().shape({ language: Yup.string() .required() .label(intl.get('language')), - time_zone: Yup.string() + timezone: Yup.string() .required() .label(intl.get('time_zone_')), date_format: Yup.string() diff --git a/client/src/containers/Preferences/General/GeneralForm.js b/client/src/containers/Preferences/General/GeneralForm.js index 6446ecacb..9e0ad0f49 100644 --- a/client/src/containers/Preferences/General/GeneralForm.js +++ b/client/src/containers/Preferences/General/GeneralForm.js @@ -1,42 +1,35 @@ import { Form } from 'formik'; import React from 'react'; -import { - Button, - FormGroup, - InputGroup, - Intent, - Position, -} from '@blueprintjs/core'; +import { Button, FormGroup, InputGroup, Intent } from '@blueprintjs/core'; import classNames from 'classnames'; import { TimezonePicker } from '@blueprintjs/timezone'; import { ErrorMessage, FastField } from 'formik'; -import { DateInput } from '@blueprintjs/datetime'; import { useHistory } from 'react-router-dom'; import { FormattedMessage as T } from 'components'; import { ListSelect, FieldRequiredHint } from 'components'; -import { - inputIntent, - momentFormatter, - tansformDateValue, - handleDateChange, -} from 'utils'; +import { inputIntent } from 'utils'; import { CLASSES } from 'common/classes'; import { getCountries } from 'common/countries'; -import { getCurrencies } from 'common/currencies'; +import { getAllCurrenciesOptions } from 'common/currencies'; import { getFiscalYear } from 'common/fiscalYearOptions'; import { getLanguages } from 'common/languagesOptions'; -import { getDateFormats } from 'common/dateFormatsOptions'; +import { useGeneralFormContext } from './GeneralFormProvider'; -export default function PreferencesGeneralForm({}) { +/** + * Preferences general form. + */ +export default function PreferencesGeneralForm({ isSubmitting }) { const history = useHistory(); const FiscalYear = getFiscalYear(); const Countries = getCountries(); const Languages = getLanguages(); - const Currencies = getCurrencies(); - const DataFormats = getDateFormats(); + const Currencies = getAllCurrenciesOptions(); + const { dateFormats } = useGeneralFormContext(); + + // Handle close click. const handleCloseClick = () => { history.go(-1); }; @@ -59,29 +52,7 @@ export default function PreferencesGeneralForm({}) { )} - {/* ---------- Financial starting date ---------- */} - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - labelInfo={} - inline={true} - intent={inputIntent({ error, touched })} - className={classNames('form-group--select-list', CLASSES.FILL)} - helperText={} - > - { - form.setFieldValue('financial_date_start', formattedDate); - })} - popoverProps={{ position: Position.BOTTOM, minimal: true }} - /> - - )} - - + {/* ---------- Industry ---------- */} {({ field, meta: { error, touched } }) => ( } textProp={'name'} - labelProp={'code'} + labelProp={'key'} popoverProps={{ minimal: true }} /> @@ -165,8 +136,8 @@ export default function PreferencesGeneralForm({}) { labelInfo={} className={classNames('form-group--fiscal-year', CLASSES.FILL)} inline={true} - helperText={} intent={inputIntent({ error, touched })} + helperText={} > } textProp={'name'} popoverProps={{ minimal: true }} @@ -210,7 +181,7 @@ export default function PreferencesGeneralForm({}) { {/* ---------- Time zone ---------- */} - + {({ form, field: { value }, meta: { error, touched } }) => ( } @@ -222,12 +193,12 @@ export default function PreferencesGeneralForm({}) { CLASSES.FILL, )} intent={inputIntent({ error, touched })} - helperText={} + helperText={} > { - form.setFieldValue('time_zone', timezone); + form.setFieldValue('timezone', timezone); }} valueDisplayFormat="composite" placeholder={} @@ -248,15 +219,14 @@ export default function PreferencesGeneralForm({}) { helperText={} > { - form.setFieldValue('date_format', dateFormat.value); + form.setFieldValue('date_format', dateFormat.key); }} selectedItem={value} - selectedItemProp={'value'} + selectedItemProp={'key'} defaultText={} - textProp={'name'} - labelProp={'label'} + textProp={'label'} popoverProps={{ minimal: true }} /> @@ -264,7 +234,7 @@ export default function PreferencesGeneralForm({}) {
-