BS-001 Initialize BortStack foundation and project workflow
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { useState } from "react";
|
||||
import { Button, Form } from "react-bootstrap";
|
||||
import styles from "../Login/Login.module.scss";
|
||||
|
||||
export default function ForgotPassword() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
setError("");
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const response = await fetch("/api/user/reset-password", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email }),
|
||||
});
|
||||
if (!response.ok) throw new Error("Unable to request a reset link");
|
||||
setSent(true);
|
||||
} catch (requestError) {
|
||||
setError(requestError.message);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<main className={styles.login}>
|
||||
{sent ? <p>If that account exists, a reset link has been sent.</p> : (
|
||||
<Form className={styles.form} onSubmit={submit}>
|
||||
<h1>Reset password</h1>
|
||||
<Form.Label htmlFor="reset-email">Email address</Form.Label>
|
||||
<Form.Control id="reset-email" type="email" value={email} onChange={(event) => setEmail(event.target.value)} required />
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading ? "Sending…" : "Send reset link"}
|
||||
</Button>
|
||||
</Form>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user