mirror of
https://github.com/TheRealOwenRees/chess-scribe-website.git
synced 2026-07-23 09:56:57 +00:00
rudimentary contact form boilerplate
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
- og / json-sd
|
- og / json-sd
|
||||||
- rearrange buttons / header space - collapse on smaller screens
|
|
||||||
- Lichess login
|
- Lichess login
|
||||||
- logger
|
- logger
|
||||||
- contact form
|
- contact form
|
||||||
- bring sections headers on all pages other than home page further up (reduce top margin / padding)
|
- bring sections headers on all pages other than home page further up (reduce top margin / padding)
|
||||||
- set game current position on game load to ply 0 and whatever the FEN is (starting position probably, but could be custom position)
|
- set game current position on game load to ply 0 and whatever the FEN is (starting position probably, but could be custom position)
|
||||||
- privacy policy - have no access to anything you generate, only keep a count of success/failed pdf generations with timestamp and error message
|
- privacy policy - have no access to anything you generate, only keep a count of success/failed pdf generations with timestamp and error message
|
||||||
- fix SSR related console errors etc
|
|
||||||
- a11y and lighthouse fixes
|
- a11y and lighthouse fixes
|
||||||
- check wcag compliance
|
- check wcag compliance
|
||||||
|
- white background?
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
const Contact = () => <div>Hello "/contact"!</div>;
|
|
||||||
|
|
||||||
export default Contact;
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import Contact from "#/pages/Contact/Contact.tsx";
|
||||||
|
|
||||||
|
const ContactContainer = () => {
|
||||||
|
const handleSubmit = async (_prevState: unknown, data: FormData) => {
|
||||||
|
const name = data.get("name");
|
||||||
|
const email = data.get("email");
|
||||||
|
const subject = data.get("subject");
|
||||||
|
const message = data.get("message");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return { success: true, message: "Message sent!" };
|
||||||
|
} catch (error) {
|
||||||
|
// TODO logger
|
||||||
|
console.error("Error sending message:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to send message. Please try again.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return <Contact handleSubmit={handleSubmit} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ContactContainer;
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import { useActionState } from "react";
|
||||||
|
import Section from "#/components/Section.tsx";
|
||||||
|
|
||||||
|
interface IFormField {
|
||||||
|
fieldName: string;
|
||||||
|
type: "text" | "email" | "textarea";
|
||||||
|
placeholder: string;
|
||||||
|
label: string;
|
||||||
|
required: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type IProps = {
|
||||||
|
handleSubmit: (
|
||||||
|
prevState: unknown,
|
||||||
|
formData: FormData,
|
||||||
|
) => Promise<{ success: boolean; message: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormField = ({
|
||||||
|
type,
|
||||||
|
fieldName,
|
||||||
|
placeholder,
|
||||||
|
label,
|
||||||
|
required,
|
||||||
|
}: IFormField) => (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<label htmlFor={fieldName}>{label}</label>
|
||||||
|
<input
|
||||||
|
type={type}
|
||||||
|
id={fieldName}
|
||||||
|
name={fieldName}
|
||||||
|
placeholder={placeholder}
|
||||||
|
required={required}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const Contact = ({ handleSubmit }: IProps) => {
|
||||||
|
const [state, formAction, isPending] = useActionState(handleSubmit, null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="px-4 pb-8 place-self-center min-h-[calc(100vh-226px)]">
|
||||||
|
<Section
|
||||||
|
title="Contact Us"
|
||||||
|
description="Do you have suggestions on how to improve this service? Would you like to get involved with this project? Ask us anything you like."
|
||||||
|
>
|
||||||
|
<form action={formAction}>
|
||||||
|
<FormField
|
||||||
|
type="text"
|
||||||
|
fieldName="name"
|
||||||
|
placeholder="Your name"
|
||||||
|
label="Name"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
fieldName="email"
|
||||||
|
type="text"
|
||||||
|
placeholder="name@example.com"
|
||||||
|
label="Email"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="subject"
|
||||||
|
placeholder="Reason for contacting us"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
name="message"
|
||||||
|
placeholder="Your message here..."
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={isPending}
|
||||||
|
className="btn btn-primary"
|
||||||
|
>
|
||||||
|
{isPending ? "Sending..." : "Send"}
|
||||||
|
</button>
|
||||||
|
{state && <p>{state.message}</p>}
|
||||||
|
</form>
|
||||||
|
</Section>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Contact;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
import { HOST_URL } from "#/config.ts";
|
import { HOST_URL } from "#/config.ts";
|
||||||
import Contact from "#/pages/Contact.tsx";
|
import ContactContainer from "#/pages/Contact/Contact.container.tsx";
|
||||||
|
|
||||||
export const Route = createFileRoute("/contact")({
|
export const Route = createFileRoute("/contact")({
|
||||||
head: () => ({
|
head: () => ({
|
||||||
@@ -11,5 +11,5 @@ export const Route = createFileRoute("/contact")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return <Contact />;
|
return <ContactContainer />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user