mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat: Login page localization.
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useMemo, useState } from 'react';
|
|||||||
import { Link, useHistory } from 'react-router-dom';
|
import { Link, useHistory } from 'react-router-dom';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import { useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
InputGroup,
|
InputGroup,
|
||||||
@@ -13,10 +13,15 @@ import {
|
|||||||
import Toaster from 'components/AppToaster';
|
import Toaster from 'components/AppToaster';
|
||||||
import ErrorMessage from 'components/ErrorMessage';
|
import ErrorMessage from 'components/ErrorMessage';
|
||||||
import AuthInsider from 'containers/Authentication/AuthInsider';
|
import AuthInsider from 'containers/Authentication/AuthInsider';
|
||||||
|
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
|
import { If } from 'components';
|
||||||
|
|
||||||
import withAuthenticationActions from './withAuthenticationActions';
|
import withAuthenticationActions from './withAuthenticationActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
|
||||||
const ERRORS_TYPES = {
|
const ERRORS_TYPES = {
|
||||||
INVALID_DETAILS: 'INVALID_DETAILS',
|
INVALID_DETAILS: 'INVALID_DETAILS',
|
||||||
USER_INACTIVE: 'USER_INACTIVE',
|
USER_INACTIVE: 'USER_INACTIVE',
|
||||||
@@ -24,7 +29,7 @@ const ERRORS_TYPES = {
|
|||||||
function Login({
|
function Login({
|
||||||
requestLogin,
|
requestLogin,
|
||||||
}) {
|
}) {
|
||||||
const intl = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [shown, setShown] = useState(false);
|
const [shown, setShown] = useState(false);
|
||||||
const passwordRevealer = () => { setShown(!shown); };
|
const passwordRevealer = () => { setShown(!shown); };
|
||||||
@@ -32,10 +37,10 @@ function Login({
|
|||||||
// Validation schema.
|
// Validation schema.
|
||||||
const loginValidationSchema = Yup.object().shape({
|
const loginValidationSchema = Yup.object().shape({
|
||||||
crediential: Yup.string()
|
crediential: Yup.string()
|
||||||
.required(intl.formatMessage({ id: 'required' }))
|
.required(formatMessage({ id: 'required' }))
|
||||||
.email(intl.formatMessage({ id: 'invalid_email_or_phone_numner' })),
|
.email(formatMessage({ id: 'invalid_email_or_phone_numner' })),
|
||||||
password: Yup.string()
|
password: Yup.string()
|
||||||
.required(intl.formatMessage({ id: 'required' }))
|
.required(formatMessage({ id: 'required' }))
|
||||||
.min(4),
|
.min(4),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,14 +69,13 @@ function Login({
|
|||||||
const toastBuilders = [];
|
const toastBuilders = [];
|
||||||
if (errors.find((e) => e.type === ERRORS_TYPES.INVALID_DETAILS)) {
|
if (errors.find((e) => e.type === ERRORS_TYPES.INVALID_DETAILS)) {
|
||||||
toastBuilders.push({
|
toastBuilders.push({
|
||||||
message: `The email and password you entered did not match our records.
|
message: formatMessage('email_and_password_entered_did_not_match'),
|
||||||
Please double-check and try again.`,
|
|
||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (errors.find((e) => e.type === ERRORS_TYPES.USER_INACTIVE)) {
|
if (errors.find((e) => e.type === ERRORS_TYPES.USER_INACTIVE)) {
|
||||||
toastBuilders.push({
|
toastBuilders.push({
|
||||||
message: intl.formatMessage({ id: 'the_user_has_been_suspended_from_admin' }),
|
message: formatMessage({ id: 'the_user_has_been_suspended_from_admin' }),
|
||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -85,25 +89,26 @@ function Login({
|
|||||||
|
|
||||||
const passwordRevealerTmp = useMemo(() => (
|
const passwordRevealerTmp = useMemo(() => (
|
||||||
<span class="password-revealer" onClick={() => passwordRevealer()}>
|
<span class="password-revealer" onClick={() => passwordRevealer()}>
|
||||||
{(shown) ? (
|
<If condition={shown}>
|
||||||
<><Icon icon='eye-slash' /> <span class="text">Hide</span></>
|
<><Icon icon='eye-slash' /> <span class="text"><T id={'hide'} /></span></>
|
||||||
) : (
|
</If>
|
||||||
<><Icon icon='eye' /> <span class="text">Show</span></>
|
<If condition={!shown}>
|
||||||
)}
|
<><Icon icon='eye' /> <span class="text"><T id={'show'} /></span></>
|
||||||
|
</If>
|
||||||
</span>), [shown, passwordRevealer]);
|
</span>), [shown, passwordRevealer]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthInsider>
|
<AuthInsider>
|
||||||
<div className='login-form'>
|
<div className='login-form'>
|
||||||
<div className={'authentication-page__label-section'}>
|
<div className={'authentication-page__label-section'}>
|
||||||
<h3>Log in</h3>
|
<h3><T id={'log_in'} /></h3>
|
||||||
Need a Bigcapital account ?
|
<T id={'need_bigcapital_account?'} />
|
||||||
<Link to='/auth/register'> Create an account</Link>
|
<Link to='/auth/register'> <T id={'create_an_account'} /></Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className={'authentication-page__form'}>
|
<form onSubmit={handleSubmit} className={'authentication-page__form'}>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={'Email or Phone Number'}
|
label={<T id={'email_or_phone_number'} />}
|
||||||
intent={(errors.crediential && touched.crediential) && Intent.DANGER}
|
intent={(errors.crediential && touched.crediential) && Intent.DANGER}
|
||||||
helperText={<ErrorMessage name={'crediential'} {...{errors, touched}} />}
|
helperText={<ErrorMessage name={'crediential'} {...{errors, touched}} />}
|
||||||
className={'form-group--crediential'}
|
className={'form-group--crediential'}
|
||||||
@@ -116,7 +121,7 @@ function Login({
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={'Password'}
|
label={<T id={'password'} />}
|
||||||
labelInfo={passwordRevealerTmp}
|
labelInfo={passwordRevealerTmp}
|
||||||
intent={(errors.password && touched.password) && Intent.DANGER}
|
intent={(errors.password && touched.password) && Intent.DANGER}
|
||||||
helperText={<ErrorMessage name={'password'} {...{errors, touched}} />}
|
helperText={<ErrorMessage name={'password'} {...{errors, touched}} />}
|
||||||
@@ -134,7 +139,7 @@ function Login({
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
large={true}
|
large={true}
|
||||||
className={'checkbox--remember-me'}>
|
className={'checkbox--remember-me'}>
|
||||||
Keep me logged in
|
<T id={'keep_me_logged_in'} />
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -146,13 +151,15 @@ function Login({
|
|||||||
lang={true}
|
lang={true}
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
>
|
>
|
||||||
{intl.formatMessage({ id: 'Log in' })}
|
<T id={'log_in'} />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="authentication-page__footer-links">
|
<div class="authentication-page__footer-links">
|
||||||
<Link to={'/auth/send_reset_password'}>Forget my password</Link>
|
<Link to={'/auth/send_reset_password'}>
|
||||||
|
<T id={'forget_my_password'} />
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AuthInsider>
|
</AuthInsider>
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ export default {
|
|||||||
'invalid_email_or_phone_numner': 'Invalid email or phone number.',
|
'invalid_email_or_phone_numner': 'Invalid email or phone number.',
|
||||||
'required': 'Required',
|
'required': 'Required',
|
||||||
'reset_password': 'Reset Password',
|
'reset_password': 'Reset Password',
|
||||||
'the_user_has_been_suspended_from_admin': 'The user has been suspended from the administrator',
|
'the_user_has_been_suspended_from_admin': 'The user has been suspended from the administrator.',
|
||||||
|
'email_and_password_entered_did_not_match': 'The email and password you entered did not match our records.',
|
||||||
'field_name_must_be_number': 'field_name_must_be_number',
|
'field_name_must_be_number': 'field_name_must_be_number',
|
||||||
'name': 'Name',
|
'name': 'Name',
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
@@ -19,4 +20,11 @@ export default {
|
|||||||
'to_date': 'To date',
|
'to_date': 'To date',
|
||||||
'accounting_basis': 'Accounting basis',
|
'accounting_basis': 'Accounting basis',
|
||||||
'report_date_range': 'Report date range',
|
'report_date_range': 'Report date range',
|
||||||
|
'log_in': 'Log in',
|
||||||
|
'forget_my_password': 'Forget my password',
|
||||||
|
'keep_me_logged_in': 'Keep me logged in',
|
||||||
|
'create_an_account': 'Create an account',
|
||||||
|
'need_bigcapital_account?': 'Need a Bigcapital account ?',
|
||||||
|
'show': 'Show',
|
||||||
|
'hide': 'Hide',
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user