-
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.
ForgotPassword page simply allows the user to invoke the ForgotPassword mutation, which sends a tokenized email to the user so that she can change her password. There is no validation done on the account, so the email will only be sent if the email is associated to an account in the system.
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
Alert, | ||
AlertDescription, | ||
AlertIcon, | ||
AlertTitle, | ||
Box, | ||
Button, | ||
Flex, | ||
} from "@chakra-ui/react"; | ||
import { Form, Formik } from "formik"; | ||
import { withUrqlClient } from "next-urql"; | ||
import React, { useState } from "react"; | ||
import InputField from "../components/InputField"; | ||
import Wrapper from "../components/Wrapper"; | ||
import { useForgotPasswordMutation } from "../generated/graphql"; | ||
import { createUrqlClient } from "../utils/createUrqlClient"; | ||
|
||
interface ForgotPasswordProps {} | ||
const ForgotPassword: React.FC<ForgotPasswordProps> = ({}) => { | ||
const [complete, setComplete] = useState(false); | ||
const [, forgotPassword] = useForgotPasswordMutation(); | ||
|
||
return ( | ||
<Wrapper variant="small"> | ||
<Formik | ||
initialValues={{ email: "" }} | ||
onSubmit={async (values) => { | ||
await forgotPassword(values); | ||
setComplete(true); | ||
}} | ||
> | ||
{({ isSubmitting }) => | ||
complete ? ( | ||
<Alert | ||
status="success" | ||
variant="subtle" | ||
flexDirection="column" | ||
alignItems="center" | ||
justifyContent="center" | ||
textAlign="center" | ||
height="200px" | ||
> | ||
<AlertIcon boxSize="40px" mr={0} /> | ||
<AlertTitle mt={4} mb={1} fontSize="lg"> | ||
Success! | ||
</AlertTitle> | ||
<AlertDescription maxWidth="sm"> | ||
If an account with that email exists, we sent you a reset | ||
password email. | ||
</AlertDescription> | ||
<AlertDescription mt={4} maxWidth="sm"> | ||
<Button colorScheme="green" onClick={() => setComplete(false)}> | ||
Send to a different email | ||
</Button> | ||
</AlertDescription> | ||
</Alert> | ||
) : ( | ||
<Form> | ||
<Box mt={4}> | ||
<InputField | ||
name="email" | ||
placeholder="email" | ||
label="Email" | ||
type="email" | ||
/> | ||
</Box> | ||
<Flex alignItems="baseline"> | ||
<Button | ||
colorScheme="teal" | ||
isLoading={isSubmitting} | ||
mt={4} | ||
type="submit" | ||
> | ||
Send Reset Password Email | ||
</Button> | ||
</Flex> | ||
</Form> | ||
) | ||
} | ||
</Formik> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default withUrqlClient(createUrqlClient)(ForgotPassword); |