-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redeem 100% off coupons (#171)
* feat: redeem coupons * feat: redeem coupons * changeset added
- Loading branch information
Showing
12 changed files
with
230 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@coursebuilder/adapter-drizzle": patch | ||
"@coursebuilder/core": patch | ||
--- | ||
|
||
enables coupon redemption for 100% of "golden tickets" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
import { use } from 'react' | ||
import { getProduct } from '@/lib/products-query' | ||
import { getCouponForCode } from '@/lib/props-for-commerce' | ||
import RedeemDialog from '@/pricing/redeem-dialog' | ||
|
||
import { Product } from '@coursebuilder/core/schemas' | ||
|
||
export const CouponContext = React.createContext<any>({}) | ||
|
||
export const CouponProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [couponLoader, setCouponLoader] = | ||
React.useState<ReturnType<typeof getCouponForCode>>() | ||
const [productLoader, setProductLoader] = React.useState< | ||
Promise<Product | null> | undefined | ||
>() | ||
|
||
React.useEffect(() => { | ||
const searchParams = new URLSearchParams(window.location.search) | ||
|
||
const codeParam = searchParams.get('code') | ||
const couponParam = searchParams.get('coupon') | ||
|
||
setCouponLoader(getCouponForCode(codeParam || couponParam)) | ||
}, []) | ||
|
||
const coupon = couponLoader ? use(couponLoader) : undefined | ||
const validCoupon = Boolean(coupon && coupon.isValid) | ||
|
||
React.useEffect(() => { | ||
if (coupon?.isValid) { | ||
setProductLoader(getProduct(coupon.restrictedToProductId as string)) | ||
} | ||
}, [coupon?.restrictedToProductId, coupon?.isValid]) | ||
|
||
const product = productLoader ? use(productLoader) : undefined | ||
const isRedeemable = validCoupon && product && coupon?.isRedeemable | ||
|
||
console.log({ coupon, product }) | ||
|
||
return ( | ||
<CouponContext.Provider value={{ coupon }}> | ||
<> | ||
{isRedeemable && ( | ||
<RedeemDialog | ||
open={validCoupon} | ||
couponId={coupon?.id} | ||
product={product} | ||
/> | ||
)} | ||
{children} | ||
</> | ||
</CouponContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
@import './commerce.css'; | ||
@import './login.css'; | ||
@import './redeem-dialog.css'; | ||
|
||
@layer base { | ||
:root { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* Redeem dialog */ | ||
[data-redeem-dialog] { | ||
@apply h-[400px] overflow-y-scroll; | ||
} | ||
[data-redeem-dialog-content] { | ||
@apply bg-background dark:bg-secondary fixed left-1/2 top-1/2 z-[60] max-h-[90vh] w-full max-w-[95%] -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-md shadow-xl sm:max-w-md; | ||
[data-title] { | ||
@apply px-8 pt-8 text-xl font-bold; | ||
} | ||
[data-description] { | ||
@apply px-8 pb-4 pt-4 opacity-80; | ||
} | ||
form { | ||
@apply px-8 py-4; | ||
[data-email] { | ||
@apply mt-2 flex flex-col; | ||
label { | ||
@apply pb-1; | ||
} | ||
input { | ||
@apply dark:bg-background rounded border border-gray-300 bg-gray-200 px-4 py-2 dark:border-gray-900; | ||
} | ||
} | ||
[data-actions] { | ||
@apply flex w-full justify-end gap-3 py-8; | ||
[data-cancel] { | ||
@apply dark:bg-background flex rounded bg-gray-200 px-4 py-2 text-sm font-medium; | ||
} | ||
[data-submit] { | ||
@apply bg-primary flex rounded border border-transparent px-4 py-2 text-sm font-medium text-white shadow-sm transition; | ||
} | ||
[data-submit]:hover { | ||
@apply brightness-105; | ||
} | ||
} | ||
} | ||
} | ||
[data-redeem-dialog-overlay] { | ||
@apply fixed inset-0 z-50 bg-black bg-opacity-30 backdrop-blur-sm; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.