generated from catze-labs/next-tailwind-recoil-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix CSS of the button component * Add sign up mock-up
- Loading branch information
1 parent
2e99ef3
commit bfdf1c1
Showing
8 changed files
with
226 additions
and
65 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
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,50 @@ | ||
import Box from '@/components/Box' | ||
import Button from '@/components/Button' | ||
import Label from '@/components/Label' | ||
import TextInput from '@/components/TextInput' | ||
import { yupResolver } from '@hookform/resolvers/yup' | ||
import { ComponentProps, Dispatch, SetStateAction, useState } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import signupSchema from '../utils/signupFormSchema' | ||
|
||
export interface SignupFormProps extends ComponentProps<'div'> { | ||
onSubmitForm: ( | ||
formData: Auth.Signup.FormData, | ||
setIsSubmitting: Dispatch<SetStateAction<boolean>>, | ||
) => void | ||
} | ||
|
||
const SignupForm: React.FC<SignupFormProps> = ({ onSubmitForm }) => { | ||
const [isSubmitting, setIsSubmitting] = useState<boolean>(false) | ||
|
||
const { register, handleSubmit } = useForm<Auth.Signup.FormData>({ | ||
resolver: yupResolver(signupSchema), | ||
}) | ||
|
||
const onSubmit = handleSubmit((data) => { | ||
setIsSubmitting(true) | ||
onSubmitForm(data, setIsSubmitting) | ||
}) | ||
|
||
return ( | ||
<Box hasBorder hasPadding> | ||
<form className="flex flex-col gap-6" onSubmit={onSubmit}> | ||
<div className="flex flex-col gap-1"> | ||
<Label htmlFor="email">Email</Label> | ||
<TextInput type="email" id="email" {...register('Email')} /> | ||
</div> | ||
<div className="flex flex-col gap-1"> | ||
<Label htmlFor="password">Password</Label> | ||
<TextInput type="password" id="password" {...register('Password')} /> | ||
</div> | ||
<div className="flex flex-col gap-1"> | ||
<Label htmlFor="name">Name</Label> | ||
<TextInput type="text" id="name" {...register('DisplayName')} /> | ||
</div> | ||
|
||
<Button type="submit">Submit</Button> | ||
</form> | ||
</Box> | ||
) | ||
} | ||
export default SignupForm |
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,11 @@ | ||
import * as Yup from 'yup' | ||
|
||
const signupSchema = Yup.object({ | ||
Email: Yup.string().email().required(), | ||
Password: Yup.string().required(), | ||
DisplayName: Yup.string().required(), | ||
}) | ||
|
||
export type SignupFormData = Yup.InferType<typeof signupSchema> | ||
|
||
export default signupSchema |
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,41 @@ | ||
import Layout from '@/components/Layout' | ||
import useEnv from '@/hooks/useEnv' | ||
import SignupForm, { SignupFormProps } from '../components/SignupForm' | ||
import useAuthService from '../service/useAuthService' | ||
|
||
export default function SignupPage() { | ||
const { titleId } = useEnv() | ||
const { registerPlayFabUser } = useAuthService() | ||
|
||
const handleFormSubmit: SignupFormProps['onSubmitForm'] = async ( | ||
formData, | ||
setIsSubmitting, | ||
) => { | ||
try { | ||
const { data } = await registerPlayFabUser({ | ||
...formData, | ||
Username: formData.DisplayName, | ||
titleId, | ||
}) | ||
|
||
if (data.SessionTicket) { | ||
localStorage.setItem('SessionTicket', data.SessionTicket) | ||
} | ||
|
||
/** | ||
* TODO: redirect to the home page | ||
*/ | ||
} catch (error) { | ||
// TODO: handle error | ||
console.log(error) | ||
} finally { | ||
setIsSubmitting(false) | ||
} | ||
} | ||
|
||
return ( | ||
<Layout> | ||
<SignupForm onSubmitForm={handleFormSubmit} /> | ||
</Layout> | ||
) | ||
} |
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 @@ | ||
export { default } from '@/features/Auth/view/SignupPage' |
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