@@ -21,6 +21,7 @@ import { Suspense, useEffect, useRef, useState } from "react";
21
21
import { useForm } from "react-hook-form" ;
22
22
import { toast } from "sonner" ;
23
23
import { z } from "zod" ;
24
+ import { ShareFreeWalletsModal } from "./share-free-wallets-modal.client" ;
24
25
25
26
export type ActiveCouponResponse = {
26
27
id : string ;
@@ -36,7 +37,10 @@ export type ActiveCouponResponse = {
36
37
37
38
function ApplyCouponCard ( props : {
38
39
teamId : string | undefined ;
39
- onCouponApplied : ( data : ActiveCouponResponse ) => void ;
40
+ onCouponApplied : (
41
+ data : ActiveCouponResponse ,
42
+ isFreeWalletsCoupon : boolean ,
43
+ ) => void ;
40
44
isPaymentSetup : boolean ;
41
45
onAddPayment : ( ) => void ;
42
46
} ) {
@@ -87,7 +91,9 @@ export function ApplyCouponCardUI(props: {
87
91
status : number ;
88
92
data : null | ActiveCouponResponse ;
89
93
} > ;
90
- onCouponApplied : ( ( data : ActiveCouponResponse ) => void ) | undefined ;
94
+ onCouponApplied :
95
+ | ( ( data : ActiveCouponResponse , isFreeWalletsCoupon : boolean ) => void )
96
+ | undefined ;
91
97
prefillPromoCode ?: string ;
92
98
scrollIntoView ?: boolean ;
93
99
isPaymentSetup : boolean ;
@@ -130,7 +136,12 @@ export function ApplyCouponCardUI(props: {
130
136
case 200 : {
131
137
toast . success ( "Coupon applied successfully" ) ;
132
138
if ( res . data ) {
133
- props . onCouponApplied ?.( res . data ) ;
139
+ props . onCouponApplied ?.(
140
+ res . data ,
141
+ // prod & dev
142
+ values . promoCode === "FREEWALLETS" ||
143
+ values . promoCode === "TESTFREEWALLETS" ,
144
+ ) ;
134
145
}
135
146
break ;
136
147
}
@@ -258,6 +269,7 @@ export function CouponSection(props: {
258
269
isPaymentSetup : boolean ;
259
270
onAddPayment : ( ) => void ;
260
271
} ) {
272
+ const [ showShareModal , setShowShareModal ] = useState ( false ) ;
261
273
const loggedInUser = useLoggedInUser ( ) ;
262
274
const [ optimisticCouponData , setOptimisticCouponData ] = useState <
263
275
| {
@@ -319,35 +331,44 @@ export function CouponSection(props: {
319
331
? optimisticCouponData . data
320
332
: activeCoupon . data ;
321
333
322
- if ( couponData ) {
323
- return (
324
- < CouponDetailsCardUI
325
- activeCoupon = { couponData }
326
- deleteCoupon = { {
327
- mutateAsync : deleteActiveCoupon . mutateAsync ,
328
- isPending : deleteActiveCoupon . isPending ,
329
- } }
330
- />
331
- ) ;
332
- }
333
-
334
334
return (
335
- < Suspense fallback = { < LoadingCouponSection /> } >
336
- < ApplyCouponCard
337
- teamId = { props . teamId }
338
- onCouponApplied = { ( coupon ) => {
339
- setOptimisticCouponData ( {
340
- type : "added" ,
341
- data : coupon ,
342
- } ) ;
343
- activeCoupon . refetch ( ) . then ( ( ) => {
344
- setOptimisticCouponData ( undefined ) ;
345
- } ) ;
346
- } }
347
- isPaymentSetup = { props . isPaymentSetup }
348
- onAddPayment = { props . onAddPayment }
335
+ < >
336
+ { couponData ? (
337
+ < CouponDetailsCardUI
338
+ activeCoupon = { couponData }
339
+ deleteCoupon = { {
340
+ mutateAsync : deleteActiveCoupon . mutateAsync ,
341
+ isPending : deleteActiveCoupon . isPending ,
342
+ } }
343
+ />
344
+ ) : (
345
+ < Suspense fallback = { < LoadingCouponSection /> } >
346
+ < ApplyCouponCard
347
+ teamId = { props . teamId }
348
+ onCouponApplied = { ( coupon , isFreeWalletsCoupon ) => {
349
+ setOptimisticCouponData ( {
350
+ type : "added" ,
351
+ data : coupon ,
352
+ } ) ;
353
+
354
+ if ( isFreeWalletsCoupon ) {
355
+ setShowShareModal ( true ) ;
356
+ }
357
+ activeCoupon . refetch ( ) . then ( ( ) => {
358
+ setOptimisticCouponData ( undefined ) ;
359
+ } ) ;
360
+ } }
361
+ isPaymentSetup = { props . isPaymentSetup }
362
+ onAddPayment = { props . onAddPayment }
363
+ />
364
+ </ Suspense >
365
+ ) }
366
+
367
+ < ShareFreeWalletsModal
368
+ isOpen = { showShareModal }
369
+ onOpenChange = { setShowShareModal }
349
370
/>
350
- </ Suspense >
371
+ </ >
351
372
) ;
352
373
}
353
374
0 commit comments