Skip to content

Commit c03734a

Browse files
committed
[TOOL-4230] Dashboard: Remove add coupon UI from team billing page (#6813)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex -->
1 parent 8da0c1f commit c03734a

File tree

1 file changed

+141
-161
lines changed
  • apps/dashboard/src/components/settings/Account/Billing/SubscriptionCoupons

1 file changed

+141
-161
lines changed

apps/dashboard/src/components/settings/Account/Billing/SubscriptionCoupons/CouponsUI.tsx

Lines changed: 141 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
"use client";
22

33
import { Spinner } from "@/components/ui/Spinner/Spinner";
4-
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
54
import { Button } from "@/components/ui/button";
6-
import {
7-
Dialog,
8-
DialogContent,
9-
DialogDescription,
10-
DialogHeader,
11-
DialogTitle,
12-
DialogTrigger,
13-
} from "@/components/ui/dialog";
14-
import {
15-
Form,
16-
FormControl,
17-
FormField,
18-
FormItem,
19-
FormLabel,
20-
} from "@/components/ui/form";
21-
import { Input } from "@/components/ui/input";
225
import {
236
Table,
247
TableBody,
@@ -29,22 +12,16 @@ import {
2912
TableRow,
3013
} from "@/components/ui/table";
3114
import { ToolTipLabel } from "@/components/ui/tooltip";
32-
import { zodResolver } from "@hookform/resolvers/zod";
3315
import { useMutation } from "@tanstack/react-query";
3416
import { format, fromUnixTime } from "date-fns";
3517
import {
36-
AlertCircleIcon,
3718
CalendarIcon,
3819
CalendarX2Icon,
3920
ClockIcon,
4021
InfinityIcon,
41-
PlusIcon,
42-
TicketCheckIcon,
4322
Trash2Icon,
4423
} from "lucide-react";
45-
import { useForm } from "react-hook-form";
4624
import { toast } from "sonner";
47-
import { z } from "zod";
4825

4926
type Coupon = {
5027
id: string;
@@ -119,21 +96,21 @@ export function CouponsUI(props: CouponsUIProps) {
11996
<div className="flex items-center justify-between border-b bg-card px-6 py-4">
12097
<h3 className="font-semibold text-xl tracking-tight">Coupons</h3>
12198

122-
<Dialog>
123-
<DialogTrigger asChild>
124-
<Button variant="outline" size="sm" className="gap-2">
125-
<PlusIcon className="size-4" />
126-
Apply Coupon
127-
</Button>
128-
</DialogTrigger>
129-
<DialogContent className="overflow-hidden p-0">
130-
<ApplyCouponModalContent
131-
isPaymentSetup={props.isPaymentSetup}
132-
applyCoupon={props.applyCoupon}
133-
accountCoupon={accountCoupon}
134-
/>
135-
</DialogContent>
136-
</Dialog>
99+
{/* <Dialog>
100+
<DialogTrigger asChild>
101+
<Button variant="outline" size="sm" className="gap-2">
102+
<PlusIcon className="size-4" />
103+
Apply Coupon
104+
</Button>
105+
</DialogTrigger>
106+
<DialogContent className="overflow-hidden p-0">
107+
<ApplyCouponModalContent
108+
isPaymentSetup={props.isPaymentSetup}
109+
applyCoupon={props.applyCoupon}
110+
accountCoupon={accountCoupon}
111+
/>
112+
</DialogContent>
113+
</Dialog> */}
137114
</div>
138115

139116
{props.status === "success" && props.activeCoupons.length > 0 ? (
@@ -255,137 +232,140 @@ function DeleteCouponButton(props: {
255232
);
256233
}
257234

258-
const applyCouponFormSchema = z.object({
259-
promoCode: z.string().min(1, "Coupon code is required"),
260-
});
235+
// UI to add coupon is disable for now
236+
// this will be enabled later in future with some changes
261237

262-
function ApplyCouponModalContent(props: {
263-
isPaymentSetup: boolean;
264-
applyCoupon: ApplyCouponFn;
265-
accountCoupon: CouponData | undefined;
266-
}) {
267-
const applyCoupon = useMutation({
268-
mutationFn: props.applyCoupon,
269-
});
238+
// const applyCouponFormSchema = z.object({
239+
// promoCode: z.string().min(1, "Coupon code is required"),
240+
// });
270241

271-
const form = useForm<z.infer<typeof applyCouponFormSchema>>({
272-
resolver: zodResolver(applyCouponFormSchema),
273-
defaultValues: {
274-
promoCode: "",
275-
},
276-
});
242+
// function ApplyCouponModalContent(props: {
243+
// isPaymentSetup: boolean;
244+
// applyCoupon: ApplyCouponFn;
245+
// accountCoupon: CouponData | undefined;
246+
// }) {
247+
// const applyCoupon = useMutation({
248+
// mutationFn: props.applyCoupon,
249+
// });
277250

278-
async function onSubmit(values: z.infer<typeof applyCouponFormSchema>) {
279-
try {
280-
const res = await applyCoupon.mutateAsync(values.promoCode);
281-
switch (res.status) {
282-
case 200: {
283-
toast.success("Coupon applied successfully");
251+
// const form = useForm<z.infer<typeof applyCouponFormSchema>>({
252+
// resolver: zodResolver(applyCouponFormSchema),
253+
// defaultValues: {
254+
// promoCode: "",
255+
// },
256+
// });
284257

285-
break;
286-
}
287-
case 400: {
288-
toast.error("Coupon code is invalid");
289-
break;
290-
}
291-
case 401: {
292-
toast.error("You are not authorized to apply coupons", {
293-
description: "Login to dashboard and try again",
294-
});
295-
break;
296-
}
297-
case 409: {
298-
toast.error("Coupon already applied");
299-
break;
300-
}
301-
case 429: {
302-
toast.error("Too many coupons applied in a short period", {
303-
description: "Please try again after some time",
304-
});
305-
break;
306-
}
307-
default: {
308-
toast.error("Failed to apply coupon");
309-
}
310-
}
311-
} catch {
312-
toast.error("Failed to apply coupon");
313-
}
314-
}
258+
// async function onSubmit(values: z.infer<typeof applyCouponFormSchema>) {
259+
// try {
260+
// const res = await applyCoupon.mutateAsync(values.promoCode);
261+
// switch (res.status) {
262+
// case 200: {
263+
// toast.success("Coupon applied successfully");
315264

316-
const couponEnabled = props.isPaymentSetup && !props.accountCoupon;
265+
// break;
266+
// }
267+
// case 400: {
268+
// toast.error("Coupon code is invalid");
269+
// break;
270+
// }
271+
// case 401: {
272+
// toast.error("You are not authorized to apply coupons", {
273+
// description: "Login to dashboard and try again",
274+
// });
275+
// break;
276+
// }
277+
// case 409: {
278+
// toast.error("Coupon already applied");
279+
// break;
280+
// }
281+
// case 429: {
282+
// toast.error("Too many coupons applied in a short period", {
283+
// description: "Please try again after some time",
284+
// });
285+
// break;
286+
// }
287+
// default: {
288+
// toast.error("Failed to apply coupon");
289+
// }
290+
// }
291+
// } catch {
292+
// toast.error("Failed to apply coupon");
293+
// }
294+
// }
317295

318-
return (
319-
<Form {...form}>
320-
<form onSubmit={form.handleSubmit(onSubmit)}>
321-
<div className="p-6">
322-
<DialogHeader>
323-
<DialogTitle>Apply Coupon</DialogTitle>
324-
{couponEnabled && (
325-
<DialogDescription>
326-
Enter coupon code to apply discounts or free trials
327-
</DialogDescription>
328-
)}
329-
</DialogHeader>
296+
// const couponEnabled = props.isPaymentSetup && !props.accountCoupon;
330297

331-
<div className="h-4" />
298+
// return (
299+
// <Form {...form}>
300+
// <form onSubmit={form.handleSubmit(onSubmit)}>
301+
// <div className="p-6">
302+
// <DialogHeader>
303+
// <DialogTitle>Apply Coupon</DialogTitle>
304+
// {couponEnabled && (
305+
// <DialogDescription>
306+
// Enter coupon code to apply discounts or free trials
307+
// </DialogDescription>
308+
// )}
309+
// </DialogHeader>
332310

333-
{couponEnabled && (
334-
<FormField
335-
control={form.control}
336-
name="promoCode"
337-
render={({ field }) => (
338-
<FormItem>
339-
<FormLabel>Coupon Code</FormLabel>
340-
<FormControl>
341-
<Input
342-
{...field}
343-
className=""
344-
disabled={!props.isPaymentSetup}
345-
/>
346-
</FormControl>
347-
</FormItem>
348-
)}
349-
/>
350-
)}
311+
// <div className="h-4" />
351312

352-
{!props.isPaymentSetup && (
353-
<Alert variant="destructive">
354-
<AlertCircleIcon className="size-5" />
355-
<AlertTitle>Payment method required</AlertTitle>
356-
<AlertDescription>
357-
A valid payment method must be added to apply a coupon.
358-
</AlertDescription>
359-
</Alert>
360-
)}
313+
// {couponEnabled && (
314+
// <FormField
315+
// control={form.control}
316+
// name="promoCode"
317+
// render={({ field }) => (
318+
// <FormItem>
319+
// <FormLabel>Coupon Code</FormLabel>
320+
// <FormControl>
321+
// <Input
322+
// {...field}
323+
// className=""
324+
// disabled={!props.isPaymentSetup}
325+
// />
326+
// </FormControl>
327+
// </FormItem>
328+
// )}
329+
// />
330+
// )}
361331

362-
{props.isPaymentSetup && props.accountCoupon && (
363-
<Alert variant="destructive">
364-
<AlertCircleIcon className="size-5" />
365-
<AlertTitle>Coupon already applied</AlertTitle>
366-
<AlertDescription>
367-
Remove coupon {`"${props.accountCoupon.coupon.name}"`} to apply
368-
a new coupon
369-
</AlertDescription>
370-
</Alert>
371-
)}
372-
</div>
332+
// {!props.isPaymentSetup && (
333+
// <Alert variant="destructive">
334+
// <AlertCircleIcon className="size-5" />
335+
// <AlertTitle>Payment method required</AlertTitle>
336+
// <AlertDescription>
337+
// A valid payment method must be added to apply a coupon.
338+
// </AlertDescription>
339+
// </Alert>
340+
// )}
373341

374-
<div className="mt-4 flex items-center justify-end border-t bg-card p-6">
375-
<Button
376-
type="submit"
377-
disabled={applyCoupon.isPending || !couponEnabled}
378-
className="gap-2"
379-
>
380-
{applyCoupon.isPending ? (
381-
<Spinner className="size-4" />
382-
) : (
383-
<TicketCheckIcon className="size-4" />
384-
)}
385-
Redeem
386-
</Button>
387-
</div>
388-
</form>
389-
</Form>
390-
);
391-
}
342+
// {props.isPaymentSetup && props.accountCoupon && (
343+
// <Alert variant="destructive">
344+
// <AlertCircleIcon className="size-5" />
345+
// <AlertTitle>Coupon already applied</AlertTitle>
346+
// <AlertDescription>
347+
// Remove coupon {`"${props.accountCoupon.coupon.name}"`} to apply
348+
// a new coupon
349+
// </AlertDescription>
350+
// </Alert>
351+
// )}
352+
// </div>
353+
354+
// <div className="mt-4 flex items-center justify-end border-t bg-card p-6">
355+
// <Button
356+
// type="submit"
357+
// disabled={applyCoupon.isPending || !couponEnabled}
358+
// className="gap-2"
359+
// >
360+
// {applyCoupon.isPending ? (
361+
// <Spinner className="size-4" />
362+
// ) : (
363+
// <TicketCheckIcon className="size-4" />
364+
// )}
365+
// Redeem
366+
// </Button>
367+
// </div>
368+
// </form>
369+
// </Form>
370+
// );
371+
// }

0 commit comments

Comments
 (0)