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,216 @@
import { useState } from 'react';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import packages from '@/content/packages';
import siteContent from '@/content/siteContent';
import { shootOptions } from '@/lib/shootOptions';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import ContactForm from './ContactForm';
const options = shootOptions(packages);
// The time check needs over 3 s between showing and sending (BR-SPAM-01)
let now = 0;
beforeEach(() => {
now = 0;
vi.spyOn(Date, 'now').mockImplementation(() => now);
});
const renderForm = (
props: Partial<React.ComponentProps<typeof ContactForm>> = {},
) =>
renderWithProviders(
<ContactForm
idPrefix="test"
options={options}
mailSubject="Vraag via andreaslop.nl"
email={siteContent.email}
submit={vi.fn().mockResolvedValue(undefined)}
{...props}
/>,
);
const field = (name: string) => screen.getByTestId(`contact-form-${name}`);
const type = (name: string, value: string) =>
fireEvent.change(field(name), { target: { value } });
const fillIn = () => {
type('naam', 'Demi');
type('email', 'demi@example.nl');
type('shoot', 'newborn');
type('bericht', 'Wanneer heb je plek?');
};
const send = () => {
now = 10_000;
fireEvent.click(screen.getByTestId('contact-form-submit'));
};
describe('ContactForm', () => {
it('shows the four labelled fields and the button', async () => {
const { container } = await renderForm();
expect(screen.getByLabelText(/Naam/)).toBe(field('naam'));
expect(screen.getByLabelText(/E-mail/)).toBe(field('email'));
expect(screen.getByLabelText(/In welke shoot/)).toBe(field('shoot'));
expect(screen.getByLabelText(/Stel hier je vraag/)).toBe(
field('bericht'),
);
expect(
screen.getByRole('option', { name: 'Kies een optie...' }),
).toBeInTheDocument();
expect(
screen.getByRole('button', { name: '(Aan)vraag versturen' }),
).toBeInTheDocument();
expect(await axeResults(container)).toHaveNoViolations();
});
it('shows nothing when tabbing through an untouched field', async () => {
await renderForm();
fireEvent.blur(field('naam'));
expect(screen.queryByText('Vul je naam in.')).toBeNull();
});
it('checks a field on leaving once typed in, and clears it once fine', async () => {
await renderForm();
type('email', 'demi@');
fireEvent.blur(field('email'));
expect(
screen.getByText('Dit e-mailadres is ongeldig.'),
).toBeInTheDocument();
expect(field('email')).toHaveAttribute('aria-invalid', 'true');
type('email', 'demi@example.nl');
expect(screen.queryByText('Dit e-mailadres is ongeldig.')).toBeNull();
});
it('stops an incomplete submit and focuses the first invalid field', async () => {
const submit = vi.fn();
await renderForm({ submit });
type('naam', 'Demi');
send();
expect(screen.getByText('Vul je e-mailadres in.')).toBeInTheDocument();
expect(screen.getByText('Kies een soort shoot.')).toBeInTheDocument();
expect(screen.getByText('Schrijf hier je vraag.')).toBeInTheDocument();
expect(field('email')).toHaveFocus();
expect(submit).not.toHaveBeenCalled();
});
it('sends the trimmed form and shows the thank-you with focus', async () => {
const submit = vi.fn().mockResolvedValue(undefined);
await renderForm({ submit });
fillIn();
type('naam', ' Demi ');
send();
expect(screen.getByTestId('contact-form-submit')).toHaveTextContent(
'Versturen…',
);
expect(submit).toHaveBeenCalledWith({
naam: 'Demi',
email: 'demi@example.nl',
shoot: 'newborn',
bericht: 'Wanneer heb je plek?',
});
const thanks = await screen.findByTestId('contact-form-sent');
expect(thanks).toHaveTextContent(
'Bedankt voor je bericht! Ik reageer binnen 1-2 werkdagen.',
);
await waitFor(() => expect(thanks).toHaveFocus());
expect(screen.queryByTestId('contact-form')).toBeNull();
});
it('keeps the input and offers the mail link when sending fails', async () => {
await renderForm({ submit: vi.fn().mockRejectedValue(new Error('x')) });
fillIn();
send();
const status = await screen.findByRole('alert');
expect(status).toHaveTextContent(
'Versturen lukte niet. Probeer het later nog eens of mail naar info@andreaslop.nl',
);
expect(
screen.getByRole('link', { name: 'info@andreaslop.nl' }),
).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
);
expect(field('naam')).toHaveValue('Demi');
expect(screen.getByTestId('contact-form-submit')).not.toBeDisabled();
});
it('treats a filled honeypot as spam: thank-you, nothing sent', async () => {
const submit = vi.fn();
const { container } = await renderForm({ submit });
fillIn();
fireEvent.change(
container.querySelector('input[name="website"]') as Element,
{ target: { value: 'https://spam.example' } },
);
send();
expect(screen.getByTestId('contact-form-sent')).toBeInTheDocument();
expect(submit).not.toHaveBeenCalled();
});
it('treats a submit within 3 seconds as spam', async () => {
const submit = vi.fn();
await renderForm({ submit });
fillIn();
now = 1_000;
fireEvent.click(screen.getByTestId('contact-form-submit'));
expect(screen.getByTestId('contact-form-sent')).toBeInTheDocument();
expect(submit).not.toHaveBeenCalled();
});
it('ignores a second submit while sending', async () => {
let finish = () => {};
const submit = vi.fn(
() => new Promise<void>((resolve) => (finish = resolve)),
);
await renderForm({ submit });
fillIn();
send();
fireEvent.click(screen.getByTestId('contact-form-submit'));
expect(submit).toHaveBeenCalledTimes(1);
await act(async () => finish());
});
it('takes over a preselected package, also again after a change', async () => {
// A second "Boek" click for the same package raises the key
function Harness() {
const [preselect, setPreselect] = useState({
shoot: 'newborn',
key: 1,
});
return (
<>
<button
type="button"
onClick={() =>
setPreselect((p) => ({ ...p, key: p.key + 1 }))
}
>
nog eens
</button>
<ContactForm
idPrefix="test"
options={options}
preselect={preselect}
mailSubject="Vraag via andreaslop.nl"
email={siteContent.email}
/>
</>
);
}
await renderWithProviders(<Harness />);
expect(field('shoot')).toHaveValue('newborn');
type('shoot', 'gezin');
expect(field('shoot')).toHaveValue('gezin');
fireEvent.click(screen.getByRole('button', { name: 'nog eens' }));
expect(field('shoot')).toHaveValue('newborn');
});
it('keeps the honeypot away from people and assistive technology', async () => {
const { container } = await renderForm();
const honeypot = container.querySelector('input[name="website"]');
expect(honeypot).toHaveAttribute('tabindex', '-1');
expect(honeypot?.closest('[aria-hidden="true"]')).not.toBeNull();
expect(container.querySelector('[data-robot-check]')).not.toBeNull();
});
});
@@ -0,0 +1,304 @@
import { useEffect, useRef, useState, useReducer } from 'react';
import {
Box,
chakra,
Field,
Input,
Link,
NativeSelect,
SimpleGrid,
Stack,
Text,
Textarea,
useRecipe,
} from '@chakra-ui/react';
import { submitContactForm } from '@/contact/submitContactForm';
import {
CONTACT_LIMITS,
type ContactField,
type ContactPayload,
type ShootOption,
} from '@/contact/types';
import type { EmailAddress } from '@/content/types';
import {
contactFormReducer,
INITIAL_CONTACT_STATE,
type ContactFormEvent,
} from '@/lib/contactFormReducer';
import { emailAddress } from '@/lib/emailAddress';
import { mailtoLink } from '@/lib/mailLink';
import { toContactPayload } from '@/lib/toContactPayload';
import { CONTACT_FIELDS } from '@/lib/validateContact';
type ContactFormProps = {
// Prefix for the field ids, so the form can appear on more than one page
idPrefix: string;
options: ShootOption[];
// A package chosen via "Boek ..."; key changes on every click, so the
// same package can be applied again after the visitor changed it
preselect?: { shoot: string; key: number };
mailSubject: string;
email: EmailAddress;
submit?: (payload: ContactPayload) => Promise<void>;
};
const SENT_MESSAGE =
'Bedankt voor je bericht! Ik reageer binnen 1-2 werkdagen.';
// The contact form (design .form): name and e-mail, the shoot, the question,
// and the browser-side anti-spam. Its behaviour is the pure
// contactFormReducer; this component wires it to the fields.
export default function ContactForm({
idPrefix,
options,
preselect,
mailSubject,
email,
submit = submitContactForm,
}: ContactFormProps) {
const reduce = (
state: typeof INITIAL_CONTACT_STATE,
event: ContactFormEvent,
) => contactFormReducer(state, event, options);
const [state, dispatch] = useReducer(reduce, INITIAL_CONTACT_STATE);
const formControl = useRecipe({ key: 'formControl' });
const linkButton = useRecipe({ key: 'linkButton' });
// When the form became usable, for the time check (BR-SPAM-01)
const [shownAt] = useState(() => Date.now());
const honeypot = useRef<HTMLInputElement>(null);
const sentMessage = useRef<HTMLDivElement>(null);
// Apply a new "Boek ..." choice while rendering (React's pattern for
// reacting to a changed prop), so it never shows a stale value first
const [seenPreselect, setSeenPreselect] = useState(0);
if (preselect && preselect.key !== seenPreselect) {
setSeenPreselect(preselect.key);
dispatch({ type: 'preselect', shoot: preselect.shoot });
}
// After a stopped submit, focus the first field with an error
useEffect(() => {
if (state.invalidSubmits === 0) return;
const first = CONTACT_FIELDS.find((field) => state.errors[field]);
if (first) document.getElementById(`${idPrefix}-${first}`)?.focus();
// Only on a new stopped submit, not on every error change
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state.invalidSubmits]);
// The thank-you replaces the form; move focus there (BR-SEND-02)
useEffect(() => {
if (state.status === 'sent') sentMessage.current?.focus();
}, [state.status]);
const address = emailAddress(email);
const disabled = state.status === 'sending';
if (state.status === 'sent') {
return (
<Box
ref={sentMessage}
role="status"
tabIndex={-1}
data-testid="contact-form-sent"
p={6}
borderStartWidth="2px"
borderStartColor="accent"
bg="paper.alt"
>
{SENT_MESSAGE}
</Box>
);
}
const onSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const submitEvent: ContactFormEvent = {
type: 'submit',
honeypot: honeypot.current?.value ?? '',
shownAt,
now: Date.now(),
};
// Sending starts here, not in an effect, so it happens exactly once
const next = reduce(state, submitEvent);
dispatch(submitEvent);
if (next.status === 'sending') {
submit(toContactPayload(state.values)).then(
() => dispatch({ type: 'resolved' }),
() => dispatch({ type: 'rejected' }),
);
}
};
// The control's id comes from Field.Root's id (Ark uses it for the
// control and the label's htmlFor), so label and error stay linked
const fieldProps = (field: ContactField) => ({
name: field,
value: state.values[field],
onChange: (
event: React.ChangeEvent<
HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
>,
) => dispatch({ type: 'edit', field, value: event.target.value }),
onBlur: () => dispatch({ type: 'blur', field }),
css: formControl(),
'data-testid': `contact-form-${field}`,
});
const label = (text: string) => (
// ink.soft instead of the design's muted grey: meets 4.5:1
<Field.Label textStyle="eyebrow" color="ink.soft" fontWeight="400">
{text}
</Field.Label>
);
const error = (field: ContactField) => (
<Field.ErrorText color="error" fontSize="sm">
{state.errors[field]}
</Field.ErrorText>
);
return (
<chakra.form
noValidate
onSubmit={onSubmit}
data-testid="contact-form"
position="relative"
>
<Stack gap={6}>
<SimpleGrid columns={{ base: 1, sm: 2 }} gap={6}>
<Field.Root
invalid={Boolean(state.errors.naam)}
required
id={`${idPrefix}-naam`}
>
{label('Naam')}
<Input
{...fieldProps('naam')}
type="text"
autoComplete="name"
maxLength={CONTACT_LIMITS.naam}
placeholder="Jouw naam"
/>
{error('naam')}
</Field.Root>
<Field.Root
invalid={Boolean(state.errors.email)}
required
id={`${idPrefix}-email`}
>
{label('E-mail')}
<Input
{...fieldProps('email')}
type="email"
autoComplete="email"
maxLength={CONTACT_LIMITS.email}
placeholder="jouw@email.nl"
/>
{error('email')}
</Field.Root>
</SimpleGrid>
<Field.Root
invalid={Boolean(state.errors.shoot)}
required
id={`${idPrefix}-shoot`}
>
{label('In welke shoot heb je interesse?')}
<NativeSelect.Root>
<NativeSelect.Field {...fieldProps('shoot')}>
<option value="">Kies een optie...</option>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</NativeSelect.Field>
<NativeSelect.Indicator />
</NativeSelect.Root>
{error('shoot')}
</Field.Root>
<Field.Root
invalid={Boolean(state.errors.bericht)}
required
id={`${idPrefix}-bericht`}
>
{label('Stel hier je vraag')}
<Textarea
{...fieldProps('bericht')}
maxLength={CONTACT_LIMITS.bericht}
placeholder="Vul hier je bericht in"
minH="170px"
resize="vertical"
/>
{error('bericht')}
</Field.Root>
{/* Honeypot: off-screen and hidden from assistive
technology; only bots fill it in (BR-SPAM-01) */}
<Box
aria-hidden="true"
position="absolute"
left="-10000px"
w="1px"
h="1px"
overflow="hidden"
>
<label htmlFor={`${idPrefix}-website`}>Website</label>
<input
ref={honeypot}
id={`${idPrefix}-website`}
name="website"
type="text"
tabIndex={-1}
autoComplete="off"
/>
</Box>
{/* Place for the robot check (Friendly Captcha), added with
the API (FR-HP-09) */}
<div data-robot-check />
{state.status === 'failed' && (
<Box
role="alert"
data-testid="contact-form-status"
p={4}
borderStartWidth="2px"
borderStartColor="error"
bg="paper.alt"
fontSize="sm"
>
<Text>
Versturen lukte niet. Probeer het later nog eens
{address ? (
<>
{' of mail naar '}
<Link
variant="underline"
href={mailtoLink(address, mailSubject)}
>
{address}
</Link>
</>
) : (
'.'
)}
</Text>
</Box>
)}
<chakra.button
type="submit"
css={linkButton({ variant: 'accent' })}
alignSelf="flex-start"
disabled={disabled}
cursor={disabled ? 'progress' : 'pointer'}
data-testid="contact-form-submit"
>
{disabled ? 'Versturen…' : '(Aan)vraag versturen'}
</chakra.button>
</Stack>
</chakra.form>
);
}
@@ -0,0 +1,59 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import siteContent from '@/content/siteContent';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import ContactFormGate from './ContactFormGate';
const renderGate = (enabled: boolean, email = siteContent.email) =>
renderWithProviders(
<ContactFormGate
enabled={enabled}
email={email}
subject="Aanvraag fotoshoot: Newborn"
>
<form aria-label="Formulier">
<input aria-label="Naam" />
</form>
</ContactFormGate>,
);
describe('ContactFormGate', () => {
it('keeps the form inert under the coming-soon notice with a mail button', async () => {
const { container } = await renderGate(false);
const form = container.querySelector('form');
expect(form?.closest('[inert]')).not.toBeNull();
const notice = screen.getByTestId('contact-gate-notice');
expect(notice).toHaveTextContent(
'Het contactformulier komt binnenkort. Mail me voor nu op info@andreaslop.nl',
);
const mail = screen.getByRole('link', { name: 'Stuur een e-mail' });
expect(mail).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Aanvraag%20fotoshoot%3A%20Newborn',
);
expect(
screen.getByRole('link', { name: 'info@andreaslop.nl' }),
).toHaveAttribute('href', mail.getAttribute('href'));
expect(await axeResults(container)).toHaveNoViolations();
});
it('shows only the coming-soon text when the address is invalid', async () => {
await renderGate(false, { user: '', domain: 'andreaslop.nl' });
expect(screen.getByTestId('contact-gate-notice')).toHaveTextContent(
'Het contactformulier komt binnenkort.',
);
expect(screen.queryByRole('link')).toBeNull();
});
it('shows just the form when switched on', async () => {
const { container } = await renderGate(true);
expect(screen.queryByTestId('contact-gate-notice')).toBeNull();
expect(container.querySelector('[inert]')).toBeNull();
expect(
screen.getByRole('textbox', { name: 'Naam' }),
).toBeInTheDocument();
expect(await axeResults(container)).toHaveNoViolations();
});
});
@@ -0,0 +1,76 @@
import type { ReactNode } from 'react';
import { Box, chakra, Link, Text, useRecipe } from '@chakra-ui/react';
import type { EmailAddress } from '@/content/types';
import { emailAddress } from '@/lib/emailAddress';
import { mailtoLink } from '@/lib/mailLink';
type ContactFormGateProps = {
enabled: boolean;
email: EmailAddress;
subject: string;
children: ReactNode;
};
// Until there is a back-end the form stays visible but dimmed and inert
// under a "coming soon" notice with a mail button (FR-HP-07). inert keeps
// keyboard and screen reader users out of a form that does nothing.
export default function ContactFormGate({
enabled,
email,
subject,
children,
}: ContactFormGateProps) {
const linkButton = useRecipe({ key: 'linkButton' });
if (enabled) return <>{children}</>;
// Assembled in the browser, so the address is nowhere in the bundle
const address = emailAddress(email);
const href = address ? mailtoLink(address, subject) : undefined;
return (
<Box position="relative" data-testid="contact-gate">
<Box inert opacity={0.35} filter="blur(1.5px)" userSelect="none">
{children}
</Box>
<Box
position="absolute"
top="50%"
left="50%"
transform="translate(-50%, -50%)"
w="min(100%, 520px)"
p="clamp(2rem, 4vw, 3rem)"
bg="white"
borderWidth="1px"
borderColor="line"
boxShadow="panel"
textAlign="center"
data-testid="contact-gate-notice"
>
{/* accent.deep instead of the design's accent: meets 4.5:1 */}
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
Binnenkort
</Text>
<Text color="ink.soft" mb={address ? 7 : 0}>
Het contactformulier komt binnenkort.
{address && (
<>
{' Mail me voor nu op '}
<Link variant="underline" href={href}>
{address}
</Link>
</>
)}
</Text>
{address && (
<chakra.a
href={href}
css={linkButton({ variant: 'accent' })}
data-testid="contact-gate-mail"
>
Stuur een e-mail
</chakra.a>
)}
</Box>
</Box>
);
}
@@ -9,6 +9,8 @@ type SectionHeadingProps = {
align?: 'center' | 'start';
// compact: little space below, for a heading above running text
spacing?: 'default' | 'compact';
// Lets code move focus to the heading (no visible ring, theme rule)
focusable?: boolean;
};
// Heading block of a homepage section (design .section__head): optional
@@ -20,6 +22,7 @@ export default function SectionHeading({
lead,
align = 'center',
spacing = 'default',
focusable = false,
}: SectionHeadingProps) {
const centered = align === 'center';
@@ -36,7 +39,12 @@ export default function SectionHeading({
{eyebrow}
</Text>
)}
<Heading as="h2" id={id} textStyle="sectionTitle">
<Heading
as="h2"
id={id}
textStyle="sectionTitle"
tabIndex={focusable ? -1 : undefined}
>
{title}
</Heading>
{lead && (
@@ -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>
);