Skip to content

Commit 41ffb94

Browse files
committed
Open Share Modal after applying freewallets coupon
1 parent 0dbb174 commit 41ffb94

File tree

3 files changed

+496
-30
lines changed

3 files changed

+496
-30
lines changed

apps/dashboard/src/components/settings/Account/Billing/CouponCard.tsx

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Suspense, useEffect, useRef, useState } from "react";
2121
import { useForm } from "react-hook-form";
2222
import { toast } from "sonner";
2323
import { z } from "zod";
24+
import { ShareFreeWalletsModal } from "./share-free-wallets-modal.client";
2425

2526
export type ActiveCouponResponse = {
2627
id: string;
@@ -36,7 +37,10 @@ export type ActiveCouponResponse = {
3637

3738
function ApplyCouponCard(props: {
3839
teamId: string | undefined;
39-
onCouponApplied: (data: ActiveCouponResponse) => void;
40+
onCouponApplied: (
41+
data: ActiveCouponResponse,
42+
isFreeWalletsCoupon: boolean,
43+
) => void;
4044
isPaymentSetup: boolean;
4145
onAddPayment: () => void;
4246
}) {
@@ -87,7 +91,9 @@ export function ApplyCouponCardUI(props: {
8791
status: number;
8892
data: null | ActiveCouponResponse;
8993
}>;
90-
onCouponApplied: ((data: ActiveCouponResponse) => void) | undefined;
94+
onCouponApplied:
95+
| ((data: ActiveCouponResponse, isFreeWalletsCoupon: boolean) => void)
96+
| undefined;
9197
prefillPromoCode?: string;
9298
scrollIntoView?: boolean;
9399
isPaymentSetup: boolean;
@@ -130,7 +136,12 @@ export function ApplyCouponCardUI(props: {
130136
case 200: {
131137
toast.success("Coupon applied successfully");
132138
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+
);
134145
}
135146
break;
136147
}
@@ -258,6 +269,7 @@ export function CouponSection(props: {
258269
isPaymentSetup: boolean;
259270
onAddPayment: () => void;
260271
}) {
272+
const [showShareModal, setShowShareModal] = useState(false);
261273
const loggedInUser = useLoggedInUser();
262274
const [optimisticCouponData, setOptimisticCouponData] = useState<
263275
| {
@@ -319,35 +331,44 @@ export function CouponSection(props: {
319331
? optimisticCouponData.data
320332
: activeCoupon.data;
321333

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-
334334
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}
349370
/>
350-
</Suspense>
371+
</>
351372
);
352373
}
353374

0 commit comments

Comments
 (0)