Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

final changes

Steven Tey15b0c6fabb87
diff --git a/apps/web/app/(ee)/api/cron/partners/deactivate/route.ts b/apps/web/app/(ee)/api/cron/partners/deactivate/route.ts
index 14c998a5f5..2658f91a60 100644
--- a/apps/web/app/(ee)/api/cron/partners/deactivate/route.ts
+++ b/apps/web/app/(ee)/api/cron/partners/deactivate/route.ts
@@ -58,7 +58,7 @@ export const POST = withCron(async ({ rawBody }) => {
const discountCodes = programEnrollments.flatMap(({ discountCodes }) =>
discountCodes.map((dc) => dc),
);
- await deleteDiscountCodes(discountCodes, { isSoftDelete: false });
+ await deleteDiscountCodes(discountCodes, { isSoftDelete: true });
console.log("[bulkDeactivatePartners] Queued discount code deletions.");
// Find the program
diff --git a/apps/web/app/(ee)/api/discount-codes/route.ts b/apps/web/app/(ee)/api/discount-codes/route.ts
index 35abe56ebe..9b2c81de3c 100644
--- a/apps/web/app/(ee)/api/discount-codes/route.ts
+++ b/apps/web/app/(ee)/api/discount-codes/route.ts
@@ -11,6 +11,7 @@ import {
DiscountCodeSchema,
getDiscountCodesQuerySchema,
} from "@/lib/zod/schemas/discount";
+import { APP_DOMAIN } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
@@ -108,7 +109,7 @@ export const POST = withWorkspace(
if (duplicateByCode) {
throw new DubApiError({
code: "conflict",
- 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.`,
+ 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.`,
});
}
}
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/route.ts
index a068d86f35..fb1f32983d 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/route.ts
@@ -37,6 +37,7 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
return {
...link,
discountCode: discountCode?.code,
+ discountCodeDisabledAt: discountCode?.disabledAt ?? null,
};
});
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx
index aa2bcde436..9bb044a58c 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/partner-link-card.tsx
@@ -28,6 +28,7 @@ import {
getApexDomain,
getPrettyUrl,
nFormatter,
+ PARTNERS_DOMAIN,
} from "@dub/utils";
import NumberFlow from "@number-flow/react";
import Link from "next/link";
@@ -75,6 +76,19 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
const isDeactivated = programEnrollment?.status === "deactivated";
+ const discountCodeSection = link.discountCode ? (
+ <div className="hidden items-center gap-1.5 rounded-xl border border-neutral-200 py-1 pl-2 pr-1 sm:flex">
+ <span className="text-sm leading-none text-neutral-500">
+ Discount code
+ </span>
+ <DiscountCodeBadge
+ code={link.discountCode}
+ disabledAt={link.discountCodeDisabledAt}
+ 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.`}
+ />
+ </div>
+ ) : null;
+
return (
<CardList.Card
innerClassName={cn("px-0 py-0 group/card", isDeactivated && "opacity-80")}
@@ -153,20 +167,14 @@ export function PartnerLinkCard({ link }: { link: PartnerProfileLinkProps }) {
</StatusBadge>
);
})()}
- {link.discountCode && (
- <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)"
- }
- >
- <div className="hidden items-center gap-1.5 rounded-xl border border-neutral-200 py-1 pl-2 pr-1 sm:flex">
- <span className="text-sm leading-none text-neutral-500">
- Discount code
- </span>
- <DiscountCodeBadge code={link.discountCode} />
- </div>
- </Tooltip>
- )}
+ {discountCodeSection &&
+ (link.discountCodeDisabledAt ? (
+ discountCodeSection
+ ) : (
+ <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)">
+ {discountCodeSection}
+ </Tooltip>
+ ))}
{displayOption === "cards" && <StatsBadge link={link} />}
<Controls link={link} />
</div>
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index 608d98a1fa..303279daf9 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -100,6 +100,7 @@ export const PartnerProfileLinkSchema = LinkSchema.pick({
createdAt: z.string().or(z.date()),
partnerGroupDefaultLinkId: z.string().nullish(),
discountCode: z.string().nullable().default(null),
+ discountCodeDisabledAt: z.coerce.date().nullable().default(null),
});
export const PartnerProfileCustomerSchema = CustomerEnrichedSchema.pick({
diff --git a/apps/web/ui/partners/discounts/discount-code-badge.tsx b/apps/web/ui/partners/discounts/discount-code-badge.tsx
index 946f414ee0..e91310f4ae 100644
--- a/apps/web/ui/partners/discounts/discount-code-badge.tsx
+++ b/apps/web/ui/partners/discounts/discount-code-badge.tsx
@@ -1,65 +1,68 @@
-import { StatusBadge, Tag, Tooltip, useCopyToClipboard } from "@dub/ui";
+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;
- return (
- <div className="flex items-center gap-2">
- <button
- type="button"
+ const content = (
+ <>
+ <Tag
+ className={cn(
+ "size-3",
+ isDisabled ? "text-neutral-500" : "text-green-700",
+ )}
+ strokeWidth={1.5}
+ />
+ <div
className={cn(
- "group/discountcode relative flex w-fit cursor-copy items-center gap-1 rounded-lg px-2 py-1",
- "transition-colors duration-150",
- copied && "cursor-default",
+ "text-xs font-medium",
isDisabled
- ? "bg-neutral-200/80 line-through hover:bg-neutral-200/80 hover:no-underline"
- : "bg-green-200 hover:bg-green-300/80",
+ ? "text-neutral-500 line-through"
+ : "text-green-700 decoration-dotted underline-offset-2 transition-colors group-hover/discountcode:underline",
)}
- onClick={() =>
- copyToClipboard(code, {
- onSuccess: () => {
- toast.success("Copied discount code to clipboard");
- },
- })
- }
>
- <Tag
- className={cn(
- "size-3",
- isDisabled ? "text-neutral-500" : "text-green-700",
- )}
- strokeWidth={1.5}
- />
- <div
- className={cn(
- "text-xs font-medium decoration-dotted underline-offset-2 transition-colors group-hover/discountcode:underline",
- isDisabled ? "text-neutral-600" : "text-green-700",
- )}
- >
- {code}
+ {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>
- </button>
- {isDisabled && (
- <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.">
- <StatusBadge
- variant="neutral"
- size="sm"
- icon={null}
- className="cursor-help"
- >
- Disabled
- </StatusBadge>
- </Tooltip>
+ </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",
)}
- </div>
+ onClick={() =>
+ copyToClipboard(code, {
+ onSuccess: () => {
+ toast.success("Copied discount code to clipboard");
+ },
+ })
+ }
+ >
+ {content}
+ </button>
);
}