-
Notifications
You must be signed in to change notification settings - Fork 28
/
pricing-section.tsx
72 lines (67 loc) 路 1.79 KB
/
pricing-section.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as React from 'react'
import type {
CommerceProps,
SanityProduct,
SanityProductModule,
} from '@skillrecordings/commerce-server/dist/@types'
import {PricingTiers} from '@skillrecordings/skill-lesson/path-to-purchase/product-tiers'
const PRODUCT_BASIC_ID = 'kcd_910c9191-5a69-4019-ad1d-c55bea7e9714'
const PRODUCT_STANDARD_ID = 'kcd_8acc60f1-8c3f-4093-b20d-f60fc6e0cf61'
const PRODUCT_PRO_ID = 'kcd_2b4f4080-4ff1-45e7-b825-7d0fff266e38'
const productsSortOrder: {[key: string]: number} = {
[PRODUCT_BASIC_ID]: 1,
[PRODUCT_PRO_ID]: 2,
[PRODUCT_STANDARD_ID]: 3,
}
const removeModuleBySlug = (
products: any[],
slugToRemove: string,
): SanityProduct[] => {
return products.map((product) => {
return {
...product,
modules:
product?.modules &&
product.modules.filter(
(module: SanityProductModule) => module.slug !== slugToRemove,
),
}
})
}
const PricingSection: React.FC<{
commerceProps: CommerceProps
className?: string
}> = ({
commerceProps: {
couponFromCode,
products,
userId,
purchases = [],
couponIdFromCoupon,
allowPurchase,
},
className,
}) => {
const sortedProducts = [...products].sort(
(a, b) => productsSortOrder[a.productId] - productsSortOrder[b.productId],
)
const filteredProducts = removeModuleBySlug(
sortedProducts,
'welcome-to-epic-react',
)
return (
<div className="relative z-0">
<div className="mx-auto max-w-screen-xl px-4 sm:px-6 lg:px-8">
<PricingTiers
products={filteredProducts}
userId={userId}
purchases={purchases}
couponIdFromCoupon={couponIdFromCoupon}
couponFromCode={couponFromCode}
allowPurchase={allowPurchase}
/>
</div>
</div>
)
}
export default PricingSection