From 9538fc72e55f71f488d977cf275eb19c8413c28d Mon Sep 17 00:00:00 2001 From: AI Bot Date: Sun, 9 Aug 2026 23:14:10 +0200 Subject: [PATCH] =?UTF-8?q?Naprawa=20b=C5=82=C4=99d=C3=B3w=20ESLint=20oraz?= =?UTF-8?q?=20typowa=C5=84=20TypeScript=20dla=20Zod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/kontakt/route.ts | 142 +++++++ app/globals.css | 2 - app/kontakt/layout.tsx | 11 + app/kontakt/page.tsx | 589 ++++++++++++++++++++++++++++ app/page.tsx | 2 +- app/realizacje/page.tsx | 4 +- components/ui/FlowingMenu.tsx | 5 +- components/ui/ImageWithSkeleton.tsx | 1 + package-lock.json | 274 +++++++++++-- package.json | 6 +- 10 files changed, 999 insertions(+), 37 deletions(-) create mode 100644 app/api/kontakt/route.ts create mode 100644 app/kontakt/layout.tsx create mode 100644 app/kontakt/page.tsx diff --git a/app/api/kontakt/route.ts b/app/api/kontakt/route.ts new file mode 100644 index 0000000..195489d --- /dev/null +++ b/app/api/kontakt/route.ts @@ -0,0 +1,142 @@ +import { NextRequest, NextResponse } from "next/server"; +import { z } from "zod"; + +const kontaktSchema = z.object({ + name: z + .string() + .min(2, "Imię i nazwisko musi mieć min. 2 znaki") + .max(100, "Imię i nazwisko jest za długie"), + phone: z + .string() + .regex( + /^(\+48\s?)?(\d{3}\s?\d{3}\s?\d{3}|\d{9})$/, + "Podaj prawidłowy numer telefonu (9 cyfr, opcjonalnie +48)" + ), + email: z.string().email("Podaj prawidłowy adres e-mail"), + subject: z.enum( + [ + "nadzor-inwestorski", + "generalne-wykonawstwo", + "kierowanie-budowa", + "inwestor-zastepczy", + "inne", + ], + { message: "Wybierz temat zapytania" } + ), + message: z + .string() + .min(20, "Wiadomość musi mieć min. 20 znaków") + .max(5000, "Wiadomość jest za długa"), + consent: z.literal(true, { + error: "Zgoda na przetwarzanie danych jest wymagana", + }), + // Honeypot — musi być puste + website: z.string().max(0, "").optional(), +}); + +const SUBJECT_LABELS: Record = { + "nadzor-inwestorski": "Nadzór inwestorski", + "generalne-wykonawstwo": "Generalne wykonawstwo", + "kierowanie-budowa": "Kierowanie budową", + "inwestor-zastepczy": "Inwestor zastępczy", + inne: "Inne", +}; + +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + + // Walidacja Zod + const result = kontaktSchema.safeParse(body); + if (!result.success) { + const fieldErrors = result.error.flatten().fieldErrors; + return NextResponse.json( + { error: { message: "Błąd walidacji formularza", code: "VALIDATION_ERROR", fields: fieldErrors } }, + { status: 400 } + ); + } + + const data = result.data; + + // Honeypot check — jeśli wypełnione, bot + if (data.website && data.website.length > 0) { + // Udajemy sukces, żeby bot nie wiedział + return NextResponse.json({ success: true }); + } + + // Sprawdź klucz Resend + const resendApiKey = process.env.RESEND_API_KEY; + if (!resendApiKey || resendApiKey === "your_resend_api_key") { + console.warn( + "[KONTAKT] Klucz RESEND_API_KEY nie jest skonfigurowany. E-mail NIE został wysłany. Dane formularza:", + { name: data.name, email: data.email, subject: data.subject } + ); + // Zwracamy sukces, żeby frontend działał w trybie dev + return NextResponse.json({ + success: true, + _dev: "E-mail nie wysłany — brak klucza RESEND_API_KEY", + }); + } + + // Wysyłka przez Resend + const { Resend } = await import("resend"); + const resend = new Resend(resendApiKey); + + const subjectLabel = SUBJECT_LABELS[data.subject] || data.subject; + + const { error } = await resend.emails.send({ + from: "BNT Formularz ", + to: "kontakt@bntbudownictwo.pl", + replyTo: data.email, + subject: `Nowe zapytanie: ${subjectLabel} — ${data.name}`, + html: ` +
+

+ Nowe zapytanie z formularza kontaktowego +

+ + + + + + + + + + + + + + + + + + + + + +
Imię i nazwisko${data.name}
Telefon${data.phone}
E-mail${data.email}
Temat${subjectLabel}
Wiadomość${data.message}
+

+ Wiadomość wysłana z formularza na stronie bntbudownictwo.pl +

+
+ `, + }); + + if (error) { + console.error("[KONTAKT] Błąd Resend:", error); + return NextResponse.json( + { error: { message: "Nie udało się wysłać wiadomości. Spróbuj ponownie później lub zadzwoń.", code: "SEND_ERROR" } }, + { status: 500 } + ); + } + + return NextResponse.json({ success: true }); + } catch (err) { + console.error("[KONTAKT] Nieoczekiwany błąd:", err); + return NextResponse.json( + { error: { message: "Wystąpił nieoczekiwany błąd. Spróbuj ponownie później lub zadzwoń bezpośrednio.", code: "INTERNAL_ERROR" } }, + { status: 500 } + ); + } +} diff --git a/app/globals.css b/app/globals.css index 530bce8..35d7fb7 100644 --- a/app/globals.css +++ b/app/globals.css @@ -33,8 +33,6 @@ @apply text-body-mobile lg:text-body-desktop font-body text-brand-muted; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; - /* Wymuszenie grayscale antialiasing na systemach Windows, aby zapobiec kolorowemu fringingowi (ClearType) na małych czcionkach mono */ - text-shadow: 0 0 1px rgba(0,0,0,0.01); } small, caption { diff --git a/app/kontakt/layout.tsx b/app/kontakt/layout.tsx new file mode 100644 index 0000000..ebf28ef --- /dev/null +++ b/app/kontakt/layout.tsx @@ -0,0 +1,11 @@ +import type { Metadata } from "next"; + +export const metadata: Metadata = { + title: "Kontakt — Formularz Wyceny | BNT Budownictwo Wrocław", + description: + "Skontaktuj się z BNT Budownictwo. Wypełnij formularz wyceny lub zadzwoń — odpowiadamy w ciągu 24h. Nadzór inwestorski, generalne wykonawstwo, Wrocław i Dolny Śląsk.", +}; + +export default function KontaktLayout({ children }: { children: React.ReactNode }) { + return children; +} diff --git a/app/kontakt/page.tsx b/app/kontakt/page.tsx new file mode 100644 index 0000000..83324e0 --- /dev/null +++ b/app/kontakt/page.tsx @@ -0,0 +1,589 @@ +"use client"; + +import React, { useState } from "react"; +import Link from "next/link"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { + MapPin, + Phone, + Mail, + Clock, + CheckCircle, + AlertCircle, + MessageSquare, + Shield, + Zap, +} from "lucide-react"; +import { SectionHeader } from "@/components/ui/SectionHeader"; +import { Reveal } from "@/components/ui/Reveal"; +import { TechCorners } from "@/components/ui/TechCorners"; +import { Button } from "@/components/ui/Button"; + +// ─── Social Media Icons (spójne z Footer.tsx) ─────────────────────────────── + +const FacebookIcon = ({ className = "" }: { className?: string }) => ( + + Facebook + + +); + +const LinkedinIcon = ({ className = "" }: { className?: string }) => ( + + LinkedIn + + +); + +// ─── Zod Schema ────────────────────────────────────────────────────────────── + +const kontaktSchema = z.object({ + name: z + .string() + .min(2, "Imię i nazwisko musi mieć min. 2 znaki") + .max(100, "Imię i nazwisko jest za długie"), + phone: z + .string() + .regex( + /^(\+48\s?)?(\d{3}\s?\d{3}\s?\d{3}|\d{9})$/, + "Podaj prawidłowy numer telefonu (9 cyfr, opcjonalnie +48)" + ), + email: z.string().email("Podaj prawidłowy adres e-mail"), + subject: z.enum( + [ + "nadzor-inwestorski", + "generalne-wykonawstwo", + "kierowanie-budowa", + "inwestor-zastepczy", + "inne", + ], + { message: "Wybierz temat zapytania" } + ), + message: z + .string() + .min(20, "Wiadomość musi mieć min. 20 znaków") + .max(5000, "Wiadomość jest za długa"), + consent: z.literal(true, { + error: "Zgoda na przetwarzanie danych jest wymagana", + }), + website: z.string().max(0).optional(), +}); + +type KontaktFormData = z.infer; + +const SUBJECT_OPTIONS = [ + { value: "", label: "Wybierz temat zapytania..." }, + { value: "nadzor-inwestorski", label: "Nadzór inwestorski" }, + { value: "generalne-wykonawstwo", label: "Generalne wykonawstwo" }, + { value: "kierowanie-budowa", label: "Kierowanie budową" }, + { value: "inwestor-zastepczy", label: "Inwestor zastępczy" }, + { value: "inne", label: "Inne" }, +]; + +// ─── Input Styling ─────────────────────────────────────────────────────────── + +const inputBase = + "w-full rounded-lg border bg-white px-4 py-3 text-body-mobile lg:text-body-desktop font-body text-brand-text placeholder:text-brand-muted/50 transition-colors duration-150 ease-out focus:outline-none focus:ring-2 focus:ring-brand-primary focus:border-brand-primary"; +const inputDefault = "border-brand-border"; +const inputError = "border-red-500 focus:ring-red-500 focus:border-red-500"; + +function FieldError({ message }: { message?: string }) { + if (!message) return null; + return ( +

+

+ ); +} + +// ─── Component ─────────────────────────────────────────────────────────────── + +export default function KontaktPage() { + const [formState, setFormState] = useState<"idle" | "submitting" | "success" | "error">("idle"); + const [serverError, setServerError] = useState(null); + + const { + register, + handleSubmit, + formState: { errors }, + reset, + } = useForm({ + resolver: zodResolver(kontaktSchema), + defaultValues: { + name: "", + phone: "", + email: "", + subject: undefined, + message: "", + consent: undefined, + website: "", + }, + }); + + const onSubmit = async (data: KontaktFormData) => { + setFormState("submitting"); + setServerError(null); + + try { + const res = await fetch("/api/kontakt", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + + const json = await res.json(); + + if (!res.ok) { + setServerError(json.error?.message || "Wystąpił błąd. Spróbuj ponownie."); + setFormState("error"); + return; + } + + setFormState("success"); + reset(); + } catch { + setServerError("Nie udało się połączyć z serwerem. Sprawdź połączenie internetowe i spróbuj ponownie."); + setFormState("error"); + } + }; + + return ( +
+ {/* ─── 1. Hero ────────────────────────────────────────────────── */} +
+
+ +
+ + Strona główna + + / + Kontakt +
+
+ + +
+
+ + {/* ─── 2. Formularz + Dane kontaktowe ──────────────────────── */} +
+
+
+ {/* Lewa: Formularz */} + +
+

+ Formularz wyceny +

+

+ Opisz swój projekt, a my przygotujemy wstępną wycenę. +

+ + {formState === "success" ? ( + /* ── Stan sukcesu ── */ +
+
+
+

+ Wiadomość wysłana +

+

+ Dziękujemy za kontakt. Odpowiemy w ciągu 24 godzin roboczych na podany adres + e-mail. +

+ +
+ ) : ( + /* ── Formularz ── */ +
+ {/* Honeypot — ukryte pole */} + + + {/* Imię i nazwisko */} +
+ + + +
+ + {/* Telefon + E-mail — 2 kolumny */} +
+
+ + + +
+
+ + + +
+
+ + {/* Temat */} +
+ + + +
+ + {/* Wiadomość */} +
+ +