|
| 1 | +import { useState } from "react"; |
| 2 | +import AccountForm from "../AccountForm/accountForm"; |
| 3 | +import accountForm from "../AccountForm/accountForm.module.css"; |
| 4 | +import FormField from "../FormField/formField"; |
| 5 | +import Layout from "../Layout/layout"; |
| 6 | +import { CONFIRMED_STATE } from "../lib/states"; |
| 7 | + |
| 8 | +export default function ForgotPassword(props) { |
| 9 | + const [email, setEmail] = useState(""); |
| 10 | + |
| 11 | + const handleEmailSubmit = (e, setConfirmed) => { |
| 12 | + fetch(`https://api.borumtech.com/api/v1/register`, { |
| 13 | + method: "put", |
| 14 | + headers: { |
| 15 | + "Content-Type": "application/x-www-form-urlencoded", |
| 16 | + }, |
| 17 | + body: `email=${email}`, |
| 18 | + }) |
| 19 | + .then(response => { |
| 20 | + if (response.ok) { |
| 21 | + return response.json(); |
| 22 | + } |
| 23 | + }) |
| 24 | + .then(response => setConfirmed(CONFIRMED_STATE.SUCCESS)) |
| 25 | + .catch(response => { |
| 26 | + setConfirmed(CONFIRMED_STATE.FAILURE); |
| 27 | + console.error(response); |
| 28 | + }); |
| 29 | + }; |
| 30 | + |
| 31 | + return ( |
| 32 | + <Layout> |
| 33 | + <AccountForm |
| 34 | + heading="Reset your Password" |
| 35 | + instructions="We'll send you an email with instructions on how to reset |
| 36 | + your password" |
| 37 | + messageAfterSubmission={ |
| 38 | + "An email will be sent to you shortly with instructions to change your password." |
| 39 | + } |
| 40 | + formProps={{ |
| 41 | + method: "post", |
| 42 | + }} |
| 43 | + handleSubmit={handleEmailSubmit} |
| 44 | + > |
| 45 | + <FormField |
| 46 | + autofocus |
| 47 | + label="email" |
| 48 | + labelContent="Enter your Email" |
| 49 | + value={email} |
| 50 | + onChange={e => setEmail(e.target.value)} |
| 51 | + /> |
| 52 | + <button type="submit" className={accountForm.card}> |
| 53 | + Send Email |
| 54 | + </button> |
| 55 | + </AccountForm> |
| 56 | + </Layout> |
| 57 | + ); |
| 58 | +} |
0 commit comments