@@ -12,24 +12,30 @@ import type { Locale } from '@/lib/i18n/i18n-config';
1212import { getTopupPackages } from '@/lib/stripe/pricing' ;
1313
1414interface CreditTopupProps {
15- dict : ( typeof lang ) [ 'credits' ] ;
15+ dict : typeof lang ;
1616 lang : Locale ;
1717}
1818
19- type ActionState = {
19+ interface ActionState {
2020 error : string | null ;
2121 success : boolean ;
22- } ;
22+ }
2323
2424const initialState : ActionState = {
2525 error : null ,
2626 success : false ,
2727} ;
2828
2929export function CreditTopup ( { dict, lang } : CreditTopupProps ) {
30+ const promoTheme = process . env . NEXT_PUBLIC_PROMO_THEME || 'pink' ; // 'orange' or 'pink'
3031 const isPromoEnabled = process . env . NEXT_PUBLIC_PROMO_ENABLED === 'true' ;
32+ const translations = process . env . NEXT_PUBLIC_PROMO_TRANSLATIONS || '' ;
33+ const bannerTranslations =
34+ Object . hasOwn ( dict . promos , translations )
35+ ? dict . promos [ translations as keyof typeof dict . promos ]
36+ : undefined ;
3137
32- const { plans : pPlans } = dict ;
38+ const { plans : pPlans } = dict . credits ;
3339
3440 const TOPUP_PACKAGES = getTopupPackages ( lang ) ;
3541
@@ -79,25 +85,28 @@ export function CreditTopup({ dict, lang }: CreditTopupProps) {
7985 ] ;
8086
8187 return (
82- < div className = "grid gap-6 md:grid-cols-1 lg:grid-cols-3" >
88+ < div
89+ className = "grid gap-6 md:grid-cols-1 lg:grid-cols-3"
90+ data-promo-theme = { promoTheme }
91+ >
8392 { plans . map ( ( plan ) => (
84- < CreditCard
85- dict = { dict }
93+ < PlanCard
94+ bannerTranslations = { bannerTranslations }
95+ dict = { dict . credits }
8696 isPromoEnabled = { isPromoEnabled }
8797 key = { plan . id }
8898 plan = { plan }
89- pPlans = { pPlans }
9099 />
91100 ) ) }
92101 </ div >
93102 ) ;
94103}
95104
96- function CreditCard ( {
105+ function PlanCard ( {
97106 plan,
98107 dict,
108+ bannerTranslations,
99109 isPromoEnabled,
100- pPlans,
101110} : {
102111 plan : {
103112 id : string ;
@@ -111,9 +120,9 @@ function CreditCard({
111120 creditsText : string ;
112121 promoBonus ?: string ;
113122 } ;
114- dict : ( typeof lang ) [ 'credits' ] ;
115123 isPromoEnabled : boolean ;
116- pPlans : ( typeof lang ) [ 'credits' ] [ 'plans' ] ;
124+ dict : ( typeof lang ) [ 'credits' ] ;
125+ bannerTranslations ?: ( typeof lang ) [ 'promos' ] [ keyof ( typeof lang ) [ 'promos' ] ] ;
117126} ) {
118127 const formAction = async (
119128 _prevState : ActionState ,
@@ -148,18 +157,20 @@ function CreditCard({
148157
149158 return (
150159 < Card
151- className = { `grid grid-rows-auto gap-2 p-6 ${ plan . isPopular ? 'border-none ring-2 ring-pink-400 ' : '' } relative overflow-hidden` }
160+ className = { `grid grid-rows-auto gap-2 p-6 ${ plan . isPopular ? 'border-none ring-2 ring-promo-accent ' : '' } relative overflow-hidden` }
152161 >
153162 { isPromoEnabled && plan . price > 0 && (
154- < div className = "absolute top-0 right-0 rounded-bl-lg bg-gradient-to-br from-pink-500 to-pink-600 px-3 py-1 font-bold text-white text-xs" >
155- Black Friday Sale
163+ < div className = "absolute top-0 right-0 rounded-bl-lg bg-gradient-to-br from-promo-primary to-promo-primary-dark px-3 py-1 font-bold text-white text-xs" >
164+ { bannerTranslations ?. pricing . bannerText }
156165 </ div >
157166 ) }
158167 < div >
159168 < div className = "flex items-center justify-between" >
160169 < h3 className = "font-semibold text-xl" > { plan . name } </ h3 >
161170 { ! isPromoEnabled && plan . isPopular ? (
162- < Badge className = "rounded-full bg-pink-600" > { pPlans . popular } </ Badge >
171+ < Badge className = "rounded-full bg-promo-text" >
172+ { dict . plans . popular }
173+ </ Badge >
163174 ) : (
164175 plan . price > 10 && (
165176 < Badge
@@ -193,7 +204,7 @@ function CreditCard({
193204 < div className = "font-medium text-sm" >
194205 { plan . creditsText } { ' ' }
195206 { isPromoEnabled && plan . promoBonus && (
196- < span className = "font-semibold text-pink-600 dark: text-pink-400 " >
207+ < span className = "font-semibold text-promo- text-dark " >
197208 (+{ plan . promoBonus } bonus)
198209 </ span >
199210 ) }
0 commit comments