Skip to content

Commit 15b0c6f

Browse files
committed
final changes
1 parent 16245c9 commit 15b0c6f

6 files changed

Lines changed: 74 additions & 60 deletions

File tree

apps/web/app/(ee)/api/cron/partners/deactivate/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const POST = withCron(async ({ rawBody }) => {
5858
const discountCodes = programEnrollments.flatMap(({ discountCodes }) =>
5959
discountCodes.map((dc) => dc),
6060
);
61-
await deleteDiscountCodes(discountCodes, { isSoftDelete: false });
61+
await deleteDiscountCodes(discountCodes, { isSoftDelete: true });
6262
console.log("[bulkDeactivatePartners] Queued discount code deletions.");
6363

6464
// Find the program

apps/web/app/(ee)/api/discount-codes/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
DiscountCodeSchema,
1212
getDiscountCodesQuerySchema,
1313
} from "@/lib/zod/schemas/discount";
14+
import { APP_DOMAIN } from "@dub/utils";
1415
import { waitUntil } from "@vercel/functions";
1516
import { NextResponse } from "next/server";
1617

@@ -108,7 +109,7 @@ export const POST = withWorkspace(
108109
if (duplicateByCode) {
109110
throw new DubApiError({
110111
code: "conflict",
111-
message: `This discount code "${code}" is already in use by [${duplicateByCode.partner.email}](https://app.dub.co/${workspace.slug}/program/partners/${duplicateByCode.partner.id}). Please choose a different code.`,
112+
message: `This discount code "${code}" is already in use by [${duplicateByCode.partner.email}](${APP_DOMAIN}/${workspace.slug}/program/partners/${duplicateByCode.partner.id}). Please choose a different code.`,
112113
});
113114
}
114115
}

apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
3737
return {
3838
...link,
3939
discountCode: discountCode?.code,
40+
discountCodeDisabledAt: discountCode?.disabledAt ?? null,
4041
};
4142
});
4243

apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
getApexDomain,
2929
getPrettyUrl,
3030
nFormatter,
31+
PARTNERS_DOMAIN,
3132
} from "@dub/utils";
3233
import NumberFlow from "@number-flow/react";
3334
import Link from "next/link";
@@ -75,6 +76,19 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
7576

7677
const isDeactivated = programEnrollment?.status === "deactivated";
7778

79+
const discountCodeSection = link.discountCode ? (
80+
<div className="hidden items-center gap-1.5 rounded-xl border border-neutral-200 py-1 pl-2 pr-1 sm:flex">
81+
<span className="text-sm leading-none text-neutral-500">
82+
Discount code
83+
</span>
84+
<DiscountCodeBadge
85+
code={link.discountCode}
86+
disabledAt={link.discountCodeDisabledAt}
87+
disabledTooltip={`This discount code was disabled by the program. [Contact the program owner](${PARTNERS_DOMAIN}/messages/${programEnrollment?.program.slug}) if you need a new code.`}
88+
/>
89+
</div>
90+
) : null;
91+
7892
return (
7993
<CardList.Card
8094
innerClassName={cn("px-0 py-0 group/card", isDeactivated && "opacity-80")}
@@ -153,20 +167,14 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
153167
</StatusBadge>
154168
);
155169
})()}
156-
{link.discountCode && (
157-
<Tooltip
158-
content={
159-
"This program supports discount code tracking. Copy the code to use it in podcasts, videos, etc. [Learn more](https://dub.co/help/article/dual-sided-incentives)"
160-
}
161-
>
162-
<div className="hidden items-center gap-1.5 rounded-xl border border-neutral-200 py-1 pl-2 pr-1 sm:flex">
163-
<span className="text-sm leading-none text-neutral-500">
164-
Discount code
165-
</span>
166-
<DiscountCodeBadge code={link.discountCode} />
167-
</div>
168-
</Tooltip>
169-
)}
170+
{discountCodeSection &&
171+
(link.discountCodeDisabledAt ? (
172+
discountCodeSection
173+
) : (
174+
<Tooltip content="This program supports discount code tracking. Copy the code to use it in podcasts, videos, etc. [Learn more](https://dub.co/help/article/dual-sided-incentives)">
175+
{discountCodeSection}
176+
</Tooltip>
177+
))}
170178
{displayOption === "cards" && <StatsBadge link={link} />}
171179
<Controls link={link} />
172180
</div>

apps/web/lib/zod/schemas/partner-profile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const PartnerProfileLinkSchema = LinkSchema.pick({
100100
createdAt: z.string().or(z.date()),
101101
partnerGroupDefaultLinkId: z.string().nullish(),
102102
discountCode: z.string().nullable().default(null),
103+
discountCodeDisabledAt: z.coerce.date().nullable().default(null),
103104
});
104105

105106
export const PartnerProfileCustomerSchema = CustomerEnrichedSchema.pick({
Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
1-
import { StatusBadge, Tag, Tooltip, useCopyToClipboard } from "@dub/ui";
1+
import { Tag, Tooltip, useCopyToClipboard } from "@dub/ui";
22
import { cn } from "@dub/utils";
33
import { toast } from "sonner";
44

55
export function DiscountCodeBadge({
66
code,
77
disabledAt,
8+
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.",
89
}: {
910
code: string;
1011
disabledAt?: Date | string | null;
12+
disabledTooltip?: string;
1113
}) {
1214
const [copied, copyToClipboard] = useCopyToClipboard();
1315
const isDisabled = !!disabledAt;
1416

15-
return (
16-
<div className="flex items-center gap-2">
17-
<button
18-
type="button"
17+
const content = (
18+
<>
19+
<Tag
20+
className={cn(
21+
"size-3",
22+
isDisabled ? "text-neutral-500" : "text-green-700",
23+
)}
24+
strokeWidth={1.5}
25+
/>
26+
<div
1927
className={cn(
20-
"group/discountcode relative flex w-fit cursor-copy items-center gap-1 rounded-lg px-2 py-1",
21-
"transition-colors duration-150",
22-
copied && "cursor-default",
28+
"text-xs font-medium",
2329
isDisabled
24-
? "bg-neutral-200/80 line-through hover:bg-neutral-200/80 hover:no-underline"
25-
: "bg-green-200 hover:bg-green-300/80",
30+
? "text-neutral-500 line-through"
31+
: "text-green-700 decoration-dotted underline-offset-2 transition-colors group-hover/discountcode:underline",
2632
)}
27-
onClick={() =>
28-
copyToClipboard(code, {
29-
onSuccess: () => {
30-
toast.success("Copied discount code to clipboard");
31-
},
32-
})
33-
}
3433
>
35-
<Tag
36-
className={cn(
37-
"size-3",
38-
isDisabled ? "text-neutral-500" : "text-green-700",
39-
)}
40-
strokeWidth={1.5}
41-
/>
42-
<div
43-
className={cn(
44-
"text-xs font-medium decoration-dotted underline-offset-2 transition-colors group-hover/discountcode:underline",
45-
isDisabled ? "text-neutral-600" : "text-green-700",
46-
)}
47-
>
48-
{code}
34+
{code}
35+
</div>
36+
</>
37+
);
38+
39+
if (isDisabled) {
40+
return (
41+
<Tooltip content={disabledTooltip}>
42+
<div className="flex w-fit cursor-help items-center gap-1 rounded-lg bg-neutral-100 px-2 py-1">
43+
{content}
4944
</div>
50-
</button>
51-
{isDisabled && (
52-
<Tooltip content="This discount code was disabled because the partner was banned or deactivated. To re-enable it, delete this code and create a new one.">
53-
<StatusBadge
54-
variant="neutral"
55-
size="sm"
56-
icon={null}
57-
className="cursor-help"
58-
>
59-
Disabled
60-
</StatusBadge>
61-
</Tooltip>
45+
</Tooltip>
46+
);
47+
}
48+
49+
return (
50+
<button
51+
type="button"
52+
className={cn(
53+
"group/discountcode relative flex w-fit cursor-copy items-center gap-1 rounded-lg bg-green-200 px-2 py-1",
54+
"transition-colors duration-150 hover:bg-green-300/80",
55+
copied && "cursor-default",
6256
)}
63-
</div>
57+
onClick={() =>
58+
copyToClipboard(code, {
59+
onSuccess: () => {
60+
toast.success("Copied discount code to clipboard");
61+
},
62+
})
63+
}
64+
>
65+
{content}
66+
</button>
6467
);
6568
}

0 commit comments

Comments
 (0)