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.

hide group cards dynamically

Steven Tey6ef200f213bb
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index ace58fa6ad..f3df675f62 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -2,8 +2,8 @@ import { tb } from "@/lib/tinybird";
import { prisma } from "@dub/prisma";
import { Link } from "@dub/prisma/client";
import { OG_AVATAR_URL } from "@dub/utils";
-import { transformLink } from "../api/links";
import { decodeLinkIfCaseSensitive } from "../api/links/case-sensitivity";
+import { transformLink } from "../api/links/utils/transform-link";
import { generateRandomName } from "../names";
import z from "../zod";
import { eventsFilterTB } from "../zod/schemas/analytics";
diff --git a/apps/web/scripts/migrations/backfill-missing-leads.ts b/apps/web/scripts/migrations/backfill-missing-leads.ts
new file mode 100644
index 0000000000..b8b04c50ef
--- /dev/null
+++ b/apps/web/scripts/migrations/backfill-missing-leads.ts
@@ -0,0 +1,51 @@
+import { createId } from "@/lib/api/create-id";
+import { prisma } from "@dub/prisma";
+import { Prisma } from "@dub/prisma/client";
+import "dotenv-flow/config";
+import { getEvents } from "../../lib/analytics/get-events";
+
+async function main() {
+ const link = await prisma.link.findUniqueOrThrow({
+ where: {
+ id: "link_xxx",
+ },
+ });
+ const leadEvents = await getEvents({
+ event: "leads",
+ interval: "all",
+ workspaceId: link.projectId!,
+ linkId: link.id,
+ sortBy: "timestamp",
+ page: 1,
+ limit: 1000,
+ });
+
+ const commissionsToCreate: Prisma.CommissionCreateManyInput[] = leadEvents
+ .filter((e) => e.event === "lead")
+ .map((e) => ({
+ id: createId({ prefix: "cm_" }),
+ programId: link.programId!,
+ partnerId: link.partnerId!,
+ rewardId: "rw_xxx",
+ customerId: e.customer!.id,
+ linkId: link.id,
+ eventId: e.eventId,
+ type: "lead",
+ quantity: 1,
+ amount: 0,
+ currency: "usd",
+ earnings: 2000,
+ status: "pending",
+ createdAt: new Date(e.timestamp),
+ }));
+
+ console.table(commissionsToCreate);
+
+ await prisma.commission.createMany({
+ data: commissionsToCreate,
+ skipDuplicates: true,
+ });
+ console.log(`Created ${commissionsToCreate.length} commissions`);
+}
+
+main();
diff --git a/apps/web/ui/partners/partner-info-cards.tsx b/apps/web/ui/partners/partner-info-cards.tsx
index 4fa268158c..fd24757111 100644
--- a/apps/web/ui/partners/partner-info-cards.tsx
+++ b/apps/web/ui/partners/partner-info-cards.tsx
@@ -244,101 +244,109 @@ export function PartnerInfoCards({
</div>
</div>
- <div className="border-border-subtle flex flex-col gap-4 rounded-xl border p-4">
- <h2 className="text-content-emphasis text-sm font-semibold">
- {isEnrolled ? "Organization" : "Invite group"}
- </h2>
+ {partner &&
+ "status" in partner &&
+ ["banned", "deactivated"].includes(
+ partner.status,
+ ) ? //hide group info for banned/deactivated partners
+ null : (
+ <div className="border-border-subtle flex flex-col gap-4 rounded-xl border p-4">
+ <h2 className="text-content-emphasis text-sm font-semibold">
+ {isEnrolled ? "Organization" : "Invite group"}
+ </h2>
- {/* Group */}
- <div className="flex flex-col gap-2">
- {isEnrolled && (
- <h3 className="text-content-emphasis text-xs font-semibold">
- Group
- </h3>
- )}
- {partner ? (
- <PartnerInfoGroup
- partner={partner}
- changeButtonText="Change"
- className="rounded-lg bg-white shadow-sm"
- selectedGroupId={selectedGroupId}
- setSelectedGroupId={setSelectedGroupId}
- />
- ) : (
- <div className="my-px h-11 w-full animate-pulse rounded-lg bg-neutral-200" />
- )}
- </div>
-
- {/* Rewards */}
- <div className="flex flex-col gap-2">
- <h3 className="text-content-emphasis text-xs font-semibold">
- Rewards
- </h3>
- {group ? (
- group.clickReward ||
- group.leadReward ||
- group.saleReward ||
- group.discount ? (
- <ProgramRewardList
- rewards={[
- group.clickReward,
- group.leadReward,
- group.saleReward,
- ].filter((r): r is RewardProps => r !== null)}
- discount={group.discount}
- variant="plain"
- className="text-content-subtle gap-2 text-xs leading-4"
- iconClassName="size-3.5"
+ {/* Group */}
+ <div className="flex flex-col gap-2">
+ {isEnrolled && (
+ <h3 className="text-content-emphasis text-xs font-semibold">
+ Group
+ </h3>
+ )}
+ {partner ? (
+ <PartnerInfoGroup
+ partner={partner}
+ changeButtonText="Change"
+ className="rounded-lg bg-white shadow-sm"
+ selectedGroupId={selectedGroupId}
+ setSelectedGroupId={setSelectedGroupId}
/>
) : (
- <span className="text-content-subtle text-xs">No rewards</span>
- )
- ) : (
- <div className="h-4 w-32 animate-pulse rounded bg-neutral-200" />
- )}
- </div>
+ <div className="my-px h-11 w-full animate-pulse rounded-lg bg-neutral-200" />
+ )}
+ </div>
- {/* Eligible bounties */}
- {isEnrolled && partner?.status === "approved" && (
+ {/* Rewards */}
<div className="flex flex-col gap-2">
<h3 className="text-content-emphasis text-xs font-semibold">
- Eligible Bounties
+ Rewards
</h3>
- {bounties ? (
- bounties.length ? (
- <div className="flex flex-col gap-2">
- {bounties.map((bounty) => {
- const Icon = bounty.type === "performance" ? Trophy : Heart;
- return (
- <Link
- key={bounty.id}
- target="_blank"
- href={`/${workspaceSlug}/program/bounties/${bounty.id}`}
- className="text-content-subtle flex cursor-alias items-center gap-2 decoration-dotted underline-offset-2 hover:underline"
- >
- <Icon className="size-3.5 shrink-0" />
- <span className="text-xs font-medium">
- {bounty.name}
- </span>
- </Link>
- );
- })}
- </div>
+ {group ? (
+ group.clickReward ||
+ group.leadReward ||
+ group.saleReward ||
+ group.discount ? (
+ <ProgramRewardList
+ rewards={[
+ group.clickReward,
+ group.leadReward,
+ group.saleReward,
+ ].filter((r): r is RewardProps => r !== null)}
+ discount={group.discount}
+ variant="plain"
+ className="text-content-subtle gap-2 text-xs leading-4"
+ iconClassName="size-3.5"
+ />
) : (
- <p className="text-content-subtle text-xs">
- No eligible bounties
- </p>
+ <span className="text-content-subtle text-xs">No rewards</span>
)
- ) : errorBounties ? (
- <p className="text-content-subtle text-xs">
- Failed to load bounties
- </p>
) : (
- <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-32 animate-pulse rounded bg-neutral-200" />
)}
</div>
- )}
- </div>
+
+ {/* Eligible bounties */}
+ {isEnrolled && partner?.status === "approved" && (
+ <div className="flex flex-col gap-2">
+ <h3 className="text-content-emphasis text-xs font-semibold">
+ Eligible Bounties
+ </h3>
+ {bounties ? (
+ bounties.length ? (
+ <div className="flex flex-col gap-2">
+ {bounties.map((bounty) => {
+ const Icon =
+ bounty.type === "performance" ? Trophy : Heart;
+ return (
+ <Link
+ key={bounty.id}
+ target="_blank"
+ href={`/${workspaceSlug}/program/bounties/${bounty.id}`}
+ className="text-content-subtle flex cursor-alias items-center gap-2 decoration-dotted underline-offset-2 hover:underline"
+ >
+ <Icon className="size-3.5 shrink-0" />
+ <span className="text-xs font-medium">
+ {bounty.name}
+ </span>
+ </Link>
+ );
+ })}
+ </div>
+ ) : (
+ <p className="text-content-subtle text-xs">
+ No eligible bounties
+ </p>
+ )
+ ) : errorBounties ? (
+ <p className="text-content-subtle text-xs">
+ Failed to load bounties
+ </p>
+ ) : (
+ <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
+ )}
+ </div>
+ )}
+ </div>
+ )}
</div>
);
}