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:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user