deploy / deploy (push) Successful in 1m24s
rebuild the public site on the Next.js App Router with static export, per-section SEO pages, metadata, sitemap, robots and a generated OG image add full-screen scroll-snap regions, staged scroll reveals, a hash-free tab navigation with a sliding indicator and region-by-region menu scrolling replace the theme text toggle with animated sun/moon icons restructure the CRM API into config, middleware, models, routes, services and utils layers redesign the CRM shell with a single surface, tab rail, full-width blurred DataTable, record dialogs and mask-based icons update Docker/Nginx publishing, Makefile targets, shared UI polish and docs Co-authored-by: Gitea Actions <-[email protected]>
158 lines
4.7 KiB
TypeScript
158 lines
4.7 KiB
TypeScript
"use client";
|
|
|
|
import { useState, type FormEvent } from "react";
|
|
import { Input } from "@cohaise/ui";
|
|
import { useLanguage } from "../contexts/LanguageContext";
|
|
import { LEADS_ENDPOINT } from "../lib/api";
|
|
import { Section, SectionHeading } from "./Section";
|
|
|
|
type Status = "idle" | "sending" | "success" | "error";
|
|
|
|
const text = (value: FormDataEntryValue | null): string =>
|
|
String(value ?? "").trim();
|
|
|
|
export const Contact = () => {
|
|
const { t } = useLanguage();
|
|
const [status, setStatus] = useState<Status>("idle");
|
|
|
|
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
const form = event.currentTarget;
|
|
const data = new FormData(form);
|
|
|
|
const payload = {
|
|
firstName: text(data.get("firstName")),
|
|
lastName: text(data.get("lastName")),
|
|
email: text(data.get("email")),
|
|
organization: text(data.get("organization")) || null,
|
|
phone: text(data.get("phone")) || null,
|
|
message: text(data.get("message")),
|
|
website: text(data.get("website")),
|
|
};
|
|
|
|
if (!payload.firstName || !payload.lastName || !payload.email) {
|
|
setStatus("error");
|
|
return;
|
|
}
|
|
|
|
setStatus("sending");
|
|
try {
|
|
const response = await fetch(LEADS_ENDPOINT, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
if (!response.ok) throw new Error("request failed");
|
|
setStatus("success");
|
|
form.reset();
|
|
} catch {
|
|
setStatus("error");
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Section id="contact">
|
|
<SectionHeading
|
|
title={t("contact.title")}
|
|
subtitle={t("contact.subtitle")}
|
|
/>
|
|
|
|
<form
|
|
onSubmit={(event) => void handleSubmit(event)}
|
|
className="glass max-w-2xl rounded-lg border border-border/60 p-5 sm:p-6"
|
|
data-reveal
|
|
data-reveal-delay="0.1"
|
|
noValidate
|
|
>
|
|
<input
|
|
type="text"
|
|
name="website"
|
|
tabIndex={-1}
|
|
autoComplete="off"
|
|
aria-hidden="true"
|
|
className="absolute -left-[9999px] h-px w-px opacity-0"
|
|
/>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<Input
|
|
name="firstName"
|
|
label={t("contact.firstName")}
|
|
required
|
|
autoComplete="given-name"
|
|
/>
|
|
<Input
|
|
name="lastName"
|
|
label={t("contact.lastName")}
|
|
required
|
|
autoComplete="family-name"
|
|
/>
|
|
</div>
|
|
|
|
<div className="mt-3 grid grid-cols-2 gap-3">
|
|
<Input
|
|
name="organization"
|
|
label={t("contact.company")}
|
|
autoComplete="organization"
|
|
/>
|
|
<Input
|
|
name="phone"
|
|
label={t("contact.phone")}
|
|
type="tel"
|
|
autoComplete="tel"
|
|
/>
|
|
</div>
|
|
|
|
<div className="mt-3">
|
|
<Input
|
|
name="email"
|
|
label={t("contact.email")}
|
|
type="email"
|
|
required
|
|
autoComplete="email"
|
|
/>
|
|
</div>
|
|
|
|
<div className="mt-3 flex flex-col gap-1.5">
|
|
<label
|
|
htmlFor="message"
|
|
className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground"
|
|
>
|
|
{t("contact.message")}
|
|
</label>
|
|
<textarea
|
|
id="message"
|
|
name="message"
|
|
rows={4}
|
|
required
|
|
className="w-full rounded-sm border border-border-control bg-surface px-3 py-2.5 text-sm text-foreground placeholder:text-subtle-foreground transition-[border-color,box-shadow] duration-fast focus-visible:border-border-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
/>
|
|
</div>
|
|
|
|
<div className="mt-5 flex flex-wrap items-center gap-4">
|
|
<button
|
|
type="submit"
|
|
disabled={status === "sending"}
|
|
className="inline-flex h-12 items-center gap-2.5 rounded-lg bg-primary px-6 font-display text-sm font-semibold uppercase tracking-label text-primary-foreground transition-colors hover:bg-primary-hover disabled:pointer-events-none disabled:opacity-50"
|
|
>
|
|
{status === "sending"
|
|
? t("contact.sending")
|
|
: t("contact.submit")}
|
|
</button>
|
|
|
|
{status === "success" ? (
|
|
<p className="text-sm text-success" role="status">
|
|
{t("contact.success")}
|
|
</p>
|
|
) : null}
|
|
|
|
{status === "error" ? (
|
|
<p className="text-sm text-destructive" role="alert">
|
|
{t("contact.error")}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
</form>
|
|
</Section>
|
|
);
|
|
};
|