From 20d686737a10da5c9bd7b5496635a3ece3a0abc9 Mon Sep 17 00:00:00 2001 From: balibabu Date: Fri, 8 Nov 2024 19:47:22 +0800 Subject: [PATCH] feat: Switch the login page to the registration component by changing the routing parameters #3221 (#3307) ### What problem does this PR solve? feat: Switch the login page to the registration component by changing the routing parameters #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/pages/login-next/form.tsx | 21 +++++++++++++++++ web/src/pages/login-next/hooks.ts | 19 ++++++++++++++++ web/src/pages/login-next/index.tsx | 36 ++++++++++++++++++++++++------ 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 web/src/pages/login-next/hooks.ts diff --git a/web/src/pages/login-next/form.tsx b/web/src/pages/login-next/form.tsx index f235447cc43..ccd0388117d 100644 --- a/web/src/pages/login-next/form.tsx +++ b/web/src/pages/login-next/form.tsx @@ -31,6 +31,7 @@ export function SignUpForm() { }), nickname: z.string({ required_error: t('nicknamePlaceholder') }), password: z.string({ required_error: t('passwordPlaceholder') }), + agree: z.boolean({ required_error: t('passwordPlaceholder') }), }); const form = useForm>({ @@ -98,6 +99,26 @@ export function SignUpForm() { )} /> + ( + + + + +
+ + I understand and agree to the Terms of Service and Privacy + Policy. + +
+
+ )} + /> diff --git a/web/src/pages/login-next/hooks.ts b/web/src/pages/login-next/hooks.ts new file mode 100644 index 00000000000..9fd6650ec1d --- /dev/null +++ b/web/src/pages/login-next/hooks.ts @@ -0,0 +1,19 @@ +import { useCallback } from 'react'; +import { useSearchParams } from 'umi'; + +export enum Step { + SignIn, + SignUp, + ForgotPassword, + ResetPassword, + VerifyEmail, +} + +export const useSwitchStep = (step: Step) => { + const [_, setSearchParams] = useSearchParams(); + const switchStep = useCallback(() => { + setSearchParams(new URLSearchParams({ step: step.toString() })); + }, [setSearchParams, step]); + + return { switchStep }; +}; diff --git a/web/src/pages/login-next/index.tsx b/web/src/pages/login-next/index.tsx index ec5aad04434..5649649f909 100644 --- a/web/src/pages/login-next/index.tsx +++ b/web/src/pages/login-next/index.tsx @@ -3,13 +3,15 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { useTranslate } from '@/hooks/common-hooks'; import { DiscordLogoIcon, GitHubLogoIcon } from '@radix-ui/react-icons'; +import { useSearchParams } from 'umi'; import { SignInForm, SignUpForm, VerifyEmailForm } from './form'; +import { Step, useSwitchStep } from './hooks'; function LoginFooter() { return ( -
+
-

or continue with

+

or continue with

@@ -21,6 +23,8 @@ function LoginFooter() { export function SignUpCard() { const { t } = useTranslate('login'); + const { switchStep } = useSwitchStep(Step.SignIn); + return ( @@ -28,6 +32,11 @@ export function SignUpCard() { +
+ +
@@ -36,6 +45,7 @@ export function SignUpCard() { export function SignInCard() { const { t } = useTranslate('login'); + const { switchStep } = useSwitchStep(Step.SignUp); return ( @@ -44,6 +54,13 @@ export function SignInCard() { + ); @@ -76,12 +93,17 @@ export function VerifyEmailCard() { } const Login = () => { + const [searchParams] = useSearchParams(); + const step = Number((searchParams.get('step') ?? Step.SignIn) as Step); + return ( - <> - - - - +
+
+ {step === Step.SignIn && } + {step === Step.SignUp && } + {step === Step.VerifyEmail && } +
+
); };