Adds the Contact section to the homepage

Adds the contact form with the live fields, validation and browser-side
anti-spam, behind a coming-soon notice with a mail button until the API
exists. A "Boek" link on a price card selects its package, tidies the
URL and moves focus to the form. The form loads only when it comes near
the screen, so the hero does not wait for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 00:36:43 +02:00
co-authored by Claude Opus 5.5
parent 0b8e8d5f8b
commit 0fce403ebc
46 changed files with 2505 additions and 16 deletions
@@ -0,0 +1,73 @@
import { screen, waitFor } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import homeContent from '@/content/homeContent';
import packages from '@/content/packages';
import siteContent from '@/content/siteContent';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import ContactSection from './ContactSection';
const renderSection = (pakket?: string, path = '/') =>
renderWithProviders(
<ContactSection
content={homeContent.contact}
packages={packages}
enabled={false}
email={siteContent.email}
pakket={pakket}
/>,
{ path },
);
const heading = () =>
screen.getByRole('heading', { level: 2, name: 'Contact' });
// The form is a lazy chunk; its first import can take over a second under
// the full suite with coverage
const LAZY_LOAD = { timeout: 10_000 };
const shoot = () =>
screen.findByTestId('contact-form-shoot', undefined, LAZY_LOAD);
describe('ContactSection', () => {
it('is the contact anchor with heading, lead and the gated form', async () => {
const { container } = await renderSection();
const section = screen.getByRole('region', { name: 'Contact' });
await shoot();
expect(section).toHaveAttribute('id', 'contact');
expect(screen.getByText(homeContent.contact.lead)).toBeInTheDocument();
expect(screen.getByTestId('contact-gate-notice')).toBeInTheDocument();
expect(
screen.getByRole('link', { name: 'Stuur een e-mail' }),
).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
);
expect(heading()).not.toHaveFocus();
expect(await axeResults(container)).toHaveNoViolations();
});
it('takes over a package from "Boek ...", tidies the URL and moves focus here', async () => {
const { router } = await renderSection(
'newborn',
'/?pakket=newborn#contact',
);
expect(await shoot()).toHaveValue('newborn');
expect(
screen.getByRole('link', { name: 'Stuur een e-mail' }),
).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Aanvraag%20fotoshoot%3A%20Newborn',
);
await waitFor(() => expect(router.state.location.searchStr).toBe(''));
expect(router.state.location.hash).toBe('contact');
expect(heading()).toHaveFocus();
});
it('ignores an unknown package but still tidies the URL', async () => {
const { router } = await renderSection(
'bruiloft',
'/?pakket=bruiloft#contact',
);
expect(await shoot()).toHaveValue('');
await waitFor(() => expect(router.state.location.searchStr).toBe(''));
});
});
@@ -0,0 +1,140 @@
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
import { Box } from '@chakra-ui/react';
import { useNavigate } from '@tanstack/react-router';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import ContactFormGate from '@/components/ContactForm/ContactFormGate';
import HomeSection from '@/components/HomeSection/HomeSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type {
EmailAddress,
HomeContent,
PricingPackage,
} from '@/content/types';
import useInView from '@/hooks/useInView';
import { mailSubject } from '@/lib/mailLink';
import { packageFromSearch } from '@/lib/packageFromSearch';
import { shootOptions } from '@/lib/shootOptions';
import { visiblePackages } from '@/lib/visiblePackages';
// The form (Chakra fields, validation, reducer) sits far below the hero.
// Loading it with the page cost ±0.03 Lighthouse performance on mobile, so
// it loads when the section comes near the screen, or straight away when
// the visitor arrives via "Boek ...".
const ContactForm = lazy(() => import('@/components/ContactForm/ContactForm'));
const TITLE_ID = 'contact-title';
// Keeps the form's space while it loads, so the notice sits where it will
// stay and the page below does not jump (measured: 604px on phones, where
// name and e-mail are stacked, 502px from sm)
const FORM_PLACEHOLDER_HEIGHT = { base: '604px', sm: '502px' };
type ContactSectionProps = {
content: HomeContent['contact'];
packages: PricingPackage[];
enabled: boolean;
email: EmailAddress;
// ?pakket= from a "Boek ..." link on a price card
pakket?: string;
};
// "Contact" on the homepage (design #contact): heading and lead, and the
// contact form behind the coming-soon gate. Takes over a package chosen via
// "Boek ...", then tidies the URL and moves focus here (BR-PARAM-02,
// BR-FOCUS-01).
export default function ContactSection({
content,
packages,
enabled,
email,
pakket,
}: ContactSectionProps) {
const navigate = useNavigate();
const shown = useMemo(() => visiblePackages(packages), [packages]);
const options = useMemo(() => shootOptions(packages), [packages]);
// Take over a new ?pakket= while rendering (React's pattern for a
// changed prop); the last "Boek" click wins (BR-PARAM-03)
const [seenPakket, setSeenPakket] = useState<string | undefined>();
const [preselect, setPreselect] = useState<{
shoot: string;
key: number;
}>();
const [chosenName, setChosenName] = useState<string>();
if (pakket !== seenPakket) {
setSeenPakket(pakket);
const id =
pakket === undefined ? undefined : packageFromSearch(pakket, shown);
if (id) {
setPreselect({ shoot: id, key: (preselect?.key ?? 0) + 1 });
setChosenName(shown.find((pkg) => pkg.id === id)?.name);
}
}
// Then remove ?pakket= from the address bar (no extra history entry, no
// scroll) and continue keyboard and screen reader users here
useEffect(() => {
if (pakket === undefined) return;
void navigate({
to: '/',
search: {},
hash: 'contact',
replace: true,
resetScroll: false,
hashScrollIntoView: false,
});
document.getElementById(TITLE_ID)?.focus({ preventScroll: true });
}, [pakket, navigate]);
const subject = mailSubject(chosenName);
const { ref, inView } = useInView<HTMLDivElement>({
rootMargin: DEFERRED_LOAD_MARGIN,
});
// Once loaded the form stays, also after ?pakket= is removed from the
// URL; otherwise it would be recreated and lose what was typed
const [formLoaded, setFormLoaded] = useState(false);
if (!formLoaded && (inView || pakket !== undefined)) setFormLoaded(true);
const placeholder = <Box minH={FORM_PLACEHOLDER_HEIGHT} />;
return (
<HomeSection
labelledBy={TITLE_ID}
id="contact"
width="narrow"
data-testid="contact-section"
>
<Reveal>
<SectionHeading
id={TITLE_ID}
title={content.title}
lead={content.lead}
focusable
/>
</Reveal>
<Reveal>
<ContactFormGate
enabled={enabled}
email={email}
subject={subject}
>
<Box ref={ref}>
{formLoaded ? (
<Suspense fallback={placeholder}>
<ContactForm
idPrefix="home-contact"
options={options}
preselect={preselect}
mailSubject={subject}
email={email}
/>
</Suspense>
) : (
placeholder
)}
</Box>
</ContactFormGate>
</Reveal>
</HomeSection>
);
}
@@ -1,7 +1,7 @@
import {
Box,
chakra,
Heading,
List,
Text,
useRecipe,
VisuallyHidden,
@@ -50,7 +50,9 @@ export default function PriceCard({ pkg }: PriceCardProps) {
>
{formatPrice(pkg.price)}
</Text>
<List.Root
{/* A plain list, not Chakra's List: its slot recipe would pull
shared code into the chunk the hero waits for */}
<chakra.ul
listStyleType="none"
display="grid"
gap={3}
@@ -62,9 +64,9 @@ export default function PriceCard({ pkg }: PriceCardProps) {
fontSize="sm"
>
{pkg.features.map((feature) => (
<List.Item key={feature}>{feature}</List.Item>
<chakra.li key={feature}>{feature}</chakra.li>
))}
</List.Root>
</chakra.ul>
{/* The router's own Link keeps the route types, so search is
checked against the homepage's ?pakket=; the button style
goes on via asChild */}
@@ -1,4 +1,4 @@
import { Blockquote, Box, Grid, Text } from '@chakra-ui/react';
import { Box, chakra, Grid, Text } from '@chakra-ui/react';
import FramedImage from '@/components/FramedImage/FramedImage';
import type { Testimonial } from '@/content/types';
@@ -48,23 +48,25 @@ export default function TestimonialSlide({
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
{testimonial.shoot}
</Text>
<Blockquote.Root variant="plain" px={0} gap={7}>
<Blockquote.Content
{/* Plain elements, not Chakra's Blockquote: its slot recipe
would pull shared code into the chunk the hero waits for */}
<chakra.figure display="flex" flexDirection="column" gap={7}>
<chakra.blockquote
fontFamily="heading"
fontSize="clamp(1.35rem, 2.2vw, 1.75rem)"
lineHeight="1.5"
color="ink"
>
{testimonial.quote}
</Blockquote.Content>
<Blockquote.Caption
</chakra.blockquote>
<chakra.figcaption
textStyle="eyebrow"
color="ink.soft"
_before={{ content: '"— "' }}
>
{testimonial.author}
</Blockquote.Caption>
</Blockquote.Root>
</chakra.figcaption>
</chakra.figure>
</Box>
</Grid>
);