396 lines
16 KiB
TypeScript
396 lines
16 KiB
TypeScript
"use client";
|
||
|
||
import { useState } from "react";
|
||
|
||
interface OeffnungsZeit { tag: string; von: string; bis: string }
|
||
|
||
interface ContactProps {
|
||
telefon?: string;
|
||
email?: string;
|
||
adresseZeile1?: string;
|
||
adresseZeile2?: string;
|
||
oeffnungszeiten?: OeffnungsZeit[];
|
||
}
|
||
|
||
type Status = "idle" | "loading" | "success" | "error";
|
||
type Zielgruppe = "privat" | "geschaeftlich";
|
||
|
||
const themen: Record<Zielgruppe, string[]> = {
|
||
privat: [
|
||
"Mein WLAN ist langsam oder instabil",
|
||
"PC / Notebook läuft nicht richtig",
|
||
"Neuen Computer einrichten",
|
||
"Daten sichern / Fotos retten",
|
||
"Familienschutz (FamilyGuard)",
|
||
"Eigene Cloud (Nextcloud)",
|
||
"Sonstiges",
|
||
],
|
||
geschaeftlich: [
|
||
"IT-Betreuung & Support",
|
||
"Netzwerk & WLAN",
|
||
"Sicherer Fernzugriff (VPN)",
|
||
"Dokumentenarchiv (Nextcloud + Paperless)",
|
||
"Datensicherung & Backup",
|
||
"IT-Sicherheit & Datenschutz",
|
||
"Server, Cloud & Hosting",
|
||
"Webseite / Webanwendung",
|
||
"Sonstiges",
|
||
],
|
||
};
|
||
|
||
const inputClass =
|
||
"w-full px-4 py-3 rounded-xl bg-slate-50 dark:bg-[#111925] border border-slate-300 dark:border-gray-700 text-slate-900 dark:text-white placeholder-slate-400 dark:placeholder-slate-600 focus:outline-none focus:border-orange-500/60 focus:ring-1 focus:ring-orange-500/20 transition-colors";
|
||
const labelClass = "block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2";
|
||
|
||
export default function Contact({
|
||
telefon = "+49 171 9345193",
|
||
email = "kontakt@mbo-tech-it.de",
|
||
adresseZeile1 = "Mörikestr. 2",
|
||
adresseZeile2 = "74564 Crailsheim",
|
||
oeffnungszeiten,
|
||
}: ContactProps = {}) {
|
||
const contactItems = [
|
||
{
|
||
icon: (
|
||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z" />
|
||
</svg>
|
||
),
|
||
label: "Telefon",
|
||
value: telefon,
|
||
href: `tel:${telefon.replace(/\s/g, "")}`,
|
||
},
|
||
{
|
||
icon: (
|
||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
||
</svg>
|
||
),
|
||
label: "E-Mail",
|
||
value: email,
|
||
href: `mailto:${email}`,
|
||
},
|
||
{
|
||
icon: (
|
||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
|
||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
|
||
</svg>
|
||
),
|
||
label: "Standort",
|
||
value: `${adresseZeile1}, ${adresseZeile2}`,
|
||
href: `https://maps.google.com/?q=${encodeURIComponent(adresseZeile1 + " " + adresseZeile2)}`,
|
||
},
|
||
];
|
||
|
||
const [name, setName] = useState("");
|
||
const [emailInput, setEmailInput] = useState("");
|
||
const [zielgruppe, setZielgruppe] = useState<Zielgruppe>("privat");
|
||
const [firma, setFirma] = useState("");
|
||
const [telefonInput, setTelefonInput] = useState("");
|
||
const [betreff, setBetreff] = useState("");
|
||
const [nachricht, setNachricht] = useState("");
|
||
const [website, setWebsite] = useState(""); // Honeypot
|
||
const [startedAt, setStartedAt] = useState(() => Date.now());
|
||
const [status, setStatus] = useState<Status>("idle");
|
||
const [errorMsg, setErrorMsg] = useState("");
|
||
|
||
async function handleSubmit(e: React.FormEvent) {
|
||
e.preventDefault();
|
||
setStatus("loading");
|
||
setErrorMsg("");
|
||
|
||
try {
|
||
const res = await fetch("/api/contact", {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify({
|
||
website,
|
||
_t: startedAt,
|
||
name,
|
||
email: emailInput,
|
||
telefon: telefonInput.trim() || undefined,
|
||
betreff: `${zielgruppe === "privat" ? "Privat" : "Geschäftlich"}: ${betreff}`,
|
||
nachricht:
|
||
zielgruppe === "geschaeftlich" && firma.trim()
|
||
? `Firma: ${firma.trim()}${nachricht ? `
|
||
|
||
${nachricht}` : ""}`
|
||
: nachricht,
|
||
}),
|
||
});
|
||
const data = await res.json();
|
||
|
||
if (!res.ok || !data.ok) {
|
||
setErrorMsg(data.error ?? "Unbekannter Fehler");
|
||
setStatus("error");
|
||
} else {
|
||
setStatus("success");
|
||
}
|
||
} catch {
|
||
setErrorMsg("Netzwerkfehler – bitte versuchen Sie es erneut.");
|
||
setStatus("error");
|
||
}
|
||
}
|
||
|
||
return (
|
||
<section id="contact" className="py-24 px-4 sm:px-6 lg:px-8 relative">
|
||
<div className="absolute inset-0 bg-[#e8eef4] dark:bg-[#111925]" />
|
||
<div className="absolute inset-0 bg-grid opacity-40" />
|
||
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,rgba(249,115,22,0.07)_0%,transparent_70%)]" />
|
||
|
||
<div className="max-w-4xl mx-auto relative">
|
||
{/* Header */}
|
||
<div className="text-center mb-12">
|
||
<h2 className="text-4xl sm:text-5xl font-black text-slate-900 dark:text-white mb-4">
|
||
Projekt anfragen
|
||
</h2>
|
||
<p className="text-slate-600 dark:text-slate-400 text-lg max-w-xl mx-auto">
|
||
Sie haben ein IT-Projekt oder eine Frage? Schreiben Sie uns,
|
||
wir melden uns schnellstmöglich bei Ihnen.
|
||
</p>
|
||
</div>
|
||
|
||
<div className="bg-white dark:bg-gray-900 border border-slate-200 dark:border-gray-800 rounded-3xl p-8 sm:p-10">
|
||
{status === "success" ? (
|
||
<div className="flex flex-col items-center justify-center py-10 text-center">
|
||
<div className="w-16 h-16 rounded-full bg-orange-500/10 border border-orange-500/30 flex items-center justify-center mb-6">
|
||
<svg className="w-8 h-8 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||
</svg>
|
||
</div>
|
||
<h3 className="text-2xl font-bold text-slate-900 dark:text-white mb-2">Anfrage gesendet!</h3>
|
||
<p className="text-slate-600 dark:text-slate-400 mb-8">
|
||
Wir haben Ihre Nachricht erhalten und melden uns schnellstmöglich bei Ihnen.
|
||
</p>
|
||
<button
|
||
onClick={() => {
|
||
setStatus("idle");
|
||
setName("");
|
||
setEmailInput("");
|
||
setTelefonInput("");
|
||
setFirma("");
|
||
setBetreff("");
|
||
setNachricht("");
|
||
setStartedAt(Date.now());
|
||
}}
|
||
className="btn-secondary px-6 py-2"
|
||
>
|
||
Neue Anfrage
|
||
</button>
|
||
</div>
|
||
) : (
|
||
<form className="space-y-6" onSubmit={handleSubmit}>
|
||
{/* Honeypot: für Menschen unsichtbar, Bots füllen es aus */}
|
||
<div aria-hidden="true" className="absolute -left-[9999px] h-0 w-0 overflow-hidden">
|
||
<label htmlFor="contact-website">Website</label>
|
||
<input
|
||
id="contact-website"
|
||
type="text"
|
||
name="website"
|
||
tabIndex={-1}
|
||
autoComplete="off"
|
||
value={website}
|
||
onChange={(e) => setWebsite(e.target.value)}
|
||
/>
|
||
</div>
|
||
<fieldset>
|
||
<legend className={labelClass}>Ich melde mich als</legend>
|
||
<div className="grid grid-cols-2 gap-3">
|
||
{([
|
||
["privat", "Privatkunde"],
|
||
["geschaeftlich", "Geschäftskunde"],
|
||
] as const).map(([value, label]) => (
|
||
<label
|
||
key={value}
|
||
className={`cursor-pointer text-center px-4 py-3 rounded-xl border text-sm font-bold transition-colors ${
|
||
zielgruppe === value
|
||
? "border-orange-500 bg-orange-500/10 text-orange-500 dark:text-orange-400"
|
||
: "border-slate-300 dark:border-gray-700 text-slate-600 dark:text-slate-400 hover:border-orange-500/40"
|
||
}`}
|
||
>
|
||
<input
|
||
type="radio"
|
||
name="zielgruppe"
|
||
value={value}
|
||
checked={zielgruppe === value}
|
||
onChange={() => {
|
||
setZielgruppe(value);
|
||
setBetreff("");
|
||
}}
|
||
className="sr-only"
|
||
/>
|
||
{label}
|
||
</label>
|
||
))}
|
||
</div>
|
||
</fieldset>
|
||
|
||
<div className="grid sm:grid-cols-2 gap-6">
|
||
<div>
|
||
<label htmlFor="contact-name" className={labelClass}>Name</label>
|
||
<input
|
||
id="contact-name"
|
||
type="text"
|
||
required
|
||
autoComplete="name"
|
||
value={name}
|
||
onChange={(e) => setName(e.target.value)}
|
||
placeholder="Max Mustermann"
|
||
className={inputClass}
|
||
/>
|
||
</div>
|
||
{zielgruppe === "geschaeftlich" ? (
|
||
<div>
|
||
<label htmlFor="contact-firma" className={labelClass}>Firma (optional)</label>
|
||
<input
|
||
id="contact-firma"
|
||
type="text"
|
||
autoComplete="organization"
|
||
value={firma}
|
||
onChange={(e) => setFirma(e.target.value)}
|
||
placeholder="Musterfirma GmbH"
|
||
className={inputClass}
|
||
/>
|
||
</div>
|
||
) : null}
|
||
<div>
|
||
<label htmlFor="contact-email" className={labelClass}>E-Mail</label>
|
||
<input
|
||
id="contact-email"
|
||
type="email"
|
||
required
|
||
autoComplete="email"
|
||
value={emailInput}
|
||
onChange={(e) => setEmailInput(e.target.value)}
|
||
placeholder="max@beispiel.de"
|
||
className={inputClass}
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label htmlFor="contact-telefon" className={labelClass}>Telefon (optional, für Rückruf)</label>
|
||
<input
|
||
id="contact-telefon"
|
||
type="tel"
|
||
autoComplete="tel"
|
||
value={telefonInput}
|
||
onChange={(e) => setTelefonInput(e.target.value)}
|
||
placeholder="0171 1234567"
|
||
className={inputClass}
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div>
|
||
<label htmlFor="contact-betreff" className={labelClass}>Worum geht es?</label>
|
||
<select
|
||
id="contact-betreff"
|
||
required
|
||
value={betreff}
|
||
onChange={(e) => setBetreff(e.target.value)}
|
||
className={`${inputClass} appearance-none`}
|
||
>
|
||
<option value="">Thema auswählen…</option>
|
||
{themen[zielgruppe].map((t) => (
|
||
<option key={t} value={t}>{t}</option>
|
||
))}
|
||
</select>
|
||
</div>
|
||
|
||
<div>
|
||
<label htmlFor="contact-nachricht" className={labelClass}>Nachricht</label>
|
||
<textarea
|
||
id="contact-nachricht"
|
||
rows={5}
|
||
value={nachricht}
|
||
onChange={(e) => setNachricht(e.target.value)}
|
||
placeholder={
|
||
zielgruppe === "privat"
|
||
? "Beschreiben Sie kurz Ihr Problem oder Ihren Wunsch..."
|
||
: "Beschreiben Sie Ihr Anliegen, z. B. Anzahl Arbeitsplätze und Standorte..."
|
||
}
|
||
className={`${inputClass} resize-none`}
|
||
/>
|
||
</div>
|
||
|
||
{status === "error" && (
|
||
<div className="flex items-start gap-3 px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
|
||
<svg className="w-5 h-5 mt-0.5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||
</svg>
|
||
<span>
|
||
Nachricht konnte nicht gesendet werden. Bitte versuchen Sie es erneut oder
|
||
kontaktieren Sie uns direkt.
|
||
{errorMsg && <span className="block mt-1 text-red-400/70 text-xs">{errorMsg}</span>}
|
||
</span>
|
||
</div>
|
||
)}
|
||
|
||
<button
|
||
type="submit"
|
||
disabled={status === "loading"}
|
||
className="btn-primary w-full py-4 text-lg disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
||
>
|
||
{status === "loading" ? (
|
||
<>
|
||
<svg className="w-5 h-5 animate-spin motion-reduce:animate-none" fill="none" viewBox="0 0 24 24" aria-hidden="true">
|
||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8z" />
|
||
</svg>
|
||
Wird gesendet…
|
||
</>
|
||
) : (
|
||
"Nachricht senden"
|
||
)}
|
||
</button>
|
||
</form>
|
||
)}
|
||
|
||
{/* Divider */}
|
||
<div className="flex items-center gap-4 my-8">
|
||
<div className="flex-1 h-px bg-slate-200 dark:bg-gray-800" />
|
||
<span className="text-slate-400 dark:text-slate-600 text-sm">oder direkt</span>
|
||
<div className="flex-1 h-px bg-slate-200 dark:bg-gray-800" />
|
||
</div>
|
||
|
||
{/* Contact info */}
|
||
<div className="flex flex-col sm:flex-row items-center justify-center gap-6">
|
||
{contactItems.map((item) => (
|
||
<a
|
||
key={item.label}
|
||
href={item.href}
|
||
data-source-element="kontakt-section"
|
||
className="flex items-center gap-3 text-slate-700 dark:text-slate-300 hover:text-orange-400 transition-colors duration-200 group"
|
||
>
|
||
<span className="w-10 h-10 rounded-lg bg-orange-500/10 border border-orange-500/20 flex items-center justify-center text-orange-400 group-hover:bg-orange-500/20 transition-colors duration-200">
|
||
{item.icon}
|
||
</span>
|
||
<div>
|
||
<div className="text-xs text-slate-500">{item.label}</div>
|
||
<div className="font-medium">{item.value}</div>
|
||
</div>
|
||
</a>
|
||
))}
|
||
</div>
|
||
|
||
{oeffnungszeiten && oeffnungszeiten.length > 0 && (
|
||
<div className="mt-6 pt-6 border-t border-slate-200 dark:border-slate-700">
|
||
<h4 className="text-sm font-semibold text-slate-500 dark:text-slate-400 mb-3">
|
||
Öffnungszeiten
|
||
</h4>
|
||
<ul className="space-y-1">
|
||
{oeffnungszeiten.map((oz) => (
|
||
<li key={oz.tag} className="flex justify-between text-sm text-slate-600 dark:text-slate-400">
|
||
<span>{oz.tag}</span>
|
||
<span>{oz.von} bis {oz.bis}</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|