fix issues.

This commit is contained in:
Ahmed Bouhuolia
2020-05-02 17:54:26 +02:00
parent a35e6d5a9c
commit 7832789a03
4 changed files with 44 additions and 29 deletions

View File

@@ -7,10 +7,10 @@ export default function({ isAuthenticated =false, ...rest }) {
const to = {pathname: '/dashboard/homepage'};
return (
<BodyClassName className={'authentication'}>
<Route path="/auth">
{ (isAuthenticated) ?
(<Redirect to={to} />) : (
<Route path="/auth">
{ (isAuthenticated) ?
(<Redirect to={to} />) : (
<BodyClassName className={'authentication'}>
<Switch>
<div class="authentication-page">
<Link
@@ -30,9 +30,10 @@ export default function({ isAuthenticated =false, ...rest }) {
))}
</div>
</div>
</Switch>)
}
</Route>
</BodyClassName>
</Switch>
</BodyClassName>
)
}
</Route>
);
}

View File

@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import BodyClassName from 'react-body-classname';
import { Route, Redirect } from 'react-router-dom';
const propTypes = {
@@ -13,19 +14,21 @@ function PrivateRoute({
...rest
}) {
return (
<Route
{...rest}
path="/dashboard"
render={_props =>
isAuthenticated ? (<Component {..._props} />) :
(
<Redirect
to={{
pathname: '/auth/login',
}}
/>
)}
/>
<BodyClassName className={''}>
<Route
{...rest}
path="/dashboard"
render={_props =>
isAuthenticated ? (<Component {..._props} />) :
(
<Redirect
to={{
pathname: '/auth/login',
}}
/>
)}
/>
</BodyClassName>
);
}

View File

@@ -63,7 +63,7 @@ function Register({
...initialValues,
country: 'libya'
},
onSubmit: (values, { setSubmitting }) => {
onSubmit: (values, { setSubmitting, setErrors }) => {
requestRegister(values)
.then((response) => {
AppToaster.show({
@@ -72,7 +72,17 @@ function Register({
setSubmitting(false);
history.push('/auth/login');
})
.catch((error) => {
.catch((errors) => {
if (errors.some(e => e.type === 'PHONE_NUMBER_EXISTS')) {
setErrors({
phone_number: 'The phone number is already used in another account.'
});
}
if (errors.some(e => e.type === 'EMAIL_EXISTS')) {
setErrors({
email: 'The email is already used in another account.'
});
}
setSubmitting(false);
});
},