fleet/frontend/pages/ForgotPasswordPage/ForgotPasswordPage.tsx
RachelElysia c9e66b221e
Frontend: Lint warning cleanup part 1 (#43411)
## Issue
- First batch of @iansltx 's work of cleaning up lint warnings #43387 

## Description
- Quick PR review and grabbed as many confirmed low-risk quick wins as I
could `git checkout lint-cleanup <file/path/1> <file/path/2>`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

This release contains internal code improvements with one minor UI
tweak:

* **Style**
* Dropdown menu background color adjusted for clearer contrast in action
lists
* **Refactor**
* Improved type safety across the codebase with stricter TypeScript
annotations
  * Removed unused imports and constants to reduce code clutter
* Enhanced React hook dependency arrays for more consistent component
behavior
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Rachel Perkins <rachel@Rachels-MacBook-Pro.local>
Co-authored-by: Ian Littman <iansltx@gmail.com>
2026-04-10 19:49:52 -05:00

89 lines
2.6 KiB
TypeScript

import React, { useEffect, useState } from "react";
import { InjectedRouter } from "react-router";
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";
import AuthenticationNav from "components/AuthenticationNav";
import AuthenticationFormWrapper from "components/AuthenticationFormWrapper";
import CustomLink from "components/CustomLink";
interface IForgotPasswordPage {
router: InjectedRouter;
}
const ForgotPasswordPage = ({ router }: IForgotPasswordPage) => {
const [email, setEmail] = useState("");
const [errors, setErrors] = useState<{ [key: string]: string }>({});
const [isLoading, setIsLoading] = useState(false);
const baseClass = "forgot-password";
useEffect(() => {
setErrors({});
}, []);
const handleSubmit = async (formData: { email: string }) => {
setIsLoading(true);
try {
await usersAPI.forgotPassword(formData);
setEmail(formData.email);
setErrors({});
} catch (response) {
const errorObject = formatErrorResponse(response);
setEmail("");
setErrors(errorObject);
} finally {
setIsLoading(false);
}
};
const renderContent = () => {
if (email) {
return (
<div className={`${baseClass}__text-wrapper`}>
<p className={`${baseClass}__text`}>
An email was sent to{" "}
<span className={`${baseClass}__email`}>{email}</span>. Click the
link in the email to proceed with the password reset process. If you
did not receive an email please contact your Fleet administrator.
<br />
<br />
You can find more information on resetting passwords at the{" "}
<CustomLink
url="https://fleetdm.com/docs/using-fleet/fleetctl-cli?utm_medium=fleetui&utm_campaign=get-api-token#using-fleetctl-with-an-api-only-user"
text="Password reset FAQ"
newTab
/>
</p>
</div>
);
}
return (
<ForgotPasswordForm
handleSubmit={handleSubmit}
onChangeFunc={() => setErrors({})}
serverErrors={errors}
isLoading={isLoading}
/>
);
};
return (
<AuthenticationFormWrapper
header="Reset password"
headerCta={
<AuthenticationNav previousLocation={PATHS.LOGIN} router={router} />
}
className={baseClass}
>
{renderContent()}
</AuthenticationFormWrapper>
);
};
export default ForgotPasswordPage;