From a064d57387d9b35ea311e228761facc04b0d6aec Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Sun, 14 Aug 2022 22:10:54 +0200 Subject: [PATCH] feat(register): Show success message and rediredt after register Signed-off-by: Erik Michelson --- locales/en.json | 4 ++++ src/pages/register.tsx | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/locales/en.json b/locales/en.json index 5246956a3..2ba77f611 100644 --- a/locales/en.json +++ b/locales/en.json @@ -556,6 +556,10 @@ "usernameInfo": "The username is your unique identifier for login.", "passwordInfo": "Choose a unique and secure password. It must contain at least 8 characters.", "infoTermsPrivacy": "With the registration of my user account I agree to the following terms:", + "success": { + "title": "Successfully registered", + "message": "Your account has been registered successfully. You can now log in with your username and password." + }, "error": { "registrationDisabled": "The registration is disabled", "usernameExisting": "There is already an account with this username.", diff --git a/src/pages/register.tsx b/src/pages/register.tsx index da4fd7646..ac1c1863b 100644 --- a/src/pages/register.tsx +++ b/src/pages/register.tsx @@ -20,14 +20,17 @@ import { PasswordAgainField } from '../components/common/fields/password-again-f import { useOnInputChange } from '../hooks/common/use-on-input-change' import { RegisterError } from '../components/register-page/register-error/register-error' import { LandingLayout } from '../components/landing-layout/landing-layout' +import { useRouter } from 'next/router' import type { NextPage } from 'next' import { Redirect } from '../components/common/redirect' +import { dispatchUiNotification } from '../redux/ui-notifications/methods' /** * Renders the registration page with fields for username, display name, password, password retype and information about terms and conditions. */ export const RegisterPage: NextPage = () => { useTranslation() + const router = useRouter() const allowRegister = useApplicationState((state) => state.config.allowRegister) const userExists = useApplicationState((state) => !!state.user) @@ -41,6 +44,8 @@ export const RegisterPage: NextPage = () => { (event: FormEvent) => { doLocalRegister(username, displayName, password) .then(() => fetchAndSetUser()) + .then(() => dispatchUiNotification('login.register.success.title', 'login.register.success.message', {})) + .then(() => router.push('/')) .catch((error: Error) => { setError( Object.values(RegisterErrorType).includes(error.message as RegisterErrorType) @@ -50,7 +55,7 @@ export const RegisterPage: NextPage = () => { }) event.preventDefault() }, - [username, displayName, password] + [username, displayName, password, router] ) const ready = useMemo(() => {