2020-01-18 02:07:52 +05:30
|
|
|
import React, { ComponentType, ReactElement, ReactNode } from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
2019-11-11 14:10:05 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2020-01-18 02:07:52 +05:30
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import { RelativeTime } from 'app/components/ui';
|
2016-05-02 13:34:23 +05:30
|
|
|
|
2016-05-15 02:23:58 +05:30
|
|
|
import messages from './errorsDict.intl.json';
|
2016-05-02 13:34:23 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
const SuggestResetPassword: ComponentType = () => (
|
|
|
|
<>
|
|
|
|
<br />
|
|
|
|
<Message
|
|
|
|
{...messages.suggestResetPassword}
|
|
|
|
values={{
|
|
|
|
forgotYourPassword: (
|
|
|
|
<Link to="/forgot-password">
|
|
|
|
<Message {...messages.forgotYourPassword} />
|
|
|
|
</Link>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const ResendKey: ComponentType<{ url: string }> = ({ url }) => (
|
|
|
|
<>
|
|
|
|
{' '}
|
|
|
|
<Link to={url}>
|
|
|
|
<Message {...messages.doYouWantRequestKey} />
|
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
const errorsMap: Record<
|
|
|
|
string,
|
|
|
|
(props?: Record<string, any>) => ReactElement
|
|
|
|
> = {
|
2019-11-27 14:33:32 +05:30
|
|
|
'error.login_required': () => <Message {...messages.loginRequired} />,
|
|
|
|
'error.login_not_exist': () => <Message {...messages.loginNotExist} />,
|
|
|
|
'error.password_required': () => <Message {...messages.passwordRequired} />,
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
'error.password_incorrect': (props) => (
|
2019-11-27 14:33:32 +05:30
|
|
|
// props are handled in validationErrorsHandler in components/auth/actions
|
2020-01-18 02:07:52 +05:30
|
|
|
<>
|
2019-11-27 14:33:32 +05:30
|
|
|
<Message {...messages.invalidPassword} />
|
2020-01-18 02:07:52 +05:30
|
|
|
{props && props.isGuest ? <SuggestResetPassword /> : null}
|
|
|
|
</>
|
2019-11-27 14:33:32 +05:30
|
|
|
),
|
|
|
|
|
|
|
|
'error.username_required': () => <Message {...messages.usernameRequired} />,
|
|
|
|
'error.username_invalid': () => <Message {...messages.usernameInvalid} />,
|
|
|
|
'error.username_too_short': () => <Message {...messages.usernameTooShort} />,
|
|
|
|
'error.username_too_long': () => <Message {...messages.usernameTooLong} />,
|
|
|
|
'error.username_not_available': () => (
|
|
|
|
<Message {...messages.usernameUnavailable} />
|
|
|
|
),
|
|
|
|
|
|
|
|
'error.email_required': () => <Message {...messages.emailRequired} />,
|
|
|
|
'error.email_too_long': () => <Message {...messages.emailToLong} />,
|
|
|
|
'error.email_invalid': () => <Message {...messages.emailInvalid} />,
|
|
|
|
'error.email_is_tempmail': () => <Message {...messages.emailIsTempmail} />,
|
2020-01-18 02:07:52 +05:30
|
|
|
'error.email_not_available': (props) => (
|
2019-11-27 14:33:32 +05:30
|
|
|
// props are handled in validationErrorsHandler in components/auth/actions
|
2020-01-18 02:07:52 +05:30
|
|
|
<>
|
2019-11-27 14:33:32 +05:30
|
|
|
<Message {...messages.emailNotAvailable} />
|
2020-01-18 02:07:52 +05:30
|
|
|
{props && props.isGuest ? <SuggestResetPassword /> : null}
|
|
|
|
</>
|
2019-11-27 14:33:32 +05:30
|
|
|
),
|
|
|
|
|
|
|
|
'error.totp_required': () => <Message {...messages.totpRequired} />,
|
|
|
|
'error.totp_incorrect': () => <Message {...messages.totpIncorrect} />,
|
|
|
|
'error.otp_already_enabled': () => (
|
|
|
|
<Message {...messages.mfaAlreadyEnabled} />
|
|
|
|
),
|
|
|
|
|
|
|
|
'error.rePassword_required': () => (
|
|
|
|
<Message {...messages.rePasswordRequired} />
|
|
|
|
),
|
|
|
|
'error.password_too_short': () => <Message {...messages.passwordTooShort} />,
|
|
|
|
'error.rePassword_does_not_match': () => (
|
|
|
|
<Message {...messages.passwordsDoesNotMatch} />
|
|
|
|
),
|
|
|
|
'error.rulesAgreement_required': () => (
|
|
|
|
<Message {...messages.rulesAgreementRequired} />
|
|
|
|
),
|
|
|
|
'error.key_required': () => <Message {...messages.keyRequired} />,
|
2020-05-20 22:05:52 +05:30
|
|
|
'error.key_not_exists': (props) => (
|
2020-01-18 02:07:52 +05:30
|
|
|
<>
|
2019-11-27 14:33:32 +05:30
|
|
|
<Message {...messages.keyNotExists} />
|
2020-01-18 02:07:52 +05:30
|
|
|
{props && props.repeatUrl ? <ResendKey url={props.repeatUrl} /> : null}
|
|
|
|
</>
|
2019-11-27 14:33:32 +05:30
|
|
|
),
|
2020-05-20 22:05:52 +05:30
|
|
|
'error.key_expire': (props) => errorsMap['error.key_not_exists'](props),
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
'error.newPassword_required': () => (
|
|
|
|
<Message {...messages.newPasswordRequired} />
|
|
|
|
),
|
|
|
|
'error.newRePassword_required': () => (
|
|
|
|
<Message {...messages.newRePasswordRequired} />
|
|
|
|
),
|
|
|
|
|
|
|
|
'error.account_not_activated': () => (
|
|
|
|
<Message {...messages.accountNotActivated} />
|
|
|
|
),
|
|
|
|
'error.account_banned': () => <Message {...messages.accountBanned} />,
|
|
|
|
|
2020-05-20 22:05:52 +05:30
|
|
|
'error.recently_sent_message': (props) => (
|
2019-11-27 14:33:32 +05:30
|
|
|
<Message
|
|
|
|
{...messages.emailFrequency}
|
|
|
|
values={{
|
|
|
|
// for msLeft @see AuthError.jsx
|
2020-01-18 02:07:52 +05:30
|
|
|
time: <RelativeTime timestamp={props!.msLeft} />,
|
2019-11-27 14:33:32 +05:30
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
|
|
|
|
'error.email_not_found': () => <Message {...messages.emailNotFound} />,
|
|
|
|
'error.account_already_activated': () => (
|
|
|
|
<Message {...messages.accountAlreadyActivated} />
|
|
|
|
),
|
|
|
|
|
|
|
|
'error.captcha_required': () => <Message {...messages.captchaRequired} />,
|
2020-05-20 22:05:52 +05:30
|
|
|
'error.captcha_invalid': (props) =>
|
|
|
|
errorsMap['error.captcha_required'](props),
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
'error.redirectUri_required': () => (
|
|
|
|
<Message {...messages.redirectUriRequired} />
|
|
|
|
),
|
|
|
|
'error.redirectUri_invalid': () => (
|
|
|
|
<Message {...messages.redirectUriInvalid} />
|
|
|
|
),
|
2020-01-18 02:07:52 +05:30
|
|
|
};
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
interface ErrorLiteral {
|
|
|
|
type: string;
|
|
|
|
payload?: Record<string, any>;
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
type Error = string | ErrorLiteral;
|
|
|
|
|
|
|
|
export function resolve(error: Error): ReactNode {
|
|
|
|
let payload = {};
|
|
|
|
|
|
|
|
if (typeof error !== 'string') {
|
|
|
|
payload = error.payload || {};
|
|
|
|
error = error.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return errorsMap[error] ? errorsMap[error](payload) : error;
|
|
|
|
}
|