-
Notifications
You must be signed in to change notification settings - Fork 37
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
1 parent
75e58e4
commit 676d3a6
Showing
6 changed files
with
144 additions
and
3 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,48 @@ | ||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { EmailSignUpSchema, EmailSignUpType } from "types"; | ||
|
||
import { Button } from "components/ui/Button/Button"; | ||
import ErrorMessage from "components/ui/ErrorMessage"; | ||
import { Input } from "components/ui/Input/Input"; | ||
|
||
const SignupWithEmail = () => { | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm<EmailSignupType>({ | ||
resolver: zodResolver(EmailSignUpSchema), | ||
}); | ||
|
||
const onSubmit: SubmitHandler<EmailSignupType> = async ( | ||
data: EmailSignupType, | ||
) => { | ||
// TODO: Add an api endpoint to create EmailSignUpToken and send email to | ||
// submitted email. User gets link in email to /register/{token} | ||
// to finish sign up | ||
|
||
console.log(data); | ||
}; | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit(onSubmit)} | ||
className="grid grid-cols-1 space-y-6"> | ||
{/* Email Input */} | ||
<div className="relative"> | ||
<Input placeholder="Email" type="text" {...register("email")} /> | ||
{errors?.email && <ErrorMessage>{errors?.email?.message}</ErrorMessage>} | ||
</div> | ||
{/* Signup Button */} | ||
<Button | ||
variant="outline" | ||
className="w-full text-white bg-blue-600 hover:bg-opacity-70"> | ||
Sign up with email | ||
</Button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default SignupWithEmail; |
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,65 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
|
||
import { paths } from "gen/api"; | ||
import { useAlertQueue } from "hooks/useAlertQueue"; | ||
import { useAuthentication } from "hooks/useAuth"; | ||
|
||
import SignupForm from "components/auth/SignupForm"; | ||
import { Button } from "components/ui/Button/Button"; | ||
|
||
type EmailSignUpResponse = | ||
paths["/emailSignUp/{token}"]["get"]["responses"][200]["content"]["application/json"]; | ||
|
||
const Register = () => { | ||
const { addErrorAlert } = useAlertQueue(); | ||
const { token } = useParams(); | ||
const [emailToken, setEmailToken] = useState<EmailSignUpResponse | null>( | ||
null, | ||
); | ||
const auth = useAuthentication(); | ||
|
||
useEffect(() => { | ||
const fetchListing = async () => { | ||
if (token === undefined) { | ||
return; | ||
} | ||
|
||
try { | ||
const { data, error } = await auth.client.GET("/emailSignUp/{token}", { | ||
params: { | ||
path: { token }, | ||
}, | ||
}); | ||
if (error) { | ||
addErrorAlert(error); | ||
} else { | ||
setEmailToken(data); | ||
} | ||
} catch (err) { | ||
addErrorAlert(err); | ||
} | ||
}; | ||
fetchListing(); | ||
}, [token]); | ||
|
||
if (!emailToken) { | ||
return ( | ||
<div> | ||
<h1>Invalid Sign Up Link</h1> | ||
<Button | ||
variant="outline" | ||
className="w-full text-white bg-blue-600 hover:bg-opacity-70"> | ||
Login / Signup | ||
</Button> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div> | ||
<SignupForm /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Register; |
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