The build still bakes the current packages and the active banner into the HTML. After hydration the page asks /api/v1/offerings and /api/v1/offerings/banner once and replaces what differs; errors and time-outs keep what was baked, and a 204 from the banner route hides the banner. The banner is now the OfferingBanner contract (title, text, optional link) instead of layout=banner. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
122 lines
4.8 KiB
TypeScript
122 lines
4.8 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { Box, Grid, Heading, VisuallyHidden } from '@chakra-ui/react';
|
|
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
|
import ContactAside, {
|
|
ASIDE_MEDIA,
|
|
} from '../components/contact/ContactAside/ContactAside';
|
|
import ContactDetails from '../components/ContactDetails/ContactDetails';
|
|
import ContactPanel from '../components/ContactPanel/ContactPanel';
|
|
import PageIntro from '../components/PageIntro/PageIntro';
|
|
import PageSection from '../components/PageSection/PageSection';
|
|
import Reveal from '../components/Reveal/Reveal';
|
|
import contactContent from '../content/contactContent';
|
|
import { usePackages } from '../components/PackagesProvider/PackagesProvider';
|
|
import siteContent from '../content/siteContent';
|
|
import { withReplyTime } from '../lib/withReplyTime';
|
|
import useHydrated from '../hooks/useHydrated';
|
|
import {
|
|
contactPage,
|
|
pageHead,
|
|
preloadImage,
|
|
structuredDataScript,
|
|
} from '../seo';
|
|
|
|
// ?pakket= from a link elsewhere on the site. Only text is kept; the panel
|
|
// checks it against the shown packages (BR-CP-10).
|
|
type ContactSearch = { pakket?: string };
|
|
|
|
const FORM_TITLE_ID = 'contact-form-title';
|
|
|
|
export const Route = createFileRoute('/contact')({
|
|
validateSearch: (search: Record<string, unknown>): ContactSearch =>
|
|
typeof search.pakket === 'string' ? { pakket: search.pakket } : {},
|
|
head: () => {
|
|
const base = pageHead('/contact');
|
|
return {
|
|
...base,
|
|
// The aside photo sits in a <picture>, which React does not hoist
|
|
links: [
|
|
...base.links,
|
|
preloadImage(contactContent.image, { media: ASIDE_MEDIA }),
|
|
],
|
|
scripts: [structuredDataScript(contactPage('/contact'))],
|
|
};
|
|
},
|
|
component: Contact,
|
|
});
|
|
|
|
// The contact page (mockup 1a): the form next to the photo with the contact
|
|
// card on wide screens; below lg the card with a small portrait above the
|
|
// form (BR-CP-01..04). The card is in the page twice, one per layout, so the
|
|
// reading order always matches what is shown.
|
|
function Contact() {
|
|
const packages = usePackages();
|
|
const { pakket: searched } = Route.useSearch();
|
|
// The search only counts after hydration, so the prerendered HTML and the
|
|
// first browser render agree (BR-HYD-10)
|
|
const pakket = useHydrated() ? searched : undefined;
|
|
const navigate = useNavigate();
|
|
const { head, formTitle, detailsTitle, image, portrait } = contactContent;
|
|
const { email, socials, contactForm } = siteContent;
|
|
|
|
// The panel has taken the package over; tidy the address bar without a
|
|
// history entry and without a focus move (BR-CP-12). This navigation can
|
|
// replace the one that brought the visitor here before the router has
|
|
// scrolled for it, so it keeps the reset to the top of the page.
|
|
useEffect(() => {
|
|
if (pakket === undefined) return;
|
|
void navigate({ to: '/contact', search: {}, replace: true });
|
|
}, [pakket, navigate]);
|
|
|
|
const details = (variant: 'narrow' | 'wide') => (
|
|
<ContactDetails
|
|
titleId={`contact-details-${variant}-title`}
|
|
title={detailsTitle}
|
|
email={email}
|
|
socials={socials}
|
|
portrait={variant === 'narrow' ? portrait : undefined}
|
|
data-testid={`contact-details-${variant}`}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<PageIntro eyebrow={head.eyebrow} title={head.title}>
|
|
{withReplyTime(head.intro, contactForm.replyTime)}
|
|
</PageIntro>
|
|
<PageSection
|
|
labelledBy={FORM_TITLE_ID}
|
|
spacing="flushTop"
|
|
data-testid="contact-page"
|
|
>
|
|
<Box display={{ base: 'block', lg: 'none' }} mb={10}>
|
|
<Reveal>{details('narrow')}</Reveal>
|
|
</Box>
|
|
<Grid
|
|
templateColumns={{ base: '1fr', lg: '3fr 2fr' }}
|
|
gap="clamp(2rem, 6vw, 5.5rem)"
|
|
alignItems="start"
|
|
>
|
|
<Reveal>
|
|
<VisuallyHidden asChild>
|
|
<Heading as="h2" id={FORM_TITLE_ID}>
|
|
{formTitle}
|
|
</Heading>
|
|
</VisuallyHidden>
|
|
<ContactPanel
|
|
idPrefix="contact"
|
|
packages={packages}
|
|
enabled={contactForm.enabled}
|
|
email={email}
|
|
replyTime={contactForm.replyTime}
|
|
pakket={pakket}
|
|
load="eager"
|
|
/>
|
|
</Reveal>
|
|
<ContactAside image={image}>{details('wide')}</ContactAside>
|
|
</Grid>
|
|
</PageSection>
|
|
</>
|
|
);
|
|
}
|