Shares the contact form, contact card and privacy line

ContactPanel holds the coming-soon gate, the shoot options, the package
chosen via ?pakket= and the form, which loads as its own chunk either
when it comes near the screen (homepage) or right away (contact page).
ContactDetails shows the ways to reach Andrea as a card with icons. A
privacy line now sits under the form and under the coming-soon notice,
and the reply time in the thank-you comes from the site content.
Instagram is listed before Facebook, so the footer and hero follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 18:26:48 +01:00
co-authored by Claude Opus 5.5
parent 4c257b7ac0
commit 26a8bd9469
20 changed files with 789 additions and 90 deletions
@@ -0,0 +1,106 @@
import { screen, within } 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 ContactDetails from './ContactDetails';
type Props = Partial<React.ComponentProps<typeof ContactDetails>>;
const card = (props: Props = {}) => (
<ContactDetails
titleId="details-title"
title="Direct contact"
email={siteContent.email}
socials={siteContent.socials}
data-testid="details"
{...props}
/>
);
const portrait = {
src: '/portret.jpg',
alt: 'Andrea',
width: 144,
height: 144,
};
describe('ContactDetails', () => {
it('lists e-mail, Instagram and Facebook under a named heading', async () => {
const { container } = await renderWithProviders(card());
expect(
screen.getByRole('heading', { level: 2, name: 'Direct contact' }),
).toHaveAttribute('id', 'details-title');
const list = screen.getByRole('list', { name: 'Direct contact' });
const names = within(list)
.getAllByRole('link')
.map((link) => link.textContent);
expect(names).toEqual([
'info@andreaslop.nl',
'@andreaslopfotografie (opent in nieuw tabblad)',
'Andrea Slop Fotografie (opent in nieuw tabblad)',
]);
expect(await axeResults(container)).toHaveNoViolations();
});
it('mails with the default subject in the same tab', async () => {
await renderWithProviders(card());
const mail = screen.getByTestId('contact-details-email');
expect(mail).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
);
expect(mail).not.toHaveAttribute('target');
});
it('opens the socials safely in a new tab and says so', async () => {
await renderWithProviders(card());
const instagram = screen.getByRole('link', {
name: '@andreaslopfotografie (opent in nieuw tabblad)',
});
expect(instagram).toHaveAttribute('target', '_blank');
expect(instagram).toHaveAttribute('rel', 'noopener noreferrer');
expect(instagram).toHaveAttribute(
'href',
'https://www.instagram.com/andreaslopfotografie/',
);
});
it('hides the icons from assistive technology', async () => {
await renderWithProviders(card());
const icons = screen.getByTestId('details').querySelectorAll('svg');
expect(icons).toHaveLength(3);
icons.forEach((icon) =>
expect(icon).toHaveAttribute('aria-hidden', 'true'),
);
});
it('renders nothing without a valid channel', async () => {
const { container } = await renderWithProviders(
card({ email: { user: '', domain: '' }, socials: [] }),
);
expect(screen.queryByTestId('details')).toBeNull();
expect(container.querySelector('h2')).toBeNull();
});
it('shows the portrait as decoration next to the heading', async () => {
const { container } = await renderWithProviders(card({ portrait }));
const photo = screen.getByTestId('contact-details-portrait');
expect(photo).toHaveAttribute('src', '/portret.jpg');
expect(photo).toHaveAttribute('alt', '');
expect(await axeResults(container)).toHaveNoViolations();
});
it('can appear twice on a page with its own heading ids', async () => {
const { container } = await renderWithProviders(
<>
{card({ titleId: 'details-a', 'data-testid': 'a' })}
{card({ titleId: 'details-b', 'data-testid': 'b' })}
</>,
);
expect(
screen.getAllByRole('list', { name: 'Direct contact' }),
).toHaveLength(2);
expect(await axeResults(container)).toHaveNoViolations();
});
});
@@ -0,0 +1,118 @@
import {
Box,
chakra,
Flex,
Image,
Link,
VisuallyHidden,
} from '@chakra-ui/react';
import mailOutlined from '@iconify-icons/ant-design/mail-outlined';
import { Icon } from '@iconify/react/offline';
import Eyebrow from '@/components/Eyebrow/Eyebrow';
import socialPlatforms from '@/content/socialPlatforms';
import type { ContentImage, EmailAddress, SocialLink } from '@/content/types';
import { contactChannels, type ContactChannel } from '@/lib/contactChannels';
type ContactDetailsProps = {
// Id of the h2, unique on the page: the card can appear twice
titleId: string;
title: string;
email: EmailAddress;
socials: SocialLink[];
// Small round photo next to the heading; decorative, the heading and
// the page already say whose card it is
portrait?: ContentImage;
'data-testid'?: string;
};
const iconOf = (channel: ContactChannel) =>
channel.kind === 'email'
? mailOutlined
: socialPlatforms[channel.platform].icon;
// "Direct contact": a card with the ways to reach Andrea, each an icon and a
// link (BR-CD-01..08). Renders nothing when no channel is valid.
export default function ContactDetails({
titleId,
title,
email,
socials,
portrait,
'data-testid': testId,
}: ContactDetailsProps) {
const channels = contactChannels(email, socials);
if (channels.length === 0) return null;
return (
<Box
bg="white"
borderWidth="1px"
borderColor="line"
boxShadow="panel"
p={{ base: 6, md: 8 }}
data-testid={testId}
>
<Flex align="center" gap={4} mb={3}>
{portrait && (
<Image
src={portrait.src}
alt=""
htmlWidth={portrait.width}
htmlHeight={portrait.height}
boxSize="72px"
rounded="full"
objectFit="cover"
flexShrink={0}
data-testid="contact-details-portrait"
/>
)}
<Eyebrow as="h2" id={titleId} mb={0}>
{title}
</Eyebrow>
</Flex>
<chakra.ul listStyleType="none" aria-labelledby={titleId}>
{channels.map((channel) => (
<chakra.li key={channel.href}>
<Link
variant="subtle"
href={channel.href}
display="flex"
alignItems="center"
gap={4}
minH="44px"
{...(channel.external && {
target: '_blank',
rel: 'noopener noreferrer',
})}
data-testid={`contact-details-${
channel.kind === 'email'
? 'email'
: channel.platform
}`}
>
<Box
as="span"
color="accent.deep"
fontSize="1.375rem"
display="inline-flex"
>
<Icon icon={iconOf(channel)} aria-hidden />
</Box>
{/* Space outside the hidden text, or it drops out
of the announced name */}
{channel.label}
{channel.external && (
<>
{' '}
<VisuallyHidden>
(opent in nieuw tabblad)
</VisuallyHidden>
</>
)}
</Link>
</chakra.li>
))}
</chakra.ul>
</Box>
);
}
@@ -26,6 +26,7 @@ const renderForm = (
options={options}
mailSubject="Vraag via andreaslop.nl"
email={siteContent.email}
replyTime="1-2 werkdagen"
submit={vi.fn().mockResolvedValue(undefined)}
{...props}
/>,
@@ -117,6 +118,24 @@ describe('ContactForm', () => {
expect(screen.queryByTestId('contact-form')).toBeNull();
});
it('takes the reply time for the thank-you from the content', async () => {
await renderForm({ replyTime: '3 werkdagen' });
fillIn();
send();
expect(
await screen.findByTestId('contact-form-sent'),
).toHaveTextContent('Ik reageer binnen 3 werkdagen.');
});
it('shows the privacy line under the submit button', async () => {
await renderForm();
const form = screen.getByTestId('contact-form');
expect(form).toContainElement(screen.getByTestId('privacy-note'));
expect(
screen.getByRole('link', { name: 'privacyverklaring' }),
).toHaveAttribute('href', '/privacyverklaring');
});
it('keeps the input and offers the mail link when sending fails', async () => {
await renderForm({ submit: vi.fn().mockRejectedValue(new Error('x')) });
fillIn();
@@ -194,6 +213,7 @@ describe('ContactForm', () => {
preselect={preselect}
mailSubject="Vraag via andreaslop.nl"
email={siteContent.email}
replyTime="1-2 werkdagen"
/>
</>
);
@@ -12,6 +12,7 @@ import {
Textarea,
useRecipe,
} from '@chakra-ui/react';
import PrivacyNote from '@/components/PrivacyNote/PrivacyNote';
import { submitContactForm } from '@/contact/submitContactForm';
import {
CONTACT_LIMITS,
@@ -39,12 +40,11 @@ type ContactFormProps = {
preselect?: { shoot: string; key: number };
mailSubject: string;
email: EmailAddress;
// How soon Andrea answers, e.g. '1-2 werkdagen' (siteContent)
replyTime: string;
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.
@@ -54,6 +54,7 @@ export default function ContactForm({
preselect,
mailSubject,
email,
replyTime,
submit = submitContactForm,
}: ContactFormProps) {
const reduce = (
@@ -106,7 +107,7 @@ export default function ContactForm({
borderStartColor="accent"
bg="paper.alt"
>
{SENT_MESSAGE}
{`Bedankt voor je bericht! Ik reageer binnen ${replyTime}.`}
</Box>
);
}
@@ -298,6 +299,7 @@ export default function ContactForm({
>
{disabled ? 'Versturen…' : '(Aan)vraag versturen'}
</chakra.button>
<PrivacyNote />
</Stack>
</chakra.form>
);
@@ -44,7 +44,21 @@ describe('ContactFormGate', () => {
expect(screen.getByTestId('contact-gate-notice')).toHaveTextContent(
'Het contactformulier komt binnenkort.',
);
expect(screen.queryByRole('link')).toBeNull();
// Only the privacy link is left; no mail link without an address
expect(
screen.getAllByRole('link').map((link) => link.textContent),
).toEqual(['privacyverklaring']);
});
it('shows the privacy line under the notice, outside the inert form', async () => {
await renderGate(false);
const notice = screen.getByTestId('contact-gate-notice');
const note = screen.getByTestId('privacy-note');
expect(notice).toContainElement(note);
expect(note.closest('[inert]')).toBeNull();
expect(
screen.getByRole('link', { name: 'privacyverklaring' }),
).toHaveAttribute('href', '/privacyverklaring');
});
it('shows just the form when switched on', async () => {
@@ -1,6 +1,7 @@
import type { ReactNode } from 'react';
import { Box, chakra, Link, Text, useRecipe } from '@chakra-ui/react';
import Eyebrow from '@/components/Eyebrow/Eyebrow';
import PrivacyNote from '@/components/PrivacyNote/PrivacyNote';
import type { EmailAddress } from '@/content/types';
import { emailAddress } from '@/lib/emailAddress';
import { mailtoLink } from '@/lib/mailLink';
@@ -68,6 +69,8 @@ export default function ContactFormGate({
Stuur een e-mail
</chakra.a>
)}
{/* Readable now, while the form's own line is inert (BR-PR-03) */}
<PrivacyNote mt={6} />
</Box>
</Box>
);
@@ -0,0 +1,124 @@
import { useState } from 'react';
import { act, fireEvent, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import packages from '@/content/packages';
import siteContent from '@/content/siteContent';
import { axeResults } from '@/test/axe';
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
import { renderWithProviders } from '@/test/renderWithProviders';
import ContactPanel from './ContactPanel';
type Props = Partial<React.ComponentProps<typeof ContactPanel>>;
const panel = (props: Props = {}) => (
<ContactPanel
idPrefix="test"
packages={packages}
enabled={false}
email={siteContent.email}
replyTime="1-2 werkdagen"
load="eager"
{...props}
/>
);
// 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);
const mailButton = () => screen.getByRole('link', { name: 'Stuur een e-mail' });
describe('ContactPanel', () => {
it('loads the form right away when eager, behind the gate', async () => {
const { container } = await renderWithProviders(panel());
expect(await shoot()).toHaveValue('');
expect(screen.getByTestId('contact-gate-notice')).toBeInTheDocument();
expect(mailButton()).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
);
expect(await axeResults(container)).toHaveNoViolations();
});
it('offers the shown packages and Overig as shoots', async () => {
await renderWithProviders(panel({ enabled: true }));
const options = [...(await shoot()).querySelectorAll('option')].map(
(option) => option.textContent,
);
expect(options).toEqual([
'Kies een optie...',
...packages.map((pkg) => pkg.name),
'Overig',
]);
});
it('waits with a placeholder until the form comes near the screen when lazy', async () => {
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
FakeIntersectionObserver.reset();
await renderWithProviders(panel({ load: 'lazy' }));
expect(screen.queryByTestId('contact-form')).toBeNull();
// The notice is already in place over the reserved space
expect(screen.getByTestId('contact-gate-notice')).toBeInTheDocument();
act(() =>
FakeIntersectionObserver.instances.forEach((observer) =>
observer.trigger(true),
),
);
expect(await shoot()).toBeInTheDocument();
});
it('loads a lazy form at once when a package is chosen', async () => {
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
FakeIntersectionObserver.reset();
await renderWithProviders(panel({ load: 'lazy', pakket: 'newborn' }));
expect(await shoot()).toHaveValue('newborn');
});
it('preselects a known package and puts it in the mail subject', async () => {
await renderWithProviders(panel({ pakket: ' NEWBORN ' }));
expect(await shoot()).toHaveValue('newborn');
expect(mailButton()).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Aanvraag%20fotoshoot%3A%20Newborn',
);
});
it('ignores an unknown package', async () => {
await renderWithProviders(panel({ pakket: 'bruiloft' }));
expect(await shoot()).toHaveValue('');
expect(mailButton()).toHaveAttribute(
'href',
'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
);
});
it('applies the same package again after the visitor changed it', async () => {
// The page clears ?pakket= after taking it over; a second "Boek"
// click on the same package brings it back
function Harness() {
const [pakket, setPakket] = useState<string | undefined>('newborn');
return (
<>
<button onClick={() => setPakket(undefined)}>wis</button>
<button onClick={() => setPakket('newborn')}>boek</button>
{panel({ enabled: true, pakket })}
</>
);
}
await renderWithProviders(<Harness />);
fireEvent.change(await shoot(), { target: { value: 'gezin' } });
fireEvent.click(screen.getByRole('button', { name: 'wis' }));
expect(await shoot()).toHaveValue('gezin');
fireEvent.click(screen.getByRole('button', { name: 'boek' }));
expect(await shoot()).toHaveValue('newborn');
});
it('shows just the form when switched on', async () => {
await renderWithProviders(panel({ enabled: true }));
await shoot();
expect(screen.queryByTestId('contact-gate-notice')).toBeNull();
expect(screen.getByTestId('privacy-note')).toBeInTheDocument();
});
});
@@ -0,0 +1,100 @@
import { lazy, Suspense, useMemo, useState } from 'react';
import { Box } from '@chakra-ui/react';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import ContactFormGate from '@/components/ContactForm/ContactFormGate';
import type { EmailAddress, 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) is its own chunk, so a page
// only pays for it when the form is about to be used. On the homepage that
// saved ±0.03 Lighthouse performance on mobile.
const ContactForm = lazy(() => import('@/components/ContactForm/ContactForm'));
// Keeps the form's space while it loads, so the notice sits where it will
// stay and the page below does not jump (measured with the privacy line:
// 649px on phones, where name and e-mail are stacked, 547px from sm)
const FORM_PLACEHOLDER_HEIGHT = { base: '649px', sm: '547px' };
type ContactPanelProps = {
// Prefix for the form's field ids, unique per page
idPrefix: string;
packages: PricingPackage[];
enabled: boolean;
email: EmailAddress;
replyTime: string;
// Raw ?pakket= value from the page; checked against the shown packages
pakket?: string;
// lazy: load the form when it comes near the screen or a package is
// chosen (homepage); eager: start loading it with the page (contact page)
load: 'lazy' | 'eager';
};
// The contact form, ready to place on a page: the coming-soon gate, the
// shoot options from the packages and a package chosen via ?pakket=, with
// the mail subject that goes with it (BR-CPN-01..06). Heading, URL clean-up,
// scrolling and focus stay with the page.
export default function ContactPanel({
idPrefix,
packages,
enabled,
email,
replyTime,
pakket,
load,
}: ContactPanelProps) {
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);
}
}
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(load === 'eager');
if (!formLoaded && (inView || pakket !== undefined)) setFormLoaded(true);
const placeholder = <Box minH={FORM_PLACEHOLDER_HEIGHT} />;
return (
<ContactFormGate enabled={enabled} email={email} subject={subject}>
<Box ref={ref}>
{formLoaded ? (
<Suspense fallback={placeholder}>
<ContactForm
idPrefix={idPrefix}
options={options}
preselect={preselect}
mailSubject={subject}
email={email}
replyTime={replyTime}
/>
</Suspense>
) : (
placeholder
)}
</Box>
</ContactFormGate>
);
}
+4 -1
View File
@@ -41,7 +41,10 @@ describe('Footer', () => {
});
expect(link).toHaveAttribute('target', '_blank');
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
expect(link).toHaveAttribute('href', siteContent.socials[0].href);
expect(link).toHaveAttribute(
'href',
siteContent.socials.find((s) => s.platform === 'facebook')?.href,
);
});
it('voegt het e-mailadres pas bij het tonen samen', async () => {
+4
View File
@@ -21,8 +21,12 @@ describe('Hero', () => {
const links = screen.getAllByRole('link', {
name: /opent in nieuw tabblad/,
});
// In content order: Instagram, then Facebook
expect(links).toHaveLength(2);
expect(links[0]).toHaveAccessibleName(
'Instagram (opent in nieuw tabblad)',
);
expect(links[1]).toHaveAccessibleName(
'Facebook (opent in nieuw tabblad)',
);
expect(links[0]).toHaveAttribute('rel', 'noopener noreferrer');
@@ -0,0 +1,18 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import PrivacyNote from './PrivacyNote';
describe('PrivacyNote', () => {
it('links to the privacy statement', async () => {
const { container } = await renderWithProviders(<PrivacyNote />);
expect(screen.getByTestId('privacy-note')).toHaveTextContent(
'Lees in de privacyverklaring wat ik met je gegevens doe.',
);
expect(
screen.getByRole('link', { name: 'privacyverklaring' }),
).toHaveAttribute('href', '/privacyverklaring');
expect(await axeResults(container)).toHaveNoViolations();
});
});
@@ -0,0 +1,24 @@
import { Link, Text, type TextProps } from '@chakra-ui/react';
import RouterLink from '@/components/RouterLink';
// The line under a contact form (and under its "coming soon" notice) that
// tells visitors where to read what happens with their details (BR-PR-01).
// One component, so the text and the link never differ between places.
export default function PrivacyNote(props: TextProps) {
return (
<Text
fontSize="sm"
color="ink.soft"
data-testid="privacy-note"
{...props}
>
Lees in de{' '}
<Link variant="underline" asChild>
<RouterLink to="/privacyverklaring">
privacyverklaring
</RouterLink>
</Link>{' '}
wat ik met je gegevens doe.
</Text>
);
}
@@ -14,6 +14,7 @@ const renderSection = (pakket?: string, path = '/') =>
packages={packages}
enabled={false}
email={siteContent.email}
replyTime={siteContent.contactForm.replyTime}
pakket={pakket}
/>,
{ path },
@@ -1,8 +1,7 @@
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
import { Box, useMediaQuery } from '@chakra-ui/react';
import { useEffect } from 'react';
import { useMediaQuery } 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 ContactPanel from '@/components/ContactPanel/ContactPanel';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
@@ -11,68 +10,34 @@ import type {
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;
replyTime: string;
// ?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).
// contact form, which sits far below the hero and so loads lazily. After a
// "Boek ..." click it tidies the URL and moves focus here (BR-PARAM-02,
// BR-FOCUS-01); the panel takes over the package itself.
export default function ContactSection({
content,
packages,
enabled,
email,
replyTime,
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) and
// Remove ?pakket= from the address bar (no extra history entry) and
// continue keyboard and screen reader users here. This navigation
// replaces the "Boek" click's before the router has scrolled for it, so
// it must ask the router to scroll to #contact itself.
@@ -98,16 +63,6 @@ export default function ContactSection({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [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 (
<PageSection
labelledBy={TITLE_ID}
@@ -124,27 +79,15 @@ export default function ContactSection({
/>
</Reveal>
<Reveal>
<ContactFormGate
<ContactPanel
idPrefix="home-contact"
packages={packages}
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>
replyTime={replyTime}
pakket={pakket}
load="lazy"
/>
</Reveal>
</PageSection>
);
+8 -5
View File
@@ -5,19 +5,22 @@ const siteContent: SiteContent = {
// Elke zin op een eigen regel; de footer toont de regelafbreking
footerIntro:
'Lifestyle fotograaf uit Huizen.\nIk leg jouw mooiste momenten vast.',
// In display order: Instagram first, her main channel
socials: [
{
platform: 'facebook',
href: 'https://www.facebook.com/andreaslopfotografie/',
},
{
platform: 'instagram',
href: 'https://www.instagram.com/andreaslopfotografie/',
label: '@andreaslopfotografie',
},
{
platform: 'facebook',
href: 'https://www.facebook.com/andreaslopfotografie/',
label: 'Andrea Slop Fotografie',
},
],
email: { user: 'info', domain: 'andreaslop.nl' },
// Switched on once the API can receive the form
contactForm: { enabled: false },
contactForm: { enabled: false, replyTime: '1-2 werkdagen' },
// Huizen and the region around it (Bussum, Hilversum, …), as the pages
// say; not the whole country, which would weaken the local signal
serviceArea: [
+6 -1
View File
@@ -7,6 +7,9 @@ import type { SocialPlatform } from './socialPlatforms.ts';
export interface SocialLink {
platform: SocialPlatform;
href: string; // alleen getoond als geldige https-URL (zie visibleSocials)
// Link text in the contact card, e.g. '@andreaslopfotografie'; without
// it the card shows the platform name
label?: string;
}
// Het e-mailadres in delen: zo staat het volledige adres nergens letterlijk
@@ -21,7 +24,9 @@ export interface SiteContent {
socials: SocialLink[];
email: EmailAddress;
// Off: the form is shown dimmed under a "coming soon" notice (FR-HP-07)
contactForm: { enabled: boolean };
// replyTime: how soon Andrea answers, e.g. '1-2 werkdagen'; used by the
// form's thank-you and the contact page, so they always agree
contactForm: { enabled: boolean; replyTime: string };
// Where Andrea mainly works, for the structured data of the business
// and its services. Matches what the pages say, not every place she
// would travel to.
+154
View File
@@ -0,0 +1,154 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import siteContent from '../content/siteContent';
import socialPlatforms from '../content/socialPlatforms';
import { anyEmail, socialLink } from '../test/arbitraries';
import { contactChannels } from './contactChannels';
import { emailAddress } from './emailAddress';
import { visibleSocials } from './visibleSocials';
const socialLinks = fc.array(socialLink, { maxLength: 5 });
describe('contactChannels', () => {
it('lists e-mail, Instagram and Facebook for the site content', () => {
expect(contactChannels(siteContent.email, siteContent.socials)).toEqual(
[
{
kind: 'email',
href: 'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
label: 'info@andreaslop.nl',
external: false,
},
{
kind: 'social',
platform: 'instagram',
href: 'https://www.instagram.com/andreaslopfotografie/',
label: '@andreaslopfotografie',
external: true,
},
{
kind: 'social',
platform: 'facebook',
href: 'https://www.facebook.com/andreaslopfotografie/',
label: 'Andrea Slop Fotografie',
external: true,
},
],
);
});
it('leaves out an invalid e-mail address and invalid links', () => {
const channels = contactChannels({ user: 'info', domain: 'nodot' }, [
{ platform: 'facebook', href: 'javascript:alert(1)' },
{ platform: 'instagram', href: 'https://instagram.com/x' },
]);
expect(channels.map((channel) => channel.kind)).toEqual(['social']);
});
it('falls back to the platform name without a usable label', () => {
const channels = contactChannels({ user: '', domain: '' }, [
{ platform: 'instagram', href: 'https://instagram.com/x' },
{
platform: 'facebook',
href: 'https://facebook.com/x',
label: ' ',
},
]);
expect(channels.map((channel) => channel.label)).toEqual([
'Instagram',
'Facebook',
]);
});
it('is empty when nothing is valid', () => {
expect(contactChannels({ user: '', domain: '' }, [])).toEqual([]);
});
it('puts the e-mail channel first exactly when the address is valid (invariant)', () => {
fc.assert(
fc.property(anyEmail, socialLinks, (email, socials) => {
const channels = contactChannels(email, socials);
const valid = emailAddress(email) !== null;
expect(channels[0]?.kind === 'email').toBe(valid);
expect(
channels.filter((channel) => channel.kind === 'email'),
).toHaveLength(valid ? 1 : 0);
}),
);
});
it('shows exactly the visible social links, in order (oracle)', () => {
fc.assert(
fc.property(anyEmail, socialLinks, (email, socials) => {
const shown = contactChannels(email, socials).flatMap(
(channel) =>
channel.kind === 'social'
? [
{
platform: channel.platform,
href: channel.href,
},
]
: [],
);
expect(shown).toEqual(
visibleSocials(socials).map(({ platform, href }) => ({
platform,
href,
})),
);
}),
);
});
it('labels a social link with its trimmed label, or else the platform name (invariant)', () => {
fc.assert(
fc.property(socialLinks, (socials) => {
const channels = contactChannels(
{ user: '', domain: '' },
socials,
);
visibleSocials(socials).forEach((link, index) => {
const expected =
link.label?.trim() ||
socialPlatforms[link.platform].name;
expect(channels[index].label).toBe(expected);
expect(channels[index].label.trim()).not.toBe('');
});
}),
);
});
it('only links to mailto: or https: (invariant)', () => {
fc.assert(
fc.property(anyEmail, socialLinks, (email, socials) => {
for (const channel of contactChannels(email, socials)) {
const scheme = new URL(channel.href).protocol;
expect(
channel.kind === 'email' ? 'mailto:' : 'https:',
).toBe(scheme);
}
}),
);
});
it('opens exactly the social channels in a new tab (invariant)', () => {
fc.assert(
fc.property(anyEmail, socialLinks, (email, socials) => {
for (const channel of contactChannels(email, socials)) {
expect(channel.external).toBe(channel.kind === 'social');
}
}),
);
});
it('has at most one channel per link plus the e-mail (invariant)', () => {
fc.assert(
fc.property(anyEmail, socialLinks, (email, socials) => {
expect(
contactChannels(email, socials).length,
).toBeLessThanOrEqual(1 + socials.length);
}),
);
});
});
+48
View File
@@ -0,0 +1,48 @@
import socialPlatforms, {
type SocialPlatform,
} from '../content/socialPlatforms.ts';
import type { EmailAddress, SocialLink } from '../content/types.ts';
import { emailAddress } from './emailAddress.ts';
import { mailSubject, mailtoLink } from './mailLink.ts';
import { visibleSocials } from './visibleSocials.ts';
// One way to reach Andrea, as the contact card shows it
export type ContactChannel =
| { kind: 'email'; href: string; label: string; external: false }
| {
kind: 'social';
platform: SocialPlatform;
href: string;
label: string;
// Opens in a new tab (BR-CD-05)
external: true;
};
// The channels of the contact card (BR-CD-01..05): the e-mail address first
// when it is valid, then the valid social links in content order, each with
// its label or else the platform name. Only mailto: and https: links come
// out, because both helpers already drop everything else.
export function contactChannels(
email: EmailAddress,
socials: readonly SocialLink[],
): ContactChannel[] {
const address = emailAddress(email);
const mail: ContactChannel[] = address
? [
{
kind: 'email',
href: mailtoLink(address, mailSubject()),
label: address,
external: false,
},
]
: [];
const social = visibleSocials(socials).map((link): ContactChannel => ({
kind: 'social',
platform: link.platform,
href: link.href,
label: link.label?.trim() || socialPlatforms[link.platform].name,
external: true,
}));
return [...mail, ...social];
}
+1
View File
@@ -47,6 +47,7 @@ function Index() {
packages={packages}
enabled={siteContent.contactForm.enabled}
email={siteContent.email}
replyTime={siteContent.contactForm.replyTime}
pakket={pakket}
/>
{instagram && (
+13 -5
View File
@@ -39,10 +39,18 @@ export const anyHref = fc.oneof(
fc.string(),
);
export const socialLink: fc.Arbitrary<SocialLink> = fc.record({
platform,
href: anyHref,
});
export const socialLink: fc.Arbitrary<SocialLink> = fc.record(
{
platform,
href: anyHref,
// Missing, blank, padded or ordinary, as an editor might type it
label: fc.oneof(
fc.constantFrom('', ' ', ' @andreaslopfotografie '),
fc.string({ maxLength: 30 }),
),
},
{ requiredKeys: ['platform', 'href'] },
);
// Een geldig deel van een e-mailadres: geen spaties, geen @
const emailPart = fc.stringMatching(/^[a-z0-9._-]{1,20}$/);
@@ -65,7 +73,7 @@ export const anySiteContent: fc.Arbitrary<SiteContent> = fc.record({
footerIntro: fc.string(),
socials: fc.array(socialLink, { maxLength: 4 }),
email: validEmail,
contactForm: fc.record({ enabled: fc.boolean() }),
contactForm: fc.record({ enabled: fc.boolean(), replyTime: fc.string() }),
serviceArea: fc.array(
fc.record({
type: fc.constantFrom(