-
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.
Merge pull request #17 from winningwizardtechnologies/feature/forgot-…
…password forgot-password
- Loading branch information
Showing
3 changed files
with
80 additions
and
2 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,75 @@ | ||
import { MailOutlined } from '@ant-design/icons'; | ||
import { Button, Col, Form, Input, Row, Typography } from 'antd'; | ||
import { sendPasswordResetEmail } from 'firebase/auth'; | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { auth } from '../Firebase/firebase'; | ||
import useNotification from 'antd/es/notification/useNotification'; | ||
|
||
const ForgotPassword: React.FC = () => { | ||
const [resetClicked, setResetClicked] = React.useState(false); | ||
const [api, contextHolder] = useNotification(); | ||
|
||
const onFinish = async (values: { email: string }) => { | ||
try { | ||
await sendPasswordResetEmail(auth, values.email); | ||
setResetClicked(true); | ||
} catch (error) { | ||
api.error({ | ||
message: 'Reset Failed', | ||
placement: 'top', | ||
description: 'Failed to send the reset email, Please try again later' | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{contextHolder} | ||
<Row gutter={[0, 20]} justify={'center'}> | ||
<Col xs={24} sm={20} md={15}> | ||
<Typography.Text> | ||
{resetClicked ? 'Reset Link Sent:' : 'Forgot Password:'} | ||
</Typography.Text> | ||
</Col> | ||
<Col xs={24} sm={20} md={15}> | ||
{resetClicked ? ( | ||
<Typography.Text> | ||
We sent a link to your email with instructions to reset your | ||
password! | ||
</Typography.Text> | ||
) : ( | ||
<Form onFinish={onFinish}> | ||
<Form.Item | ||
rules={[ | ||
{ required: true, message: 'Please input your email!' } | ||
]} | ||
name='email' | ||
> | ||
<Input | ||
prefix={<MailOutlined className='site-form-item-icon' />} | ||
placeholder='Enter Your Email' | ||
type='email' | ||
/> | ||
</Form.Item> | ||
<Form.Item style={{ display: 'flex', justifyContent: 'center' }}> | ||
<Button | ||
type='primary' | ||
htmlType='submit' | ||
className='login-form-button' | ||
> | ||
Reset | ||
</Button> | ||
</Form.Item> | ||
</Form> | ||
)} | ||
</Col> | ||
<Col xs={24} sm={20} md={15}> | ||
<Link to='/'>Go Back to Login Page</Link> | ||
</Col> | ||
</Row> | ||
</> | ||
); | ||
}; | ||
|
||
export default ForgotPassword; |