From 64957d8a74dda24c524e0159a59881bc0bcfb088 Mon Sep 17 00:00:00 2001 From: David Matejka Date: Wed, 29 May 2024 13:32:09 +0200 Subject: [PATCH] refactor(playground): extract texts from pages, set autoComplete fields, add forget password link etc --- packages/playground/admin/index.tsx | 66 +++++++++++-------- .../tenant/changeMyPasswordForm.tsx | 6 +- .../admin/lib/components/tenant/loginForm.tsx | 12 +++- .../components/tenant/passwordResetForm.tsx | 8 +-- .../tenant/passwordResetRequestForm.tsx | 2 +- packages/playground/admin/lib/dict.ts | 14 ++++ 6 files changed, 71 insertions(+), 37 deletions(-) diff --git a/packages/playground/admin/index.tsx b/packages/playground/admin/index.tsx index 6dcb500cb..f164f3eea 100644 --- a/packages/playground/admin/index.tsx +++ b/packages/playground/admin/index.tsx @@ -15,38 +15,51 @@ import { ToastContent, Toaster, useShowToast } from './lib/components/ui/toast' import { Loader } from './lib/components/ui/loader' import { Overlay } from './lib/components/ui/overlay' import { useEffect } from 'react' +import { dict } from './lib/dict' const errorHandler = createErrorHandler((dom, react, onRecoverableError) => createRoot(dom, { onRecoverableError }).render(react)) const rootEl = document.body.appendChild(document.createElement('div')) +const Idps = { + google: 'Login with Google', +} + +const hasTokenFromEnv = import.meta.env.VITE_CONTEMBER_ADMIN_SESSION_TOKEN !== '__SESSION_TOKEN__' +const appUrl = '/app' + const Login = () => { const showToast = useShowToast() return <> showToast(Failed to initialize IdP login: {error}, { type: 'error' })} - onResponseError={error => showToast(Failed to process IdP response: {error}, { type: 'error' })} + onInitError={error => showToast({dict.tenant.login.idpInitError} {error}, { type: 'error' })} + onResponseError={error => showToast({dict.tenant.login.idpResponseError} {error}, { type: 'error' })} > - Login + {dict.tenant.login.title} - Enter your email below to login to your account + {dict.tenant.login.description} + {hasTokenFromEnv && + Continue as default user + }
- - - + {Object.entries(Idps).map(([idp, label]) => ( + + + + ))}
@@ -60,8 +73,8 @@ const LoggedIn = () => { const identity = useIdentity() useEffect(() => { setTimeout(() => { - window.location.href = '/app/' - }, 2000) + window.location.href = appUrl + }, 500) }, []) return ( @@ -111,9 +124,9 @@ const PasswordResetRequestPage = () => { return ( - Password reset request + {dict.tenant.passwordResetRequest.title} - Enter your email below to reset your password + {dict.tenant.passwordResetRequest.description} @@ -126,7 +139,7 @@ const PasswordResetRequestPage = () => { - Back to login + {dict.tenant.login.backToLogin} @@ -142,14 +155,16 @@ const PasswordResetPage = () => { return ( - Password reset + {dict.tenant.passwordReset.title} - Enter new password + {dict.tenant.passwordReset.description} { - showToast(Password has been reset, { type: 'success' }) + showToast( + Password has been reset + , { type: 'success' }) redirect('index') }} token={token}>
@@ -160,7 +175,7 @@ const PasswordResetPage = () => { - Back to login + {dict.tenant.login.backToLogin} @@ -171,26 +186,26 @@ const PasswordResetPage = () => { const PasswordResetRequestSuccessPage = () => ( - Password reset request + {dict.tenant.passwordResetRequest.title} - Password reset link has been sent + {dict.tenant.passwordResetRequest.description}
- Please check you mailbox for instructions on how to reset your password. + An email with password reset instructions has been sent to your email address.
- Back to login + {dict.tenant.login.backToLogin} @@ -204,7 +219,8 @@ const Layout = ({ children }: { children?: React.ReactNode }) => (
-
+
Welcome to your app
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor, sem eget ultricies ultricies, sapien urna tristique eros, ac tincidunt felis lacus nec nunc.

@@ -225,8 +241,6 @@ errorHandler(onRecoverableError => createRoot(rootEl, { onRecoverableError }).re resetRequest: PasswordResetRequestPage, resetRequestSuccess: PasswordResetRequestSuccessPage, passwordReset: PasswordResetPage, - passwordResetSuccess:
password reset success
, - }} /> diff --git a/packages/playground/admin/lib/components/tenant/changeMyPasswordForm.tsx b/packages/playground/admin/lib/components/tenant/changeMyPasswordForm.tsx index cbfa52224..2fd06f05b 100644 --- a/packages/playground/admin/lib/components/tenant/changeMyPasswordForm.tsx +++ b/packages/playground/admin/lib/components/tenant/changeMyPasswordForm.tsx @@ -15,19 +15,19 @@ export const ChangeMyPasswordFormFields = () => { /> {dict.tenant.changePassword.currentPassword} {dict.tenant.changePassword.newPassword} {dict.tenant.changePassword.confirmPassword} diff --git a/packages/playground/admin/lib/components/tenant/loginForm.tsx b/packages/playground/admin/lib/components/tenant/loginForm.tsx index 2bade4667..b1b276491 100644 --- a/packages/playground/admin/lib/components/tenant/loginForm.tsx +++ b/packages/playground/admin/lib/components/tenant/loginForm.tsx @@ -3,6 +3,7 @@ import { Button } from '../ui/button' import { Loader } from '../ui/loader' import { TenantFormError, TenantFormField } from './common' import { dict } from '../../dict' +import { Link } from '@contember/interface' export const LoginFormFields = () => { const form = useLoginForm() @@ -17,21 +18,26 @@ export const LoginFormFields = () => { {dict.tenant.login.email} {dict.tenant.login.password} + + + {dict.tenant.login.forgotPassword} + + {(form.state === 'otp-required' || fieldErrors.includes('otpToken')) && ( {dict.tenant.login.otpToken} diff --git a/packages/playground/admin/lib/components/tenant/passwordResetForm.tsx b/packages/playground/admin/lib/components/tenant/passwordResetForm.tsx index 5ad4fc611..ffd82cf9e 100644 --- a/packages/playground/admin/lib/components/tenant/passwordResetForm.tsx +++ b/packages/playground/admin/lib/components/tenant/passwordResetForm.tsx @@ -1,4 +1,4 @@ -import { PasswordResetFormErrorCode, usePasswordResetForm } from '@contember/react-identity' +import { usePasswordResetForm } from '@contember/react-identity' import { Button } from '../ui/button' import { Loader } from '../ui/loader' import { TenantFormError, TenantFormField } from './common' @@ -17,21 +17,21 @@ export const PasswordResetFormFields = ({ hasToken }: { hasToken?: boolean }) => {dict.tenant.passwordReset.token} {dict.tenant.passwordReset.password} {dict.tenant.passwordReset.passwordConfirmation} diff --git a/packages/playground/admin/lib/components/tenant/passwordResetRequestForm.tsx b/packages/playground/admin/lib/components/tenant/passwordResetRequestForm.tsx index 2dfdbd432..dda598ba7 100644 --- a/packages/playground/admin/lib/components/tenant/passwordResetRequestForm.tsx +++ b/packages/playground/admin/lib/components/tenant/passwordResetRequestForm.tsx @@ -17,7 +17,7 @@ export const PasswordResetRequestFormFields = () => { {dict.tenant.passwordResetRequest.email} diff --git a/packages/playground/admin/lib/dict.ts b/packages/playground/admin/lib/dict.ts index 311a3ffd6..82f7e21f3 100644 --- a/packages/playground/admin/lib/dict.ts +++ b/packages/playground/admin/lib/dict.ts @@ -193,6 +193,7 @@ export const dict = { email: 'Email', password: 'Password', otpToken: 'OTP token', + forgotPassword: 'Forgot password?', login: 'Login', errorMessages: { 'FIELD_REQUIRED': 'This field is required', @@ -205,6 +206,11 @@ export const dict = { 'UNKNOWN_EMAIL': 'Unknown email', 'OTP_REQUIRED': undefined, } satisfies Record, + idpInitError: 'Failed to initialize IdP login:', + idpResponseError: 'Failed to process IdP response:', + title: 'Login', + description: 'Enter your email below to login to your account', + backToLogin: 'Back to login', }, personList: { email: 'Email', @@ -268,6 +274,9 @@ export const dict = { 'TOKEN_NOT_FOUND': 'Token not found', 'TOKEN_USED': 'Token already used', } satisfies Record, + title: 'Reset password', + description: 'Enter new password below', + success: 'Password has been reset', }, passwordResetRequest: { email: 'Email', @@ -278,6 +287,11 @@ export const dict = { 'UNKNOWN_ERROR': 'Something went wrong. Please try again later', 'PERSON_NOT_FOUND': 'Unknown email', } satisfies Record, + title: 'Reset password', + description: 'Enter your email below to reset your password', + success: 'Password reset link has been sent', + checkMail: 'Please check your mailbox for instructions on how to reset your password.', + entryCode: 'Or enter the reset code directly.', }, updateProjectMember: { updateSuccess: 'Roles updated',