mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
Fix: RegisterOrganization
This commit is contained in:
@@ -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 }) {
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className={'authentication-page__form'}>
|
||||
<FormGroup
|
||||
label={<T id={'organization_name'} />}
|
||||
className={'form-group--name'}
|
||||
intent={
|
||||
errors.organization_name &&
|
||||
touched.organization_name &&
|
||||
Intent.DANGER
|
||||
}
|
||||
helperText={
|
||||
<ErrorMessage
|
||||
{...{ errors, touched }}
|
||||
name={'organization_name'}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<InputGroup
|
||||
intent={
|
||||
errors.organization_name &&
|
||||
touched.organization_name &&
|
||||
Intent.DANGER
|
||||
}
|
||||
{...getFieldProps('organization_name')}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
|
||||
<Row className={'name-section'}>
|
||||
<Col md={6}>
|
||||
<FormGroup
|
||||
|
||||
@@ -61,11 +61,11 @@ function RegisterLeftSidebar() {
|
||||
</section>
|
||||
<section>
|
||||
<div className={'wizard-right-side'}>
|
||||
<RegisterWizardSteps />
|
||||
{/* <RegisterOrganizationForm /> */}
|
||||
{/* <RegisterWizardSteps /> */}
|
||||
{/* <Register /> */}
|
||||
{/* <Login/> */}
|
||||
<RegisterSubscriptionForm />
|
||||
<RegisterOrganizationForm />
|
||||
{/* <RegisterSubscriptionForm /> */}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -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() {
|
||||
<T id={'organization_details'} />
|
||||
</h3>
|
||||
|
||||
<FormGroup
|
||||
label={<T id={'name'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={'form-group--name'}
|
||||
intent={errors.name && touched.name && Intent.DANGER}
|
||||
helperText={<ErrorMessage {...{ errors, touched }} name={'name'} />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={errors.name && touched.name && Intent.DANGER}
|
||||
{...getFieldProps('name')}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
{/* financial starting date */}
|
||||
<FormGroup
|
||||
label={<T id={'financial_starting_date'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={errors.date_start && touched.date_start && Intent.DANGER}
|
||||
helperText={
|
||||
<ErrorMessage {...{ errors, touched }} name={'date_start'} />
|
||||
<ErrorMessage name="date_start" {...{ errors, touched }} />
|
||||
}
|
||||
className={classNames('form-group--select-list', Classes.FILL)}
|
||||
>
|
||||
<DateInput
|
||||
fill={true}
|
||||
{...momentFormatter('MMMM Do YYYY')}
|
||||
value={tansformDateValue(values.date_start)}
|
||||
onChange={handleDateChange('date_start')}
|
||||
onChange={handleDateChange}
|
||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||
/>
|
||||
</FormGroup>
|
||||
@@ -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={
|
||||
<ErrorMessage {...{ errors, touched }} name={'fiscal_year'} />
|
||||
<ErrorMessage name={'fiscal_year'} {...{ errors, touched }} />
|
||||
}
|
||||
>
|
||||
<ListSelect
|
||||
@@ -354,6 +400,7 @@ function RegisterOrganizationForm() {
|
||||
<div className={'register-org-button'}>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
type="submit"
|
||||
// loading={isSubmitting}
|
||||
>
|
||||
@@ -365,4 +412,7 @@ function RegisterOrganizationForm() {
|
||||
);
|
||||
}
|
||||
|
||||
export default RegisterOrganizationForm;
|
||||
export default compose(
|
||||
withSettingsActions,
|
||||
withRegisterOrganizationActions,
|
||||
)(RegisterOrganizationForm);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
buildTenant,
|
||||
seedTenant,
|
||||
} from 'store/organization/organization.actions';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
requestBuildTenant: (id, token) => dispatch(buildTenant({ id, token })),
|
||||
requestSeedTenant: (id, token) => dispatch(seedTenant({ id, token })),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
Reference in New Issue
Block a user