diff --git a/client/src/containers/Authentication/Register.js b/client/src/containers/Authentication/Register.js index b35eb1bc0..2f15d64c7 100644 --- a/client/src/containers/Authentication/Register.js +++ b/client/src/containers/Authentication/Register.js @@ -22,7 +22,7 @@ import withAuthenticationActions from './withAuthenticationActions'; import { compose } from 'utils'; -function Register({ requestRegister }) { +function Register({ requestRegister, requestLogin }) { const { formatMessage } = useIntl(); const history = useHistory(); const [shown, setShown] = useState(false); @@ -31,9 +31,6 @@ function Register({ requestRegister }) { }, [shown]); const ValidationSchema = Yup.object().shape({ - organization_name: Yup.string() - .required() - .label(formatMessage({ id: 'organization_name_' })), first_name: Yup.string() .required() .label(formatMessage({ id: 'first_name_' })), @@ -56,7 +53,6 @@ function Register({ requestRegister }) { const initialValues = useMemo( () => ({ - organization_name: '', first_name: '', last_name: '', email: '', @@ -82,14 +78,28 @@ function Register({ requestRegister }) { onSubmit: (values, { setSubmitting, setErrors }) => { requestRegister(values) .then((response) => { - AppToaster.show({ - message: formatMessage({ - id: 'welcome_organization_account_has_been_created', - }), - intent: Intent.SUCCESS, - }); - setSubmitting(false); - history.push('/auth/login'); + // AppToaster.show({ + // message: formatMessage({ + // id: 'welcome_organization_account_has_been_created', + // }), + // intent: Intent.SUCCESS, + // }); + requestLogin({ + crediential: values.email, + password: values.password, + }) + .then(() => { + setSubmitting(false); + }) + .catch((errors) => { + AppToaster.show({ + message: formatMessage({ + id: 'something_wentwrong', + }), + intent: Intent.SUCCESS, + }); + }); + // history.push('/auth/login'); }) .catch((errors) => { if (errors.some((e) => e.type === 'PHONE_NUMBER_EXISTS')) { @@ -150,31 +160,7 @@ function Register({ requestRegister }) {
- } - className={'form-group--name'} - intent={ - errors.organization_name && - touched.organization_name && - Intent.DANGER - } - helperText={ - - } - > - - - +
- - {/* */} + {/* */} {/* */} {/* */} - + + {/* */}
diff --git a/client/src/containers/Authentication/RegisterOrganizationForm.js b/client/src/containers/Authentication/RegisterOrganizationForm.js index d23c684d7..b35ae69ee 100644 --- a/client/src/containers/Authentication/RegisterOrganizationForm.js +++ b/client/src/containers/Authentication/RegisterOrganizationForm.js @@ -6,6 +6,7 @@ import { Button, Intent, FormGroup, + InputGroup, MenuItem, Classes, Position, @@ -17,12 +18,16 @@ import { FormattedMessage as T, useIntl } from 'react-intl'; import { DateInput } from '@blueprintjs/datetime'; import { momentFormatter, tansformDateValue } from 'utils'; import AppToaster from 'components/AppToaster'; - import { ListSelect, ErrorMessage, FieldRequiredHint } from 'components'; +import { useHistory } from 'react-router-dom'; +import withSettingsActions from 'containers/Settings/withSettingsActions'; +import withRegisterOrganizationActions from './withRegisterOrganizationActions'; +import { compose, optionsMapToArray } from 'utils'; -function RegisterOrganizationForm() { +function RegisterOrganizationForm({ requestSubmitOptions, requestSeedTenant }) { const { formatMessage } = useIntl(); const [selected, setSelected] = useState(); + const history = useHistory(); const baseCurrency = [ { id: 0, name: 'LYD - Libyan Dinar', value: 'LYD' }, @@ -122,11 +127,15 @@ function RegisterOrganizationForm() { ]; const ValidationSchema = Yup.object().shape({ - date_start: Yup.date().required(), - // .label(formatMessage({id:''})) - base_currency: Yup.string().required( - formatMessage({ id: 'base_currency_' }), - ), + name: Yup.string() + .required() + .label(formatMessage({ id: 'organization_name_' })), + date_start: Yup.date() + .required() + .label(formatMessage({ id: 'date_start_' })), + base_currency: Yup.string() + .required() + .label(formatMessage({ id: 'base_currency_' })), language: Yup.string() .required() .label(formatMessage({ id: 'language' })), @@ -136,7 +145,17 @@ function RegisterOrganizationForm() { time_zone: Yup.string(), }); - const initialValues = useMemo(() => ({}), []); + const initialValues = useMemo( + () => ({ + name: '', + date_start: moment(new Date()).format('YYYY-MM-DD'), + base_currency: '', + language: '', + fiscal_year: '', + time_zone: '', + }), + [], + ); const { values, @@ -152,7 +171,20 @@ function RegisterOrganizationForm() { initialValues: { ...initialValues, }, - onSubmit: (values, { setSubmitting, setErrors }) => {}, + onSubmit: (values, { setSubmitting, setErrors }) => { + const options = optionsMapToArray(values).map((option) => { + return { key: option.key, ...option, group: 'organization' }; + }); + requestSubmitOptions({ options }) + .then((response) => { + requestSeedTenant().then(() => { + setSubmitting(false); + }); + }) + .catch((erros) => { + setSubmitting(false); + }); + }, }); const onItemsSelect = (filedName) => { @@ -188,9 +220,9 @@ function RegisterOrganizationForm() { ); const handleDateChange = useCallback( - (date_filed) => (date) => { + (date) => { const formatted = moment(date).format('YYYY-MM-DD'); - setFieldValue(date_filed, formatted); + setFieldValue('date_start', formatted); }, [setFieldValue], ); @@ -211,20 +243,33 @@ function RegisterOrganizationForm() { + } + labelInfo={} + className={'form-group--name'} + intent={errors.name && touched.name && Intent.DANGER} + helperText={} + > + + + {/* financial starting date */} } labelInfo={} intent={errors.date_start && touched.date_start && Intent.DANGER} helperText={ - + } + className={classNames('form-group--select-list', Classes.FILL)} > @@ -237,6 +282,7 @@ function RegisterOrganizationForm() { className={classNames( 'form-group--base-currency', 'form-group--select-list', + Classes.LOADING, Classes.FILL, )} intent={ @@ -304,7 +350,7 @@ function RegisterOrganizationForm() { )} intent={errors.fiscal_year && touched.fiscal_year && Intent.DANGER} helperText={ - + } >