fleet/frontend/pages/ForgotPasswordPage/ForgotPasswordPage.tsx
Martavis Parker 384c987389
Removed all traces of Redux from the app! (#5287)
* clean up routes and useless components

* component clean up

* removed redux from routes

* rename file

* moved useDeepEffect hook with others

* removed redux, fleet, app_constants dirs; added types to utilities

* style cleanup

* typo fix

* removed unused ts-ignore comments

* removed redux packages!!!

* formatting

* fixed typing for simple search function

* updated frontend readme
2022-04-22 09:45:35 -07:00

73 lines
1.9 KiB
TypeScript

import React, { useEffect, useState } from "react";
import PATHS from "router/paths";
import usersAPI from "services/entities/users";
import formatErrorResponse from "utilities/format_error_response";
// @ts-ignore
import ForgotPasswordForm from "components/forms/ForgotPasswordForm";
// @ts-ignore
import StackedWhiteBoxes from "components/StackedWhiteBoxes";
import AuthenticationFormWrapper from "components/AuthenticationFormWrapper";
const ForgotPasswordPage = () => {
const [email, setEmail] = useState<string>("");
const [errors, setErrors] = useState<{ [key: string]: string }>({});
useEffect(() => {
setErrors({});
}, []);
const handleSubmit = async (formData: any) => {
try {
await usersAPI.forgotPassword(formData);
setEmail(formData.email);
setErrors({});
} catch (response) {
const errorObject = formatErrorResponse(response);
setEmail("");
setErrors(errorObject);
return false;
}
};
const renderContent = () => {
const baseClass = "forgot-password";
if (email) {
return (
<div>
<div className={`${baseClass}__text-wrapper`}>
<p className={`${baseClass}__text`}>
An email was sent to
<span className={`${baseClass}__email`}> {email}</span>. Click the
link on the email to proceed with the password reset process.
</p>
</div>
</div>
);
}
return (
<ForgotPasswordForm
handleSubmit={handleSubmit}
onChangeFunc={() => setErrors({})}
serverErrors={errors}
/>
);
};
const leadText =
"Enter your email below and we will email you a link so that you can reset your password.";
return (
<AuthenticationFormWrapper>
<StackedWhiteBoxes leadText={leadText} previousLocation={PATHS.LOGIN}>
{renderContent()}
</StackedWhiteBoxes>
</AuthenticationFormWrapper>
);
};
export default ForgotPasswordPage;