Skip to content

Commit

Permalink
fix: Manually approved user registration flow (RocketChat#29420)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocostadev authored Jun 16, 2023
1 parent 3de6641 commit 6938bcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changeset/registration-flow.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 10 additions & 1 deletion packages/web-ui-registration/src/RegisterForm.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,6 +33,8 @@ export const RegisterForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRo
const formLabelId = useUniqueId();
const registerUser = useRegisterMethod();

const dispatchToastMessage = useToastMessageDispatch();

const {
register,
handleSubmit,
Expand Down Expand Up @@ -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');
}
},
},
);
Expand Down

0 comments on commit 6938bcd

Please sign in to comment.