-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathdiscount-code-badge.tsx
More file actions
68 lines (64 loc) · 1.74 KB
/
Copy pathdiscount-code-badge.tsx
File metadata and controls
68 lines (64 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Tag, Tooltip, useCopyToClipboard } from "@dub/ui";
import { cn } from "@dub/utils";
import { toast } from "sonner";
export function DiscountCodeBadge({
code,
disabledAt,
disabledTooltip = "This discount code was disabled because the partner was banned or deactivated. To re-enable it, delete this code and create a new one.",
}: {
code: string;
disabledAt?: Date | string | null;
disabledTooltip?: string;
}) {
const [copied, copyToClipboard] = useCopyToClipboard();
const isDisabled = !!disabledAt;
const content = (
<>
<Tag
className={cn(
"size-3",
isDisabled ? "text-neutral-500" : "text-green-700",
)}
strokeWidth={1.5}
/>
<div
className={cn(
"text-xs font-medium",
isDisabled
? "text-neutral-500 line-through"
: "text-green-700 decoration-dotted underline-offset-2 transition-colors group-hover/discountcode:underline",
)}
>
{code}
</div>
</>
);
if (isDisabled) {
return (
<Tooltip content={disabledTooltip}>
<div className="flex w-fit cursor-help items-center gap-1 rounded-lg bg-neutral-100 px-2 py-1">
{content}
</div>
</Tooltip>
);
}
return (
<button
type="button"
className={cn(
"group/discountcode relative flex w-fit cursor-copy items-center gap-1 rounded-lg bg-green-200 px-2 py-1",
"transition-colors duration-150 hover:bg-green-300/80",
copied && "cursor-default",
)}
onClick={() =>
copyToClipboard(code, {
onSuccess: () => {
toast.success("Copied discount code to clipboard");
},
})
}
>
{content}
</button>
);
}