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.

add firstSaleDate indicator customers

Steven Teybecbe66d22e3
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
index 519558750a..e06eacb24b 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts
@@ -41,6 +41,14 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
where: {
id: customerId,
},
+ include: {
+ commissions: {
+ take: 1,
+ orderBy: {
+ createdAt: "asc",
+ },
+ },
+ },
});
if (!customer || customer?.projectId !== program.workspaceId) {
@@ -107,6 +115,7 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
ltv,
timeToLead,
timeToSale,
+ firstSaleDate: customer.commissions[0]?.createdAt ?? null,
events,
link,
},
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
index eb5511cc40..f6566ce5b9 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
@@ -10,10 +10,12 @@ import { CustomerSalesTable } from "@/ui/customers/customer-sales-table";
import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { BackLink } from "@/ui/shared/back-link";
import { Button, MoneyBill2, Tooltip } from "@dub/ui";
-import { fetcher, OG_AVATAR_URL } from "@dub/utils";
+import { fetcher, formatDate, OG_AVATAR_URL } from "@dub/utils";
+import { addMonths, isBefore } from "date-fns";
+import { AlertCircle } from "lucide-react";
import Link from "next/link";
import { redirect, useParams } from "next/navigation";
-import { memo } from "react";
+import { memo, useMemo } from "react";
import useSWR from "swr";
export function ProgramCustomerPageClient() {
@@ -27,6 +29,22 @@ export function ProgramCustomerPageClient() {
customerId,
});
+ const rewardPeriodEndDate = useMemo(() => {
+ if (!programEnrollment?.rewards || !customer?.activity?.firstSaleDate)
+ return null;
+ const saleReward = programEnrollment?.rewards.find(
+ (r) => r.event === "sale",
+ );
+ if (!saleReward) return null;
+
+ // infinite duration
+ if (saleReward.maxDuration === null || saleReward.maxDuration === undefined)
+ return null;
+
+ // add the max duration to the first sale date
+ return addMonths(customer.activity.firstSaleDate, saleReward.maxDuration);
+ }, [programEnrollment]);
+
if ((!customer && !isLoading) || !showDetailedAnalytics) {
redirect(`/programs/${programSlug}`);
}
@@ -67,29 +85,39 @@ export function ProgramCustomerPageClient() {
<div className="mt-8 grid grid-cols-1 items-start gap-x-16 gap-y-10 lg:grid-cols-[minmax(0,1fr)_240px]">
{/* Main content */}
<div className="flex flex-col gap-10">
- <section className="flex flex-col">
+ <section className="flex flex-col gap-4">
<div className="flex items-center justify-between">
- <h2 className="py-3 text-lg font-semibold text-neutral-900">
+ <h2 className="text-lg font-semibold text-neutral-900">
Earnings
</h2>
{programEnrollment?.rewards && (
<Tooltip
content={
- <div>
- <ProgramRewardList
- rewards={programEnrollment?.rewards}
- className="gap-2 border-none p-3"
- showModifiersTooltip={false}
- />
- </div>
+ <ProgramRewardList
+ rewards={programEnrollment?.rewards}
+ className="gap-2 border-none p-3"
+ showModifiersTooltip={false}
+ />
}
>
- <div className="border-border-subtle flex size-8 items-center justify-center rounded-full border hover:bg-neutral-50">
- <MoneyBill2 className="size-4 text-neutral-800" />
+ <div className="border-border-subtle flex cursor-default items-center justify-center gap-1.5 rounded-md border px-2 py-1 transition-all hover:bg-neutral-50">
+ <MoneyBill2 className="size-4" />
+ <span className="text-sm">Eligible rewards</span>
</div>
</Tooltip>
)}
</div>
+ {rewardPeriodEndDate &&
+ isBefore(rewardPeriodEndDate, new Date()) && (
+ <div className="flex items-center gap-2 rounded-lg border border-amber-100 bg-amber-50 px-3 py-2">
+ <AlertCircle className="size-4 shrink-0 text-amber-600" />
+ <p className="text-sm text-amber-900">
+ The earning period for this customer has ended as of{" "}
+ {formatDate(rewardPeriodEndDate)}. No future conversions
+ will be rewarded.
+ </p>
+ </div>
+ )}
<EarningsTable customerId={customerId} />
</section>
diff --git a/apps/web/lib/zod/schemas/customer-activity.ts b/apps/web/lib/zod/schemas/customer-activity.ts
index bb737e0829..83ac1504d3 100644
--- a/apps/web/lib/zod/schemas/customer-activity.ts
+++ b/apps/web/lib/zod/schemas/customer-activity.ts
@@ -5,6 +5,7 @@ export const customerActivityResponseSchema = z.object({
ltv: z.number(),
timeToLead: z.number().nullable(),
timeToSale: z.number().nullable(),
+ firstSaleDate: z.date().nullable(),
events: z.array(z.any()), // we've already parsed the events in get-customer-events.ts
link: LinkSchema.pick({
id: true,
diff --git a/apps/web/scripts/partners/check-pending-paypal-payouts.ts b/apps/web/scripts/partners/check-pending-paypal-payouts.ts
index a266e25dfe..f818f256bf 100644
--- a/apps/web/scripts/partners/check-pending-paypal-payouts.ts
+++ b/apps/web/scripts/partners/check-pending-paypal-payouts.ts
@@ -21,7 +21,7 @@ async function main() {
partner: payout.partner.email,
status: payout.status,
country: payout.partner.country,
- amount: payout.amount / 100,
+ amount: payout.amount,
}));
console.table(finalPayouts);