feat(register): Show success message and rediredt after register

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2022-08-14 22:10:54 +02:00
parent 1cdc8dfeb2
commit a064d57387
2 changed files with 10 additions and 1 deletions

View file

@ -556,6 +556,10 @@
"usernameInfo": "The username is your unique identifier for login.", "usernameInfo": "The username is your unique identifier for login.",
"passwordInfo": "Choose a unique and secure password. It must contain at least 8 characters.", "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:", "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": { "error": {
"registrationDisabled": "The registration is disabled", "registrationDisabled": "The registration is disabled",
"usernameExisting": "There is already an account with this username.", "usernameExisting": "There is already an account with this username.",

View file

@ -20,14 +20,17 @@ import { PasswordAgainField } from '../components/common/fields/password-again-f
import { useOnInputChange } from '../hooks/common/use-on-input-change' import { useOnInputChange } from '../hooks/common/use-on-input-change'
import { RegisterError } from '../components/register-page/register-error/register-error' import { RegisterError } from '../components/register-page/register-error/register-error'
import { LandingLayout } from '../components/landing-layout/landing-layout' import { LandingLayout } from '../components/landing-layout/landing-layout'
import { useRouter } from 'next/router'
import type { NextPage } from 'next' import type { NextPage } from 'next'
import { Redirect } from '../components/common/redirect' 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. * Renders the registration page with fields for username, display name, password, password retype and information about terms and conditions.
*/ */
export const RegisterPage: NextPage = () => { export const RegisterPage: NextPage = () => {
useTranslation() useTranslation()
const router = useRouter()
const allowRegister = useApplicationState((state) => state.config.allowRegister) const allowRegister = useApplicationState((state) => state.config.allowRegister)
const userExists = useApplicationState((state) => !!state.user) const userExists = useApplicationState((state) => !!state.user)
@ -41,6 +44,8 @@ export const RegisterPage: NextPage = () => {
(event: FormEvent) => { (event: FormEvent) => {
doLocalRegister(username, displayName, password) doLocalRegister(username, displayName, password)
.then(() => fetchAndSetUser()) .then(() => fetchAndSetUser())
.then(() => dispatchUiNotification('login.register.success.title', 'login.register.success.message', {}))
.then(() => router.push('/'))
.catch((error: Error) => { .catch((error: Error) => {
setError( setError(
Object.values(RegisterErrorType).includes(error.message as RegisterErrorType) Object.values(RegisterErrorType).includes(error.message as RegisterErrorType)
@ -50,7 +55,7 @@ export const RegisterPage: NextPage = () => {
}) })
event.preventDefault() event.preventDefault()
}, },
[username, displayName, password] [username, displayName, password, router]
) )
const ready = useMemo(() => { const ready = useMemo(() => {