Skip to content

Commit 80fb54a

Browse files
Filipclaude
authored andcommitted
feat(checkout): prefill details form from query params with optional lock
Merges useCheckoutPrefill values into the details setValues effect (buyer + ticket attendees, email_confirmation derived from email) and disables prefilled fields when lock is set. 🤖 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9f8c953 commit 80fb54a

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

  • frontend/src/components/routes/product-widget/CollectInformation

frontend/src/components/routes/product-widget/CollectInformation/index.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import countries from "../../../../../data/countries.json";
3333
import classes from "./CollectInformation.module.scss";
3434
import {trackEvent, AnalyticsEvents} from "../../../../utilites/analytics.ts";
3535
import {clearWaitlistJoinedForEvent} from "../../../../hooks/useWaitlistJoined.ts";
36+
import {useCheckoutPrefill, CheckoutPrefill} from "../../../../hooks/useCheckoutPrefill.ts";
3637

3738
const LoadingSkeleton = () =>
3839
(
@@ -48,6 +49,8 @@ export const CollectInformation = () => {
4849
const navigate = useNavigate();
4950
const [searchParams] = useSearchParams();
5051
const isFromWaitlist = searchParams.get('waitlist') === 'true';
52+
const {prefill, lock} = useCheckoutPrefill();
53+
const isLocked = (field: keyof CheckoutPrefill) => lock && prefill[field] !== undefined;
5154
const {
5255
isFetched: isOrderFetched,
5356
data: order,
@@ -296,14 +299,33 @@ export const CollectInformation = () => {
296299

297300
useEffect(() => {
298301
if (isEventFetched && isOrderFetched && isQuestionsFetched && productQuestions && orderQuestions) {
299-
const products = createProductsAndQuestions(createProductIdToQuestionMap());
302+
const builtProducts = createProductsAndQuestions(createProductIdToQuestionMap());
300303
const formOrderQuestions = createFormOrderQuestions();
301304

305+
const orderPrefill = {
306+
...(prefill.first_name !== undefined && {first_name: prefill.first_name}),
307+
...(prefill.last_name !== undefined && {last_name: prefill.last_name}),
308+
...(prefill.email !== undefined && {email: prefill.email, email_confirmation: prefill.email}),
309+
};
310+
311+
const ticketProductIds = new Set(
312+
(products ?? [])
313+
.filter(product => product && product.product_type === 'TICKET')
314+
.map(product => product!.id)
315+
);
316+
317+
const prefilledProducts = builtProducts.map((product: any) =>
318+
ticketProductIds.has(product.product_id)
319+
? {...product, ...orderPrefill}
320+
: product
321+
);
322+
302323
form.setValues({
303324
...form.values,
304-
products: products,
325+
products: prefilledProducts,
305326
order: {
306327
...form.values.order,
328+
...orderPrefill,
307329
questions: formOrderQuestions,
308330
},
309331
});
@@ -433,12 +455,14 @@ export const CollectInformation = () => {
433455
withAsterisk
434456
label={t`First Name`}
435457
placeholder={t`First name`}
458+
disabled={isLocked('first_name')}
436459
{...form.getInputProps("order.first_name")}
437460
/>
438461
<TextInput
439462
withAsterisk
440463
label={t`Last Name`}
441464
placeholder={t`Last Name`}
465+
disabled={isLocked('last_name')}
442466
{...form.getInputProps("order.last_name")}
443467
/>
444468
</InputGroup>
@@ -449,6 +473,7 @@ export const CollectInformation = () => {
449473
type={"email"}
450474
label={t`Email Address`}
451475
placeholder={t`Email Address`}
476+
disabled={isLocked('email')}
452477
rightSection={isEmailValid(form.values.order.email) ? <EmailCheckIcon/> : null}
453478
{...form.getInputProps("order.email")}
454479
/>
@@ -457,6 +482,7 @@ export const CollectInformation = () => {
457482
type={"email"}
458483
label={t`Confirm Email Address`}
459484
placeholder={t`Confirm Email Address`}
485+
disabled={isLocked('email')}
460486
rightSection={isEmailValid(form.values.order.email_confirmation) ? <EmailCheckIcon/> : null}
461487
{...form.getInputProps("order.email_confirmation")}
462488
/>
@@ -645,12 +671,14 @@ export const CollectInformation = () => {
645671
withAsterisk
646672
label={t`First Name`}
647673
placeholder={t`First name`}
674+
disabled={isLocked('first_name')}
648675
{...form.getInputProps(`products.${currentProductIndex}.first_name`)}
649676
/>
650677
<TextInput
651678
withAsterisk
652679
label={t`Last Name`}
653680
placeholder={t`Last Name`}
681+
disabled={isLocked('last_name')}
654682
{...form.getInputProps(`products.${currentProductIndex}.last_name`)}
655683
/>
656684
</InputGroup>
@@ -661,6 +689,7 @@ export const CollectInformation = () => {
661689
type={"email"}
662690
label={t`Email Address`}
663691
placeholder={t`Email Address`}
692+
disabled={isLocked('email')}
664693
rightSection={isEmailValid(form.values.products[currentProductIndex]?.email || '') ?
665694
<EmailCheckIcon/> : null}
666695
{...form.getInputProps(`products.${currentProductIndex}.email`)}
@@ -670,6 +699,7 @@ export const CollectInformation = () => {
670699
type={"email"}
671700
label={t`Confirm Email Address`}
672701
placeholder={t`Confirm Email Address`}
702+
disabled={isLocked('email')}
673703
rightSection={isEmailValid(form.values.products[currentProductIndex]?.email_confirmation || '') ?
674704
<EmailCheckIcon/> : null}
675705
{...form.getInputProps(`products.${currentProductIndex}.email_confirmation`)}

0 commit comments

Comments
 (0)