1
1
"use client" ;
2
2
3
3
import { Spinner } from "@/components/ui/Spinner/Spinner" ;
4
- import { Alert , AlertDescription , AlertTitle } from "@/components/ui/alert" ;
5
4
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" ;
22
5
import {
23
6
Table ,
24
7
TableBody ,
@@ -29,22 +12,16 @@ import {
29
12
TableRow ,
30
13
} from "@/components/ui/table" ;
31
14
import { ToolTipLabel } from "@/components/ui/tooltip" ;
32
- import { zodResolver } from "@hookform/resolvers/zod" ;
33
15
import { useMutation } from "@tanstack/react-query" ;
34
16
import { format , fromUnixTime } from "date-fns" ;
35
17
import {
36
- AlertCircleIcon ,
37
18
CalendarIcon ,
38
19
CalendarX2Icon ,
39
20
ClockIcon ,
40
21
InfinityIcon ,
41
- PlusIcon ,
42
- TicketCheckIcon ,
43
22
Trash2Icon ,
44
23
} from "lucide-react" ;
45
- import { useForm } from "react-hook-form" ;
46
24
import { toast } from "sonner" ;
47
- import { z } from "zod" ;
48
25
49
26
type Coupon = {
50
27
id : string ;
@@ -119,21 +96,21 @@ export function CouponsUI(props: CouponsUIProps) {
119
96
< div className = "flex items-center justify-between border-b bg-card px-6 py-4" >
120
97
< h3 className = "font-semibold text-xl tracking-tight" > Coupons</ h3 >
121
98
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> */ }
137
114
</ div >
138
115
139
116
{ props . status === "success" && props . activeCoupons . length > 0 ? (
@@ -255,137 +232,140 @@ function DeleteCouponButton(props: {
255
232
) ;
256
233
}
257
234
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
261
237
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
+ // });
270
241
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
+ // });
277
250
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
+ // } );
284
257
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");
315
264
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
+ // }
317
295
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;
330
297
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>
332
310
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" />
351
312
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
+ // )}
361
331
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
+ // )}
373
341
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