-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Display reset password option on log in modal only - Display `resetPassword` modal only when state is not login or signup - Use Firebase hook to send email with reset instructions
- Loading branch information
Showing
3 changed files
with
145 additions
and
6 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,107 @@ | ||
import { Button, Flex, Icon, Image, Input, Text } from "@chakra-ui/react"; | ||
import React, { useState } from "react"; | ||
import { useSendPasswordResetEmail } from "react-firebase-hooks/auth"; | ||
import { BsDot } from "react-icons/bs"; | ||
import { useSetRecoilState } from "recoil"; | ||
import { authModalState } from "../../../atoms/authModalAtom"; | ||
import { auth } from "../../../firebase/clientApp"; | ||
|
||
const ResetPassword: React.FC = () => { | ||
const setAuthModalState = useSetRecoilState(authModalState); | ||
const [email, setEmail] = useState(""); | ||
const [success, setSuccess] = useState(false); | ||
const [sendPasswordResetEmail, sending, error] = | ||
useSendPasswordResetEmail(auth); | ||
|
||
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
await sendPasswordResetEmail(email); | ||
setSuccess(true); | ||
}; | ||
return ( | ||
<Flex direction="column" alignItems="center" width="100%"> | ||
<Image src="/images/logo.svg" height="40px" mb={2} alt="Website logo"/> | ||
<Text fontWeight={700} mb={2}> | ||
Reset your password | ||
</Text> | ||
{success ? ( | ||
<Text mb={4}>Check your email</Text> | ||
) : ( | ||
<> | ||
<Text fontSize="sm" textAlign="center" mb={2}> | ||
Enter the email associated with your account and we will send you a | ||
reset link | ||
</Text> | ||
<form onSubmit={onSubmit} style={{ width: "100%" }}> | ||
<Input | ||
required | ||
name="email" | ||
placeholder="Email" | ||
type="email" | ||
mb={2} | ||
onChange={(event) => setEmail(event.target.value)} | ||
fontSize="10pt" | ||
_placeholder={{ color: "gray.500" }} | ||
_hover={{ | ||
bg: "white", | ||
border: "1px solid", | ||
borderColor: "blue.500", | ||
}} | ||
_focus={{ | ||
outline: "none", | ||
bg: "white", | ||
border: "1px solid", | ||
borderColor: "blue.500", | ||
}} | ||
bg="gray.50" | ||
/> | ||
<Text textAlign="center" fontSize="10pt" color="red"> | ||
{error?.message} | ||
</Text> | ||
<Button | ||
width="100%" | ||
height="36px" | ||
mb={2} | ||
mt={2} | ||
type="submit" | ||
isLoading={sending} | ||
> | ||
Reset Password | ||
</Button> | ||
</form> | ||
</> | ||
)} | ||
<Flex | ||
alignItems="center" | ||
fontSize="9pt" | ||
color="red.500" | ||
fontWeight={700} | ||
cursor="pointer" | ||
> | ||
<Text | ||
onClick={() => | ||
setAuthModalState((prev) => ({ | ||
...prev, | ||
view: "login", | ||
})) | ||
} | ||
> | ||
LOGIN | ||
</Text> | ||
<Icon as={BsDot} /> | ||
<Text | ||
onClick={() => | ||
setAuthModalState((prev) => ({ | ||
...prev, | ||
view: "signup", | ||
})) | ||
} | ||
> | ||
SIGN UP | ||
</Text> | ||
</Flex> | ||
</Flex> | ||
); | ||
}; | ||
export default ResetPassword; |