From 20282a16f76a1619b13f5b5df1b17eab788e9142 Mon Sep 17 00:00:00 2001 From: alannnc Date: Mon, 25 Sep 2023 10:57:02 -0700 Subject: [PATCH] fix: verify-rerender-checkout-stripe-session (#11493) --- apps/web/pages/auth/verify.tsx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/web/pages/auth/verify.tsx b/apps/web/pages/auth/verify.tsx index 48c52773d8..12d2c4c4f5 100644 --- a/apps/web/pages/auth/verify.tsx +++ b/apps/web/pages/auth/verify.tsx @@ -60,10 +60,16 @@ export default function Verify() { const routerQuery = useRouterQuery(); const { t, sessionId, stripeCustomerId } = querySchema.parse(routerQuery); const [secondsLeft, setSecondsLeft] = useState(30); - const { data } = trpc.viewer.public.stripeCheckoutSession.useQuery({ - stripeCustomerId, - checkoutSessionId: sessionId, - }); + const { data } = trpc.viewer.public.stripeCheckoutSession.useQuery( + { + stripeCustomerId, + checkoutSessionId: sessionId, + }, + { + enabled: !!stripeCustomerId || !!sessionId, + staleTime: Infinity, + } + ); useSendFirstVerificationLogin({ email: data?.customer?.email, username: data?.customer?.username }); // @note: check for t=timestamp and apply disabled state and secondsLeft accordingly // to avoid refresh to skip waiting 30 seconds to re-send email @@ -123,12 +129,12 @@ export default function Verify() { {hasPaymentFailed ? ( ) : sessionId ? ( - + ) : ( )} -

+

{hasPaymentFailed ? "Your payment failed" : sessionId @@ -138,7 +144,7 @@ export default function Verify() { {hasPaymentFailed && (

Your account has been created, but your premium has not been reserved.

)} -

+

We have sent an email to {customer?.email} with a link to activate your account.{" "} {hasPaymentFailed && "Once you activate your account you will be able to try purchase your premium username again or select a different one."} @@ -158,7 +164,7 @@ export default function Verify() { e.preventDefault(); setSecondsLeft(30); // Update query params with t:timestamp, shallow: true doesn't re-render the page - const _searchParams = new URLSearchParams(searchParams); + const _searchParams = new URLSearchParams(searchParams.toString()); _searchParams.set("t", `${Date.now()}`); router.replace(`${pathname}?${_searchParams.toString()}`); return await sendVerificationLogin(customer.email, customer.username);