Skip to content

Commit

Permalink
Add ForgotPassword functionality
Browse files Browse the repository at this point in the history
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
deduced committed May 6, 2021
1 parent 516c346 commit 5dabd2e
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions client/src/pages/forgot-password.tsx
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);

0 comments on commit 5dabd2e

Please sign in to comment.