@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
5
5
import useTranslation from 'next-translate/useTranslation' ;
6
6
import { useState } from 'react' ;
7
7
import useStyle from '../hooks/useStyle' ;
8
+ import useSignup from '../store/actions/signupAction' ;
8
9
import Text from './Text' ;
9
10
import Icon from './Icon' ;
10
11
import { parseQuerys } from '../../utils/url' ;
@@ -13,12 +14,22 @@ import { usePersistentBySession } from '../hooks/usePersistent';
13
14
14
15
export default function PricingCard ( { item, courseData, isFetching, relatedSubscription, ...rest } ) {
15
16
const { t, lang } = useTranslation ( 'signup' ) ;
17
+ const { getPriceWithDiscount, state } = useSignup ( ) ;
18
+ const { coupon : selfApliedCoupon } = state ;
16
19
const { fontColor, hexColor, featuredCard, featuredColor } = useStyle ( ) ;
17
20
const [ selectedFinancing , setSelectedFinancing ] = useState ( { } ) ;
18
21
const [ accordionState , setAccordionState ] = useState ( false ) ;
19
22
const isBootcampType = item ?. planType && item ?. planType . toLowerCase ( ) === 'bootcamp' ;
20
23
const queryCoupon = getQueryString ( 'coupon' ) ;
21
24
const [ coupon ] = usePersistentBySession ( 'coupon' , [ ] ) ;
25
+
26
+ const courseCoupon = selfApliedCoupon ?. plan === item . plan_slug && selfApliedCoupon ;
27
+
28
+ const priceProcessed = getPriceWithDiscount ( selectedFinancing ?. price || item ?. optionList ?. [ 0 ] ?. price , courseCoupon ) ;
29
+ const discountApplied = priceProcessed ?. originalPrice && priceProcessed . price !== priceProcessed . originalPrice ;
30
+
31
+ const premiumColor = ( ) => ( courseCoupon ? hexColor . green : hexColor . blueDefault ) ;
32
+
22
33
const utilProps = {
23
34
already_have_it : t ( 'pricing.already-have-plan' ) ,
24
35
bootcamp : {
@@ -69,8 +80,8 @@ export default function PricingCard({ item, courseData, isFetching, relatedSubsc
69
80
service_items : t ( 'pricing.premium-plan.service_items' , { } , { returnObjects : true } ) ,
70
81
featured_info : t ( 'pricing.premium-plan.featured_info' , { } , { returnObjects : true } ) ,
71
82
color : 'white' ,
72
- featured : hexColor . blueDefault ,
73
- border : hexColor . blueDefault ,
83
+ featured : courseCoupon ? hexColor . green : hexColor . blueDefault ,
84
+ border : isFetching ? hexColor . lightColor : premiumColor ( ) ,
74
85
featuredFontColor : hexColor . yellowDefault ,
75
86
button : {
76
87
variant : 'default' ,
@@ -125,9 +136,45 @@ export default function PricingCard({ item, courseData, isFetching, relatedSubsc
125
136
background = { featuredCard . background }
126
137
height = "fit-content"
127
138
color = { fontColor }
139
+ position = "relative"
128
140
{ ...rest }
129
141
>
130
- < Flex height = "auto" position = "relative" padding = "8px" flexDirection = "column" gridGap = "16px" background = { featured } borderRadius = "8px 8px 0 0" >
142
+ { discountApplied && (
143
+ < Box position = "absolute" right = "20px" top = "-20px" >
144
+ < Box
145
+ borderRadius = "55px"
146
+ background = { hexColor . green }
147
+ padding = "2px 8px"
148
+ position = "relative"
149
+ zIndex = "10"
150
+ >
151
+ < Box
152
+ top = "-9px"
153
+ left = "-37px"
154
+ display = "flex"
155
+ justifyContent = "center"
156
+ flexDirection = "column"
157
+ alignItems = "center"
158
+ textAlign = "center"
159
+ width = "44px"
160
+ height = "44px"
161
+ fontSize = "24px"
162
+ position = "absolute"
163
+ borderRadius = "41px"
164
+ padding = "10px"
165
+ border = "2px solid"
166
+ borderColor = "#03823E"
167
+ background = { hexColor . green }
168
+ >
169
+ 🔥
170
+ </ Box >
171
+ < Text fontSize = "15px" color = "#FFF" >
172
+ { t ( 'discount' , { discount : priceProcessed . discount } ) }
173
+ </ Text >
174
+ </ Box >
175
+ </ Box >
176
+ ) }
177
+ < Flex height = "auto" position = "relative" padding = "8px" paddingTop = { discountApplied && '14px' } flexDirection = "column" gridGap = "16px" background = { isFetching ? hexColor . lightColor : featured } borderRadius = "8px 8px 0 0" >
131
178
< Text fontSize = "18px" lineHeight = "21px" height = "auto" fontWeight = { 700 } color = { color } textAlign = "center" >
132
179
{ viewProps . hookMessage }
133
180
</ Text >
@@ -140,10 +187,25 @@ export default function PricingCard({ item, courseData, isFetching, relatedSubsc
140
187
< Skeleton height = "48px" width = "10rem" borderRadius = "4px" />
141
188
) : (
142
189
< Flex gridGap = "8px" alignItems = "center" >
143
- < Box color = { color } fontFamily = "Space Grotesk Variable" fontSize = "64px" fontWeight = { 700 } textAlign = "center" >
190
+ < Box color = { color } textAlign = "center" >
144
191
{ existsOptionList
145
- ? `$${ selectedFinancing ?. price || item ?. optionList ?. [ 0 ] ?. price } `
146
- : ( item ?. price_text || item ?. priceText ) }
192
+ ? (
193
+ < >
194
+ { priceProcessed . originalPrice && (
195
+ < s style = { { fontSize : '16px' } } >
196
+ { `$${ priceProcessed . originalPrice } ` }
197
+ </ s >
198
+ ) }
199
+ < Text fontSize = "64px" fontFamily = "Space Grotesk Variable" fontWeight = { 700 } lineHeight = "70px" >
200
+ { `$${ priceProcessed . price } ` }
201
+ </ Text >
202
+ </ >
203
+ )
204
+ : (
205
+ < Text fontSize = "64px" fontFamily = "Space Grotesk Variable" fontWeight = { 700 } lineHeight = "70px" >
206
+ { item ?. price_text || item ?. priceText }
207
+ </ Text >
208
+ ) }
147
209
</ Box >
148
210
{ existsOptionList && manyMonths > 1 && (
149
211
< Text size = "36px" fontFamily = "Space Grotesk Variable" color = { color } letterSpacing = "normal" fontWeight = "700" >
0 commit comments