New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: redeem 100% off coupons #171
Conversation
joelhooks
commented
May 4, 2024
•
edited
edited
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -54,7 +55,7 @@ export default function RootLayout({ | |||
*/ | |||
routerConfig={extractRouterConfig(ourFileRouter)} | |||
/> | |||
{children} | |||
<CouponProvider>{children}</CouponProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes it global, so any page will pop the redeem dialog if it's a golden ticket
React.useEffect(() => { | ||
const searchParams = new URLSearchParams(window.location.search) | ||
|
||
const codeParam = searchParams.get('code') | ||
const couponParam = searchParams.get('coupon') | ||
|
||
setCouponLoader(getCouponForCode(codeParam || couponParam)) | ||
}, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this effect inspects the search params for a code/coupon and sets the LOADER (server action)
setCouponLoader(getCouponForCode(codeParam || couponParam)) | ||
}, []) | ||
|
||
const coupon = couponLoader ? use(couponLoader) : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we have a LOADER, we can use
it here 🫦
React.useEffect(() => { | ||
if (coupon?.isValid) { | ||
setProductLoader(getProduct(coupon.restrictedToProductId as string)) | ||
} | ||
}, [coupon?.restrictedToProductId, coupon?.isValid]) | ||
|
||
const product = productLoader ? use(productLoader) : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there's a coupon loaded, and it's restricted to a product id and is valid, we set a product loader and use
it 🦦
{isRedeemable && ( | ||
<RedeemDialog | ||
open={validCoupon} | ||
couponId={coupon?.id} | ||
product={product} | ||
/> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is a redeemable coupon we add the dialog