fix(ui): forgot password success feedback (#11437)

This commit is contained in:
Chirag Madlani 2023-05-08 13:49:35 +05:30 committed by GitHub
parent 7c60c85d71
commit 94ef30c3d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View File

@ -166,7 +166,6 @@ const BasicAuthProvider = ({
const handleForgotPassword = async (email: string) => { const handleForgotPassword = async (email: string) => {
try { try {
setLoadingIndicator(true);
await generatePasswordResetLink(email); await generatePasswordResetLink(email);
} catch (err) { } catch (err) {
if ( if (
@ -177,8 +176,6 @@ const BasicAuthProvider = ({
} else { } else {
showErrorToast(t('server.email-not-found')); showErrorToast(t('server.email-not-found'));
} }
} finally {
setLoadingIndicator(false);
} }
}; };

View File

@ -13,7 +13,7 @@
import { Button, Card, Col, Divider, Form, Input, Row, Typography } from 'antd'; import { Button, Card, Col, Divider, Form, Input, Row, Typography } from 'antd';
import { useBasicAuth } from 'components/authentication/auth-provider/basic-auth.provider'; import { useBasicAuth } from 'components/authentication/auth-provider/basic-auth.provider';
import React, { useState } from 'react'; import React, { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { ROUTES } from '../../constants/constants'; import { ROUTES } from '../../constants/constants';
@ -24,17 +24,24 @@ const ForgotPassword = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { handleForgotPassword } = useBasicAuth(); const { handleForgotPassword } = useBasicAuth();
const history = useHistory(); const history = useHistory();
const [loading, setLoading] = useState(false);
const [showResetLinkSentAlert, setShowResetLinkSentAlert] = useState(false); const [showResetLinkSentAlert, setShowResetLinkSentAlert] = useState(false);
const handleSubmit = async (data: { email: string }) => { const handleSubmit = useCallback(
try { async (data: { email: string }) => {
handleForgotPassword && (await handleForgotPassword(data.email)); try {
setShowResetLinkSentAlert(true); setLoading(true);
} catch (error) { handleForgotPassword && (await handleForgotPassword(data.email));
setShowResetLinkSentAlert(false); setShowResetLinkSentAlert(true);
} } catch (error) {
}; setShowResetLinkSentAlert(false);
} finally {
setLoading(false);
}
},
[setShowResetLinkSentAlert, handleForgotPassword]
);
return ( return (
<div className="h-full py-24 forgot-password-container "> <div className="h-full py-24 forgot-password-container ">
@ -77,7 +84,7 @@ const ForgotPassword = () => {
</Form.Item> </Form.Item>
</Col> </Col>
<Col className="m-t-md" span={24}> <Col className="m-t-md" span={24}>
<Button className="w-full" htmlType="submit" type="primary"> <Button block htmlType="submit" loading={loading} type="primary">
{t('label.submit')} {t('label.submit')}
</Button> </Button>
</Col> </Col>