From 5b95ea40471d27a544a5dde363b5574470aae1c0 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Mon, 12 Oct 2020 17:40:39 +0200 Subject: [PATCH] Fix : setupSubScription & BillingForm & setupOrganizationForm --- .../containers/Preferences/General/General.js | 76 ++++++++++++------- .../containers/Setup/SetupOrganizationForm.js | 21 ++--- .../containers/Setup/SetupSubscriptionForm.js | 52 ++++++++++--- .../containers/Subscriptions/BillingForm.js | 37 +-------- .../containers/Subscriptions/BillingTab.js | 1 - .../containers/Subscriptions/billingPlans.js | 2 +- client/src/lang/en/index.js | 2 +- client/src/store/billing/Billing.action.js | 2 +- 8 files changed, 101 insertions(+), 92 deletions(-) diff --git a/client/src/containers/Preferences/General/General.js b/client/src/containers/Preferences/General/General.js index e9aea064c..228fd90fe 100644 --- a/client/src/containers/Preferences/General/General.js +++ b/client/src/containers/Preferences/General/General.js @@ -40,7 +40,6 @@ function GeneralPreferences({ }) { const { formatMessage } = useIntl(); const [selectedItems, setSelectedItems] = useState({}); - const [timeZone, setTimeZone] = useState(''); const fetchHook = useQuery( ['settings'], @@ -65,67 +64,89 @@ function GeneralPreferences({ { id: 1, name: 'Libyan Dinar ', value: 'LYD' }, ]; - // @todo @mohamed - Translate the months. - // eg. > `${formatMessage({ id: 'january' })} - ${formatMessage({ id: 'december' })}` const fiscalYear = [ { id: 0, - name: `${formatMessage({ id: 'january' })} - ${formatMessage({ id: 'december' })}`, + name: `${formatMessage({ id: 'january' })} - ${formatMessage({ + id: 'december', + })}`, value: 'january', }, { id: 1, - name: `${formatMessage({ id: 'february' })} - ${formatMessage({ id: 'january' })}`, + name: `${formatMessage({ id: 'february' })} - ${formatMessage({ + id: 'january', + })}`, value: 'february', }, { id: 2, - name: `${formatMessage({ id: 'march' })} - ${formatMessage({ id: 'february' })}`, + name: `${formatMessage({ id: 'march' })} - ${formatMessage({ + id: 'february', + })}`, value: 'March', }, { id: 3, - name: `${formatMessage({ id: 'april' })} - ${formatMessage({ id: 'march' })}`, + name: `${formatMessage({ id: 'april' })} - ${formatMessage({ + id: 'march', + })}`, value: 'april', }, { id: 4, - name: `${formatMessage({ id: 'may' })} - ${formatMessage({ id: 'april' })}`, + name: `${formatMessage({ id: 'may' })} - ${formatMessage({ + id: 'april', + })}`, value: 'may', }, { id: 5, - name: `${formatMessage({ id: 'june' })} - ${formatMessage({ id: 'may' })}`, + name: `${formatMessage({ id: 'june' })} - ${formatMessage({ + id: 'may', + })}`, value: 'june', }, { id: 6, - name: `${formatMessage({ id: 'july' })} - ${formatMessage({ id: 'june' })}`, + name: `${formatMessage({ id: 'july' })} - ${formatMessage({ + id: 'june', + })}`, value: 'july', }, { id: 7, - name: `${formatMessage({ id: 'august' })} - ${formatMessage({ id: 'july' })}`, + name: `${formatMessage({ id: 'august' })} - ${formatMessage({ + id: 'july', + })}`, value: 'August', }, { id: 8, - name: `${formatMessage({ id: 'september' })} - ${formatMessage({ id: 'august' })}`, + name: `${formatMessage({ id: 'september' })} - ${formatMessage({ + id: 'august', + })}`, value: 'september', }, { id: 9, - name: `${formatMessage({ id: 'october' })} - ${formatMessage({ id: 'november' })}`, + name: `${formatMessage({ id: 'october' })} - ${formatMessage({ + id: 'november', + })}`, value: 'october', }, { id: 10, - name: `${formatMessage({ id: 'november' })} - ${formatMessage({ id: 'october' })}`, + name: `${formatMessage({ id: 'november' })} - ${formatMessage({ + id: 'october', + })}`, value: 'november', }, { id: 11, - name: `${formatMessage({ id: 'december' })} - ${formatMessage({ id: 'november' })}`, + name: `${formatMessage({ id: 'december' })} - ${formatMessage({ + id: 'november', + })}`, value: 'december', }, ]; @@ -185,9 +206,9 @@ function GeneralPreferences({ language: Yup.string() .required() .label(formatMessage({ id: 'language' })), - // time_zone: Yup.string() - // .required() - // .label(formatMessage({ id: 'time_zone' })), + time_zone: Yup.string() + .required() + .label(formatMessage({ id: 'time_zone_' })), date_format: Yup.string() .required() .label(formatMessage({ id: 'date_format_' })), @@ -230,15 +251,8 @@ function GeneralPreferences({ }, }); - // @todo @mohamed remove duplicate functions. - - const onItemRenderer = (item, { handleClick }) => ( - + ); const currencyItem = (item, { handleClick }) => ( @@ -280,8 +294,12 @@ function GeneralPreferences({ } }; - const handleTimezoneChange = (timezone) => setTimeZone(timezone); - + const handleTimezoneChange = useCallback( + (timezone) => { + setFieldValue('time_zone', timezone); + }, + [setFieldValue], + ); return (
} diff --git a/client/src/containers/Setup/SetupOrganizationForm.js b/client/src/containers/Setup/SetupOrganizationForm.js index 23ba2d122..596d9b037 100644 --- a/client/src/containers/Setup/SetupOrganizationForm.js +++ b/client/src/containers/Setup/SetupOrganizationForm.js @@ -26,10 +26,7 @@ import withOrganizationActions from 'containers/Organization/withOrganizationAct import { compose, optionsMapToArray } from 'utils'; -function SetupOrganizationForm({ - requestSubmitOptions, - requestSeedTenant -}) { +function SetupOrganizationForm({ requestSubmitOptions, requestSeedTenant }) { const { formatMessage } = useIntl(); const [selected, setSelected] = useState(); const history = useHistory(); @@ -180,11 +177,10 @@ function SetupOrganizationForm({ const options = optionsMapToArray(values).map((option) => { return { key: option.key, ...option, group: 'organization' }; }); + console.log(options, 'Op'); requestSubmitOptions({ options }) .then((response) => { - requestSeedTenant().then(() => { - setSubmitting(false); - }); + setSubmitting(false); }) .catch((erros) => { setSubmitting(false); @@ -306,8 +302,7 @@ function SetupOrganizationForm({ itemPredicate={filterItems} selectedItem={values.base_currency} selectedItemProp={'value'} - // defaultText={} - defaultText={'LYD - Libyan Dinar'} + defaultText={} labelProp={'name'} /> @@ -337,8 +332,7 @@ function SetupOrganizationForm({ itemPredicate={filterItems} selectedItem={values.language} selectedItemProp={'value'} - defaultText={'English'} - // defaultText={} + defaultText={} labelProp={'name'} /> @@ -367,8 +361,7 @@ function SetupOrganizationForm({ itemPredicate={filterItems} selectedItem={values.fiscal_year} selectedItemProp={'value'} - defaultText={'January - December'} - // defaultText={} + defaultText={} labelProp={'name'} /> @@ -407,7 +400,7 @@ function SetupOrganizationForm({ intent={Intent.PRIMARY} loading={isSubmitting} type="submit" - // loading={isSubmitting} + loading={isSubmitting} > diff --git a/client/src/containers/Setup/SetupSubscriptionForm.js b/client/src/containers/Setup/SetupSubscriptionForm.js index 5ae1e9684..1bea9dd5b 100644 --- a/client/src/containers/Setup/SetupSubscriptionForm.js +++ b/client/src/containers/Setup/SetupSubscriptionForm.js @@ -1,33 +1,61 @@ import React, { useMemo } from 'react'; import * as Yup from 'yup'; import { useFormik } from 'formik'; -import { FormattedMessage as T } from 'react-intl'; +import { FormattedMessage as T, useIntl } from 'react-intl'; import { Button, Intent } from '@blueprintjs/core'; -import BillingTab from 'containers/Subscriptions/BillingTab'; +import BillingPlans from 'containers/Subscriptions/billingPlans'; +import BillingPeriods from 'containers/Subscriptions/billingPeriods'; +import { BillingPaymentmethod } from 'containers/Subscriptions/billingPaymentmethod'; + +import withBillingActions from 'containers/Subscriptions/withBillingActions'; +import { compose } from 'utils'; /** * Subscription step of wizard setup. */ -export default function SetupSubscriptionForm({ - +function SetupSubscriptionForm({ + //#withBillingActions + requestSubmitBilling, }) { - const ValidationSchema = Yup.object().shape({}); + const { formatMessage } = useIntl(); - const initialValues = useMemo(() => ({}), []); + const validationSchema = Yup.object().shape({ + plan_slug: Yup.string() + .required() + .label(formatMessage({ id: 'plan_slug' })), + license_code: Yup.string().trim(), + }); + + const initialValues = useMemo( + () => ({ + plan_slug: '', + license_code: '', + }), + [], + ); const formik = useFormik({ enableReinitialize: true, - validationSchema: ValidationSchema, + validationSchema: validationSchema, initialValues: { ...initialValues, }, - onSubmit: (values, { setSubmitting, setErrors }) => {}, + onSubmit: (values, { setSubmitting, setErrors }) => { + requestSubmitBilling(values) + .then((response) => { + setSubmitting(false); + }) + .catch((errors) => { + setSubmitting(false); + }); + }, }); return (
-
- - + + + +