BS-001 Initialize BortStack foundation and project workflow
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { useState } from "react";
|
||||
import { Button, Form } from "react-bootstrap";
|
||||
import styles from "./Contact.module.scss";
|
||||
|
||||
const initialValues = {
|
||||
name: "",
|
||||
email: "",
|
||||
subject: "",
|
||||
message: "",
|
||||
website: "",
|
||||
};
|
||||
|
||||
export default function Contact() {
|
||||
const [values, setValues] = useState(initialValues);
|
||||
const [status, setStatus] = useState("idle");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
function update(field, value) {
|
||||
setValues((current) => ({ ...current, [field]: value }));
|
||||
}
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
setStatus("sending");
|
||||
setError("");
|
||||
try {
|
||||
const response = await fetch("/api/contact", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(values),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || "Unable to send message");
|
||||
}
|
||||
setValues(initialValues);
|
||||
setStatus("sent");
|
||||
} catch (requestError) {
|
||||
setError(requestError.message);
|
||||
setStatus("error");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<main className={styles.contact}>
|
||||
<section>
|
||||
<h1>Contact</h1>
|
||||
<p>Use this form to contact the application team.</p>
|
||||
{status === "sent" ? (
|
||||
<p role="status">Your message has been sent.</p>
|
||||
) : (
|
||||
<Form onSubmit={submit}>
|
||||
<Form.Group className={styles.field} controlId="contact-name">
|
||||
<Form.Label>Name</Form.Label>
|
||||
<Form.Control value={values.name} maxLength={100} onChange={(event) => update("name", event.target.value)} required />
|
||||
</Form.Group>
|
||||
<Form.Group className={styles.field} controlId="contact-email">
|
||||
<Form.Label>Email</Form.Label>
|
||||
<Form.Control type="email" value={values.email} onChange={(event) => update("email", event.target.value)} required />
|
||||
</Form.Group>
|
||||
<Form.Group className={styles.field} controlId="contact-subject">
|
||||
<Form.Label>Subject</Form.Label>
|
||||
<Form.Control value={values.subject} maxLength={150} onChange={(event) => update("subject", event.target.value)} required />
|
||||
</Form.Group>
|
||||
<Form.Group className={styles.field} controlId="contact-message">
|
||||
<Form.Label>Message</Form.Label>
|
||||
<Form.Control as="textarea" rows={6} minLength={10} maxLength={5000} value={values.message} onChange={(event) => update("message", event.target.value)} required />
|
||||
</Form.Group>
|
||||
<div className={styles.honeypot} aria-hidden="true">
|
||||
<label htmlFor="contact-website">Website</label>
|
||||
<input id="contact-website" name="website" tabIndex={-1} autoComplete="off" value={values.website} onChange={(event) => update("website", event.target.value)} />
|
||||
</div>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<Button type="submit" disabled={status === "sending"}>
|
||||
{status === "sending" ? "Sending…" : "Send message"}
|
||||
</Button>
|
||||
</Form>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
.contact {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
|
||||
section {
|
||||
width: min(100%, 36rem);
|
||||
}
|
||||
}
|
||||
|
||||
.field {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.honeypot {
|
||||
position: absolute;
|
||||
left: -10000px;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
}
|
||||
Reference in New Issue
Block a user