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.

Block pending partners from referrals embed (#4021)

Pedro Ladeira299c0372a867
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/get-referrals-embed-data.ts b/apps/web/app/(ee)/app.dub.co/embed/referrals/get-referrals-embed-data.ts
index 92801681de..7208a1b713 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/get-referrals-embed-data.ts
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/get-referrals-embed-data.ts
@@ -143,6 +143,7 @@ export const getReferralsEmbedData = async (token: string) => {
},
programEnrollment: {
createdAt: programEnrollment.createdAt,
+ status: programEnrollment.status,
},
group: {
id: group.id,
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/page-client.tsx b/apps/web/app/(ee)/app.dub.co/embed/referrals/page-client.tsx
index 732169f77f..4637ebb36c 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/page-client.tsx
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/page-client.tsx
@@ -9,13 +9,20 @@ import {
ProgramEnrollmentProps,
RewardProps,
} from "@/lib/types";
+import { ACTIVE_ENROLLMENT_STATUSES } from "@/lib/zod/schemas/partners";
import { programEmbedSchema } from "@/lib/zod/schemas/program-embed";
import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
import { HeroBackground } from "@/ui/partners/hero-background";
+import { PartnerStatusBadges } from "@/ui/partners/partner-status-badges";
import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { ProgramRewardTerms } from "@/ui/partners/program-reward-terms";
import { ThreeDots } from "@/ui/shared/icons";
-import { Partner, PlatformType, Program } from "@dub/prisma/client";
+import {
+ Partner,
+ PlatformType,
+ Program,
+ ProgramEnrollmentStatus,
+} from "@dub/prisma/client";
import {
Button,
Check,
@@ -23,6 +30,7 @@ import {
Copy,
Directions,
Popover,
+ StatusBadge,
TabSelect,
useCopyToClipboard,
useLocalStorage,
@@ -66,7 +74,9 @@ type ReferralsEmbedData = {
| "embedData"
| "resources"
>;
- programEnrollment: Pick<ProgramEnrollmentProps, "createdAt">;
+ programEnrollment: Pick<ProgramEnrollmentProps, "createdAt"> & {
+ status: ProgramEnrollmentStatus;
+ };
partner: Pick<Partner, "id" | "name" | "email">;
partnerPlatforms: Array<{
type: PlatformType;
@@ -169,6 +179,9 @@ export function ReferralsEmbedPageClient({
);
const activeBountiesCount = bounties.length;
+ const hasEmbedAccess = ACTIVE_ENROLLMENT_STATUSES.includes(
+ programEnrollment.status,
+ );
const tabs = useMemo(
() => [
@@ -226,6 +239,17 @@ export function ReferralsEmbedPageClient({
],
);
+ if (!hasEmbedAccess) {
+ return (
+ <ReferralsEmbedUnapproved
+ status={programEnrollment.status}
+ programName={program.name}
+ themeOptions={themeOptions}
+ dynamicHeight={dynamicHeight}
+ />
+ );
+ }
+
return (
<ReferralsEmbedDataProvider value={embedData}>
<div
@@ -370,6 +394,54 @@ export function ReferralsEmbedPageClient({
);
}
+function ReferralsEmbedUnapproved({
+ status,
+ programName,
+ themeOptions,
+ dynamicHeight,
+}: {
+ status: ProgramEnrollmentStatus;
+ programName: string;
+ themeOptions: ThemeOptions;
+ dynamicHeight: boolean;
+}) {
+ const badge = PartnerStatusBadges[status];
+ const isPending = status === "pending";
+
+ return (
+ <div
+ style={{
+ backgroundColor: themeOptions.backgroundColor || "transparent",
+ }}
+ className={cn(
+ "flex flex-col items-center justify-center p-8 text-center",
+ !dynamicHeight && "min-h-screen",
+ )}
+ >
+ <StatusBadge
+ variant={badge.variant}
+ icon={badge.icon}
+ className="px-1.5 py-0.5"
+ >
+ {badge.label}
+ </StatusBadge>
+ <h2 className="text-content-default mt-4 text-base font-semibold">
+ {isPending ? "Application in review" : "Program unavailable"}
+ </h2>
+ <p className="text-content-subtle [&_strong]:text-content-default mt-2 max-w-sm text-balance text-sm font-medium [&_strong]:font-semibold">
+ {isPending ? (
+ <>
+ You&apos;ll be notified when <strong>{programName}</strong> has
+ finished reviewing your application.
+ </>
+ ) : (
+ "You don't have access to this program."
+ )}
+ </p>
+ </div>
+ );
+}
+
function ReferralLinkDisplay({ onSelectTab }) {
const { links, group } = useReferralsEmbedData();
const [copied, copyToClipboard] = useCopyToClipboard();