-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use client' | ||
import { startTransition } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { Flex, Heading } from '@chakra-ui/react' | ||
import * as z from 'zod' | ||
import { PrimaryButton } from '@/components/button' | ||
import { signUp } from './action' | ||
|
||
const signUpSchema = z.object({ | ||
email: z.string().email(), | ||
password: z.string().min(8), | ||
confirmationPassword: z.string().min(8) | ||
}) | ||
export type SignUpSchema = z.infer<typeof signUpSchema> | ||
|
||
export default function SignUp() { | ||
const { | ||
register, | ||
handleSubmit, | ||
setError, | ||
formState: { errors } | ||
} = useForm<SignUpSchema>() | ||
return ( | ||
<> | ||
<Heading>Welcome!</Heading> | ||
<Heading>Create an Account</Heading> | ||
<form | ||
onSubmit={handleSubmit((data) => { | ||
const result = signUpSchema.safeParse(data) | ||
if (!result.success) { | ||
console.error(result.error) | ||
return | ||
} | ||
|
||
if (result.data.password !== result.data.confirmationPassword) { | ||
setError('confirmationPassword', { | ||
message: 'Your password and confirmation password must match' | ||
}) | ||
} | ||
startTransition(() => { | ||
signUp(result.data).catch(console.error) | ||
}) | ||
})} | ||
> | ||
<Flex flexDirection={'column'}> | ||
<label htmlFor="email">Email address</label> | ||
<input type="email" id="email" required {...register('email')} /> | ||
<label htmlFor="password">Password</label> | ||
<input | ||
type="password" | ||
id="password" | ||
required | ||
{...register('password', { | ||
minLength: { | ||
value: 8, | ||
message: 'min length is 8' | ||
} | ||
})} | ||
/> | ||
{errors.password && ( | ||
<span role="alert">{errors.password.message}</span> | ||
)} | ||
<label htmlFor="re-type-password">Confirmation Password</label> | ||
<input | ||
type="password" | ||
id="re-type-password" | ||
required | ||
{...register('confirmationPassword', { | ||
minLength: { | ||
value: 8, | ||
message: 'min length is 8' | ||
} | ||
})} | ||
/> | ||
{errors.confirmationPassword && ( | ||
<span role="alert">{errors.confirmationPassword.message}</span> | ||
)} | ||
<PrimaryButton type={'submit'}>Sign Up</PrimaryButton> | ||
</Flex> | ||
</form> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,34 @@ | ||
'use client' | ||
import { startTransition } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { Flex, Heading } from '@chakra-ui/react' | ||
import * as z from 'zod' | ||
import { PrimaryButton } from '@/components/button' | ||
import { signUp } from './action' | ||
|
||
const signUpSchema = z.object({ | ||
email: z.string().email(), | ||
password: z.string() | ||
}) | ||
export type SignUpSchema = z.infer<typeof signUpSchema> | ||
import { Heading, List, ListItem } from '@chakra-ui/react' | ||
import Link from 'next/link' | ||
import { SecondaryButton } from '@/components/button' | ||
|
||
export default function SignUp() { | ||
const { register, handleSubmit } = useForm() | ||
return ( | ||
<> | ||
<Heading>SignUp Page</Heading> | ||
<form | ||
onSubmit={handleSubmit((data) => { | ||
const result = signUpSchema.safeParse(data) | ||
if (!result.success) { | ||
console.error(result.error) | ||
return | ||
} | ||
startTransition(() => { | ||
signUp(result.data).catch(console.error) | ||
}) | ||
})} | ||
> | ||
<Flex flexDirection={'column'}> | ||
<label htmlFor="email">Email</label> | ||
<input type="email" id="email" required {...register('email')} /> | ||
<label htmlFor="password">Password</label> | ||
<input | ||
type="password" | ||
id="password" | ||
required | ||
{...register('password')} | ||
/> | ||
<PrimaryButton type={'submit'}>Sign Up</PrimaryButton> | ||
</Flex> | ||
</form> | ||
<Heading>Welcome!</Heading> | ||
<Heading>Create an Account</Heading> | ||
<List spacing={3}> | ||
<ListItem> | ||
<Link href="/auth/signup/email"> | ||
<SecondaryButton>Sign up with Email</SecondaryButton> | ||
</Link> | ||
</ListItem> | ||
<ListItem> | ||
<Link href="/auth/signup/google"> | ||
<SecondaryButton>Sign up with Google</SecondaryButton> | ||
</Link> | ||
</ListItem> | ||
<ListItem> | ||
<Link href="/auth/signup/facebook"> | ||
<SecondaryButton>Sign up with Facebook</SecondaryButton> | ||
</Link> | ||
</ListItem> | ||
<ListItem> | ||
<Link href="/auth/signup/apple"> | ||
<SecondaryButton>Sign up with Apple</SecondaryButton> | ||
</Link> | ||
</ListItem> | ||
</List> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.