From c03734aea9c8c41594ee61e5c0c70864e2f88223 Mon Sep 17 00:00:00 2001 From: MananTank Date: Tue, 22 Apr 2025 15:51:19 +0000 Subject: [PATCH] [TOOL-4230] Dashboard: Remove add coupon UI from team billing page (#6813) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR primarily focuses on commenting out the coupon application UI components and related functionality in the `CouponsUI` component, indicating that the feature is disabled for now and will be revisited in the future. ### Detailed summary - Commented out the entire `Dialog` component for applying coupons. - Commented out the `applyCouponFormSchema` and its related form handling logic. - Disabled the submission functionality for applying coupons. - Added comments indicating that the coupon UI will be enabled later. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../Billing/SubscriptionCoupons/CouponsUI.tsx | 302 ++++++++---------- 1 file changed, 141 insertions(+), 161 deletions(-) diff --git a/apps/dashboard/src/components/settings/Account/Billing/SubscriptionCoupons/CouponsUI.tsx b/apps/dashboard/src/components/settings/Account/Billing/SubscriptionCoupons/CouponsUI.tsx index 990fd5e0124..e5bdf1f0aa9 100644 --- a/apps/dashboard/src/components/settings/Account/Billing/SubscriptionCoupons/CouponsUI.tsx +++ b/apps/dashboard/src/components/settings/Account/Billing/SubscriptionCoupons/CouponsUI.tsx @@ -1,24 +1,7 @@ "use client"; import { Spinner } from "@/components/ui/Spinner/Spinner"; -import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, -} from "@/components/ui/form"; -import { Input } from "@/components/ui/input"; import { Table, TableBody, @@ -29,22 +12,16 @@ import { TableRow, } from "@/components/ui/table"; import { ToolTipLabel } from "@/components/ui/tooltip"; -import { zodResolver } from "@hookform/resolvers/zod"; import { useMutation } from "@tanstack/react-query"; import { format, fromUnixTime } from "date-fns"; import { - AlertCircleIcon, CalendarIcon, CalendarX2Icon, ClockIcon, InfinityIcon, - PlusIcon, - TicketCheckIcon, Trash2Icon, } from "lucide-react"; -import { useForm } from "react-hook-form"; import { toast } from "sonner"; -import { z } from "zod"; type Coupon = { id: string; @@ -119,21 +96,21 @@ export function CouponsUI(props: CouponsUIProps) {

Coupons

- - - - - - - - + {/* + + + + + + + */}
{props.status === "success" && props.activeCoupons.length > 0 ? ( @@ -255,137 +232,140 @@ function DeleteCouponButton(props: { ); } -const applyCouponFormSchema = z.object({ - promoCode: z.string().min(1, "Coupon code is required"), -}); +// UI to add coupon is disable for now +// this will be enabled later in future with some changes -function ApplyCouponModalContent(props: { - isPaymentSetup: boolean; - applyCoupon: ApplyCouponFn; - accountCoupon: CouponData | undefined; -}) { - const applyCoupon = useMutation({ - mutationFn: props.applyCoupon, - }); +// const applyCouponFormSchema = z.object({ +// promoCode: z.string().min(1, "Coupon code is required"), +// }); - const form = useForm>({ - resolver: zodResolver(applyCouponFormSchema), - defaultValues: { - promoCode: "", - }, - }); +// function ApplyCouponModalContent(props: { +// isPaymentSetup: boolean; +// applyCoupon: ApplyCouponFn; +// accountCoupon: CouponData | undefined; +// }) { +// const applyCoupon = useMutation({ +// mutationFn: props.applyCoupon, +// }); - async function onSubmit(values: z.infer) { - try { - const res = await applyCoupon.mutateAsync(values.promoCode); - switch (res.status) { - case 200: { - toast.success("Coupon applied successfully"); +// const form = useForm>({ +// resolver: zodResolver(applyCouponFormSchema), +// defaultValues: { +// promoCode: "", +// }, +// }); - break; - } - case 400: { - toast.error("Coupon code is invalid"); - break; - } - case 401: { - toast.error("You are not authorized to apply coupons", { - description: "Login to dashboard and try again", - }); - break; - } - case 409: { - toast.error("Coupon already applied"); - break; - } - case 429: { - toast.error("Too many coupons applied in a short period", { - description: "Please try again after some time", - }); - break; - } - default: { - toast.error("Failed to apply coupon"); - } - } - } catch { - toast.error("Failed to apply coupon"); - } - } +// async function onSubmit(values: z.infer) { +// try { +// const res = await applyCoupon.mutateAsync(values.promoCode); +// switch (res.status) { +// case 200: { +// toast.success("Coupon applied successfully"); - const couponEnabled = props.isPaymentSetup && !props.accountCoupon; +// break; +// } +// case 400: { +// toast.error("Coupon code is invalid"); +// break; +// } +// case 401: { +// toast.error("You are not authorized to apply coupons", { +// description: "Login to dashboard and try again", +// }); +// break; +// } +// case 409: { +// toast.error("Coupon already applied"); +// break; +// } +// case 429: { +// toast.error("Too many coupons applied in a short period", { +// description: "Please try again after some time", +// }); +// break; +// } +// default: { +// toast.error("Failed to apply coupon"); +// } +// } +// } catch { +// toast.error("Failed to apply coupon"); +// } +// } - return ( -
- -
- - Apply Coupon - {couponEnabled && ( - - Enter coupon code to apply discounts or free trials - - )} - +// const couponEnabled = props.isPaymentSetup && !props.accountCoupon; -
+// return ( +// +// +//
+// +// Apply Coupon +// {couponEnabled && ( +// +// Enter coupon code to apply discounts or free trials +// +// )} +// - {couponEnabled && ( - ( - - Coupon Code - - - - - )} - /> - )} +//
- {!props.isPaymentSetup && ( - - - Payment method required - - A valid payment method must be added to apply a coupon. - - - )} +// {couponEnabled && ( +// ( +// +// Coupon Code +// +// +// +// +// )} +// /> +// )} - {props.isPaymentSetup && props.accountCoupon && ( - - - Coupon already applied - - Remove coupon {`"${props.accountCoupon.coupon.name}"`} to apply - a new coupon - - - )} -
+// {!props.isPaymentSetup && ( +// +// +// Payment method required +// +// A valid payment method must be added to apply a coupon. +// +// +// )} -
- -
- - - ); -} +// {props.isPaymentSetup && props.accountCoupon && ( +// +// +// Coupon already applied +// +// Remove coupon {`"${props.accountCoupon.coupon.name}"`} to apply +// a new coupon +// +// +// )} +//
+ +//
+// +//
+// +// +// ); +// }