Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Switch the login page to the registration component by changing the routing parameters #3221 #3307

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions web/src/pages/login-next/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<z.infer<typeof FormSchema>>({
Expand Down Expand Up @@ -98,6 +99,26 @@ export function SignUpForm() {
</FormItem>
)}
/>
<FormField
control={form.control}
name="agree"
render={({ field }) => (
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md">
<FormControl>
<Checkbox
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
<div className="space-y-1 leading-none">
<FormLabel>
I understand and agree to the Terms of Service and Privacy
Policy.
</FormLabel>
</div>
</FormItem>
)}
/>
<Button type="submit" className="w-full">
{t('signUp')}
</Button>
Expand Down
19 changes: 19 additions & 0 deletions web/src/pages/login-next/hooks.ts
Original file line number Diff line number Diff line change
@@ -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 };
};
36 changes: 29 additions & 7 deletions web/src/pages/login-next/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<section className="pt-[30px]">
<section className="pt-4">
<Separator />
<p className="text-center pt-[20px]">or continue with</p>
<p className="text-center pt-4">or continue with</p>
<div className="flex gap-4 justify-center pt-[20px]">
<GitHubLogoIcon className="w-8 h-8"></GitHubLogoIcon>
<DiscordLogoIcon className="w-8 h-8"></DiscordLogoIcon>
Expand All @@ -21,13 +23,20 @@ function LoginFooter() {
export function SignUpCard() {
const { t } = useTranslate('login');

const { switchStep } = useSwitchStep(Step.SignIn);

return (
<Card className="w-[400px]">
<CardHeader>
<CardTitle>{t('signUp')}</CardTitle>
</CardHeader>
<CardContent>
<SignUpForm></SignUpForm>
<div className="text-center">
<Button variant={'link'} className="pt-6" onClick={switchStep}>
Already have an account? Log In
</Button>
</div>
<LoginFooter></LoginFooter>
</CardContent>
</Card>
Expand All @@ -36,6 +45,7 @@ export function SignUpCard() {

export function SignInCard() {
const { t } = useTranslate('login');
const { switchStep } = useSwitchStep(Step.SignUp);

return (
<Card className="w-[400px]">
Expand All @@ -44,6 +54,13 @@ export function SignInCard() {
</CardHeader>
<CardContent>
<SignInForm></SignInForm>
<Button
className="w-full mt-2"
onClick={switchStep}
variant={'secondary'}
>
{t('signUp')}
</Button>
</CardContent>
</Card>
);
Expand Down Expand Up @@ -76,12 +93,17 @@ export function VerifyEmailCard() {
}

const Login = () => {
const [searchParams] = useSearchParams();
const step = Number((searchParams.get('step') ?? Step.SignIn) as Step);

return (
<>
<SignUpCard></SignUpCard>
<SignInCard></SignInCard>
<VerifyEmailCard></VerifyEmailCard>
</>
<div className="w-full h-full flex items-center pl-[15%]">
<div className="inline-block">
{step === Step.SignIn && <SignInCard></SignInCard>}
{step === Step.SignUp && <SignUpCard></SignUpCard>}
{step === Step.VerifyEmail && <VerifyEmailCard></VerifyEmailCard>}
</div>
</div>
);
};

Expand Down