Skip to content

Commit 8a19f14

Browse files
committed
fix(discover): fix 500 error caused by BigInt serialization of amountMinor in eventPriceSchema
A previous fix (36258b8) converted startDate/endDate in eventInfoSchema from z.bigint() to z.coerce.number() to avoid JSON serialization failures during SSR dehydration. The same issue existed for amountMinor in eventPriceSchema, nested inside eventInfoSchema via pricesGroups. On production, events with paid prices caused JSON.stringify to throw on BigInt values during HydrationBoundary prop serialization, resulting in 500 errors on /discover/upcoming and /discover/past. Closes #1036
1 parent 0558c75 commit 8a19f14

6 files changed

Lines changed: 19 additions & 10 deletions

File tree

app/(dashboard)/dashboard/event/[id]/(default)/gatekeepers/gatekeepers-edition-context-provider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ export function GatekeepersEditionContextProvider({
101101
})),
102102
exclusive: eventInfo.privacy?.eventPrivacy.case === "guarded",
103103
password: "",
104-
pricesGroups: eventInfo.pricesGroups ?? [],
104+
pricesGroups: (eventInfo.pricesGroups ?? []).map((group) => ({
105+
...group,
106+
prices: group.prices.map((price) => ({
107+
...price,
108+
amountMinor: BigInt(price.amountMinor),
109+
})),
110+
})),
105111
communityId: communityId || null,
106112
};
107113

components/features/event/event-registration/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const selectCheckoutPrice = (
5252
groups: SafeEventPriceGroup[],
5353
): CheckoutPrice | null => {
5454
const prices = groups.flatMap((group) => group.prices);
55-
const paidPrices = prices.filter((price) => price.amountMinor > BigInt(0));
55+
const paidPrices = prices.filter((price) => price.amountMinor > 0);
5656
if (paidPrices.length === 0) {
5757
return null;
5858
}
@@ -108,7 +108,7 @@ export function EventRegistrationForm({
108108
(buyerIsCounted ? 1 : 0) + (guestsValue ? guestsValue.length : 0);
109109
const totalMinor =
110110
checkoutPrice && attendeeCount > 0
111-
? checkoutPrice.amountMinor * BigInt(attendeeCount)
111+
? checkoutPrice.amountMinor * attendeeCount
112112
: null;
113113

114114
const onSubmit = async (data: EventRegistrationFormSchemaType) => {

components/features/event/event-registration/paid-purchase-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type PaidPurchaseFormProps = {
1919
isPending: boolean;
2020
maxGuests: number;
2121
requireEmail: boolean;
22-
totalMinor: bigint | null;
22+
totalMinor: number | null;
2323
};
2424

2525
export function PaidPurchaseForm({

components/providers/dashboard-event-edition-context-provider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ export default function DashboardEventEditionContextProvider({
107107
})),
108108
exclusive: eventInfo.privacy?.eventPrivacy.case === "guarded",
109109
password: "",
110-
pricesGroups: eventInfo.pricesGroups ?? [],
110+
pricesGroups: (eventInfo.pricesGroups ?? []).map((group) => ({
111+
...group,
112+
prices: group.prices.map((price) => ({
113+
...price,
114+
amountMinor: BigInt(price.amountMinor),
115+
})),
116+
})),
111117
communityId: communityId || null,
112118
};
113119

components/widgets/price-label.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { useTranslations } from "next-intl";
22
import { useMemo } from "react";
33
import { formatPrice } from "@/lib/pricing";
4-
import { EventPriceGroup } from "@/app/gen/zenao/v1/zenao_pb";
54
import { SafeEventPriceGroup } from "@/types/schemas";
65

7-
export const usePriceLabel = (
8-
pricesGroups: (SafeEventPriceGroup | EventPriceGroup)[],
9-
) => {
6+
export const usePriceLabel = (pricesGroups: SafeEventPriceGroup[]) => {
107
const t = useTranslations("event");
118
return useMemo(() => {
129
const priceGroups = pricesGroups ?? [];

types/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export type SafeEventLocation = z.infer<typeof eventInfoLocationSchema>;
444444

445445
export const eventPriceSchema = z
446446
.object({
447-
amountMinor: z.bigint(),
447+
amountMinor: z.coerce.number(),
448448
currencyCode: z.string(),
449449
paymentAccountId: z.string(),
450450
paymentAccountType: z.string().optional().default(""),

0 commit comments

Comments
 (0)