Skip to content

Commit 5ab6fd4

Browse files
authored
Merge pull request #584 from topcoder-platform/TCA-920
Add price info on cert details page
2 parents c2fd187 + a5a63a5 commit 5ab6fd4

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

src-ts/tools/learn/certification-details/certification-details-sidebar/CertificationDetailsSidebar.tsx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
TCACertificationProgress,
1313
} from '../../learn-lib'
1414
import { EnrollCtaBtn } from '../enroll-cta-btn'
15+
import { EnvironmentConfig } from '../../../../config'
16+
import { StripeProduct, useGetStripeProduct } from '../../learn-lib/data-providers/payments'
1517

1618
import styles from './CertificationDetailsSidebar.module.scss'
1719

@@ -33,9 +35,25 @@ function renderTooltipContents(icon: ReactNode, text: Array<string>): ReactNode
3335
)
3436
}
3537

38+
// eslint-disable-next-line complexity
3639
const CertificationDetailsSidebar: FC<CertificationDetailsSidebarProps> = (props: CertificationDetailsSidebarProps) => {
3740
const completed: boolean = !!props.certProgress?.completedAt
3841

42+
const tcaMonetizationEnabled: boolean = EnvironmentConfig.REACT_APP_ENABLE_TCA_CERT_MONETIZATION || false
43+
44+
// fetch Stripe product data conditionally
45+
const { product }: { product: StripeProduct | undefined }
46+
= useGetStripeProduct(
47+
tcaMonetizationEnabled && !completed && !props.certProgress
48+
? props.certification?.stripeProductId as string
49+
: '',
50+
)
51+
const price: string
52+
= Number((product?.default_price.unit_amount || 0) / 100)
53+
.toFixed(2)
54+
55+
const suggestedRetailPrice: string = product?.metadata?.estimatedRetailPrice || '20'
56+
3957
return (
4058
<StickySidebar>
4159
<div className={styles['certificate-placeholder']}>
@@ -85,9 +103,34 @@ const CertificationDetailsSidebar: FC<CertificationDetailsSidebarProps> = (props
85103
<IconSolid.CurrencyDollarIcon />
86104
</span>
87105
<span className='quote-main'>
88-
<span className='strike'>$20&nbsp;</span>
89-
<strong className={styles.freeLabel}>FREE</strong>
90-
<span className='body-main-bold'>&nbsp;enrollment ends on April 30th</span>
106+
<span className='strike'>
107+
$
108+
{suggestedRetailPrice}
109+
&nbsp;
110+
</span>
111+
{tcaMonetizationEnabled ? (
112+
<>
113+
<span>
114+
$
115+
{price}
116+
&nbsp;
117+
</span>
118+
<span>one-time payment</span>
119+
<Tooltip
120+
content={renderTooltipContents(<IconSolid.CurrencyDollarIcon />, [
121+
'One-off, non-recurring payment',
122+
])}
123+
place='bottom'
124+
trigger={<IconOutline.InformationCircleIcon />}
125+
triggerOn='hover'
126+
/>
127+
</>
128+
) : (
129+
<>
130+
<strong className={styles.freeLabel}>FREE</strong>
131+
<span className='body-main-bold'>&nbsp;enrollment ends on April 30th</span>
132+
</>
133+
)}
91134
</span>
92135
</li>
93136
)}

src-ts/tools/learn/learn-lib/data-providers/payments/stripe/stripe-product.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function useGetStripeProduct(productId: string): StripeProductData {
1515
)
1616
const swrCacheConfig: SWRConfiguration = useSwrCache(url)
1717

18-
const { data: product, error }: SWRResponse<StripeProduct> = useSWR(url, swrCacheConfig)
18+
const { data: product, error }: SWRResponse<StripeProduct> = useSWR(productId ? url : undefined, swrCacheConfig)
1919

2020
return {
2121
loading: !product && !error,

0 commit comments

Comments
 (0)