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>
101 lines
4.0 KiB
TypeScript
101 lines
4.0 KiB
TypeScript
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>
|
|
);
|
|
}
|