balibabu
commited on
Commit
·
56dceef
1
Parent(s):
907411d
feat: Switch the login page to the registration component by changing the routing parameters #3221 (#3307)
Browse files### 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
CHANGED
@@ -31,6 +31,7 @@ export function SignUpForm() {
|
|
31 |
}),
|
32 |
nickname: z.string({ required_error: t('nicknamePlaceholder') }),
|
33 |
password: z.string({ required_error: t('passwordPlaceholder') }),
|
|
|
34 |
});
|
35 |
|
36 |
const form = useForm<z.infer<typeof FormSchema>>({
|
@@ -98,6 +99,26 @@ export function SignUpForm() {
|
|
98 |
</FormItem>
|
99 |
)}
|
100 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
<Button type="submit" className="w-full">
|
102 |
{t('signUp')}
|
103 |
</Button>
|
|
|
31 |
}),
|
32 |
nickname: z.string({ required_error: t('nicknamePlaceholder') }),
|
33 |
password: z.string({ required_error: t('passwordPlaceholder') }),
|
34 |
+
agree: z.boolean({ required_error: t('passwordPlaceholder') }),
|
35 |
});
|
36 |
|
37 |
const form = useForm<z.infer<typeof FormSchema>>({
|
|
|
99 |
</FormItem>
|
100 |
)}
|
101 |
/>
|
102 |
+
<FormField
|
103 |
+
control={form.control}
|
104 |
+
name="agree"
|
105 |
+
render={({ field }) => (
|
106 |
+
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md">
|
107 |
+
<FormControl>
|
108 |
+
<Checkbox
|
109 |
+
checked={field.value}
|
110 |
+
onCheckedChange={field.onChange}
|
111 |
+
/>
|
112 |
+
</FormControl>
|
113 |
+
<div className="space-y-1 leading-none">
|
114 |
+
<FormLabel>
|
115 |
+
I understand and agree to the Terms of Service and Privacy
|
116 |
+
Policy.
|
117 |
+
</FormLabel>
|
118 |
+
</div>
|
119 |
+
</FormItem>
|
120 |
+
)}
|
121 |
+
/>
|
122 |
<Button type="submit" className="w-full">
|
123 |
{t('signUp')}
|
124 |
</Button>
|
web/src/pages/login-next/hooks.ts
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useCallback } from 'react';
|
2 |
+
import { useSearchParams } from 'umi';
|
3 |
+
|
4 |
+
export enum Step {
|
5 |
+
SignIn,
|
6 |
+
SignUp,
|
7 |
+
ForgotPassword,
|
8 |
+
ResetPassword,
|
9 |
+
VerifyEmail,
|
10 |
+
}
|
11 |
+
|
12 |
+
export const useSwitchStep = (step: Step) => {
|
13 |
+
const [_, setSearchParams] = useSearchParams();
|
14 |
+
const switchStep = useCallback(() => {
|
15 |
+
setSearchParams(new URLSearchParams({ step: step.toString() }));
|
16 |
+
}, [setSearchParams, step]);
|
17 |
+
|
18 |
+
return { switchStep };
|
19 |
+
};
|
web/src/pages/login-next/index.tsx
CHANGED
@@ -3,13 +3,15 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
3 |
import { Separator } from '@/components/ui/separator';
|
4 |
import { useTranslate } from '@/hooks/common-hooks';
|
5 |
import { DiscordLogoIcon, GitHubLogoIcon } from '@radix-ui/react-icons';
|
|
|
6 |
import { SignInForm, SignUpForm, VerifyEmailForm } from './form';
|
|
|
7 |
|
8 |
function LoginFooter() {
|
9 |
return (
|
10 |
-
<section className="pt-
|
11 |
<Separator />
|
12 |
-
<p className="text-center pt-
|
13 |
<div className="flex gap-4 justify-center pt-[20px]">
|
14 |
<GitHubLogoIcon className="w-8 h-8"></GitHubLogoIcon>
|
15 |
<DiscordLogoIcon className="w-8 h-8"></DiscordLogoIcon>
|
@@ -21,6 +23,8 @@ function LoginFooter() {
|
|
21 |
export function SignUpCard() {
|
22 |
const { t } = useTranslate('login');
|
23 |
|
|
|
|
|
24 |
return (
|
25 |
<Card className="w-[400px]">
|
26 |
<CardHeader>
|
@@ -28,6 +32,11 @@ export function SignUpCard() {
|
|
28 |
</CardHeader>
|
29 |
<CardContent>
|
30 |
<SignUpForm></SignUpForm>
|
|
|
|
|
|
|
|
|
|
|
31 |
<LoginFooter></LoginFooter>
|
32 |
</CardContent>
|
33 |
</Card>
|
@@ -36,6 +45,7 @@ export function SignUpCard() {
|
|
36 |
|
37 |
export function SignInCard() {
|
38 |
const { t } = useTranslate('login');
|
|
|
39 |
|
40 |
return (
|
41 |
<Card className="w-[400px]">
|
@@ -44,6 +54,13 @@ export function SignInCard() {
|
|
44 |
</CardHeader>
|
45 |
<CardContent>
|
46 |
<SignInForm></SignInForm>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
</CardContent>
|
48 |
</Card>
|
49 |
);
|
@@ -76,12 +93,17 @@ export function VerifyEmailCard() {
|
|
76 |
}
|
77 |
|
78 |
const Login = () => {
|
|
|
|
|
|
|
79 |
return (
|
80 |
-
|
81 |
-
<
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
85 |
);
|
86 |
};
|
87 |
|
|
|
3 |
import { Separator } from '@/components/ui/separator';
|
4 |
import { useTranslate } from '@/hooks/common-hooks';
|
5 |
import { DiscordLogoIcon, GitHubLogoIcon } from '@radix-ui/react-icons';
|
6 |
+
import { useSearchParams } from 'umi';
|
7 |
import { SignInForm, SignUpForm, VerifyEmailForm } from './form';
|
8 |
+
import { Step, useSwitchStep } from './hooks';
|
9 |
|
10 |
function LoginFooter() {
|
11 |
return (
|
12 |
+
<section className="pt-4">
|
13 |
<Separator />
|
14 |
+
<p className="text-center pt-4">or continue with</p>
|
15 |
<div className="flex gap-4 justify-center pt-[20px]">
|
16 |
<GitHubLogoIcon className="w-8 h-8"></GitHubLogoIcon>
|
17 |
<DiscordLogoIcon className="w-8 h-8"></DiscordLogoIcon>
|
|
|
23 |
export function SignUpCard() {
|
24 |
const { t } = useTranslate('login');
|
25 |
|
26 |
+
const { switchStep } = useSwitchStep(Step.SignIn);
|
27 |
+
|
28 |
return (
|
29 |
<Card className="w-[400px]">
|
30 |
<CardHeader>
|
|
|
32 |
</CardHeader>
|
33 |
<CardContent>
|
34 |
<SignUpForm></SignUpForm>
|
35 |
+
<div className="text-center">
|
36 |
+
<Button variant={'link'} className="pt-6" onClick={switchStep}>
|
37 |
+
Already have an account? Log In
|
38 |
+
</Button>
|
39 |
+
</div>
|
40 |
<LoginFooter></LoginFooter>
|
41 |
</CardContent>
|
42 |
</Card>
|
|
|
45 |
|
46 |
export function SignInCard() {
|
47 |
const { t } = useTranslate('login');
|
48 |
+
const { switchStep } = useSwitchStep(Step.SignUp);
|
49 |
|
50 |
return (
|
51 |
<Card className="w-[400px]">
|
|
|
54 |
</CardHeader>
|
55 |
<CardContent>
|
56 |
<SignInForm></SignInForm>
|
57 |
+
<Button
|
58 |
+
className="w-full mt-2"
|
59 |
+
onClick={switchStep}
|
60 |
+
variant={'secondary'}
|
61 |
+
>
|
62 |
+
{t('signUp')}
|
63 |
+
</Button>
|
64 |
</CardContent>
|
65 |
</Card>
|
66 |
);
|
|
|
93 |
}
|
94 |
|
95 |
const Login = () => {
|
96 |
+
const [searchParams] = useSearchParams();
|
97 |
+
const step = Number((searchParams.get('step') ?? Step.SignIn) as Step);
|
98 |
+
|
99 |
return (
|
100 |
+
<div className="w-full h-full flex items-center pl-[15%]">
|
101 |
+
<div className="inline-block">
|
102 |
+
{step === Step.SignIn && <SignInCard></SignInCard>}
|
103 |
+
{step === Step.SignUp && <SignUpCard></SignUpCard>}
|
104 |
+
{step === Step.VerifyEmail && <VerifyEmailCard></VerifyEmailCard>}
|
105 |
+
</div>
|
106 |
+
</div>
|
107 |
);
|
108 |
};
|
109 |
|