fix: Manually approved user registration flow (#29420)

pull/29457/head^2
Hugo Costa 3 years ago committed by GitHub
parent 3de6641573
commit 6938bcd1a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .changeset/registration-flow.md
  2. 11
      packages/web-ui-registration/src/RegisterForm.tsx

@ -0,0 +1,8 @@
---
"@rocket.chat/web-ui-registration": patch
---
fix: Manually approved user registration flow
The new user gets redirected to the login page with a toast message saying:
> Before you can login, your account must be manually activated by an administrator.

@ -1,7 +1,7 @@
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import { FieldGroup, TextInput, Field, PasswordInput, ButtonGroup, Button, TextAreaInput } from '@rocket.chat/fuselage';
import { Form, ActionLink } from '@rocket.chat/layout';
import { useSetting } from '@rocket.chat/ui-contexts';
import { useSetting, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import { useForm } from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';
@ -33,6 +33,8 @@ export const RegisterForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRo
const formLabelId = useUniqueId();
const registerUser = useRegisterMethod();
const dispatchToastMessage = useToastMessageDispatch();
const {
register,
handleSubmit,
@ -62,6 +64,13 @@ export const RegisterForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRo
if (/Username is already in use/.test(error.error)) {
setError('username', { type: 'username-already-exists', message: t('registration.component.form.userAlreadyExist') });
}
if (/error-too-many-requests/.test(error.error)) {
dispatchToastMessage({ type: 'error', message: error.error });
}
if (/error-user-is-not-activated/.test(error.error)) {
dispatchToastMessage({ type: 'info', message: t('registration.page.registration.waitActivationWarning') });
setLoginRoute('login');
}
},
},
);

Loading…
Cancel
Save