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.

`PartnerReferral` → `SubmittedLead` (#3869)

Kiran K798f89e95794
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts
index 763140260d..0a82baf6a1 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/activity-logs/route.ts
@@ -14,11 +14,11 @@ export const GET = withPartnerProfile(
const { resourceType, resourceId, action } =
getActivityLogsQuerySchema.parse(searchParams);
- // Limit to referral for now
- if (resourceType !== "referral") {
+ // Limit to submitted lead for now
+ if (resourceType !== "submittedLead") {
throw new DubApiError({
code: "bad_request",
- message: "Resource type must be referral.",
+ message: "Resource type must be submitted lead.",
});
}
@@ -29,24 +29,22 @@ export const GET = withPartnerProfile(
});
// Check if the resource is a referral and belongs to the program and partner
- if (resourceType === "referral") {
- const referral = await prisma.partnerReferral.findUnique({
- where: {
- id: resourceId,
- programId: programEnrollment.programId,
- partnerId: partner.id,
- },
- select: {
- id: true,
- },
- });
+ const lead = await prisma.submittedLead.findUnique({
+ where: {
+ id: resourceId,
+ programId: programEnrollment.programId,
+ partnerId: partner.id,
+ },
+ select: {
+ id: true,
+ },
+ });
- if (!referral) {
- throw new DubApiError({
- code: "not_found",
- message: "Referral not found.",
- });
- }
+ if (!lead) {
+ throw new DubApiError({
+ code: "not_found",
+ message: "Submitted lead not found.",
+ });
}
const activityLogs = await prisma.activityLog.findMany({
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/referrals/count/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/count/route.ts
similarity index 64%
rename from apps/web/app/(ee)/api/partner-profile/programs/[programId]/referrals/count/route.ts
rename to apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/count/route.ts
index bb764946dc..430cd5a892 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/referrals/count/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/count/route.ts
@@ -1,19 +1,19 @@
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { withPartnerProfile } from "@/lib/auth/partner";
import {
- getPartnerReferralsCountQuerySchema,
- partnerReferralsCountResponseSchema,
+ getPartnerSubmittedLeadsCountQuerySchema,
+ partnerSubmittedLeadsCountResponseSchema,
} from "@/lib/zod/schemas/partner-profile";
import { prisma, sanitizeFullTextSearch } from "@dub/prisma";
-import { Prisma, ReferralStatus } from "@dub/prisma/client";
+import { Prisma, SubmittedLeadStatus } from "@dub/prisma/client";
import { NextResponse } from "next/server";
-// GET /api/partner-profile/programs/[programId]/referrals/count - get the count of referrals for the current partner in a program
+// GET /api/partner-profile/programs/[programId]/submitted-leads/count
export const GET = withPartnerProfile(
async ({ partner, params, searchParams }) => {
const { programId } = params;
const { status, search, groupBy } =
- getPartnerReferralsCountQuerySchema.parse(searchParams);
+ getPartnerSubmittedLeadsCountQuerySchema.parse(searchParams);
const { program } = await getProgramEnrollmentOrThrow({
partnerId: partner.id,
@@ -23,7 +23,7 @@ export const GET = withPartnerProfile(
},
});
- const commonWhere: Prisma.PartnerReferralWhereInput = {
+ const commonWhere: Prisma.SubmittedLeadWhereInput = {
programId: program.id,
partnerId: partner.id,
...(status && groupBy !== "status" && { status }),
@@ -37,9 +37,9 @@ export const GET = withPartnerProfile(
: {}),
};
- // Get referral count by status
+ // Get submitted lead count by status
if (groupBy === "status") {
- const data = await prisma.partnerReferral.groupBy({
+ const data = await prisma.submittedLead.groupBy({
by: ["status"],
where: commonWhere,
_count: true,
@@ -51,20 +51,24 @@ export const GET = withPartnerProfile(
});
// Fill in missing statuses with zero counts
- Object.values(ReferralStatus).forEach((status) => {
+ Object.values(SubmittedLeadStatus).forEach((status) => {
if (!data.some((d) => d.status === status)) {
data.push({ _count: 0, status });
}
});
- return NextResponse.json(partnerReferralsCountResponseSchema.parse(data));
+ return NextResponse.json(
+ partnerSubmittedLeadsCountResponseSchema.parse(data),
+ );
}
- // Get referral count
- const count = await prisma.partnerReferral.count({
+ // Get submitted lead count
+ const count = await prisma.submittedLead.count({
where: commonWhere,
});
- return NextResponse.json(partnerReferralsCountResponseSchema.parse(count));
+ return NextResponse.json(
+ partnerSubmittedLeadsCountResponseSchema.parse(count),
+ );
},
);
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/referrals/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/route.ts
similarity index 77%
rename from apps/web/app/(ee)/api/partner-profile/programs/[programId]/referrals/route.ts
rename to apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/route.ts
index 263eaa1c31..58d9d94f0c 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/referrals/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/route.ts
@@ -1,14 +1,14 @@
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { withPartnerProfile } from "@/lib/auth/partner";
import {
- getPartnerReferralsQuerySchema,
- partnerProfileReferralSchema,
+ getPartnerSubmittedLeadsQuerySchema,
+ partnerProfileSubmittedLeadSchema,
} from "@/lib/zod/schemas/partner-profile";
import { prisma, sanitizeFullTextSearch } from "@dub/prisma";
import { NextResponse } from "next/server";
import * as z from "zod/v4";
-// GET /api/partner-profile/programs/[programId]/referrals - get all referrals for the current partner in a program
+// GET /api/partner-profile/programs/[programId]/submitted-leads
export const GET = withPartnerProfile(
async ({ partner, params, searchParams }) => {
const { programId } = params;
@@ -17,7 +17,7 @@ export const GET = withPartnerProfile(
search,
page = 1,
pageSize,
- } = getPartnerReferralsQuerySchema.parse(searchParams);
+ } = getPartnerSubmittedLeadsQuerySchema.parse(searchParams);
const { program } = await getProgramEnrollmentOrThrow({
partnerId: partner.id,
@@ -27,7 +27,7 @@ export const GET = withPartnerProfile(
},
});
- const referrals = await prisma.partnerReferral.findMany({
+ const lead = await prisma.submittedLead.findMany({
where: {
programId: program.id,
partnerId: partner.id,
@@ -49,7 +49,7 @@ export const GET = withPartnerProfile(
});
return NextResponse.json(
- z.array(partnerProfileReferralSchema).parse(referrals),
+ z.array(partnerProfileSubmittedLeadSchema).parse(lead),
);
},
);
diff --git a/apps/web/app/(ee)/api/programs/[programId]/referrals/count/route.ts b/apps/web/app/(ee)/api/programs/[programId]/submitted-leads/count/route.ts
similarity index 62%
rename from apps/web/app/(ee)/api/programs/[programId]/referrals/count/route.ts
rename to apps/web/app/(ee)/api/programs/[programId]/submitted-leads/count/route.ts
index 7ab7548572..e8262414b4 100644
--- a/apps/web/app/(ee)/api/programs/[programId]/referrals/count/route.ts
+++ b/apps/web/app/(ee)/api/programs/[programId]/submitted-leads/count/route.ts
@@ -1,22 +1,22 @@
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
- getPartnerReferralsCountQuerySchema,
- partnerReferralsCountResponseSchema,
-} from "@/lib/zod/schemas/referrals";
+ getSubmittedLeadsCountQuerySchema,
+ submittedLeadsCountResponseSchema,
+} from "@/lib/zod/schemas/submitted-leads";
import { prisma, sanitizeFullTextSearch } from "@dub/prisma";
-import { Prisma, ReferralStatus } from "@dub/prisma/client";
+import { Prisma, SubmittedLeadStatus } from "@dub/prisma/client";
import { NextResponse } from "next/server";
-// GET /api/programs/[programId]/referrals/count - get the count of partner referrals for a program
+// GET /api/programs/[programId]/submitted-leads/count
export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
const { partnerId, status, search, groupBy } =
- getPartnerReferralsCountQuerySchema.parse(searchParams);
+ getSubmittedLeadsCountQuerySchema.parse(searchParams);
- const commonWhere: Prisma.PartnerReferralWhereInput = {
+ const commonWhere: Prisma.SubmittedLeadWhereInput = {
programId,
...(partnerId && groupBy !== "partnerId" && { partnerId }),
...(groupBy === "status"
@@ -25,7 +25,10 @@ export const GET = withWorkspace(
? { status }
: {
status: {
- notIn: [ReferralStatus.unqualified, ReferralStatus.closedLost],
+ notIn: [
+ SubmittedLeadStatus.unqualified,
+ SubmittedLeadStatus.closedLost,
+ ],
},
}),
...(search
@@ -38,9 +41,9 @@ export const GET = withWorkspace(
: {}),
};
- // Get referral count by status
+ // Get submitted leads count by status
if (groupBy === "status") {
- const data = await prisma.partnerReferral.groupBy({
+ const data = await prisma.submittedLead.groupBy({
by: ["status"],
where: commonWhere,
_count: true,
@@ -52,18 +55,18 @@ export const GET = withWorkspace(
});
// Fill in missing statuses with zero counts
- Object.values(ReferralStatus).forEach((status) => {
+ Object.values(SubmittedLeadStatus).forEach((status) => {
if (!data.some((d) => d.status === status)) {
data.push({ _count: 0, status });
}
});
- return NextResponse.json(partnerReferralsCountResponseSchema.parse(data));
+ return NextResponse.json(submittedLeadsCountResponseSchema.parse(data));
}
- // Get referral count by partnerId
+ // Get submitted leads count by partnerId
if (groupBy === "partnerId") {
- const data = await prisma.partnerReferral.groupBy({
+ const data = await prisma.submittedLead.groupBy({
by: ["partnerId"],
where: commonWhere,
_count: true,
@@ -75,15 +78,15 @@ export const GET = withWorkspace(
take: 10000,
});
- return NextResponse.json(partnerReferralsCountResponseSchema.parse(data));
+ return NextResponse.json(submittedLeadsCountResponseSchema.parse(data));
}
- // Get referral count
- const count = await prisma.partnerReferral.count({
+ // Get submitted lead count
+ const count = await prisma.submittedLead.count({
where: commonWhere,
});
- return NextResponse.json(partnerReferralsCountResponseSchema.parse(count));
+ return NextResponse.json(submittedLeadsCountResponseSchema.parse(count));
},
{
requiredPlan: [
diff --git a/apps/web/app/(ee)/api/programs/[programId]/referrals/route.ts b/apps/web/app/(ee)/api/programs/[programId]/submitted-leads/route.ts
similarity index 71%
rename from apps/web/app/(ee)/api/programs/[programId]/referrals/route.ts
rename to apps/web/app/(ee)/api/programs/[programId]/submitted-leads/route.ts
index 80dbcf34df..dddd683cfa 100644
--- a/apps/web/app/(ee)/api/programs/[programId]/referrals/route.ts
+++ b/apps/web/app/(ee)/api/programs/[programId]/submitted-leads/route.ts
@@ -1,15 +1,15 @@
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
- getPartnerReferralsQuerySchema,
- referralSchema,
-} from "@/lib/zod/schemas/referrals";
+ getSubmittedLeadsQuerySchema,
+ submittedLeadSchema,
+} from "@/lib/zod/schemas/submitted-leads";
import { prisma, sanitizeFullTextSearch } from "@dub/prisma";
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { NextResponse } from "next/server";
import * as z from "zod/v4";
-// GET /api/programs/[programId]/referrals - get all partner referrals for a program
+// GET /api/programs/[programId]/submitted-leads
export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
@@ -20,9 +20,9 @@ export const GET = withWorkspace(
search,
page = 1,
pageSize,
- } = getPartnerReferralsQuerySchema.parse(searchParams);
+ } = getSubmittedLeadsQuerySchema.parse(searchParams);
- const partnerReferrals = await prisma.partnerReferral.findMany({
+ const submittedLeads = await prisma.submittedLead.findMany({
where: {
programId,
...(partnerId && { partnerId }),
@@ -30,7 +30,10 @@ export const GET = withWorkspace(
? { status }
: {
status: {
- notIn: [ReferralStatus.unqualified, ReferralStatus.closedLost],
+ notIn: [
+ SubmittedLeadStatus.unqualified,
+ SubmittedLeadStatus.closedLost,
+ ],
},
}),
...(search
@@ -59,7 +62,9 @@ export const GET = withWorkspace(
},
});
- return NextResponse.json(z.array(referralSchema).parse(partnerReferrals));
+ return NextResponse.json(
+ z.array(submittedLeadSchema).parse(submittedLeads),
+ );
},
{
requiredPlan: [
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/layout.tsx
index b156257f57..ceb060528c 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/layout.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/layout.tsx
@@ -1,13 +1,13 @@
"use client";
-import { REFERRAL_ENABLED_PROGRAM_IDS } from "@/lib/referrals/constants";
+import { SUBMITTED_LEADS_ENABLED_PROGRAM_IDS } from "@/lib/submitted-leads/constants";
import usePartnerCustomersCount from "@/lib/swr/use-partner-customers-count";
-import usePartnerReferralsCount from "@/lib/swr/use-partner-referrals-count";
+import { usePartnerSubmittedLeadsCount } from "@/lib/swr/use-partner-submitted-leads-count";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
-import { referralFormSchema } from "@/lib/zod/schemas/referral-form";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
-import { SubmitReferralSheet } from "@/ui/referrals/submit-referral-sheet";
+import { SubmitLeadSheet } from "@/ui/submitted-leads/submit-lead-sheet";
import { Button, InfoTooltip } from "@dub/ui";
import { cn, nFormatter } from "@dub/utils";
import Link from "next/link";
@@ -23,35 +23,35 @@ export default function PartnerCustomersLayout({
const pathname = usePathname();
const { programEnrollment } = useProgramEnrollment();
const { programSlug } = useParams<{ programSlug: string }>();
- const [showReferralSheet, setShowReferralSheet] = useState(false);
+ const [showLeadSheet, setShowLeadSheet] = useState(false);
const { data: customersCount } = usePartnerCustomersCount<number>({
includeParams: [],
});
- const { data: referralsCount } = usePartnerReferralsCount<number>({
+ const { data: leadsCount } = usePartnerSubmittedLeadsCount<number>({
ignoreParams: true,
});
- const referralFormDataRaw = programEnrollment?.program?.referralFormData;
+ const leadFormDataRaw = programEnrollment?.program?.referralFormData;
const programId = programEnrollment?.programId;
const isEnabled = programId
- ? REFERRAL_ENABLED_PROGRAM_IDS.includes(programId)
+ ? SUBMITTED_LEADS_ENABLED_PROGRAM_IDS.includes(programId)
: false;
- const referralFormData = useMemo(() => {
- if (!referralFormDataRaw) {
+ const leadFormData = useMemo(() => {
+ if (!leadFormDataRaw) {
return null;
}
try {
- return referralFormSchema.parse(referralFormDataRaw) as z.infer<
- typeof referralFormSchema
+ return submittedLeadFormSchema.parse(leadFormDataRaw) as z.infer<
+ typeof submittedLeadFormSchema
>;
} catch {
return null;
}
- }, [referralFormDataRaw]);
+ }, [leadFormDataRaw]);
const tabs = useMemo(() => {
if (!isEnabled) {
@@ -67,14 +67,14 @@ export default function PartnerCustomersLayout({
count: customersCount,
},
{
- label: "Submitted Referrals",
- id: "invited",
- href: "referrals",
- info: "Shows your submitted referrals and their status.",
- count: referralsCount,
+ label: "Leads",
+ id: "leads",
+ href: "leads",
+ info: "Shows your submitted leads.",
+ count: leadsCount,
},
];
- }, [isEnabled, customersCount, referralsCount]);
+ }, [isEnabled, customersCount, leadsCount]);
return (
<PageContent
@@ -83,28 +83,26 @@ export default function PartnerCustomersLayout({
<>
{isEnabled && (
<Button
- text="Submit referral"
+ text="Submit lead"
className="h-9 w-fit rounded-lg"
- disabled={!referralFormData}
+ disabled={!leadFormData}
disabledTooltip={
- referralFormData
- ? undefined
- : "Submitted referrals are not offered."
+ leadFormData ? undefined : "Submitted leads are not offered."
}
onClick={() => {
- setShowReferralSheet(true);
+ setShowLeadSheet(true);
}}
/>
)}
</>
}
>
- {isEnabled && referralFormData && programEnrollment?.programId && (
- <SubmitReferralSheet
- isOpen={showReferralSheet}
- setIsOpen={setShowReferralSheet}
+ {isEnabled && leadFormData && programEnrollment?.programId && (
+ <SubmitLeadSheet
+ isOpen={showLeadSheet}
+ setIsOpen={setShowLeadSheet}
programId={programEnrollment.programId}
- referralFormData={referralFormData}
+ leadFormData={leadFormData}
/>
)}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/referrals/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/leads/page.tsx
similarity index 62%
rename from apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/referrals/page.tsx
rename to apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/leads/page.tsx
index 7028a3c5ac..e5ec1f97b7 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/referrals/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/leads/page.tsx
@@ -1,15 +1,15 @@
"use client";
-import usePartnerReferrals from "@/lib/swr/use-partner-referrals";
-import usePartnerReferralsCount from "@/lib/swr/use-partner-referrals-count";
-import { PartnerProfileReferralsCountByStatus } from "@/lib/types";
-import { PartnerProfileReferral } from "@/lib/zod/schemas/partner-profile";
-import { PartnerProfileReferralSheet } from "@/ui/referrals/partner-profile-referral-sheet";
-import { PartnerProfileReferralsEmptyState } from "@/ui/referrals/partner-profile-referrals-empty-state";
-import { ReferralStatusBadges } from "@/ui/referrals/referral-status-badges";
-import { getCompanyLogoUrl } from "@/ui/referrals/referral-utils";
+import { usePartnerSubmittedLeads } from "@/lib/swr/use-partner-submitted-leads";
+import { usePartnerSubmittedLeadsCount } from "@/lib/swr/use-partner-submitted-leads-count";
+import { PartnerProfileSubmittedLeadsCountByStatus } from "@/lib/types";
+import { PartnerProfileSubmittedLead } from "@/lib/zod/schemas/partner-profile";
import { SearchBoxPersisted } from "@/ui/shared/search-box";
-import { ReferralStatus } from "@dub/prisma/client";
+import { PartnerProfileSubmittedLeadSheet } from "@/ui/submitted-leads/partner-profile-submitted-lead-sheet";
+import { PartnerProfileSubmittedLeadsEmptyState } from "@/ui/submitted-leads/partner-profile-submitted-leads-empty-state";
+import { SubmittedLeadStatusBadges } from "@/ui/submitted-leads/submitted-lead-status-badges";
+import { getCompanyLogoUrl } from "@/ui/submitted-leads/submitted-lead-utils";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import {
AnimatedSizeContainer,
Filter,
@@ -26,50 +26,50 @@ import { cn, formatDate, nFormatter, OG_AVATAR_URL } from "@dub/utils";
import { Row } from "@tanstack/react-table";
import { useEffect, useMemo, useState } from "react";
-export default function PartnerCustomersReferralsPage() {
+export default function PartnerSubmittedLeadsPage() {
const { queryParams, searchParams } = useRouterStuff();
const { pagination, setPagination } = usePagination();
- const referralIdFromUrl = searchParams.get("referralId");
+ const leadIdFromUrl = searchParams.get("leadId");
const [detailsSheetState, setDetailsSheetState] = useState<{
- referralId: string | null;
+ leadId: string | null;
open: boolean;
}>({
- referralId: referralIdFromUrl,
- open: !!referralIdFromUrl,
+ leadId: leadIdFromUrl,
+ open: !!leadIdFromUrl,
});
const { searchParamsObj } = useRouterStuff();
- const status = searchParamsObj.status as ReferralStatus | undefined;
+ const status = searchParamsObj.status as SubmittedLeadStatus | undefined;
const search = searchParamsObj.search as string | undefined;
- const { data: referralsCountByStatus } = usePartnerReferralsCount<
- PartnerProfileReferralsCountByStatus[] | undefined
+ const { data: countByStatus } = usePartnerSubmittedLeadsCount<
+ PartnerProfileSubmittedLeadsCountByStatus[] | undefined
>({
query: {
groupBy: "status",
},
});
- const { data: totalReferralsCount, error: countError } =
- usePartnerReferralsCount<number>({
+ const { data: totalCount, error: countError } =
+ usePartnerSubmittedLeadsCount<number>({
query: {
...(status && { status }),
...(search && { search }),
},
});
- const { data: referrals, error, isLoading } = usePartnerReferrals();
+ const { data: leads, error, isLoading } = usePartnerSubmittedLeads();
- const referralsColumns = {
+ const leadsColumns = {
all: ["lead", "name", "company", "submitted", "status"],
defaultVisible: ["lead", "name", "company", "submitted", "status"],
};
const { columnVisibility, setColumnVisibility } = useColumnVisibility(
- "partner-profile-referrals-table-columns",
- referralsColumns,
+ "partner-profile-leads-table-columns",
+ leadsColumns,
);
const filters = useMemo(
@@ -79,8 +79,8 @@ export default function PartnerCustomersReferralsPage() {
icon: CircleDotted,
label: "Status",
options:
- referralsCountByStatus?.map(({ status, _count }) => {
- const badge = ReferralStatusBadges[status];
+ countByStatus?.map(({ status, _count }) => {
+ const badge = SubmittedLeadStatusBadges[status];
const Icon = badge.icon;
return {
@@ -101,7 +101,7 @@ export default function PartnerCustomersReferralsPage() {
},
},
],
- [referralsCountByStatus],
+ [countByStatus],
);
const activeFilters = useMemo(() => {
@@ -134,19 +134,19 @@ export default function PartnerCustomersReferralsPage() {
header: "Lead",
enableHiding: false,
minSize: 250,
- cell: ({ row }: { row: Row<PartnerProfileReferral> }) => {
- const referral = row.original;
- const companyLogoUrl = getCompanyLogoUrl(referral.email);
+ cell: ({ row }: { row: Row<PartnerProfileSubmittedLead> }) => {
+ const lead = row.original;
+ const companyLogoUrl = getCompanyLogoUrl(lead.email);
return (
<div className="flex items-center gap-2 truncate">
<img
- alt={referral.email}
- src={companyLogoUrl || `${OG_AVATAR_URL}${referral.id}`}
+ alt={lead.email}
+ src={companyLogoUrl || `${OG_AVATAR_URL}${lead.id}`}
className="size-5 shrink-0 rounded-full border border-neutral-200"
/>
- <span className="truncate" title={referral.email}>
- {referral.email}
+ <span className="truncate" title={lead.email}>
+ {lead.email}
</span>
</div>
);
@@ -157,7 +157,7 @@ export default function PartnerCustomersReferralsPage() {
header: "Name",
accessorKey: "name",
minSize: 150,
- cell: ({ row }: { row: Row<PartnerProfileReferral> }) => {
+ cell: ({ row }: { row: Row<PartnerProfileSubmittedLead> }) => {
return (
<span className="min-w-0 truncate" title={row.original.name}>
{row.original.name}
@@ -170,7 +170,7 @@ export default function PartnerCustomersReferralsPage() {
header: "Company",
accessorKey: "company",
minSize: 150,
- cell: ({ row }: { row: Row<PartnerProfileReferral> }) => {
+ cell: ({ row }: { row: Row<PartnerProfileSubmittedLead> }) => {
return (
<span className="min-w-0 truncate" title={row.original.company}>
{row.original.company}
@@ -181,7 +181,7 @@ export default function PartnerCustomersReferralsPage() {
{
id: "submitted",
header: "Submitted",
- cell: ({ row }: { row: Row<PartnerProfileReferral> }) => (
+ cell: ({ row }: { row: Row<PartnerProfileSubmittedLead> }) => (
<TimestampTooltip
timestamp={row.original.createdAt}
rows={["local"]}
@@ -198,9 +198,9 @@ export default function PartnerCustomersReferralsPage() {
id: "status",
header: "Status",
accessorKey: "status",
- cell: ({ row }: { row: Row<PartnerProfileReferral> }) => {
+ cell: ({ row }: { row: Row<PartnerProfileSubmittedLead> }) => {
const status = row.original.status;
- const badge = ReferralStatusBadges[status];
+ const badge = SubmittedLeadStatusBadges[status];
return (
<StatusBadge
@@ -213,12 +213,12 @@ export default function PartnerCustomersReferralsPage() {
);
},
},
- ].filter((c) => referralsColumns.all.includes(c.id)),
+ ].filter((c) => leadsColumns.all.includes(c.id)),
[],
);
const { table, ...tableProps } = useTable({
- data: referrals || [],
+ data: leads || [],
columns,
pagination,
onPaginationChange: setPagination,
@@ -226,91 +226,89 @@ export default function PartnerCustomersReferralsPage() {
onColumnVisibilityChange: setColumnVisibility,
thClassName: "border-l-0",
tdClassName: "border-l-0",
- resourceName: (p) => `referral${p ? "s" : ""}`,
- rowCount: totalReferralsCount || 0,
+ resourceName: (p) => `lead${p ? "s" : ""}`,
+ rowCount: totalCount || 0,
loading: isLoading,
- error: error || countError ? "Failed to load referrals" : undefined,
+ error: error || countError ? "Failed to load submitted leads" : undefined,
onRowClick: (row) => {
queryParams({
- set: { referralId: row.original.id },
+ set: { leadId: row.original.id },
scroll: false,
});
setDetailsSheetState({
- referralId: row.original.id,
+ leadId: row.original.id,
open: true,
});
},
});
- const currentReferral = useMemo(() => {
- if (!referrals || !detailsSheetState.referralId) return null;
- return referrals.find((r) => r.id === detailsSheetState.referralId) || null;
- }, [referrals, detailsSheetState.referralId]);
+ const currentLead = useMemo(() => {
+ if (!leads || !detailsSheetState.leadId) return null;
+ return leads.find((l) => l.id === detailsSheetState.leadId) || null;
+ }, [leads, detailsSheetState.leadId]);
- const [previousReferralId, nextReferralId] = useMemo(() => {
- if (!referrals || !detailsSheetState.referralId) return [null, null];
+ const [previousLeadId, nextLeadId] = useMemo(() => {
+ if (!leads || !detailsSheetState.leadId) return [null, null];
- const currentIndex = referrals.findIndex(
- ({ id }) => id === detailsSheetState.referralId,
+ const currentIndex = leads.findIndex(
+ ({ id }) => id === detailsSheetState.leadId,
);
if (currentIndex === -1) return [null, null];
return [
- currentIndex > 0 ? referrals[currentIndex - 1].id : null,
- currentIndex < referrals.length - 1
- ? referrals[currentIndex + 1].id
- : null,
+ currentIndex > 0 ? leads[currentIndex - 1].id : null,
+ currentIndex < leads.length - 1 ? leads[currentIndex + 1].id : null,
];
- }, [referrals, detailsSheetState.referralId]);
+ }, [leads, detailsSheetState.leadId]);
// Sync state with URL params
useEffect(() => {
- const urlReferralId = searchParams.get("referralId");
- if (urlReferralId && urlReferralId !== detailsSheetState.referralId) {
+ const urlLeadId = searchParams.get("leadId");
+ if (urlLeadId && urlLeadId !== detailsSheetState.leadId) {
setDetailsSheetState({
- referralId: urlReferralId,
+ leadId: urlLeadId,
open: true,
});
- } else if (!urlReferralId && detailsSheetState.referralId) {
+ } else if (!urlLeadId && detailsSheetState.leadId) {
setDetailsSheetState({
- referralId: null,
+ leadId: null,
open: false,
});
}
- }, [searchParams, detailsSheetState.referralId]);
+ }, [searchParams, detailsSheetState.leadId]);
return (
<div className="flex flex-col gap-3">
- {detailsSheetState.referralId && currentReferral && (
- <PartnerProfileReferralSheet
+ {detailsSheetState.leadId && currentLead && (
+ <PartnerProfileSubmittedLeadSheet
isOpen={detailsSheetState.open}
setIsOpen={(open) =>
setDetailsSheetState((s) => ({ ...s, open }) as any)
}
- referral={currentReferral}
+ lead={currentLead}
onPrevious={
- previousReferralId
+ previousLeadId
? () => {
queryParams({
- set: { referralId: previousReferralId },
+ set: { leadId: previousLeadId },
scroll: false,
});
setDetailsSheetState({
- referralId: previousReferralId,
+ leadId: previousLeadId,
open: true,
});
}
: undefined
}
onNext={
- nextReferralId
+ nextLeadId
? () => {
queryParams({
- set: { referralId: nextReferralId },
+ set: { leadId: nextLeadId },
scroll: false,
});
setDetailsSheetState({
- referralId: nextReferralId,
+ leadId: nextLeadId,
open: true,
});
}
@@ -348,10 +346,10 @@ export default function PartnerCustomersReferralsPage() {
</div>
</AnimatedSizeContainer>
</div>
- {referrals && referrals.length !== 0 ? (
+ {leads && leads.length !== 0 ? (
<Table {...tableProps} table={table} />
) : !isLoading ? (
- <PartnerProfileReferralsEmptyState />
+ <PartnerProfileSubmittedLeadsEmptyState />
) : null}
</div>
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-menu-popover.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-menu-popover.tsx
index 403514daf4..9a206eda83 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-menu-popover.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-menu-popover.tsx
@@ -2,13 +2,7 @@
import { useExportCommissionsModal } from "@/ui/modals/export-commissions-modal";
import { ThreeDots } from "@/ui/shared/icons";
-import {
- Button,
- Download,
- IconMenu,
- Popover,
- Refresh2,
-} from "@dub/ui";
+import { Button, Download, IconMenu, Popover, Refresh2 } from "@dub/ui";
import { useState } from "react";
import { useCreateClawbackSheet } from "./create-clawback-sheet";
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/layout.tsx
index 8cd8b21dac..1867125737 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/layout.tsx
@@ -1,8 +1,8 @@
"use client";
-import { REFERRAL_ENABLED_PROGRAM_IDS } from "@/lib/referrals/constants";
+import { SUBMITTED_LEADS_ENABLED_PROGRAM_IDS } from "@/lib/submitted-leads/constants";
import useCustomersCount from "@/lib/swr/use-customers-count";
-import { useProgramReferralsCount } from "@/lib/swr/use-program-referrals-count";
+import { useProgramSubmittedLeadsCount } from "@/lib/swr/use-program-submitted-leads-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { ExportCustomersButton } from "@/ui/customers/export-customers-button";
import { PageContent } from "@/ui/layout/page-content";
@@ -26,10 +26,10 @@ export default function PartnerCustomersLayout({
});
const isReferralEnabled = defaultProgramId
- ? REFERRAL_ENABLED_PROGRAM_IDS.includes(defaultProgramId)
+ ? SUBMITTED_LEADS_ENABLED_PROGRAM_IDS.includes(defaultProgramId)
: false;
- const { data: referralsCount } = useProgramReferralsCount<number>({
+ const { data: leadsCount } = useProgramSubmittedLeadsCount<number>({
ignoreParams: true,
enabled: isReferralEnabled,
});
@@ -48,14 +48,14 @@ export default function PartnerCustomersLayout({
count: customersCount,
},
{
- label: "Partner Referrals",
- id: "invited",
- href: "referrals",
- info: "Shows your partners' submitted referrals.",
- count: referralsCount,
+ label: "Leads",
+ id: "leads",
+ href: "leads",
+ info: "Shows your partners' submitted leads.",
+ count: leadsCount,
},
];
- }, [isReferralEnabled, customersCount, referralsCount]);
+ }, [isReferralEnabled, customersCount, leadsCount]);
return (
<PageContent
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/leads/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/leads/page.tsx
new file mode 100644
index 0000000000..fd39273f9a
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/leads/page.tsx
@@ -0,0 +1,7 @@
+"use client";
+
+import { SubmittedLeadTable } from "@/ui/submitted-leads/submitted-lead-table";
+
+export default function SubmittedLeadsPage() {
+ return <SubmittedLeadTable />;
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/referrals/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/referrals/page.tsx
deleted file mode 100644
index 16f11b406c..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/referrals/page.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-"use client";
-
-import { PartnerReferralTable } from "@/ui/referrals/partner-referral-table";
-
-export default function PartnerCustomersReferralsPage() {
- return <PartnerReferralTable />;
-}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx
index 8f4efcc0d1..99c182516f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx
@@ -17,7 +17,8 @@ export const GroupDiscounts = () => {
const { searchParams } = useRouterStuff();
const [discountSheetState, setDiscountSheetState] = useState<
- { open: false; discountId: string | null } | { open: true; discountId: string }
+ | { open: false; discountId: string | null }
+ | { open: true; discountId: string }
>({ open: false, discountId: null });
useEffect(() => {
@@ -46,7 +47,9 @@ export const GroupDiscounts = () => {
return (
<div>
- {discountSheetState.discountId && (currentDiscount || isNewDiscount) && DiscountSheet}
+ {discountSheetState.discountId &&
+ (currentDiscount || isNewDiscount) &&
+ DiscountSheet}
{loading || !group ? (
<DiscountSkeleton />
@@ -70,7 +73,11 @@ const DiscountItem = ({
return (
<As
- href={discount ? `/${slug}/program/groups/${group.slug}/discounts?discountId=${discount.id}` : ""}
+ href={
+ discount
+ ? `/${slug}/program/groups/${group.slug}/discounts?discountId=${discount.id}`
+ : ""
+ }
scroll={false}
className={cn(
"flex cursor-pointer flex-col gap-4 rounded-lg p-6 transition-all md:flex-row md:items-center",
diff --git a/apps/web/lib/actions/partners/update-program.ts b/apps/web/lib/actions/partners/update-program.ts
index b6a67b7b21..b898597ccc 100644
--- a/apps/web/lib/actions/partners/update-program.ts
+++ b/apps/web/lib/actions/partners/update-program.ts
@@ -3,7 +3,7 @@
import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
-import { referralFormSchema } from "@/lib/zod/schemas/referral-form";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { prisma } from "@dub/prisma";
import { waitUntil } from "@vercel/functions";
import { revalidatePath } from "next/cache";
@@ -16,7 +16,7 @@ import { throwIfNoPermission } from "../throw-if-no-permission";
const schema = updateProgramSchema.partial().extend({
workspaceId: z.string(),
applyHoldingPeriodDaysToAllGroups: z.boolean().optional(),
- referralFormData: referralFormSchema.optional(),
+ referralFormData: submittedLeadFormSchema.optional(),
});
export const updateProgramAction = authActionClient
diff --git a/apps/web/lib/actions/referrals/update-referral-status.ts b/apps/web/lib/actions/referrals/update-referral-status.ts
deleted file mode 100644
index 3741d3d83f..0000000000
--- a/apps/web/lib/actions/referrals/update-referral-status.ts
+++ /dev/null
@@ -1,121 +0,0 @@
-"use server";
-
-import { trackActivityLog } from "@/lib/api/activity-log/track-activity-log";
-import { DubApiError } from "@/lib/api/errors";
-import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
-import { getReferralOrThrow } from "@/lib/api/referrals/get-referral-or-throw";
-import { markReferralClosedWon } from "@/lib/api/referrals/mark-referral-closed-won";
-import { markReferralQualified } from "@/lib/api/referrals/mark-referral-qualified";
-import { notifyReferralStatusUpdate } from "@/lib/api/referrals/notify-referral-status-update";
-import {
- REFERRAL_STATUS_TO_ACTIVITY_ACTION,
- REFERRAL_STATUS_TRANSITIONS,
-} from "@/lib/referrals/constants";
-import { ReferralWithCustomer } from "@/lib/types";
-import { updateReferralStatusSchema } from "@/lib/zod/schemas/referrals";
-import { prisma } from "@dub/prisma";
-import { ReferralStatus } from "@dub/prisma/client";
-import { waitUntil } from "@vercel/functions";
-import { authActionClient } from "../safe-action";
-import { throwIfNoPermission } from "../throw-if-no-permission";
-
-export const updateReferralStatusAction = authActionClient
- .inputSchema(updateReferralStatusSchema)
- .action(async ({ parsedInput, ctx }) => {
- const { workspace, user } = ctx;
- const { referralId, status, notes } = parsedInput;
-
- const programId = getDefaultProgramIdOrThrow(workspace);
-
- throwIfNoPermission({
- role: workspace.role,
- requiredRoles: ["owner", "member"],
- });
-
- let referral = await getReferralOrThrow({
- referralId,
- programId,
- });
-
- if (!REFERRAL_STATUS_TRANSITIONS[referral.status].includes(status)) {
- throw new DubApiError({
- code: "bad_request",
- message: `Cannot transition from ${referral.status} to ${status}.`,
- });
- }
-
- if (referral.status === status) {
- throw new DubApiError({
- code: "bad_request",
- message: "Referral is already in this status.",
- });
- }
-
- if (status === ReferralStatus.closedWon && !referral.customer) {
- throw new DubApiError({
- code: "bad_request",
- message: "This referral does not have a customer associated with it.",
- });
- }
-
- const updatedReferral = await prisma.partnerReferral.update({
- where: {
- id: referral.id,
- status: referral.status,
- },
- data: {
- status,
- },
- include: {
- customer: true,
- },
- });
-
- waitUntil(
- (async () => {
- await Promise.allSettled([
- notifyReferralStatusUpdate({
- referral,
- notes,
- }),
-
- trackActivityLog({
- workspaceId: workspace.id,
- programId,
- resourceType: "referral",
- resourceId: referral.id,
- userId: user.id,
- action: REFERRAL_STATUS_TO_ACTIVITY_ACTION[status],
- description: notes,
- changeSet: {
- status: {
- old: referral.status,
- new: updatedReferral.status,
- },
- },
- }),
-
- ...(status === ReferralStatus.qualified
- ? [
- markReferralQualified({
- workspace,
- referral: updatedReferral,
- externalId: parsedInput.externalId ?? null,
- }),
- ]
- : []),
-
- ...(status === ReferralStatus.closedWon
- ? [
- markReferralClosedWon({
- workspace,
- referral: updatedReferral as ReferralWithCustomer,
- saleAmount: parsedInput.saleAmount,
- stripeCustomerId: parsedInput.stripeCustomerId ?? null,
- }),
- ]
- : []),
- ]);
- })(),
- );
- });
diff --git a/apps/web/lib/api/activity-log/track-activity-log.ts b/apps/web/lib/api/activity-log/track-activity-log.ts
index af0da626c8..0e90db17e4 100644
--- a/apps/web/lib/api/activity-log/track-activity-log.ts
+++ b/apps/web/lib/api/activity-log/track-activity-log.ts
@@ -9,7 +9,7 @@ import { Prisma } from "@dub/prisma/client";
import { prettyPrint } from "@dub/utils";
const ACTIONS_WITHOUT_CHANGE_SET: ActivityLogAction[] = [
- "referral.created",
+ "submittedLead.created",
"reward.created",
"reward.deleted",
];
diff --git a/apps/web/lib/api/audit-logs/schemas.ts b/apps/web/lib/api/audit-logs/schemas.ts
index 9d582b820f..4716ae2cd8 100644
--- a/apps/web/lib/api/audit-logs/schemas.ts
+++ b/apps/web/lib/api/audit-logs/schemas.ts
@@ -8,8 +8,8 @@ import { GroupSchema } from "@/lib/zod/schemas/groups";
import { PartnerSchema } from "@/lib/zod/schemas/partners";
import { PayoutSchema } from "@/lib/zod/schemas/payouts";
import { ProgramSchema } from "@/lib/zod/schemas/programs";
-import { referralSchema } from "@/lib/zod/schemas/referrals";
import { RewardSchema } from "@/lib/zod/schemas/rewards";
+import { submittedLeadSchema } from "@/lib/zod/schemas/submitted-leads";
import * as z from "zod/v4";
// Schema that represents the audit log schema in Tinybird
@@ -194,7 +194,7 @@ export const auditLogTarget = z.union([
z.object({
type: z.literal("partner_referral"),
id: z.string(),
- metadata: referralSchema.pick({
+ metadata: submittedLeadSchema.pick({
email: true,
name: true,
company: true,
diff --git a/apps/web/lib/api/create-id.ts b/apps/web/lib/api/create-id.ts
index d233b23840..e10a8cb281 100644
--- a/apps/web/lib/api/create-id.ts
+++ b/apps/web/lib/api/create-id.ts
@@ -43,7 +43,7 @@ const prefixes = [
"fr_", // fraud rule
"fre_", // fraud event
"frg_", // fraud event group
- "ref_", // referral
+ "sbl_", // submitted lead
"pb_", // partner postback
"req_", // api request log
] as const;
diff --git a/apps/web/lib/api/programs/get-default-program-id-or-throw.ts b/apps/web/lib/api/programs/get-default-program-id-or-throw.ts
index 7434b46af7..4e0111eece 100644
--- a/apps/web/lib/api/programs/get-default-program-id-or-throw.ts
+++ b/apps/web/lib/api/programs/get-default-program-id-or-throw.ts
@@ -1,12 +1,11 @@
-import { DubApiError } from "../errors";
import { WorkspaceWithUsers } from "@/lib/types";
+import { DubApiError } from "../errors";
export const getDefaultProgramIdOrThrow = (
workspace: WorkspaceWithUsers | { defaultProgramId?: string | null },
) => {
- const programId = (
- workspace as { defaultProgramId?: string | null }
- ).defaultProgramId;
+ const programId = (workspace as { defaultProgramId?: string | null })
+ .defaultProgramId;
if (!programId) {
throw new DubApiError({
diff --git a/apps/web/lib/api/referrals/get-referral-or-throw.ts b/apps/web/lib/api/referrals/get-referral-or-throw.ts
deleted file mode 100644
index f41272cccb..0000000000
--- a/apps/web/lib/api/referrals/get-referral-or-throw.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { prisma } from "@dub/prisma";
-import { DubApiError } from "../errors";
-
-interface GetReferralOrThrowParams {
- referralId: string;
- programId: string;
-}
-
-export const getReferralOrThrow = async ({
- referralId,
- programId,
-}: GetReferralOrThrowParams) => {
- const referral = await prisma.partnerReferral.findUnique({
- where: {
- id: referralId,
- },
- include: {
- customer: true,
- },
- });
-
- if (!referral) {
- throw new DubApiError({
- code: "not_found",
- message: "Partner referral not found.",
- });
- }
-
- if (referral.programId !== programId) {
- throw new DubApiError({
- code: "forbidden",
- message: "You don't have access to this partner referral.",
- });
- }
-
- return referral;
-};
diff --git a/apps/web/lib/firstpromoter/importer.ts b/apps/web/lib/firstpromoter/importer.ts
index b6920bc8dd..fff08bdf07 100644
--- a/apps/web/lib/firstpromoter/importer.ts
+++ b/apps/web/lib/firstpromoter/importer.ts
@@ -31,10 +31,7 @@ class FirstPromoterImporter {
return await redis.del(`${CACHE_KEY_PREFIX}:${workspaceId}`);
}
- async queue(
- body: FirstPromoterImportPayload,
- options?: { delay?: number },
- ) {
+ async queue(body: FirstPromoterImportPayload, options?: { delay?: number }) {
return await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/firstpromoter`,
body,
diff --git a/apps/web/lib/planetscale/get-partner-enrollment-info.ts b/apps/web/lib/planetscale/get-partner-enrollment-info.ts
index 496f99b9d5..4cd3e6d5d9 100644
--- a/apps/web/lib/planetscale/get-partner-enrollment-info.ts
+++ b/apps/web/lib/planetscale/get-partner-enrollment-info.ts
@@ -16,9 +16,7 @@ interface QueryResult {
partnerTagIds: string | string[] | null;
}
-function parsePartnerTagIds(
- value: QueryResult["partnerTagIds"],
-): string[] {
+function parsePartnerTagIds(value: QueryResult["partnerTagIds"]): string[] {
if (value == null) return [];
if (Array.isArray(value)) {
return value.filter(
diff --git a/apps/web/lib/referrals/constants.ts b/apps/web/lib/referrals/constants.ts
deleted file mode 100644
index 0653986bfe..0000000000
--- a/apps/web/lib/referrals/constants.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-import { ActivityLogAction } from "@/lib/types";
-import { textFieldSchema } from "@/lib/zod/schemas/referral-form";
-import { ReferralStatus } from "@dub/prisma/client";
-import { ACME_PROGRAM_ID } from "@dub/utils";
-import * as z from "zod/v4";
-
-// Required fields configuration for referral forms
-export const REFERRAL_FORM_REQUIRED_FIELDS: z.infer<typeof textFieldSchema>[] =
- [
- {
- key: "name",
- label: "Name",
- type: "text",
- required: true,
- locked: true,
- position: -3,
- },
- {
- key: "email",
- label: "Email",
- type: "text",
- required: true,
- locked: true,
- position: -2,
- },
- {
- key: "company",
- label: "Company",
- type: "text",
- required: true,
- locked: true,
- position: -1,
- },
- ];
-
-// Set of required field keys for quick lookup (derived from REQUIRED_FIELDS)
-export const REFERRAL_FORM_REQUIRED_FIELD_KEYS = new Set(
- REFERRAL_FORM_REQUIRED_FIELDS.map((field) => field.key),
-);
-
-// Input props map for required fields
-export const REFERRAL_FORM_FIELD_INPUT_PROPS: Record<
- string,
- React.InputHTMLAttributes<HTMLInputElement>
-> = {
- email: { type: "email", autoComplete: "email" },
- name: { autoComplete: "name" },
- company: { autoComplete: "organization" },
-};
-
-export const REFERRAL_ENABLED_PROGRAM_IDS = [
- ACME_PROGRAM_ID, // Acme
- "prog_1K7Y2RGFC4BKZQQZAZEEK9MVE", // SelectCode
- "prog_1KFZQJZRDRV62C037FQZSY0Y8", // FFG
- "prog_1K57RA7GVBT9V3S7HRWSV4ADA", // Truss
- "prog_1KH1SFVYG79SV5JQJQRDJH56V", // Brightwave
-];
-
-export const REFERRAL_STATUS_TO_ACTIVITY_ACTION: Record<
- ReferralStatus,
- ActivityLogAction
-> = {
- [ReferralStatus.pending]: "referral.created",
- [ReferralStatus.qualified]: "referral.qualified",
- [ReferralStatus.meeting]: "referral.meeting",
- [ReferralStatus.negotiation]: "referral.negotiation",
- [ReferralStatus.unqualified]: "referral.unqualified",
- [ReferralStatus.closedWon]: "referral.closedWon",
- [ReferralStatus.closedLost]: "referral.closedLost",
-};
-
-export const REFERRAL_STATUS_TRANSITIONS: Record<
- ReferralStatus,
- readonly ReferralStatus[]
-> = {
- pending: ["qualified", "meeting", "closedLost", "unqualified"],
- qualified: [
- "meeting",
- "negotiation",
- "closedWon",
- "closedLost",
- "unqualified",
- ],
- meeting: [
- "negotiation",
- "qualified",
- "closedWon",
- "closedLost",
- "unqualified",
- ],
- negotiation: [
- "closedWon",
- "qualified",
- "meeting",
- "closedLost",
- "unqualified",
- ],
- closedWon: [],
- closedLost: [],
- unqualified: [],
-};
diff --git a/apps/web/lib/rewardful/importer.ts b/apps/web/lib/rewardful/importer.ts
index 0e776fe6fa..16a1f33dee 100644
--- a/apps/web/lib/rewardful/importer.ts
+++ b/apps/web/lib/rewardful/importer.ts
@@ -34,10 +34,7 @@ class RewardfulImporter {
return await redis.del(`${CACHE_KEY_PREFIX}:${workspaceId}`);
}
- async queue(
- body: RewardfulImportPayload,
- options?: { delay?: number },
- ) {
+ async queue(body: RewardfulImportPayload, options?: { delay?: number }) {
return await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/rewardful`,
body,
diff --git a/apps/web/lib/submitted-leads/constants.ts b/apps/web/lib/submitted-leads/constants.ts
new file mode 100644
index 0000000000..cbef4c6ffc
--- /dev/null
+++ b/apps/web/lib/submitted-leads/constants.ts
@@ -0,0 +1,100 @@
+import { ActivityLogAction } from "@/lib/types";
+import { textFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
+import { ACME_PROGRAM_ID } from "@dub/utils";
+import * as z from "zod/v4";
+
+export const SUBMITTED_LEAD_FORM_REQUIRED_FIELDS: z.infer<
+ typeof textFieldSchema
+>[] = [
+ {
+ key: "name",
+ label: "Name",
+ type: "text",
+ required: true,
+ locked: true,
+ position: -3,
+ },
+ {
+ key: "email",
+ label: "Email",
+ type: "text",
+ required: true,
+ locked: true,
+ position: -2,
+ },
+ {
+ key: "company",
+ label: "Company",
+ type: "text",
+ required: true,
+ locked: true,
+ position: -1,
+ },
+];
+
+export const SUBMITTED_LEAD_FORM_REQUIRED_FIELD_KEYS = new Set(
+ SUBMITTED_LEAD_FORM_REQUIRED_FIELDS.map((field) => field.key),
+);
+
+export const SUBMITTED_LEAD_FORM_FIELD_INPUT_PROPS: Record<
+ string,
+ React.InputHTMLAttributes<HTMLInputElement>
+> = {
+ email: { type: "email", autoComplete: "email" },
+ name: { autoComplete: "name" },
+ company: { autoComplete: "organization" },
+};
+
+export const SUBMITTED_LEADS_ENABLED_PROGRAM_IDS = [
+ "prog_1K2J9DRWPPJ2F1RX53N92TSGA", // Remove this
+ ACME_PROGRAM_ID, // Acme
+ "prog_1K7Y2RGFC4BKZQQZAZEEK9MVE", // SelectCode
+ "prog_1KFZQJZRDRV62C037FQZSY0Y8", // FFG
+ "prog_1K57RA7GVBT9V3S7HRWSV4ADA", // Truss
+ "prog_1KH1SFVYG79SV5JQJQRDJH56V", // Brightwave
+];
+
+export const SUBMITTED_LEAD_STATUS_TO_ACTIVITY_ACTION: Record<
+ SubmittedLeadStatus,
+ ActivityLogAction
+> = {
+ [SubmittedLeadStatus.pending]: "submittedLead.created",
+ [SubmittedLeadStatus.qualified]: "submittedLead.qualified",
+ [SubmittedLeadStatus.meeting]: "submittedLead.meeting",
+ [SubmittedLeadStatus.negotiation]: "submittedLead.negotiation",
+ [SubmittedLeadStatus.unqualified]: "submittedLead.unqualified",
+ [SubmittedLeadStatus.closedWon]: "submittedLead.closedWon",
+ [SubmittedLeadStatus.closedLost]: "submittedLead.closedLost",
+};
+
+export const SUBMITTED_LEAD_STATUS_TRANSITIONS: Record<
+ SubmittedLeadStatus,
+ readonly SubmittedLeadStatus[]
+> = {
+ pending: ["qualified", "meeting", "closedLost", "unqualified"],
+ qualified: [
+ "meeting",
+ "negotiation",
+ "closedWon",
+ "closedLost",
+ "unqualified",
+ ],
+ meeting: [
+ "negotiation",
+ "qualified",
+ "closedWon",
+ "closedLost",
+ "unqualified",
+ ],
+ negotiation: [
+ "closedWon",
+ "qualified",
+ "meeting",
+ "closedLost",
+ "unqualified",
+ ],
+ closedWon: [],
+ closedLost: [],
+ unqualified: [],
+};
diff --git a/apps/web/lib/submitted-leads/get-submitted-lead-or-throw.ts b/apps/web/lib/submitted-leads/get-submitted-lead-or-throw.ts
new file mode 100644
index 0000000000..2907007726
--- /dev/null
+++ b/apps/web/lib/submitted-leads/get-submitted-lead-or-throw.ts
@@ -0,0 +1,37 @@
+import { prisma } from "@dub/prisma";
+import { DubApiError } from "../api/errors";
+
+interface GetSubmittedLeadOrThrowParams {
+ leadId: string;
+ programId: string;
+}
+
+export const getSubmittedLeadOrThrow = async ({
+ leadId,
+ programId,
+}: GetSubmittedLeadOrThrowParams) => {
+ const lead = await prisma.submittedLead.findUnique({
+ where: {
+ id: leadId,
+ },
+ include: {
+ customer: true,
+ },
+ });
+
+ if (!lead) {
+ throw new DubApiError({
+ code: "not_found",
+ message: "Submitted lead not found.",
+ });
+ }
+
+ if (lead.programId !== programId) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "You don't have access to this submitted lead.",
+ });
+ }
+
+ return lead;
+};
diff --git a/apps/web/lib/api/referrals/mark-referral-closed-won.ts b/apps/web/lib/submitted-leads/mark-submitted-lead-closed-won.ts
similarity index 63%
rename from apps/web/lib/api/referrals/mark-referral-closed-won.ts
rename to apps/web/lib/submitted-leads/mark-submitted-lead-closed-won.ts
index 81411d1cac..4be252ccbe 100644
--- a/apps/web/lib/api/referrals/mark-referral-closed-won.ts
+++ b/apps/web/lib/submitted-leads/mark-submitted-lead-closed-won.ts
@@ -2,33 +2,33 @@
import { trackSale } from "@/lib/api/conversions/track-sale";
import { DubApiError } from "@/lib/api/errors";
-import { ReferralWithCustomer } from "@/lib/types";
+import { SubmittedLeadWithCustomer } from "@/lib/types";
import { prisma } from "@dub/prisma";
import { Project } from "@dub/prisma/client";
-interface MarkReferralClosedWonInput {
+interface MarkSubmittedLeadClosedWonInput {
workspace: Pick<Project, "id" | "stripeConnectId" | "webhookEnabled">;
- referral: ReferralWithCustomer;
+ lead: SubmittedLeadWithCustomer;
saleAmount: number;
stripeCustomerId: string | null;
}
-// Mark a partner referral as closed won
-export const markReferralClosedWon = async ({
+// Mark a submitted lead as closed won
+export const markSubmittedLeadClosedWon = async ({
workspace,
- referral,
+ lead,
saleAmount,
stripeCustomerId,
-}: MarkReferralClosedWonInput) => {
- if (!referral.customer) {
+}: MarkSubmittedLeadClosedWonInput) => {
+ if (!lead.customer) {
throw new DubApiError({
code: "bad_request",
- message: "This referral does not have a customer associated with it.",
+ message: "This lead does not have a customer associated with it.",
});
}
await trackSale({
- customerExternalId: referral.customer.externalId,
+ customerExternalId: lead.customer.externalId,
amount: saleAmount,
eventName: "Closed Won",
paymentProcessor: "custom",
@@ -41,7 +41,7 @@ export const markReferralClosedWon = async ({
if (stripeCustomerId) {
await prisma.customer.update({
where: {
- id: referral.customerId!,
+ id: lead.customerId!,
},
data: {
stripeCustomerId,
diff --git a/apps/web/lib/api/referrals/mark-referral-qualified.ts b/apps/web/lib/submitted-leads/mark-submitted-lead-qualified.ts
similarity index 70%
rename from apps/web/lib/api/referrals/mark-referral-qualified.ts
rename to apps/web/lib/submitted-leads/mark-submitted-lead-qualified.ts
index 9e1c74e164..87996d0a85 100644
--- a/apps/web/lib/api/referrals/mark-referral-qualified.ts
+++ b/apps/web/lib/submitted-leads/mark-submitted-lead-qualified.ts
@@ -3,26 +3,26 @@
import { trackLead } from "@/lib/api/conversions/track-lead";
import { recordFakeClick } from "@/lib/tinybird/record-fake-click";
import { prisma } from "@dub/prisma";
-import { PartnerReferral, Project } from "@dub/prisma/client";
+import { Project, SubmittedLead } from "@dub/prisma/client";
import { pick } from "@dub/utils";
-interface MarkReferralQualifiedInput {
+interface MarkSubmittedLeadQualifiedInput {
workspace: Pick<Project, "id" | "stripeConnectId" | "webhookEnabled">;
- referral: PartnerReferral;
+ lead: SubmittedLead;
externalId: string | null;
}
-// Mark a partner referral as qualified
-export const markReferralQualified = async ({
+// Mark a submitted lead as qualified
+export const markSubmittedLeadQualified = async ({
workspace,
- referral,
+ lead,
externalId,
-}: MarkReferralQualifiedInput) => {
+}: MarkSubmittedLeadQualifiedInput) => {
// Find the default link for the partner
const links = await prisma.link.findMany({
where: {
- programId: referral.programId,
- partnerId: referral.partnerId,
+ programId: lead.programId,
+ partnerId: lead.partnerId,
},
orderBy: {
partnerGroupDefaultLinkId: "asc",
@@ -35,7 +35,7 @@ export const markReferralQualified = async ({
if (links.length === 0) {
console.error(
- `[markReferralQualified] No links found for partner ${referral.partnerId} in program ${referral.programId}`,
+ `[markSubmittedLeadQualified] No links found for partner ${lead.partnerId} in program ${lead.programId}`,
);
return;
}
@@ -56,9 +56,9 @@ export const markReferralQualified = async ({
const trackedLead = await trackLead({
clickId: clickEvent.click_id,
eventName: "Qualified Lead",
- customerExternalId: externalId || referral.email,
- customerName: referral.name,
- customerEmail: referral.email,
+ customerExternalId: externalId || lead.email,
+ customerName: lead.name,
+ customerEmail: lead.email,
mode: "wait",
workspace: pick(workspace, ["id", "stripeConnectId", "webhookEnabled"]),
source: "submitted",
@@ -73,9 +73,9 @@ export const markReferralQualified = async ({
},
});
- await prisma.partnerReferral.update({
+ await prisma.submittedLead.update({
where: {
- id: referral.id,
+ id: lead.id,
},
data: {
customerId: customer.id,
diff --git a/apps/web/lib/api/referrals/notify-partner-referral-submitted.ts b/apps/web/lib/submitted-leads/notify-partner-lead-submitted.ts
similarity index 60%
rename from apps/web/lib/api/referrals/notify-partner-referral-submitted.ts
rename to apps/web/lib/submitted-leads/notify-partner-lead-submitted.ts
index 35fc2c6ce5..efcda4f211 100644
--- a/apps/web/lib/api/referrals/notify-partner-referral-submitted.ts
+++ b/apps/web/lib/submitted-leads/notify-partner-lead-submitted.ts
@@ -1,18 +1,15 @@
-import { getCompanyLogoUrl } from "@/ui/referrals/referral-utils";
+import { getCompanyLogoUrl } from "@/ui/submitted-leads/submitted-lead-utils";
import { sendBatchEmail } from "@dub/email";
-import PartnerReferralSubmitted from "@dub/email/templates/partner-referral-submitted";
+import NewLeadSubmitted from "@dub/email/templates/new-lead-submitted";
import { prisma } from "@dub/prisma";
-import { Partner, PartnerReferral, Program } from "@dub/prisma/client";
+import { Partner, Program, SubmittedLead } from "@dub/prisma/client";
-export async function notifyPartnerReferralSubmitted({
- referral,
+export async function notifyPartnerLeadSubmitted({
+ lead,
program,
partner,
}: {
- referral: Pick<
- PartnerReferral,
- "id" | "name" | "email" | "company" | "formData"
- >;
+ lead: Pick<SubmittedLead, "id" | "name" | "email" | "company" | "formData">;
program: Pick<Program, "workspaceId">;
partner: Pick<Partner, "name" | "email" | "image">;
}) {
@@ -45,26 +42,24 @@ export async function notifyPartnerReferralSubmitted({
});
// Parse formData from JSON
- const formData = referral.formData as
- | { label: string; value: unknown }[]
- | null;
+ const formData = lead.formData as { label: string; value: unknown }[] | null;
const emailsRes = await sendBatchEmail(
workspaceUsers.map(({ user, project }) => ({
- subject: "New partner referral submitted",
+ subject: "New partner lead submitted",
variant: "notifications",
to: user.email!,
- react: PartnerReferralSubmitted({
+ react: NewLeadSubmitted({
email: user.email!,
workspace: {
slug: project.slug,
},
- referral: {
- id: referral.id,
- name: referral.name,
- email: referral.email,
- company: referral.company,
- image: getCompanyLogoUrl(referral.email),
+ lead: {
+ id: lead.id,
+ name: lead.name,
+ email: lead.email,
+ company: lead.company,
+ image: getCompanyLogoUrl(lead.email),
formData,
},
partner: {
diff --git a/apps/web/lib/api/referrals/notify-referral-status-update.ts b/apps/web/lib/submitted-leads/notify-submitted-lead-status-update.ts
similarity index 53%
rename from apps/web/lib/api/referrals/notify-referral-status-update.ts
rename to apps/web/lib/submitted-leads/notify-submitted-lead-status-update.ts
index 774979d577..17466c3533 100644
--- a/apps/web/lib/api/referrals/notify-referral-status-update.ts
+++ b/apps/web/lib/submitted-leads/notify-submitted-lead-status-update.ts
@@ -1,21 +1,21 @@
-import { ReferralStatusBadges } from "@/ui/referrals/referral-status-badges";
-import { getCompanyLogoUrl } from "@/ui/referrals/referral-utils";
+import { SubmittedLeadStatusBadges } from "@/ui/submitted-leads/submitted-lead-status-badges";
+import { getCompanyLogoUrl } from "@/ui/submitted-leads/submitted-lead-utils";
import { sendEmail } from "@dub/email";
-import ReferralStatusUpdate from "@dub/email/templates/referral-status-update";
+import LeadStatusUpdated from "@dub/email/templates/lead-status-updated";
import { prisma } from "@dub/prisma";
-import { PartnerReferral } from "@dub/prisma/client";
+import { SubmittedLead } from "@dub/prisma/client";
-export async function notifyReferralStatusUpdate({
- referral,
+export async function notifySubmittedLeadStatusUpdate({
+ lead,
notes,
}: {
- referral: PartnerReferral;
+ lead: SubmittedLead;
notes?: string | null;
}) {
const [program, partner] = await Promise.all([
prisma.program.findUnique({
where: {
- id: referral.programId,
+ id: lead.programId,
},
select: {
name: true,
@@ -25,7 +25,7 @@ export async function notifyReferralStatusUpdate({
prisma.partner.findUnique({
where: {
- id: referral.partnerId,
+ id: lead.partnerId,
},
select: {
name: true,
@@ -36,13 +36,13 @@ export async function notifyReferralStatusUpdate({
if (!program || !partner) return;
- const statusLabel = ReferralStatusBadges[referral.status].label;
+ const statusLabel = SubmittedLeadStatusBadges[lead.status].label;
const emailRes = await sendEmail({
- subject: `Your referral status has been updated to ${statusLabel}`,
+ subject: `Your submitted lead status has been updated to ${statusLabel}`,
variant: "notifications",
to: partner.email!,
- react: ReferralStatusUpdate({
+ react: LeadStatusUpdated({
partner: {
name: partner.name,
email: partner.email!,
@@ -51,11 +51,11 @@ export async function notifyReferralStatusUpdate({
name: program.name,
slug: program.slug,
},
- referral: {
- name: referral.name,
- email: referral.email,
- company: referral.company,
- image: getCompanyLogoUrl(referral.email),
+ lead: {
+ name: lead.name,
+ email: lead.email,
+ company: lead.company,
+ image: getCompanyLogoUrl(lead.email),
status: statusLabel,
},
notes,
diff --git a/apps/web/lib/actions/referrals/submit-referral.ts b/apps/web/lib/submitted-leads/submit-lead-action.ts
similarity index 73%
rename from apps/web/lib/actions/referrals/submit-referral.ts
rename to apps/web/lib/submitted-leads/submit-lead-action.ts
index 1a63e15c7a..04d59281c8 100644
--- a/apps/web/lib/actions/referrals/submit-referral.ts
+++ b/apps/web/lib/submitted-leads/submit-lead-action.ts
@@ -4,21 +4,21 @@ import { trackActivityLog } from "@/lib/api/activity-log/track-activity-log";
import { createId } from "@/lib/api/create-id";
import { DubApiError } from "@/lib/api/errors";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
-import { notifyPartnerReferralSubmitted } from "@/lib/api/referrals/notify-partner-referral-submitted";
-import { REFERRAL_FORM_REQUIRED_FIELD_KEYS } from "@/lib/referrals/constants";
-import { ReferralFormDataField } from "@/lib/types";
+import { SUBMITTED_LEAD_FORM_REQUIRED_FIELD_KEYS } from "@/lib/submitted-leads/constants";
+import { notifyPartnerLeadSubmitted } from "@/lib/submitted-leads/notify-partner-lead-submitted";
+import { SubmittedLeadFormDataField } from "@/lib/types";
import {
formFieldSchema,
- referralFormSchema,
- referralRequiredFieldsSchema,
-} from "@/lib/zod/schemas/referral-form";
-import { createPartnerReferralSchema } from "@/lib/zod/schemas/referrals";
+ submittedLeadFormSchema,
+ submittedLeadRequiredFieldsSchema,
+} from "@/lib/zod/schemas/submitted-lead-form";
+import { submitLeadSchema } from "@/lib/zod/schemas/submitted-leads";
import { prisma } from "@dub/prisma";
import { Prisma } from "@dub/prisma/client";
import { COUNTRIES } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import * as z from "zod/v4";
-import { authPartnerActionClient } from "../safe-action";
+import { authPartnerActionClient } from "../actions/safe-action";
/**
* Converts field values based on field type:
@@ -57,9 +57,9 @@ function convertFieldValue(
}
}
-// Create a partner referral
-export const submitReferralAction = authPartnerActionClient
- .inputSchema(createPartnerReferralSchema)
+// Submit a lead
+export const submitLeadAction = authPartnerActionClient
+ .inputSchema(submitLeadSchema)
.action(async ({ parsedInput, ctx }) => {
const { partner, user } = ctx;
const { programId, formData: rawFormData } = parsedInput;
@@ -75,7 +75,7 @@ export const submitReferralAction = authPartnerActionClient
// Make sure required fields are present
const requiredFieldsResult =
- referralRequiredFieldsSchema.safeParse(rawFormData);
+ submittedLeadRequiredFieldsSchema.safeParse(rawFormData);
if (!requiredFieldsResult.success) {
const firstError = requiredFieldsResult.error.issues[0];
@@ -88,15 +88,17 @@ export const submitReferralAction = authPartnerActionClient
const { name, email, company } = requiredFieldsResult.data;
// Parse custom fields from formData
- const customFormData: ReferralFormDataField[] = [];
+ const customFormData: SubmittedLeadFormDataField[] = [];
// Parse and get form schema fields to extract labels
- const parsedReferralFormData = programEnrollment.program.referralFormData
- ? referralFormSchema.safeParse(programEnrollment.program.referralFormData)
+ const parsedLeadFormData = programEnrollment.program.referralFormData
+ ? submittedLeadFormSchema.safeParse(
+ programEnrollment.program.referralFormData,
+ )
: null;
const formSchemaFields =
- parsedReferralFormData?.success && parsedReferralFormData.data.fields
- ? parsedReferralFormData.data.fields
+ parsedLeadFormData?.success && parsedLeadFormData.data.fields
+ ? parsedLeadFormData.data.fields
: [];
const fieldMap = new Map<string, z.infer<typeof formFieldSchema>>();
@@ -107,7 +109,7 @@ export const submitReferralAction = authPartnerActionClient
// Process all fields in rawFormData except required ones
for (const [key, value] of Object.entries(rawFormData)) {
// Skip required fields
- if (REFERRAL_FORM_REQUIRED_FIELD_KEYS.has(key)) {
+ if (SUBMITTED_LEAD_FORM_REQUIRED_FIELD_KEYS.has(key)) {
continue;
}
@@ -132,9 +134,9 @@ export const submitReferralAction = authPartnerActionClient
});
}
- const referral = await prisma.partnerReferral.create({
+ const submittedLead = await prisma.submittedLead.create({
data: {
- id: createId({ prefix: "ref_" }),
+ id: createId({ prefix: "sbl_" }),
programId,
partnerId: partner.id,
name,
@@ -149,8 +151,8 @@ export const submitReferralAction = authPartnerActionClient
waitUntil(
Promise.allSettled([
- notifyPartnerReferralSubmitted({
- referral,
+ notifyPartnerLeadSubmitted({
+ lead: submittedLead,
program: programEnrollment.program,
partner: programEnrollment.partner,
}),
@@ -158,10 +160,10 @@ export const submitReferralAction = authPartnerActionClient
trackActivityLog({
workspaceId: programEnrollment.program.workspaceId,
programId,
- resourceType: "referral",
- resourceId: referral.id,
+ resourceType: "submittedLead",
+ resourceId: submittedLead.id,
userId: user.id,
- action: "referral.created",
+ action: "submittedLead.created",
}),
]),
);
diff --git a/apps/web/lib/actions/referrals/update-referral.ts b/apps/web/lib/submitted-leads/update-submitted-lead-action.ts
similarity index 57%
rename from apps/web/lib/actions/referrals/update-referral.ts
rename to apps/web/lib/submitted-leads/update-submitted-lead-action.ts
index 24109aebac..a90a0e8d21 100644
--- a/apps/web/lib/actions/referrals/update-referral.ts
+++ b/apps/web/lib/submitted-leads/update-submitted-lead-action.ts
@@ -3,20 +3,20 @@
import { getResourceDiff } from "@/lib/api/activity-log/get-resource-diff";
import { trackActivityLog } from "@/lib/api/activity-log/track-activity-log";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
-import { getReferralOrThrow } from "@/lib/api/referrals/get-referral-or-throw";
-import { updateReferralSchema } from "@/lib/zod/schemas/referrals";
+import { getSubmittedLeadOrThrow } from "@/lib/submitted-leads/get-submitted-lead-or-throw";
+import { updateSubmittedLeadSchema } from "@/lib/zod/schemas/submitted-leads";
import { prisma } from "@dub/prisma";
import { Prisma } from "@dub/prisma/client";
import { waitUntil } from "@vercel/functions";
-import { authActionClient } from "../safe-action";
-import { throwIfNoPermission } from "../throw-if-no-permission";
+import { authActionClient } from "../actions/safe-action";
+import { throwIfNoPermission } from "../actions/throw-if-no-permission";
-// Update a partner referral's details
-export const updateReferralAction = authActionClient
- .inputSchema(updateReferralSchema)
+// Update a submitted lead's details
+export const updateSubmittedLeadAction = authActionClient
+ .inputSchema(updateSubmittedLeadSchema)
.action(async ({ parsedInput, ctx }) => {
const { workspace, user } = ctx;
- const { referralId, name, email, company, formData } = parsedInput;
+ const { leadId, name, email, company, formData } = parsedInput;
const programId = getDefaultProgramIdOrThrow(workspace);
@@ -25,14 +25,14 @@ export const updateReferralAction = authActionClient
requiredRoles: ["owner", "member"],
});
- const existingReferral = await getReferralOrThrow({
- referralId,
+ const lead = await getSubmittedLeadOrThrow({
+ leadId,
programId,
});
- const updatedReferral = await prisma.partnerReferral.update({
+ const updatedLead = await prisma.submittedLead.update({
where: {
- id: referralId,
+ id: leadId,
},
data: {
name,
@@ -44,7 +44,7 @@ export const updateReferralAction = authActionClient
},
});
- const diff = getResourceDiff(existingReferral, updatedReferral, {
+ const diff = getResourceDiff(lead, updatedLead, {
fields: ["name", "email", "company"],
});
@@ -53,10 +53,10 @@ export const updateReferralAction = authActionClient
trackActivityLog({
workspaceId: workspace.id,
programId,
- resourceType: "referral",
- resourceId: referralId,
+ resourceType: "submittedLead",
+ resourceId: leadId,
userId: user.id,
- action: "referral.updated",
+ action: "submittedLead.updated",
changeSet: diff,
}),
);
diff --git a/apps/web/lib/submitted-leads/update-submitted-lead-status-action.ts b/apps/web/lib/submitted-leads/update-submitted-lead-status-action.ts
new file mode 100644
index 0000000000..86651b28b7
--- /dev/null
+++ b/apps/web/lib/submitted-leads/update-submitted-lead-status-action.ts
@@ -0,0 +1,121 @@
+"use server";
+
+import { trackActivityLog } from "@/lib/api/activity-log/track-activity-log";
+import { DubApiError } from "@/lib/api/errors";
+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import {
+ SUBMITTED_LEAD_STATUS_TO_ACTIVITY_ACTION,
+ SUBMITTED_LEAD_STATUS_TRANSITIONS,
+} from "@/lib/submitted-leads/constants";
+import { getSubmittedLeadOrThrow } from "@/lib/submitted-leads/get-submitted-lead-or-throw";
+import { markSubmittedLeadClosedWon } from "@/lib/submitted-leads/mark-submitted-lead-closed-won";
+import { markSubmittedLeadQualified } from "@/lib/submitted-leads/mark-submitted-lead-qualified";
+import { notifySubmittedLeadStatusUpdate } from "@/lib/submitted-leads/notify-submitted-lead-status-update";
+import { SubmittedLeadWithCustomer } from "@/lib/types";
+import { updateSubmittedLeadStatusSchema } from "@/lib/zod/schemas/submitted-leads";
+import { prisma } from "@dub/prisma";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
+import { waitUntil } from "@vercel/functions";
+import { authActionClient } from "../actions/safe-action";
+import { throwIfNoPermission } from "../actions/throw-if-no-permission";
+
+export const updateSubmittedLeadStatusAction = authActionClient
+ .inputSchema(updateSubmittedLeadStatusSchema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace, user } = ctx;
+ const { leadId, status, notes } = parsedInput;
+
+ const programId = getDefaultProgramIdOrThrow(workspace);
+
+ throwIfNoPermission({
+ role: workspace.role,
+ requiredRoles: ["owner", "member"],
+ });
+
+ const lead = await getSubmittedLeadOrThrow({
+ leadId,
+ programId,
+ });
+
+ if (!SUBMITTED_LEAD_STATUS_TRANSITIONS[lead.status].includes(status)) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: `Cannot transition from ${lead.status} to ${status}.`,
+ });
+ }
+
+ if (lead.status === status) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "Lead is already in this status.",
+ });
+ }
+
+ if (status === SubmittedLeadStatus.closedWon && !lead.customer) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "This lead does not have a customer associated with it.",
+ });
+ }
+
+ const updatedLead = await prisma.submittedLead.update({
+ where: {
+ id: lead.id,
+ status: lead.status,
+ },
+ data: {
+ status,
+ },
+ include: {
+ customer: true,
+ },
+ });
+
+ waitUntil(
+ (async () => {
+ await Promise.allSettled([
+ notifySubmittedLeadStatusUpdate({
+ lead,
+ notes,
+ }),
+
+ trackActivityLog({
+ workspaceId: workspace.id,
+ programId,
+ resourceType: "submittedLead",
+ resourceId: lead.id,
+ userId: user.id,
+ action: SUBMITTED_LEAD_STATUS_TO_ACTIVITY_ACTION[status],
+ description: notes,
+ changeSet: {
+ status: {
+ old: lead.status,
+ new: updatedLead.status,
+ },
+ },
+ }),
+
+ ...(status === SubmittedLeadStatus.qualified
+ ? [
+ markSubmittedLeadQualified({
+ workspace,
+ lead: updatedLead,
+ externalId: parsedInput.externalId ?? null,
+ }),
+ ]
+ : []),
+
+ ...(status === SubmittedLeadStatus.closedWon
+ ? [
+ markSubmittedLeadClosedWon({
+ workspace,
+ lead: updatedLead as SubmittedLeadWithCustomer,
+ saleAmount: parsedInput.saleAmount,
+ stripeCustomerId: parsedInput.stripeCustomerId ?? null,
+ }),
+ ]
+ : []),
+ ]);
+ })(),
+ );
+ });
diff --git a/apps/web/lib/swr/use-partner-referrals-count.ts b/apps/web/lib/swr/use-partner-submitted-leads-count.ts
similarity index 73%
rename from apps/web/lib/swr/use-partner-referrals-count.ts
rename to apps/web/lib/swr/use-partner-submitted-leads-count.ts
index 7370ae4809..28e0288447 100644
--- a/apps/web/lib/swr/use-partner-referrals-count.ts
+++ b/apps/web/lib/swr/use-partner-submitted-leads-count.ts
@@ -1,16 +1,16 @@
-import { getPartnerReferralsCountQuerySchema } from "@/lib/zod/schemas/partner-profile";
+import { getPartnerSubmittedLeadsCountQuerySchema } from "@/lib/zod/schemas/partner-profile";
import { useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
import useSWR from "swr";
import * as z from "zod/v4";
-export default function usePartnerReferralsCount<T = number>({
+export function usePartnerSubmittedLeadsCount<T = number>({
query,
ignoreParams,
enabled = true,
}: {
- query?: Partial<z.infer<typeof getPartnerReferralsCountQuerySchema>>;
+ query?: Partial<z.infer<typeof getPartnerSubmittedLeadsCountQuerySchema>>;
ignoreParams?: boolean;
enabled?: boolean;
} = {}) {
@@ -20,7 +20,7 @@ export default function usePartnerReferralsCount<T = number>({
const { data, error } = useSWR<T>(
enabled &&
programSlug &&
- `/api/partner-profile/programs/${programSlug}/referrals/count${getQueryString(
+ `/api/partner-profile/programs/${programSlug}/submitted-leads/count${getQueryString(
query
? Object.fromEntries(
Object.entries(query).filter(
diff --git a/apps/web/lib/swr/use-partner-referrals.ts b/apps/web/lib/swr/use-partner-submitted-leads.ts
similarity index 57%
rename from apps/web/lib/swr/use-partner-referrals.ts
rename to apps/web/lib/swr/use-partner-submitted-leads.ts
index bd64895b2f..64da53ea80 100644
--- a/apps/web/lib/swr/use-partner-referrals.ts
+++ b/apps/web/lib/swr/use-partner-submitted-leads.ts
@@ -1,16 +1,16 @@
-import { PartnerProfileReferral } from "@/lib/zod/schemas/partner-profile";
+import { PartnerProfileSubmittedLead } from "@/lib/zod/schemas/partner-profile";
import { useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
import useSWR from "swr";
-export default function usePartnerReferrals() {
+export function usePartnerSubmittedLeads() {
const { programSlug } = useParams<{ programSlug: string }>();
const { getQueryString } = useRouterStuff();
- const { data, isLoading, error } = useSWR<PartnerProfileReferral[]>(
+ const { data, isLoading, error } = useSWR<PartnerProfileSubmittedLead[]>(
programSlug &&
- `/api/partner-profile/programs/${programSlug}/referrals${getQueryString()}`,
+ `/api/partner-profile/programs/${programSlug}/submitted-leads${getQueryString()}`,
fetcher,
{
keepPreviousData: true,
diff --git a/apps/web/lib/swr/use-program-referrals-count.ts b/apps/web/lib/swr/use-program-submitted-leads-count.ts
similarity index 73%
rename from apps/web/lib/swr/use-program-referrals-count.ts
rename to apps/web/lib/swr/use-program-submitted-leads-count.ts
index 74da1785ba..05e68a00bb 100644
--- a/apps/web/lib/swr/use-program-referrals-count.ts
+++ b/apps/web/lib/swr/use-program-submitted-leads-count.ts
@@ -1,16 +1,16 @@
import useWorkspace from "@/lib/swr/use-workspace";
-import { getPartnerReferralsCountQuerySchema } from "@/lib/zod/schemas/referrals";
+import { getSubmittedLeadsCountQuerySchema } from "@/lib/zod/schemas/submitted-leads";
import { useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
import useSWR from "swr";
import * as z from "zod/v4";
-export function useProgramReferralsCount<T = number>({
+export function useProgramSubmittedLeadsCount<T = number>({
query,
ignoreParams,
enabled = true,
}: {
- query?: z.infer<typeof getPartnerReferralsCountQuerySchema>;
+ query?: z.infer<typeof getSubmittedLeadsCountQuerySchema>;
ignoreParams?: boolean;
enabled?: boolean;
} = {}) {
@@ -21,7 +21,7 @@ export function useProgramReferralsCount<T = number>({
enabled &&
workspaceId &&
defaultProgramId &&
- `/api/programs/${defaultProgramId}/referrals/count${getQueryString(
+ `/api/programs/${defaultProgramId}/submitted-leads/count${getQueryString(
{ workspaceId, ...query },
{
include: ignoreParams ? [] : ["partnerId", "status", "search"],
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 4533ab16e1..a2acea0cd2 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -6,7 +6,7 @@ import {
partnerPayoutMethodSchema,
PartnerProfileCustomerSchema,
PartnerProfileLinkSchema,
- partnerReferralsCountByStatusSchema,
+ partnerSubmittedLeadsCountByStatusSchema,
partnerUserSchema,
} from "@/lib/zod/schemas/partner-profile";
import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
@@ -20,12 +20,12 @@ import {
Link,
PartnerGroup,
PartnerPayoutMethod,
- PartnerReferral,
PartnerRole,
PayoutStatus,
Prisma,
ProgramEnrollmentStatus,
Project,
+ SubmittedLead,
User,
UtmTemplate,
Webhook,
@@ -170,11 +170,6 @@ import {
ProgramEnrollmentSchema,
ProgramSchema,
} from "./zod/schemas/programs";
-import { referralFormDataSchema } from "./zod/schemas/referral-form";
-import {
- referralSchema,
- updateReferralStatusSchema,
-} from "./zod/schemas/referrals";
import {
CUSTOMER_SOURCES,
rewardConditionsArraySchema,
@@ -188,6 +183,11 @@ import {
trackSaleResponseSchema,
} from "./zod/schemas/sales";
import { fraudEventContext } from "./zod/schemas/schemas";
+import { submittedLeadFormDataSchema } from "./zod/schemas/submitted-lead-form";
+import {
+ submittedLeadSchema,
+ updateSubmittedLeadStatusSchema,
+} from "./zod/schemas/submitted-leads";
import { tokenSchema } from "./zod/schemas/token";
import { usageResponse } from "./zod/schemas/usage";
import {
@@ -541,8 +541,8 @@ export type PartnerPayoutMethodSetting = z.infer<
typeof partnerPayoutMethodSchema
>;
-export type PartnerProfileReferralsCountByStatus = z.infer<
- typeof partnerReferralsCountByStatusSchema
+export type PartnerProfileSubmittedLeadsCountByStatus = z.infer<
+ typeof partnerSubmittedLeadsCountByStatusSchema
>;
export type EnrolledPartnerProps = z.infer<typeof EnrolledPartnerSchema> & {
@@ -865,17 +865,19 @@ export interface WorkflowContext {
};
}
-export type ReferralProps = z.infer<typeof referralSchema>;
+export type SubmittedLeadProps = z.infer<typeof submittedLeadSchema>;
-export type ReferralFormDataField = z.infer<typeof referralFormDataSchema>;
+export type SubmittedLeadFormDataField = z.infer<
+ typeof submittedLeadFormDataSchema
+>;
-export type UpdateReferralStatusPayload = z.infer<
- typeof updateReferralStatusSchema
+export type UpdateSubmittedLeadStatusPayload = z.infer<
+ typeof updateSubmittedLeadStatusSchema
>;
export type CustomerSource = (typeof CUSTOMER_SOURCES)[number];
-export type ReferralWithCustomer = PartnerReferral & {
+export type SubmittedLeadWithCustomer = SubmittedLead & {
customer: Customer | null;
};
diff --git a/apps/web/lib/zod/schemas/activity-log.ts b/apps/web/lib/zod/schemas/activity-log.ts
index 315244bfb7..bb866cb6f7 100644
--- a/apps/web/lib/zod/schemas/activity-log.ts
+++ b/apps/web/lib/zod/schemas/activity-log.ts
@@ -2,27 +2,18 @@ import * as z from "zod/v4";
import { UserSchema } from "./users";
export const activityLogResourceTypeSchema = z.enum([
- "referral",
"partner",
"commission",
"clickReward",
"saleReward",
"leadReward",
+ "submittedLead",
]);
export const activityLogActionSchema = z.enum([
- "referral.created",
- "referral.updated",
- "referral.qualified",
- "referral.meeting",
- "referral.negotiation",
- "referral.unqualified",
- "referral.closedWon",
- "referral.closedLost",
-
- "partner_application.approved",
- "partner_application.rejected",
- "partner.groupChanged", // TODO: change to partner.group_updated
+ "partner_application.approved", // TODO: change to partnerApplication.approved
+ "partner_application.rejected", // TODO: change to partnerApplication.rejected
+ "partner.groupChanged",
"partner.banned",
"partner.unbanned",
"partner.deactivated",
@@ -38,6 +29,15 @@ export const activityLogActionSchema = z.enum([
"reward.conditionAdded",
"reward.conditionRemoved",
"reward.conditionUpdated",
+
+ "submittedLead.created",
+ "submittedLead.updated",
+ "submittedLead.qualified",
+ "submittedLead.meeting",
+ "submittedLead.negotiation",
+ "submittedLead.unqualified",
+ "submittedLead.closedWon",
+ "submittedLead.closedLost",
]);
export const getActivityLogsQuerySchema = z.object({
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index 70fc5ece7f..ef5acd4ead 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -10,7 +10,7 @@ import {
PartnerProfileType,
PartnerRole,
ProgramEnrollmentStatus,
- ReferralStatus,
+ SubmittedLeadStatus,
} from "@dub/prisma/client";
import * as z from "zod/v4";
import { analyticsQuerySchema, eventsQuerySchema } from "./analytics";
@@ -29,7 +29,7 @@ import { CustomerEnrichedSchema } from "./customers";
import { LinkSchema } from "./links";
import { getPaginationQuerySchema } from "./misc";
import { payoutsQuerySchema } from "./payouts";
-import { referralFormDataSchema } from "./referral-form";
+import { submittedLeadFormDataSchema } from "./submitted-lead-form";
import { centsSchema } from "./utils";
export const PartnerEarningsSchema = CommissionSchema.omit({
@@ -283,31 +283,31 @@ export const getPartnerCustomersCountQuerySchema =
groupBy: z.enum(["country", "linkId"]).optional(),
});
-export const partnerProfileReferralSchema = z.object({
+export const partnerProfileSubmittedLeadSchema = z.object({
id: z.string(),
name: z.string(),
email: z.email(),
company: z.string(),
- status: z.enum(ReferralStatus),
+ status: z.enum(SubmittedLeadStatus),
customerId: z.string().nullable(),
- formData: z.array(referralFormDataSchema).nullable().optional(),
+ formData: z.array(submittedLeadFormDataSchema).nullable().optional(),
createdAt: z.date(),
updatedAt: z.date(),
});
-export type PartnerProfileReferral = z.infer<
- typeof partnerProfileReferralSchema
+export type PartnerProfileSubmittedLead = z.infer<
+ typeof partnerProfileSubmittedLeadSchema
>;
-export const getPartnerReferralsQuerySchema = z
+export const getPartnerSubmittedLeadsQuerySchema = z
.object({
- status: z.enum(ReferralStatus).optional(),
+ status: z.enum(SubmittedLeadStatus).optional(),
search: z.string().optional(),
})
.extend(getPaginationQuerySchema({ pageSize: 100 }));
-export const getPartnerReferralsCountQuerySchema =
- getPartnerReferralsQuerySchema
+export const getPartnerSubmittedLeadsCountQuerySchema =
+ getPartnerSubmittedLeadsQuerySchema
.omit({
page: true,
pageSize: true,
@@ -316,12 +316,12 @@ export const getPartnerReferralsCountQuerySchema =
groupBy: z.enum(["status"]).optional(),
});
-export const partnerReferralsCountByStatusSchema = z.object({
- status: z.enum(ReferralStatus),
+export const partnerSubmittedLeadsCountByStatusSchema = z.object({
+ status: z.enum(SubmittedLeadStatus),
_count: z.number(),
});
-export const partnerReferralsCountResponseSchema = z.union([
- z.array(partnerReferralsCountByStatusSchema),
+export const partnerSubmittedLeadsCountResponseSchema = z.union([
+ z.array(partnerSubmittedLeadsCountByStatusSchema),
z.number(),
]);
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index ec54f222cc..3750d254d2 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -21,8 +21,8 @@ import { GroupSchema } from "./groups";
import { LinkSchema } from "./links";
import { programApplicationFormDataWithValuesSchema } from "./program-application-form";
import { programInviteEmailDataSchema } from "./program-invite-email";
-import { referralFormSchema } from "./referral-form";
import { RewardSchema } from "./rewards";
+import { submittedLeadFormSchema } from "./submitted-lead-form";
import { UserSchema } from "./users";
import { centsSchemaWithDefault, parseDateSchema } from "./utils";
@@ -107,7 +107,7 @@ export const updateProgramSchema = z.object({
helpUrl: z.httpUrl().max(500).nullish(),
termsUrl: z.httpUrl().max(500).nullish(),
messagingEnabledAt: z.coerce.date().nullish(),
- referralFormData: referralFormSchema.nullish(),
+ referralFormData: submittedLeadFormSchema.nullish(),
});
export const ProgramPartnerLinkSchema = LinkSchema.pick({
@@ -194,7 +194,7 @@ export const ProgramEnrollmentSchema = z.object({
}).nullish(),
customerDataSharingEnabledAt: z.date().nullable(),
groupMoveDisabledAt: z.date().nullable(),
- referralFormData: referralFormSchema.nullish(),
+ referralFormData: submittedLeadFormSchema.nullish(),
application: ProgramEnrollmentApplicationSchema.nullish().describe(
"Linked program application, including review outcome when applicable.",
),
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.ts
index aff6e3c75f..9242b859a4 100644
--- a/apps/web/lib/zod/schemas/rewards.ts
+++ b/apps/web/lib/zod/schemas/rewards.ts
@@ -112,7 +112,7 @@ export const REWARD_CONDITIONS: Record<
},
{
id: "submitted",
- label: "submitted referral",
+ label: "submitted lead",
},
{
id: "trial",
diff --git a/apps/web/lib/zod/schemas/referral-form.ts b/apps/web/lib/zod/schemas/submitted-lead-form.ts
similarity index 94%
rename from apps/web/lib/zod/schemas/referral-form.ts
rename to apps/web/lib/zod/schemas/submitted-lead-form.ts
index 916bdd48d7..fef682bc80 100644
--- a/apps/web/lib/zod/schemas/referral-form.ts
+++ b/apps/web/lib/zod/schemas/submitted-lead-form.ts
@@ -118,12 +118,12 @@ export const formFieldsSchema = z
});
// Full form schema (builder storage)
-export const referralFormSchema = z.object({
+export const submittedLeadFormSchema = z.object({
fields: formFieldsSchema,
});
// This is the schema for the submitted form data that is stored in the database
-export const referralFormDataSchema = z.object({
+export const submittedLeadFormDataSchema = z.object({
key: z.string().min(1),
label: z.string().min(1),
value: z.unknown(),
@@ -131,7 +131,7 @@ export const referralFormDataSchema = z.object({
});
// Schema for validating required fields
-export const referralRequiredFieldsSchema = z.object({
+export const submittedLeadRequiredFieldsSchema = z.object({
name: z.string().min(1, "Name is required"),
email: z.email("Invalid email address"),
company: z.string().min(1, "Company is required"),
diff --git a/apps/web/lib/zod/schemas/referrals.ts b/apps/web/lib/zod/schemas/submitted-leads.ts
similarity index 52%
rename from apps/web/lib/zod/schemas/referrals.ts
rename to apps/web/lib/zod/schemas/submitted-leads.ts
index ec673389d6..68fef06805 100644
--- a/apps/web/lib/zod/schemas/referrals.ts
+++ b/apps/web/lib/zod/schemas/submitted-leads.ts
@@ -1,19 +1,19 @@
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import * as z from "zod/v4";
import { getPaginationQuerySchema } from "./misc";
import { PartnerSchema } from "./partners";
-import { referralFormDataSchema } from "./referral-form";
+import { submittedLeadFormDataSchema } from "./submitted-lead-form";
import { centsSchema } from "./utils";
-export const referralSchema = z.object({
+export const submittedLeadSchema = z.object({
id: z.string(),
programId: z.string(),
partnerId: z.string(),
name: z.string(),
email: z.email(),
company: z.string(),
- status: z.enum(ReferralStatus),
- formData: z.array(referralFormDataSchema).nullable().optional(),
+ status: z.enum(SubmittedLeadStatus),
+ formData: z.array(submittedLeadFormDataSchema).nullable().optional(),
createdAt: z.date(),
updatedAt: z.date(),
partner: PartnerSchema.pick({
@@ -24,56 +24,55 @@ export const referralSchema = z.object({
}),
});
-export const getPartnerReferralsQuerySchema = z
+export const getSubmittedLeadsQuerySchema = z
.object({
partnerId: z.string().optional(),
- status: z.enum(ReferralStatus).optional(),
+ status: z.enum(SubmittedLeadStatus).optional(),
search: z.string().optional(),
})
.extend(getPaginationQuerySchema({ pageSize: 100 }));
-export const getPartnerReferralsCountQuerySchema =
- getPartnerReferralsQuerySchema
- .omit({
- page: true,
- pageSize: true,
- })
- .extend({
- groupBy: z.enum(["status", "partnerId"]).optional(),
- });
-
-export const partnerReferralsCountByStatusSchema = z.object({
- status: z.enum(ReferralStatus),
+export const getSubmittedLeadsCountQuerySchema = getSubmittedLeadsQuerySchema
+ .omit({
+ page: true,
+ pageSize: true,
+ })
+ .extend({
+ groupBy: z.enum(["status", "partnerId"]).optional(),
+ });
+
+export const submittedLeadsCountByStatusSchema = z.object({
+ status: z.enum(SubmittedLeadStatus),
_count: z.number(),
});
-export const partnerReferralsCountByPartnerIdSchema = z.object({
+export const submittedLeadsCountByPartnerSchema = z.object({
partnerId: z.string(),
_count: z.number(),
});
-export const partnerReferralsCountResponseSchema = z.union([
- z.array(partnerReferralsCountByStatusSchema),
- z.array(partnerReferralsCountByPartnerIdSchema),
+export const submittedLeadsCountResponseSchema = z.union([
+ z.array(submittedLeadsCountByStatusSchema),
+ z.array(submittedLeadsCountByPartnerSchema),
z.number(),
]);
-export const createPartnerReferralSchema = z.object({
+export const submitLeadSchema = z.object({
programId: z.string(),
formData: z.record(z.string(), z.unknown()), // Contains all form fields including name, email, company
});
-export const updateReferralSchema = z.object({
- referralId: z.string(),
+export const updateSubmittedLeadSchema = z.object({
+ leadId: z.string(),
workspaceId: z.string(),
name: z.string().min(1, "Name is required"),
email: z.email("Invalid email address"),
company: z.string().min(1, "Company is required"),
- formData: z.array(referralFormDataSchema).nullable().optional(),
+ formData: z.array(submittedLeadFormDataSchema).nullable().optional(),
});
-const updateReferralStatusBaseSchema = z.object({
- referralId: z.string(),
+const baseSchema = z.object({
+ leadId: z.string(),
workspaceId: z.string(),
notes: z
.string()
@@ -82,29 +81,29 @@ const updateReferralStatusBaseSchema = z.object({
.optional(),
});
-export const updateReferralStatusSchema = z.discriminatedUnion("status", [
- updateReferralStatusBaseSchema.extend({
+export const updateSubmittedLeadStatusSchema = z.discriminatedUnion("status", [
+ baseSchema.extend({
status: z.literal("pending"),
}),
- updateReferralStatusBaseSchema.extend({
+ baseSchema.extend({
status: z.literal("qualified"),
externalId: z.string().trim().optional(),
}),
- updateReferralStatusBaseSchema.extend({
+ baseSchema.extend({
status: z.literal("meeting"),
}),
- updateReferralStatusBaseSchema.extend({
+ baseSchema.extend({
status: z.literal("negotiation"),
}),
- updateReferralStatusBaseSchema.extend({
+ baseSchema.extend({
status: z.literal("unqualified"),
}),
- updateReferralStatusBaseSchema.extend({
+ baseSchema.extend({
status: z.literal("closedWon"),
saleAmount: centsSchema.pipe(
z.number().min(0, "Sale amount must be greater than or equal to 0"),
@@ -112,7 +111,7 @@ export const updateReferralStatusSchema = z.discriminatedUnion("status", [
stripeCustomerId: z.string().optional(),
}),
- updateReferralStatusBaseSchema.extend({
+ baseSchema.extend({
status: z.literal("closedLost"),
}),
]);
diff --git a/apps/web/scripts/referral-form-sample.json b/apps/web/scripts/lead-form-sample.json
similarity index 100%
rename from apps/web/scripts/referral-form-sample.json
rename to apps/web/scripts/lead-form-sample.json
diff --git a/apps/web/scripts/migrations/backfill-submitted-leads.ts b/apps/web/scripts/migrations/backfill-submitted-leads.ts
new file mode 100644
index 0000000000..4d64f95d5e
--- /dev/null
+++ b/apps/web/scripts/migrations/backfill-submitted-leads.ts
@@ -0,0 +1,67 @@
+import { prisma } from "@dub/prisma";
+import { Prisma, SubmittedLeadStatus } from "@dub/prisma/client";
+import "dotenv-flow/config";
+
+const BATCH_SIZE = 100;
+
+async function main() {
+ let cursor: string | undefined;
+ let totalProcessed = 0;
+ let totalInserted = 0;
+
+ while (true) {
+ const referrals = await prisma.partnerReferral.findMany({
+ take: BATCH_SIZE,
+ ...(cursor
+ ? {
+ skip: 1,
+ cursor: {
+ id: cursor,
+ },
+ }
+ : {}),
+ orderBy: {
+ id: "asc",
+ },
+ });
+
+ if (referrals.length === 0) {
+ break;
+ }
+
+ const data: Prisma.SubmittedLeadCreateManyInput[] = referrals.map((r) => ({
+ // Preserve IDs (but change prefix) so historical references (e.g. ActivityLog.resourceId) remain valid.
+ id: r.id.replace("ref_", "sbl_"),
+ programId: r.programId,
+ partnerId: r.partnerId,
+ customerId: r.customerId,
+ name: r.name,
+ email: r.email,
+ company: r.company,
+ formData: (r.formData ?? Prisma.JsonNull) as Prisma.InputJsonValue,
+ status: r.status as unknown as SubmittedLeadStatus,
+ createdAt: r.createdAt,
+ updatedAt: r.updatedAt,
+ }));
+
+ const { count } = await prisma.submittedLead.createMany({
+ data,
+ skipDuplicates: true,
+ });
+
+ totalProcessed += referrals.length;
+ totalInserted += count;
+
+ console.log(
+ `Backfilled ${count} submitted leads (batch=${referrals.length}, processed=${totalProcessed}, inserted=${totalInserted})`,
+ );
+
+ cursor = referrals[referrals.length - 1].id;
+ }
+
+ console.log(
+ `Done backfilling submitted leads (processed=${totalProcessed}, inserted=${totalInserted})`,
+ );
+}
+
+main();
diff --git a/apps/web/scripts/migrations/migrate-referrals-activity-log.ts b/apps/web/scripts/migrations/migrate-referrals-activity-log.ts
new file mode 100644
index 0000000000..e49d4e4d33
--- /dev/null
+++ b/apps/web/scripts/migrations/migrate-referrals-activity-log.ts
@@ -0,0 +1,33 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+
+const BATCH_SIZE = 20;
+
+async function main() {
+ while (true) {
+ const logs = await prisma.activityLog.findMany({
+ where: {
+ resourceType: "referral",
+ },
+ take: BATCH_SIZE,
+ });
+
+ if (logs.length === 0) {
+ break;
+ }
+
+ for (const log of logs) {
+ await prisma.activityLog.update({
+ where: { id: log.id },
+ data: {
+ resourceType: "submittedLead",
+ resourceId: log.resourceId.replace("ref_", "sbl_"),
+ action: log.action.replace("referral.", "submittedLead."),
+ },
+ });
+ console.log(`Migrated ${log.id}`);
+ }
+ }
+}
+
+main();
diff --git a/apps/web/scripts/update-referral-form-data.ts b/apps/web/scripts/update-lead-form-data.ts
similarity index 79%
rename from apps/web/scripts/update-referral-form-data.ts
rename to apps/web/scripts/update-lead-form-data.ts
index 5aa609374f..a5ecaf27f7 100644
--- a/apps/web/scripts/update-referral-form-data.ts
+++ b/apps/web/scripts/update-lead-form-data.ts
@@ -1,4 +1,4 @@
-import { referralFormSchema } from "@/lib/zod/schemas/referral-form";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { prisma } from "@dub/prisma";
import { ACME_PROGRAM_ID } from "@dub/utils";
import "dotenv-flow/config";
@@ -6,7 +6,7 @@ import { readFileSync } from "fs";
async function main() {
const programId = ACME_PROGRAM_ID;
- const jsonFilePath = "./scripts/referral-form-sample.json";
+ const jsonFilePath = "./scripts/lead-form-sample.json";
// Read and parse JSON file
let formData;
@@ -21,7 +21,7 @@ async function main() {
// Validate JSON against schema
let validatedData;
try {
- validatedData = referralFormSchema.parse(formData);
+ validatedData = submittedLeadFormSchema.parse(formData);
} catch (error) {
console.error("Validation failed:", error);
process.exit(1);
diff --git a/apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx b/apps/web/ui/activity-logs/action-renderers/submitted-lead-created-renderer.tsx
similarity index 86%
rename from apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx
rename to apps/web/ui/activity-logs/action-renderers/submitted-lead-created-renderer.tsx
index 80d299de70..860ff2f023 100644
--- a/apps/web/ui/activity-logs/action-renderers/referral-created-renderer.tsx
+++ b/apps/web/ui/activity-logs/action-renderers/submitted-lead-created-renderer.tsx
@@ -12,11 +12,13 @@ function Label({ children }: { children: ReactNode }) {
);
}
-interface ReferralCreatedRendererProps {
+interface SubmittedLeadCreatedRendererProps {
log: ActivityLog;
}
-export function ReferralCreatedRenderer({ log }: ReferralCreatedRendererProps) {
+export function SubmittedLeadCreatedRenderer({
+ log,
+}: SubmittedLeadCreatedRendererProps) {
const { view } = useActivityLogContext();
return view === "partner" ? (
diff --git a/apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx b/apps/web/ui/activity-logs/action-renderers/submitted-lead-status-changed-renderer.tsx
similarity index 62%
rename from apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx
rename to apps/web/ui/activity-logs/action-renderers/submitted-lead-status-changed-renderer.tsx
index ae21fd3591..204c31ddfc 100644
--- a/apps/web/ui/activity-logs/action-renderers/referral-status-changed-renderer.tsx
+++ b/apps/web/ui/activity-logs/action-renderers/submitted-lead-status-changed-renderer.tsx
@@ -1,13 +1,13 @@
"use client";
import { ActivityLog } from "@/lib/types";
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { ReactNode } from "react";
-import { ActorChip, ReferralStatusPill } from "../activity-entry-chips";
+import { ActorChip, SubmittedLeadStatusPill } from "../activity-entry-chips";
interface StatusChangeSet {
- old: ReferralStatus | null;
- new: ReferralStatus | null;
+ old: SubmittedLeadStatus | null;
+ new: SubmittedLeadStatus | null;
}
function Label({ children }: { children: ReactNode }) {
@@ -16,7 +16,11 @@ function Label({ children }: { children: ReactNode }) {
);
}
-export function ReferralStatusChangedRenderer({ log }: { log: ActivityLog }) {
+export function SubmittedLeadStatusChangedRenderer({
+ log,
+}: {
+ log: ActivityLog;
+}) {
const statusChange = log.changeSet?.status as StatusChangeSet | undefined;
const status = statusChange?.new ?? null;
@@ -27,7 +31,7 @@ export function ReferralStatusChangedRenderer({ log }: { log: ActivityLog }) {
return (
<>
<Label>Lead</Label>
- <ReferralStatusPill status={status} />
+ <SubmittedLeadStatusPill status={status} />
<Label>by</Label>
<ActorChip log={log} />
</>
diff --git a/apps/web/ui/activity-logs/activity-entry-chips.tsx b/apps/web/ui/activity-logs/activity-entry-chips.tsx
index 8a3f27d631..e3c360066e 100644
--- a/apps/web/ui/activity-logs/activity-entry-chips.tsx
+++ b/apps/web/ui/activity-logs/activity-entry-chips.tsx
@@ -1,7 +1,7 @@
import { ActivityLog, GroupProps, ProgramProps } from "@/lib/types";
import { getResourceColorData, RAINBOW_CONIC_GRADIENT } from "@/ui/colors";
-import { ReferralStatusBadges } from "@/ui/referrals/referral-status-badges";
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadStatusBadges } from "@/ui/submitted-leads/submitted-lead-status-badges";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { Bolt, Tooltip } from "@dub/ui";
import { cn, OG_AVATAR_URL } from "@dub/utils";
import { ReactNode } from "react";
@@ -122,8 +122,12 @@ export function ActorChip({ log }: ActorChipProps) {
return <SystemChip />;
}
-export function ReferralStatusPill({ status }: { status: ReferralStatus }) {
- const badge = ReferralStatusBadges[status];
+export function SubmittedLeadStatusPill({
+ status,
+}: {
+ status: SubmittedLeadStatus;
+}) {
+ const badge = SubmittedLeadStatusBadges[status];
if (!badge) return null;
diff --git a/apps/web/ui/activity-logs/activity-feed.tsx b/apps/web/ui/activity-logs/activity-feed.tsx
index e74185d470..65df8fe36b 100644
--- a/apps/web/ui/activity-logs/activity-feed.tsx
+++ b/apps/web/ui/activity-logs/activity-feed.tsx
@@ -1,7 +1,7 @@
import { ActivityLog, ActivityLogResourceType } from "@/lib/types";
import { PartnerGroupActivityItem } from "@/ui/activity-logs/partner-group-activity-item";
-import { ReferralActivityItem } from "@/ui/activity-logs/referral-activity-item";
import { RewardActivityItem } from "@/ui/activity-logs/reward-activity-item";
+import { SubmittedLeadActivityItem } from "@/ui/activity-logs/submitted-lead-activity-item";
import { ComponentType } from "react";
const ACTIVITY_ITEM_MAP: Record<
@@ -9,7 +9,7 @@ const ACTIVITY_ITEM_MAP: Record<
ComponentType<{ log: ActivityLog; isLast?: boolean }>
> = {
partner: PartnerGroupActivityItem,
- referral: ReferralActivityItem,
+ submittedLead: SubmittedLeadActivityItem,
clickReward: RewardActivityItem,
leadReward: RewardActivityItem,
saleReward: RewardActivityItem,
diff --git a/apps/web/ui/activity-logs/activity-log-registry.tsx b/apps/web/ui/activity-logs/activity-log-registry.tsx
index 51b8ec67e5..b0af2243de 100644
--- a/apps/web/ui/activity-logs/activity-log-registry.tsx
+++ b/apps/web/ui/activity-logs/activity-log-registry.tsx
@@ -10,9 +10,9 @@ import {
import { CircleMinus, CirclePlusIcon } from "lucide-react";
import { ComponentType, ReactNode } from "react";
import { PartnerGroupChangedRenderer } from "./action-renderers/partner-group-changed-renderer";
-import { ReferralCreatedRenderer } from "./action-renderers/referral-created-renderer";
-import { ReferralStatusChangedRenderer } from "./action-renderers/referral-status-changed-renderer";
import { RewardActivityRenderer } from "./action-renderers/reward-activity-renderer";
+import { SubmittedLeadCreatedRenderer } from "./action-renderers/submitted-lead-created-renderer";
+import { SubmittedLeadStatusChangedRenderer } from "./action-renderers/submitted-lead-status-changed-renderer";
export type ActorType = "USER" | "SYSTEM";
@@ -27,13 +27,13 @@ const ACTIVITY_LOG_ICONS: Partial<
> = {
"partner.groupChanged": UserArrowRight,
- "referral.created": FileSend,
- "referral.qualified": UserClock,
- "referral.meeting": UserClock,
- "referral.negotiation": UserClock,
- "referral.unqualified": UserClock,
- "referral.closedWon": UserClock,
- "referral.closedLost": UserClock,
+ "submittedLead.created": FileSend,
+ "submittedLead.qualified": UserClock,
+ "submittedLead.meeting": UserClock,
+ "submittedLead.negotiation": UserClock,
+ "submittedLead.unqualified": UserClock,
+ "submittedLead.closedWon": UserClock,
+ "submittedLead.closedLost": UserClock,
"reward.created": MoneyBill2,
"reward.updated": Pen2,
@@ -52,21 +52,21 @@ const ACTIVITY_LOG_REGISTRY: Array<{
renderer: PartnerGroupChangedRenderer,
},
{
- action: "referral.created",
- renderer: ReferralCreatedRenderer,
+ action: "submittedLead.created",
+ renderer: SubmittedLeadCreatedRenderer,
},
...(
[
- "referral.qualified",
- "referral.meeting",
- "referral.negotiation",
- "referral.unqualified",
- "referral.closedWon",
- "referral.closedLost",
+ "submittedLead.qualified",
+ "submittedLead.meeting",
+ "submittedLead.negotiation",
+ "submittedLead.unqualified",
+ "submittedLead.closedWon",
+ "submittedLead.closedLost",
] as const
).map((action) => ({
action,
- renderer: ReferralStatusChangedRenderer,
+ renderer: SubmittedLeadStatusChangedRenderer,
})),
...(
[
diff --git a/apps/web/ui/activity-logs/referral-activity-item.tsx b/apps/web/ui/activity-logs/submitted-lead-activity-item.tsx
similarity index 93%
rename from apps/web/ui/activity-logs/referral-activity-item.tsx
rename to apps/web/ui/activity-logs/submitted-lead-activity-item.tsx
index edfc763395..d573e2843b 100644
--- a/apps/web/ui/activity-logs/referral-activity-item.tsx
+++ b/apps/web/ui/activity-logs/submitted-lead-activity-item.tsx
@@ -7,15 +7,15 @@ import {
getActivityLogRenderer,
} from "./activity-log-registry";
-interface ReferralActivityItemProps {
+interface SubmittedLeadActivityItemProps {
log: ActivityLog;
isLast?: boolean;
}
-export function ReferralActivityItem({
+export function SubmittedLeadActivityItem({
log,
isLast = false,
-}: ReferralActivityItemProps) {
+}: SubmittedLeadActivityItemProps) {
const icon = getActivityLogIcon(log);
const Renderer = getActivityLogRenderer(log.action);
diff --git a/apps/web/ui/activity-logs/partner-referral-activity-section.tsx b/apps/web/ui/activity-logs/submitted-lead-activity-section-partner.tsx
similarity index 83%
rename from apps/web/ui/activity-logs/partner-referral-activity-section.tsx
rename to apps/web/ui/activity-logs/submitted-lead-activity-section-partner.tsx
index e5cfd9d107..a0bd1fa521 100644
--- a/apps/web/ui/activity-logs/partner-referral-activity-section.tsx
+++ b/apps/web/ui/activity-logs/submitted-lead-activity-section-partner.tsx
@@ -8,19 +8,19 @@ import {
} from "@/ui/activity-logs/activity-feed";
import { ActivityLogProvider } from "@/ui/activity-logs/activity-log-context";
-export function PartnerReferralActivitySection({
- referralId,
+export function SubmittedLeadActivitySectionPartner({
+ leadId,
}: {
- referralId: string;
+ leadId: string;
}) {
const { programEnrollment } = useProgramEnrollment();
const { activityLogs, loading, error } = usePartnerActivityLogs({
query: {
- resourceType: "referral",
- resourceId: referralId,
+ resourceType: "submittedLead",
+ resourceId: leadId,
},
- enabled: !!referralId,
+ enabled: !!leadId,
});
const logs = activityLogs ?? [];
@@ -46,7 +46,7 @@ export function PartnerReferralActivitySection({
</p>
) : (
<ActivityLogProvider program={program} view="partner">
- <ActivityFeed logs={logs} resourceType="referral" />
+ <ActivityFeed logs={logs} resourceType="submittedLead" />
</ActivityLogProvider>
)}
</section>
diff --git a/apps/web/ui/activity-logs/referral-activity-section.tsx b/apps/web/ui/activity-logs/submitted-lead-activity-section.tsx
similarity index 77%
rename from apps/web/ui/activity-logs/referral-activity-section.tsx
rename to apps/web/ui/activity-logs/submitted-lead-activity-section.tsx
index c7c3f56f04..7e0e7f14ca 100644
--- a/apps/web/ui/activity-logs/referral-activity-section.tsx
+++ b/apps/web/ui/activity-logs/submitted-lead-activity-section.tsx
@@ -6,17 +6,13 @@ import {
ActivityFeedSkeleton,
} from "@/ui/activity-logs/activity-feed";
-export function ReferralActivitySection({
- referralId,
-}: {
- referralId: string;
-}) {
+export function SubmittedLeadActivitySection({ leadId }: { leadId: string }) {
const { activityLogs, loading, error } = useActivityLogs({
query: {
- resourceType: "referral",
- resourceId: referralId,
+ resourceType: "submittedLead",
+ resourceId: leadId,
},
- enabled: !!referralId,
+ enabled: !!leadId,
});
const logs = activityLogs ?? [];
@@ -40,7 +36,7 @@ export function ReferralActivitySection({
Failed to load activity. Please try again.
</p>
) : (
- <ActivityFeed logs={logs} resourceType="referral" />
+ <ActivityFeed logs={logs} resourceType="submittedLead" />
)}
</section>
);
diff --git a/apps/web/ui/analytics/use-analytics-filters.tsx b/apps/web/ui/analytics/use-analytics-filters.tsx
index f76d7e16a3..2664296b97 100644
--- a/apps/web/ui/analytics/use-analytics-filters.tsx
+++ b/apps/web/ui/analytics/use-analytics-filters.tsx
@@ -222,13 +222,7 @@ export function useAnalyticsFilters({
VALID_ANALYTICS_FILTERS.forEach((filter) => {
// Skip special cases we handled above
if (
- [
- "key",
- "tagId",
- "partnerTagId",
- "root",
- "customerId",
- ].includes(filter)
+ ["key", "tagId", "partnerTagId", "root", "customerId"].includes(filter)
)
return;
// Also skip date range filters and qr
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index 053a34438e..f95d7a4f52 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -1,7 +1,7 @@
"use client";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
-import { REFERRAL_ENABLED_PROGRAM_IDS } from "@/lib/referrals/constants";
+import { SUBMITTED_LEADS_ENABLED_PROGRAM_IDS } from "@/lib/submitted-leads/constants";
import {
SubmissionsCountByStatus,
useBountySubmissionsCount,
@@ -10,7 +10,7 @@ import { useFraudGroupCount } from "@/lib/swr/use-fraud-groups-count";
import { usePartnerMessagesCount } from "@/lib/swr/use-partner-messages-count";
import { usePayoutsCount } from "@/lib/swr/use-payouts-count";
import useProgram from "@/lib/swr/use-program";
-import { useProgramReferralsCount } from "@/lib/swr/use-program-referrals-count";
+import { useProgramSubmittedLeadsCount } from "@/lib/swr/use-program-submitted-leads-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { type Icon, useRouterStuff } from "@dub/ui";
import {
@@ -74,7 +74,7 @@ type SidebarNavData = {
submittedBountiesCount?: number;
unreadMessagesCount?: number;
pendingFraudEventsCount?: number;
- pendingReferralsCount?: number;
+ pendingLeadsCount?: number;
showConversionGuides?: boolean;
partnerNetworkEnabled?: boolean;
};
@@ -124,7 +124,7 @@ const NAV_AREAS: SidebarNavAreas<SidebarNavData> = {
submittedBountiesCount,
unreadMessagesCount,
pendingFraudEventsCount,
- pendingReferralsCount,
+ pendingLeadsCount,
partnerNetworkEnabled,
}) => ({
title: "Partner Program",
@@ -211,10 +211,10 @@ const NAV_AREAS: SidebarNavAreas<SidebarNavData> = {
name: "Customers",
icon: User as Icon,
href: `/${slug}/program/customers`,
- badge: pendingReferralsCount
- ? pendingReferralsCount > 99
+ badge: pendingLeadsCount
+ ? pendingLeadsCount > 99
? "99+"
- : pendingReferralsCount
+ : pendingLeadsCount
: undefined,
},
{
@@ -554,13 +554,13 @@ export function AppSidebarNav({
ignoreParams: true,
});
- const { data: pendingReferralsCount } = useProgramReferralsCount<number>({
+ const { data: pendingLeadsCount } = useProgramSubmittedLeadsCount<number>({
query: { status: "pending" },
ignoreParams: true,
enabled: Boolean(
currentArea === "program" &&
defaultProgramId &&
- REFERRAL_ENABLED_PROGRAM_IDS.includes(defaultProgramId),
+ SUBMITTED_LEADS_ENABLED_PROGRAM_IDS.includes(defaultProgramId),
),
});
@@ -585,7 +585,7 @@ export function AppSidebarNav({
submittedBountiesCount,
unreadMessagesCount,
pendingFraudEventsCount,
- pendingReferralsCount,
+ pendingLeadsCount,
showConversionGuides:
canTrackConversions && pathname.startsWith(`/${slug}/links`),
partnerNetworkEnabled:
diff --git a/apps/web/ui/modals/confirm-referral-status-change-modal.tsx b/apps/web/ui/modals/confirm-submitted-lead-status-change-modal.tsx
similarity index 82%
rename from apps/web/ui/modals/confirm-referral-status-change-modal.tsx
rename to apps/web/ui/modals/confirm-submitted-lead-status-change-modal.tsx
index 8aa9f64fb7..3e6351826a 100644
--- a/apps/web/ui/modals/confirm-referral-status-change-modal.tsx
+++ b/apps/web/ui/modals/confirm-submitted-lead-status-change-modal.tsx
@@ -1,12 +1,15 @@
"use client";
-import { updateReferralStatusAction } from "@/lib/actions/referrals/update-referral-status";
import { handleMoneyInputChange, handleMoneyKeyDown } from "@/lib/form-utils";
+import { updateSubmittedLeadStatusAction } from "@/lib/submitted-leads/update-submitted-lead-status-action";
import { mutatePrefix } from "@/lib/swr/mutate";
import useWorkspace from "@/lib/swr/use-workspace";
-import { ReferralProps, UpdateReferralStatusPayload } from "@/lib/types";
-import { ReferralStatusBadge } from "@/ui/referrals/referral-status-badge";
-import { ReferralStatus } from "@dub/prisma/client";
+import {
+ SubmittedLeadProps,
+ UpdateSubmittedLeadStatusPayload,
+} from "@/lib/types";
+import { SubmittedLeadStatusBadge } from "@/ui/submitted-leads/submitted-lead-status-badge";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { AnimatedSizeContainer, Button, Modal, useMediaQuery } from "@dub/ui";
import { cn } from "@dub/utils";
import { ArrowRight, ChevronDown } from "lucide-react";
@@ -28,12 +31,12 @@ type StatusChangeFormData = {
type StatusConfig = {
fields: StatusField[];
buildPayload: (
- base: { referralId: string; workspaceId: string; notes?: string },
+ base: { leadId: string; workspaceId: string; notes?: string },
data: StatusChangeFormData,
- ) => UpdateReferralStatusPayload;
+ ) => UpdateSubmittedLeadStatusPayload;
};
-const STATUS_CONFIG: Record<ReferralStatus, StatusConfig> = {
+const STATUS_CONFIG: Record<SubmittedLeadStatus, StatusConfig> = {
pending: {
fields: [],
buildPayload: (base) => ({ ...base, status: "pending" }),
@@ -73,36 +76,39 @@ const STATUS_CONFIG: Record<ReferralStatus, StatusConfig> = {
},
};
-type ConfirmReferralStatusChangeModalProps = {
+type ConfirmSubmittedLeadStatusChangeModalProps = {
showModal: boolean;
setShowModal: (showModal: boolean) => void;
- referral: Pick<ReferralProps, "id" | "status">;
- newStatus: ReferralStatus;
+ lead: Pick<SubmittedLeadProps, "id" | "status">;
+ newStatus: SubmittedLeadStatus;
};
-function ConfirmReferralStatusChangeModal({
+function ConfirmSubmittedLeadStatusChangeModal({
showModal,
setShowModal,
- referral,
+ lead,
newStatus,
-}: ConfirmReferralStatusChangeModalProps) {
+}: ConfirmSubmittedLeadStatusChangeModalProps) {
const { isMobile } = useMediaQuery();
const { id: workspaceId, defaultProgramId } = useWorkspace();
const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);
- const { executeAsync, isPending } = useAction(updateReferralStatusAction, {
- onSuccess: async () => {
- setShowModal(false);
- toast.success("Referral status updated successfully!");
- await mutatePrefix([
- `/api/programs/${defaultProgramId}/referrals`,
- "/api/activity-logs",
- ]);
- },
- onError({ error }) {
- toast.error(error.serverError || "Failed to update referral status");
+ const { executeAsync, isPending } = useAction(
+ updateSubmittedLeadStatusAction,
+ {
+ onSuccess: async () => {
+ setShowModal(false);
+ toast.success("Lead status updated successfully!");
+ await mutatePrefix([
+ `/api/programs/${defaultProgramId}/submitted-leads`,
+ "/api/activity-logs",
+ ]);
+ },
+ onError({ error }) {
+ toast.error(error.serverError || "Failed to update lead status");
+ },
},
- });
+ );
const {
register,
@@ -135,12 +141,12 @@ function ConfirmReferralStatusChangeModal({
const hasAdvancedSettings = visibleFields.has("stripeCustomerId");
const onSubmit = async (data: StatusChangeFormData) => {
- if (!workspaceId || !referral.id) return;
+ if (!workspaceId || !lead.id) return;
const payload = config.buildPayload(
{
workspaceId,
- referralId: referral.id,
+ leadId: lead.id,
notes: data.notes || undefined,
},
data,
@@ -175,9 +181,12 @@ function ConfirmReferralStatusChangeModal({
}}
/>
<div className="relative flex items-center justify-center gap-4">
- <ReferralStatusBadge status={referral.status} className="h-7" />
+ <SubmittedLeadStatusBadge
+ status={lead.status}
+ className="h-7"
+ />
<ArrowRight className="size-4 text-neutral-400" />
- <ReferralStatusBadge status={newStatus} className="h-7" />
+ <SubmittedLeadStatusBadge status={newStatus} className="h-7" />
</div>
</div>
@@ -200,8 +209,8 @@ function ConfirmReferralStatusChangeModal({
})}
/>
<p className="text-content-subtle mt-1 text-xs">
- The customer's external ID. If not provided, the referral
- email will be used.
+ The customer's external ID. If not provided, the lead email
+ will be used.
</p>
</div>
)}
@@ -344,39 +353,39 @@ function ConfirmReferralStatusChangeModal({
);
}
-export function useConfirmReferralStatusChangeModal(options?: {
+export function useConfirmSubmittedLeadStatusChangeModal(options?: {
onClose?: () => void;
}) {
const [state, setState] = useState<{
- referral: Pick<ReferralProps, "id" | "status">;
- newStatus: ReferralStatus;
+ lead: Pick<SubmittedLeadProps, "id" | "status">;
+ newStatus: SubmittedLeadStatus;
} | null>(null);
- function openConfirmReferralStatusChangeModal(
- referral: Pick<ReferralProps, "id" | "status">,
- newStatus: ReferralStatus,
+ function openConfirmSubmittedLeadStatusChangeModal(
+ lead: Pick<SubmittedLeadProps, "id" | "status">,
+ newStatus: SubmittedLeadStatus,
) {
- setState({ referral, newStatus });
+ setState({ lead, newStatus });
}
- function closeConfirmReferralStatusChangeModal() {
+ function closeConfirmSubmittedLeadStatusChangeModal() {
setState(null);
options?.onClose?.();
}
return {
- openConfirmReferralStatusChangeModal,
- closeConfirmReferralStatusChangeModal,
- ConfirmReferralStatusChangeModal: state ? (
- <ConfirmReferralStatusChangeModal
- referral={state.referral}
+ openConfirmSubmittedLeadStatusChangeModal,
+ closeConfirmSubmittedLeadStatusChangeModal,
+ ConfirmSubmittedLeadStatusChangeModal: state ? (
+ <ConfirmSubmittedLeadStatusChangeModal
+ lead={state.lead}
newStatus={state.newStatus}
showModal
setShowModal={(show) => {
- if (!show) closeConfirmReferralStatusChangeModal();
+ if (!show) closeConfirmSubmittedLeadStatusChangeModal();
}}
/>
) : null,
- isConfirmReferralStatusChangeModalOpen: state !== null,
+ isConfirmSubmittedLeadStatusChangeModalOpen: state !== null,
};
}
diff --git a/apps/web/ui/modals/edit-referral-modal.tsx b/apps/web/ui/modals/edit-submitted-lead-modal.tsx
similarity index 80%
rename from apps/web/ui/modals/edit-referral-modal.tsx
rename to apps/web/ui/modals/edit-submitted-lead-modal.tsx
index ebdeaba7e3..9ad03adaae 100644
--- a/apps/web/ui/modals/edit-referral-modal.tsx
+++ b/apps/web/ui/modals/edit-submitted-lead-modal.tsx
@@ -1,10 +1,10 @@
"use client";
-import { updateReferralAction } from "@/lib/actions/referrals/update-referral";
+import { updateSubmittedLeadAction } from "@/lib/submitted-leads/update-submitted-lead-action";
import { mutatePrefix } from "@/lib/swr/mutate";
import useWorkspace from "@/lib/swr/use-workspace";
-import { ReferralFormDataField, ReferralProps } from "@/lib/types";
-import { updateReferralSchema } from "@/lib/zod/schemas/referrals";
+import { SubmittedLeadFormDataField, SubmittedLeadProps } from "@/lib/types";
+import { updateSubmittedLeadSchema } from "@/lib/zod/schemas/submitted-leads";
import { CountryCombobox } from "@/ui/partners/country-combobox";
import { Button, Modal, useMediaQuery } from "@dub/ui";
import { COUNTRIES } from "@dub/utils";
@@ -14,21 +14,21 @@ import { Controller, useForm } from "react-hook-form";
import { toast } from "sonner";
import * as z from "zod/v4";
-type EditReferralFormData = Omit<
- z.infer<typeof updateReferralSchema>,
- "workspaceId" | "referralId" | "formData"
+type EditSubmittedLeadFormData = Omit<
+ z.infer<typeof updateSubmittedLeadSchema>,
+ "workspaceId" | "leadId" | "formData"
> & {
formData: Record<string, unknown>;
};
-type EditReferralModalProps = {
+type EditSubmittedLeadModalProps = {
showModal: boolean;
setShowModal: (showModal: boolean) => void;
- referral: ReferralProps;
+ lead: SubmittedLeadProps;
};
function getInputTypeForField(
- fieldType: ReferralFormDataField["type"],
+ fieldType: SubmittedLeadFormDataField["type"],
): string {
if (fieldType === "number") return "number";
if (fieldType === "phone") return "tel";
@@ -37,7 +37,7 @@ function getInputTypeForField(
}
function convertFormDataArrayToObject(
- formData: ReferralFormDataField[] | null | undefined,
+ formData: SubmittedLeadFormDataField[] | null | undefined,
): Record<string, unknown> {
if (!formData) return {};
@@ -47,15 +47,15 @@ function convertFormDataArrayToObject(
}, {});
}
-function EditReferralModal({
+function EditSubmittedLeadModal({
showModal,
setShowModal,
- referral,
-}: EditReferralModalProps) {
+ lead,
+}: EditSubmittedLeadModalProps) {
const { isMobile } = useMediaQuery();
const { id: workspaceId, defaultProgramId } = useWorkspace();
- const customFormData = referral.formData ?? [];
+ const customFormData = lead.formData ?? [];
const {
register,
@@ -63,11 +63,11 @@ function EditReferralModal({
handleSubmit,
reset,
formState: { isDirty },
- } = useForm<EditReferralFormData>({
+ } = useForm<EditSubmittedLeadFormData>({
defaultValues: {
- name: referral.name || "",
- email: referral.email || "",
- company: referral.company || "",
+ name: lead.name || "",
+ email: lead.email || "",
+ company: lead.company || "",
formData: convertFormDataArrayToObject(customFormData),
},
});
@@ -76,34 +76,34 @@ function EditReferralModal({
useEffect(() => {
if (showModal) {
reset({
- name: referral.name || "",
- email: referral.email || "",
- company: referral.company || "",
+ name: lead.name || "",
+ email: lead.email || "",
+ company: lead.company || "",
formData: convertFormDataArrayToObject(customFormData),
});
}
- }, [showModal, referral, reset, customFormData]);
+ }, [showModal, lead, reset, customFormData]);
- const { executeAsync, isPending } = useAction(updateReferralAction, {
+ const { executeAsync, isPending } = useAction(updateSubmittedLeadAction, {
onSuccess: async () => {
setShowModal(false);
- await mutatePrefix(`/api/programs/${defaultProgramId}/referrals`);
- toast.success("Referral updated successfully!");
+ await mutatePrefix(`/api/programs/${defaultProgramId}/submitted-leads`);
+ toast.success("Lead updated successfully!");
},
onError({ error }) {
- toast.error(error.serverError || "Failed to update referral");
+ toast.error(error.serverError || "Failed to update lead");
},
});
- const onSubmit = async (data: EditReferralFormData) => {
- if (!workspaceId || !referral.id) {
+ const onSubmit = async (data: EditSubmittedLeadFormData) => {
+ if (!workspaceId || !lead.id) {
return;
}
- const originalFormData = referral.formData ?? [];
+ const originalFormData = lead.formData ?? [];
// Convert formData back to array format with preserved metadata
- const updatedFormData: ReferralFormDataField[] = originalFormData.map(
+ const updatedFormData: SubmittedLeadFormDataField[] = originalFormData.map(
(field) => ({
...field,
value:
@@ -113,7 +113,7 @@ function EditReferralModal({
await executeAsync({
workspaceId,
- referralId: referral.id,
+ leadId: lead.id,
name: data.name,
email: data.email,
company: data.company,
@@ -124,7 +124,7 @@ function EditReferralModal({
return (
<Modal showModal={showModal} setShowModal={setShowModal}>
<div className="space-y-2 border-b border-neutral-200 px-4 py-4 sm:px-6">
- <h3 className="text-lg font-medium">Edit referral</h3>
+ <h3 className="text-lg font-medium">Edit lead</h3>
</div>
<div className="bg-neutral-50">
@@ -286,35 +286,35 @@ function EditReferralModal({
);
}
-export function useEditReferralModal() {
- const [referral, setReferral] = useState<ReferralProps | null>(null);
+export function useEditSubmittedLeadModal() {
+ const [lead, setLead] = useState<SubmittedLeadProps | null>(null);
- function openEditReferralModal(referral: ReferralProps) {
- setReferral(referral);
+ function openEditSubmittedLeadModal(lead: SubmittedLeadProps) {
+ setLead(lead);
}
- function closeEditReferralModal() {
- setReferral(null);
+ function closeEditSubmittedLeadModal() {
+ setLead(null);
}
- function EditReferralModalWrapper() {
- if (!referral) return null;
+ function EditSubmittedLeadModalWrapper() {
+ if (!lead) return null;
return (
- <EditReferralModal
- referral={referral}
+ <EditSubmittedLeadModal
+ lead={lead}
showModal
setShowModal={(show) => {
- if (!show) closeEditReferralModal();
+ if (!show) closeEditSubmittedLeadModal();
}}
/>
);
}
return {
- openEditReferralModal,
- closeEditReferralModal,
- EditReferralModal: EditReferralModalWrapper,
- isEditReferralModalOpen: referral !== null,
+ openEditSubmittedLeadModal,
+ closeEditSubmittedLeadModal,
+ EditSubmittedLeadModal: EditSubmittedLeadModalWrapper,
+ isEditSubmittedLeadModalOpen: lead !== null,
};
}
diff --git a/apps/web/ui/partners/rewards/rewards-logic.tsx b/apps/web/ui/partners/rewards/rewards-logic.tsx
index 6d4c04a187..d09f277b1e 100644
--- a/apps/web/ui/partners/rewards/rewards-logic.tsx
+++ b/apps/web/ui/partners/rewards/rewards-logic.tsx
@@ -2,7 +2,7 @@
import { constructRewardAmount } from "@/lib/api/sales/construct-reward-amount";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
-import { REFERRAL_ENABLED_PROGRAM_IDS } from "@/lib/referrals/constants";
+import { SUBMITTED_LEADS_ENABLED_PROGRAM_IDS } from "@/lib/submitted-leads/constants";
import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
import { RECURRING_MAX_DURATIONS } from "@/lib/zod/schemas/misc";
@@ -427,7 +427,9 @@ function ConditionLogic({
(attribute) =>
attribute.id !== "source" ||
(program &&
- REFERRAL_ENABLED_PROGRAM_IDS.includes(program.id)),
+ SUBMITTED_LEADS_ENABLED_PROGRAM_IDS.includes(
+ program.id,
+ )),
)
.map((attribute) => ({
text: attribute.label,
diff --git a/apps/web/ui/referrals/referral-form.tsx b/apps/web/ui/referrals/referral-form.tsx
deleted file mode 100644
index 78a234e5b6..0000000000
--- a/apps/web/ui/referrals/referral-form.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-"use client";
-
-import {
- REFERRAL_FORM_FIELD_INPUT_PROPS,
- REFERRAL_FORM_REQUIRED_FIELDS,
-} from "@/lib/referrals/constants";
-import { referralFormSchema } from "@/lib/zod/schemas/referral-form";
-import { useMemo } from "react";
-import * as z from "zod/v4";
-import { ReferralFormField } from "./form-fields";
-
-export function ReferralForm({
- referralFormData,
-}: {
- referralFormData: z.infer<typeof referralFormSchema>;
-}) {
- // Combine required fields with custom fields and sort by position
- const allFields = useMemo(() => {
- const customFields = referralFormData.fields || [];
-
- return [...REFERRAL_FORM_REQUIRED_FIELDS, ...customFields].sort(
- (a, b) => a.position - b.position,
- );
- }, [referralFormData.fields]);
-
- return (
- <div className="flex flex-col gap-5">
- {allFields.map((field) => {
- const keyPath = `formData.${field.key}`;
- const inputProps = REFERRAL_FORM_FIELD_INPUT_PROPS[field.key];
-
- return (
- <ReferralFormField
- key={field.key}
- field={field}
- keyPath={keyPath}
- {...(inputProps && { inputProps })}
- />
- );
- })}
- </div>
- );
-}
diff --git a/apps/web/ui/referrals/referral-status-badge.tsx b/apps/web/ui/referrals/referral-status-badge.tsx
deleted file mode 100644
index f1a87897c7..0000000000
--- a/apps/web/ui/referrals/referral-status-badge.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { ReferralStatus } from "@dub/prisma/client";
-import { StatusBadge } from "@dub/ui";
-import { ReferralStatusBadges } from "./referral-status-badges";
-
-interface ReferralStatusBadgeProps {
- status: ReferralStatus;
- className?: string;
-}
-
-export function ReferralStatusBadge({
- status,
- className,
-}: ReferralStatusBadgeProps) {
- const badge = ReferralStatusBadges[status];
-
- return (
- <StatusBadge
- variant={badge.variant}
- icon={null}
- className={`border-0 ${badge.className} ${className || ""}`}
- >
- {badge.label}
- </StatusBadge>
- );
-}
diff --git a/apps/web/ui/referrals/form-fields/country-field.tsx b/apps/web/ui/submitted-leads/form-fields/country-field.tsx
similarity index 94%
rename from apps/web/ui/referrals/form-fields/country-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/country-field.tsx
index 0fca2ec5e7..fc65ae27a5 100644
--- a/apps/web/ui/referrals/form-fields/country-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/country-field.tsx
@@ -1,4 +1,4 @@
-import { countryFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { countryFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { CountryCombobox } from "@/ui/partners/country-combobox";
import { Controller, useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/referrals/form-fields/date-field.tsx b/apps/web/ui/submitted-leads/form-fields/date-field.tsx
similarity index 94%
rename from apps/web/ui/referrals/form-fields/date-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/date-field.tsx
index 00f3012596..a67b726a87 100644
--- a/apps/web/ui/referrals/form-fields/date-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/date-field.tsx
@@ -1,4 +1,4 @@
-import { dateFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { dateFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { cn } from "@dub/utils";
import { useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/referrals/form-fields/form-control.tsx b/apps/web/ui/submitted-leads/form-fields/form-control.tsx
similarity index 100%
rename from apps/web/ui/referrals/form-fields/form-control.tsx
rename to apps/web/ui/submitted-leads/form-fields/form-control.tsx
diff --git a/apps/web/ui/referrals/form-fields/index.tsx b/apps/web/ui/submitted-leads/form-fields/index.tsx
similarity index 87%
rename from apps/web/ui/referrals/form-fields/index.tsx
rename to apps/web/ui/submitted-leads/form-fields/index.tsx
index bcec1f7f4d..e17f563a66 100644
--- a/apps/web/ui/referrals/form-fields/index.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/index.tsx
@@ -1,4 +1,4 @@
-import { formFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { formFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import * as z from "zod/v4";
import { CountryField } from "./country-field";
import { DateField } from "./date-field";
@@ -22,17 +22,17 @@ const FIELD_COMPONENTS: Record<
phone: PhoneField,
};
-interface ReferralFormFieldProps {
+interface LeadFormFieldProps {
field: z.infer<typeof formFieldSchema>;
keyPath?: string;
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
}
-export const ReferralFormField = ({
+export const LeadFormField = ({
field,
keyPath,
inputProps,
-}: ReferralFormFieldProps) => {
+}: LeadFormFieldProps) => {
// Handle text fields specially to pass inputProps
if (field.type === "text") {
return (
diff --git a/apps/web/ui/referrals/form-fields/max-character-count.tsx b/apps/web/ui/submitted-leads/form-fields/max-character-count.tsx
similarity index 100%
rename from apps/web/ui/referrals/form-fields/max-character-count.tsx
rename to apps/web/ui/submitted-leads/form-fields/max-character-count.tsx
diff --git a/apps/web/ui/referrals/form-fields/multi-select-field.tsx b/apps/web/ui/submitted-leads/form-fields/multi-select-field.tsx
similarity index 97%
rename from apps/web/ui/referrals/form-fields/multi-select-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/multi-select-field.tsx
index 45757ee476..4211bafd5c 100644
--- a/apps/web/ui/referrals/form-fields/multi-select-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/multi-select-field.tsx
@@ -1,4 +1,4 @@
-import { multiSelectFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { multiSelectFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { Checkbox } from "@dub/ui";
import { Controller, useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/referrals/form-fields/number-field.tsx b/apps/web/ui/submitted-leads/form-fields/number-field.tsx
similarity index 94%
rename from apps/web/ui/referrals/form-fields/number-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/number-field.tsx
index a6c1e58aa3..1db6a79d26 100644
--- a/apps/web/ui/referrals/form-fields/number-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/number-field.tsx
@@ -1,4 +1,4 @@
-import { numberFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { numberFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { cn } from "@dub/utils";
import { useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/referrals/form-fields/phone-field.tsx b/apps/web/ui/submitted-leads/form-fields/phone-field.tsx
similarity index 94%
rename from apps/web/ui/referrals/form-fields/phone-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/phone-field.tsx
index 8afe08c079..578c096e37 100644
--- a/apps/web/ui/referrals/form-fields/phone-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/phone-field.tsx
@@ -1,4 +1,4 @@
-import { phoneFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { phoneFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { cn } from "@dub/utils";
import { useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/referrals/form-fields/select-field.tsx b/apps/web/ui/submitted-leads/form-fields/select-field.tsx
similarity index 96%
rename from apps/web/ui/referrals/form-fields/select-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/select-field.tsx
index b99b637bc0..28c73cb34c 100644
--- a/apps/web/ui/referrals/form-fields/select-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/select-field.tsx
@@ -1,4 +1,4 @@
-import { selectFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { selectFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { Combobox } from "@dub/ui";
import { cn } from "@dub/utils";
import { Controller, useFormContext } from "react-hook-form";
diff --git a/apps/web/ui/referrals/form-fields/text-field.tsx b/apps/web/ui/submitted-leads/form-fields/text-field.tsx
similarity index 96%
rename from apps/web/ui/referrals/form-fields/text-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/text-field.tsx
index 050f26b6d9..028c13474a 100644
--- a/apps/web/ui/referrals/form-fields/text-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/text-field.tsx
@@ -1,4 +1,4 @@
-import { textFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { textFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { cn } from "@dub/utils";
import { useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/referrals/form-fields/textarea-field.tsx b/apps/web/ui/submitted-leads/form-fields/textarea-field.tsx
similarity index 95%
rename from apps/web/ui/referrals/form-fields/textarea-field.tsx
rename to apps/web/ui/submitted-leads/form-fields/textarea-field.tsx
index b84c0c5c01..a67bbd38ff 100644
--- a/apps/web/ui/referrals/form-fields/textarea-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/textarea-field.tsx
@@ -1,4 +1,4 @@
-import { textareaFieldSchema } from "@/lib/zod/schemas/referral-form";
+import { textareaFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { cn } from "@dub/utils";
import { useFormContext } from "react-hook-form";
import * as z from "zod/v4";
diff --git a/apps/web/ui/submitted-leads/lead-form.tsx b/apps/web/ui/submitted-leads/lead-form.tsx
new file mode 100644
index 0000000000..fbe01831d8
--- /dev/null
+++ b/apps/web/ui/submitted-leads/lead-form.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import {
+ SUBMITTED_LEAD_FORM_FIELD_INPUT_PROPS,
+ SUBMITTED_LEAD_FORM_REQUIRED_FIELDS,
+} from "@/lib/submitted-leads/constants";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
+import { useMemo } from "react";
+import * as z from "zod/v4";
+import { LeadFormField } from "./form-fields";
+
+export function LeadForm({
+ leadFormData,
+}: {
+ leadFormData: z.infer<typeof submittedLeadFormSchema>;
+}) {
+ // Combine required fields with custom fields and sort by position
+ const allFields = useMemo(() => {
+ const customFields = leadFormData.fields || [];
+
+ return [...SUBMITTED_LEAD_FORM_REQUIRED_FIELDS, ...customFields].sort(
+ (a, b) => a.position - b.position,
+ );
+ }, [leadFormData.fields]);
+
+ return (
+ <div className="flex flex-col gap-5">
+ {allFields.map((field) => {
+ const keyPath = `formData.${field.key}`;
+ const inputProps = SUBMITTED_LEAD_FORM_FIELD_INPUT_PROPS[field.key];
+
+ return (
+ <LeadFormField
+ key={field.key}
+ field={field}
+ keyPath={keyPath}
+ {...(inputProps && { inputProps })}
+ />
+ );
+ })}
+ </div>
+ );
+}
diff --git a/apps/web/ui/referrals/partner-profile-referral-sheet.tsx b/apps/web/ui/submitted-leads/partner-profile-submitted-lead-sheet.tsx
similarity index 71%
rename from apps/web/ui/referrals/partner-profile-referral-sheet.tsx
rename to apps/web/ui/submitted-leads/partner-profile-submitted-lead-sheet.tsx
index 523157f701..a228c240ad 100644
--- a/apps/web/ui/referrals/partner-profile-referral-sheet.tsx
+++ b/apps/web/ui/submitted-leads/partner-profile-submitted-lead-sheet.tsx
@@ -1,5 +1,5 @@
-import { PartnerProfileReferral } from "@/lib/zod/schemas/partner-profile";
-import { PartnerReferralActivitySection } from "@/ui/activity-logs/partner-referral-activity-section";
+import { PartnerProfileSubmittedLead } from "@/lib/zod/schemas/partner-profile";
+import { SubmittedLeadActivitySectionPartner } from "@/ui/activity-logs/submitted-lead-activity-section-partner";
import { X } from "@/ui/shared/icons";
import {
Button,
@@ -10,21 +10,21 @@ import {
useRouterStuff,
} from "@dub/ui";
import { Dispatch, SetStateAction } from "react";
-import { ReferralDetails } from "./referral-details";
-import { ReferralLeadDetails } from "./referral-lead-details";
+import { SubmittedLeadContactDetails } from "./submitted-lead-contact-details";
+import { SubmittedLeadDetails } from "./submitted-lead-details";
-type PartnerProfileReferralSheetProps = {
- referral: PartnerProfileReferral;
+type PartnerProfileSubmittedLeadSheetProps = {
+ lead: PartnerProfileSubmittedLead;
onNext?: () => void;
onPrevious?: () => void;
setIsOpen: Dispatch<SetStateAction<boolean>>;
};
-function PartnerProfileReferralSheetContent({
- referral,
+function PartnerProfileSubmittedLeadSheetContent({
+ lead,
onPrevious,
onNext,
-}: Omit<PartnerProfileReferralSheetProps, "setIsOpen">) {
+}: Omit<PartnerProfileSubmittedLeadSheetProps, "setIsOpen">) {
// right arrow key onNext
useKeyboardShortcut(
"ArrowRight",
@@ -51,7 +51,7 @@ function PartnerProfileReferralSheetContent({
<div className="flex size-full flex-col">
<div className="flex h-16 shrink-0 items-center justify-between border-b border-neutral-200 px-6 py-4">
<Sheet.Title className="text-lg font-semibold">
- Referral details
+ Lead details
</Sheet.Title>
<div className="flex items-center gap-4">
<div className="flex items-center">
@@ -83,26 +83,26 @@ function PartnerProfileReferralSheetContent({
</div>
<div className="@3xl/sheet:grid-cols-[minmax(440px,1fr)_minmax(0,360px)] scrollbar-hide grid min-h-0 grow grid-cols-1 gap-x-6 gap-y-2 overflow-y-auto p-4 sm:gap-y-4 sm:p-6">
- {/* Left side - Referral details */}
+ {/* Left side - Lead details */}
<div className="flex flex-col gap-6">
- <ReferralDetails referral={{ formData: referral.formData }} />
- <PartnerReferralActivitySection referralId={referral.id} />
+ <SubmittedLeadDetails lead={{ formData: lead.formData }} />
+ <SubmittedLeadActivitySectionPartner leadId={lead.id} />
</div>
{/* Right side - Customer details */}
<div className="@3xl/sheet:order-2 flex flex-col gap-2 sm:gap-4">
- <ReferralLeadDetails referral={referral} mode="readonly" />
+ <SubmittedLeadContactDetails lead={lead} mode="readonly" />
</div>
</div>
</div>
);
}
-export function PartnerProfileReferralSheet({
+export function PartnerProfileSubmittedLeadSheet({
isOpen,
nested,
...rest
-}: PartnerProfileReferralSheetProps & {
+}: PartnerProfileSubmittedLeadSheetProps & {
isOpen: boolean;
nested?: boolean;
}) {
@@ -111,14 +111,14 @@ export function PartnerProfileReferralSheet({
<Sheet
open={isOpen}
onOpenChange={rest.setIsOpen}
- onClose={() => queryParams({ del: "referralId", scroll: false })}
+ onClose={() => queryParams({ del: "leadId", scroll: false })}
nested={nested}
contentProps={{
// 540px - 1170px width based on viewport
className: "md:w-[max(min(calc(100vw-334px),1170px),540px)]",
}}
>
- <PartnerProfileReferralSheetContent {...rest} />
+ <PartnerProfileSubmittedLeadSheetContent {...rest} />
</Sheet>
);
}
diff --git a/apps/web/ui/referrals/partner-profile-referrals-empty-state.tsx b/apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx
similarity index 78%
rename from apps/web/ui/referrals/partner-profile-referrals-empty-state.tsx
rename to apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx
index cb2de3e3f3..03544b0629 100644
--- a/apps/web/ui/referrals/partner-profile-referrals-empty-state.tsx
+++ b/apps/web/ui/submitted-leads/partner-profile-submitted-leads-empty-state.tsx
@@ -1,9 +1,9 @@
"use client";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
-import { referralFormSchema } from "@/lib/zod/schemas/referral-form";
-import { SubmitReferralSheet } from "@/ui/referrals/submit-referral-sheet";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { SubmitLeadSheet } from "@/ui/submitted-leads/submit-lead-sheet";
import { Button } from "@dub/ui";
import { cn } from "@dub/utils";
import { useMemo, useState } from "react";
@@ -68,46 +68,46 @@ const EMPTY_STATE_CARDS = [
},
];
-export function PartnerProfileReferralsEmptyState() {
+export function PartnerProfileSubmittedLeadsEmptyState() {
const { programEnrollment } = useProgramEnrollment();
- const [showReferralSheet, setShowReferralSheet] = useState(false);
+ const [showLeadSheet, setShowLeadSheet] = useState(false);
- const referralFormDataRaw = programEnrollment?.program?.referralFormData;
- const submittedReferralsEnabled = referralFormDataRaw !== null;
+ const leadFormDataRaw = programEnrollment?.program?.referralFormData;
+ const submittedLeadsEnabled = leadFormDataRaw !== null;
- const referralFormData = useMemo(() => {
- if (!referralFormDataRaw) {
+ const leadFormData = useMemo(() => {
+ if (!leadFormDataRaw) {
return null;
}
try {
- return referralFormSchema.parse(referralFormDataRaw) as z.infer<
- typeof referralFormSchema
+ return submittedLeadFormSchema.parse(leadFormDataRaw) as z.infer<
+ typeof submittedLeadFormSchema
>;
} catch {
return null;
}
- }, [referralFormDataRaw]);
+ }, [leadFormDataRaw]);
return (
<>
<AnimatedEmptyState
title={
- submittedReferralsEnabled
- ? "No referrals submitted"
- : "Submitted referrals not offered"
+ submittedLeadsEnabled
+ ? "No leads submitted"
+ : "Submitted leads not offered"
}
description={
- submittedReferralsEnabled
+ submittedLeadsEnabled
? "Submit leads and track their progress through the sales process."
: "You can still earn from regular referrals using your links and codes."
}
learnMoreHref="https://dub.co/help/article/submitted-referrals"
addButton={
- submittedReferralsEnabled ? (
+ submittedLeadsEnabled ? (
<Button
type="button"
- text="Submit referral"
- onClick={() => setShowReferralSheet(true)}
+ text="Submit lead"
+ onClick={() => setShowLeadSheet(true)}
className="h-9 rounded-lg"
/>
) : undefined
@@ -149,12 +149,12 @@ export function PartnerProfileReferralsEmptyState() {
cardContainerClassName="max-w-96"
cardClassName="rounded-xl"
/>
- {referralFormData && programEnrollment?.programId && (
- <SubmitReferralSheet
- isOpen={showReferralSheet}
- setIsOpen={setShowReferralSheet}
+ {leadFormData && programEnrollment?.programId && (
+ <SubmitLeadSheet
+ isOpen={showLeadSheet}
+ setIsOpen={setShowLeadSheet}
programId={programEnrollment.programId}
- referralFormData={referralFormData}
+ leadFormData={leadFormData}
/>
)}
</>
diff --git a/apps/web/ui/referrals/submit-referral-sheet.tsx b/apps/web/ui/submitted-leads/submit-lead-sheet.tsx
similarity index 75%
rename from apps/web/ui/referrals/submit-referral-sheet.tsx
rename to apps/web/ui/submitted-leads/submit-lead-sheet.tsx
index cca8d6b7cc..75d3bfb12f 100644
--- a/apps/web/ui/referrals/submit-referral-sheet.tsx
+++ b/apps/web/ui/submitted-leads/submit-lead-sheet.tsx
@@ -1,8 +1,8 @@
"use client";
-import { submitReferralAction } from "@/lib/actions/referrals/submit-referral";
+import { submitLeadAction } from "@/lib/submitted-leads/submit-lead-action";
import { mutatePrefix } from "@/lib/swr/mutate";
-import { referralFormSchema } from "@/lib/zod/schemas/referral-form";
+import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";
import { X } from "@/ui/shared/icons";
import { Button, Sheet } from "@dub/ui";
import { useAction } from "next-safe-action/hooks";
@@ -11,38 +11,38 @@ import { Dispatch, SetStateAction, useMemo } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { toast } from "sonner";
import * as z from "zod/v4";
-import { ReferralForm } from "./referral-form";
+import { LeadForm } from "./lead-form";
-interface SubmitReferralSheetProps {
+interface SubmitLeadSheetProps {
isOpen: boolean;
setIsOpen: Dispatch<SetStateAction<boolean>>;
programId: string;
- referralFormData: z.infer<typeof referralFormSchema>;
+ leadFormData: z.infer<typeof submittedLeadFormSchema>;
onSuccess?: () => void;
}
-type ReferralFormData = {
+type LeadFormData = {
formData: Record<string, any>;
};
-export function SubmitReferralSheet({
+export function SubmitLeadSheet({
isOpen,
setIsOpen,
programId,
- referralFormData,
+ leadFormData,
onSuccess,
-}: SubmitReferralSheetProps) {
+}: SubmitLeadSheetProps) {
const { programSlug } = useParams<{ programSlug: string }>();
const validatedFormData = useMemo(() => {
try {
- return referralFormSchema.parse(referralFormData);
+ return submittedLeadFormSchema.parse(leadFormData);
} catch {
return null;
}
- }, [referralFormData]);
+ }, [leadFormData]);
- const form = useForm<ReferralFormData>({
+ const form = useForm<LeadFormData>({
defaultValues: {
formData: {},
},
@@ -50,22 +50,22 @@ export function SubmitReferralSheet({
const { handleSubmit, setError, reset } = form;
- const { executeAsync, isPending } = useAction(submitReferralAction, {
+ const { executeAsync, isPending } = useAction(submitLeadAction, {
onSuccess: async () => {
- toast.success("Referral submitted successfully");
+ toast.success("Lead submitted successfully.");
reset();
onSuccess?.();
setIsOpen(false);
if (programSlug) {
await mutatePrefix([
- `/api/partner-profile/programs/${programSlug}/referrals`,
- `/api/partner-profile/programs/${programSlug}/referrals/count`,
+ `/api/partner-profile/programs/${programSlug}/submitted-leads`,
+ `/api/partner-profile/programs/${programSlug}/submitted-leads/count`,
]);
}
},
onError: ({ error }) => {
- const errorMessage = error.serverError || "Failed to submit referral";
+ const errorMessage = error.serverError || "Failed to submit lead";
toast.error(errorMessage);
setError("root.serverError", {
message: errorMessage,
@@ -73,7 +73,7 @@ export function SubmitReferralSheet({
},
});
- const onSubmit = async (data: ReferralFormData) => {
+ const onSubmit = async (data: LeadFormData) => {
if (!validatedFormData) {
return;
}
@@ -111,7 +111,7 @@ export function SubmitReferralSheet({
<div className="sticky top-0 z-10 border-b border-neutral-200 bg-neutral-50">
<div className="flex h-16 items-center justify-between px-6 py-4">
<Sheet.Title className="text-lg font-semibold">
- Submit Referral
+ Submit Lead
</Sheet.Title>
<Sheet.Close asChild>
<Button
@@ -125,7 +125,7 @@ export function SubmitReferralSheet({
<div className="min-h-0 flex-1 overflow-y-auto">
<div className="flex flex-col gap-6 p-5 sm:p-6">
- <ReferralForm referralFormData={validatedFormData} />
+ <LeadForm leadFormData={validatedFormData} />
</div>
</div>
@@ -133,7 +133,7 @@ export function SubmitReferralSheet({
<Button
type="submit"
variant="primary"
- text="Submit Referral"
+ text="Submit Lead"
loading={isPending}
/>
</div>
diff --git a/apps/web/ui/referrals/referral-lead-details.tsx b/apps/web/ui/submitted-leads/submitted-lead-contact-details.tsx
similarity index 52%
rename from apps/web/ui/referrals/referral-lead-details.tsx
rename to apps/web/ui/submitted-leads/submitted-lead-contact-details.tsx
index 5017730b74..ffb8d85894 100644
--- a/apps/web/ui/referrals/referral-lead-details.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-contact-details.tsx
@@ -1,59 +1,63 @@
"use client";
-import { ReferralProps } from "@/lib/types";
-import { useConfirmReferralStatusChangeModal } from "@/ui/modals/confirm-referral-status-change-modal";
-import { useEditReferralModal } from "@/ui/modals/edit-referral-modal";
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadProps } from "@/lib/types";
+import { useConfirmSubmittedLeadStatusChangeModal } from "@/ui/modals/confirm-submitted-lead-status-change-modal";
+import { useEditSubmittedLeadModal } from "@/ui/modals/edit-submitted-lead-modal";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { Button, Envelope, OfficeBuilding } from "@dub/ui";
import { OG_AVATAR_URL } from "@dub/utils";
import { Pencil } from "lucide-react";
-import { ReferralStatusBadge } from "./referral-status-badge";
-import { ReferralStatusDropdown } from "./referral-status-dropdown";
-import { getCompanyLogoUrl } from "./referral-utils";
+import { SubmittedLeadStatusBadge } from "./submitted-lead-status-badge";
+import { SubmittedLeadStatusDropdown } from "./submitted-lead-status-dropdown";
+import { getCompanyLogoUrl } from "./submitted-lead-utils";
-interface ReferralLeadDetailsProps {
- referral: Pick<ReferralProps, "id" | "name" | "email" | "company" | "status">;
+interface SubmittedLeadContactDetailsProps {
+ lead: Pick<
+ SubmittedLeadProps,
+ "id" | "name" | "email" | "company" | "status"
+ >;
mode?: "interactive" | "readonly";
- selectedStatus?: ReferralStatus;
- onStatusChange?: (newStatus: ReferralStatus) => void;
+ selectedStatus?: SubmittedLeadStatus;
+ onStatusChange?: (newStatus: SubmittedLeadStatus) => void;
}
-export function ReferralLeadDetails({
- referral,
+export function SubmittedLeadContactDetails({
+ lead,
mode = "interactive",
selectedStatus,
onStatusChange,
-}: ReferralLeadDetailsProps) {
- const { EditReferralModal, openEditReferralModal } = useEditReferralModal();
+}: SubmittedLeadContactDetailsProps) {
+ const { EditSubmittedLeadModal, openEditSubmittedLeadModal } =
+ useEditSubmittedLeadModal();
+
const {
- ConfirmReferralStatusChangeModal,
- openConfirmReferralStatusChangeModal,
- } = useConfirmReferralStatusChangeModal();
+ ConfirmSubmittedLeadStatusChangeModal,
+ openConfirmSubmittedLeadStatusChangeModal,
+ } = useConfirmSubmittedLeadStatusChangeModal();
const isInteractive = mode === "interactive";
const isControlled = onStatusChange !== undefined;
- const handleStatusChange = (newStatus: ReferralStatus) => {
+ const handleStatusChange = (newStatus: SubmittedLeadStatus) => {
if (onStatusChange) {
onStatusChange(newStatus);
} else {
- openConfirmReferralStatusChangeModal(referral, newStatus);
+ openConfirmSubmittedLeadStatusChangeModal(lead, newStatus);
}
};
return (
<>
- {isInteractive && <EditReferralModal />}
- {isInteractive && !isControlled && ConfirmReferralStatusChangeModal}
+ {isInteractive && <EditSubmittedLeadModal />}
+ {isInteractive && !isControlled && ConfirmSubmittedLeadStatusChangeModal}
<div className="border-border-subtle overflow-hidden rounded-xl border bg-white">
<div className="flex items-start justify-between px-4 pt-4">
<div className="relative w-fit shrink-0">
<img
src={
- getCompanyLogoUrl(referral.email) ||
- `${OG_AVATAR_URL}${referral.id}`
+ getCompanyLogoUrl(lead.email) || `${OG_AVATAR_URL}${lead.id}`
}
- alt={referral.company}
+ alt={lead.company}
className="size-10 rounded-full"
/>
</div>
@@ -65,21 +69,23 @@ export function ReferralLeadDetails({
icon={<Pencil className="size-3.5" />}
text="Edit"
className="h-7 w-fit rounded-lg px-2"
- onClick={() => openEditReferralModal(referral as ReferralProps)}
+ onClick={() =>
+ openEditSubmittedLeadModal(lead as SubmittedLeadProps)
+ }
/>
)}
</div>
<div className="mt-2 px-4">
<div className="text-content-emphasis text-base font-semibold">
- {referral.name}
+ {lead.name}
</div>
</div>
<div className="mt-2 flex flex-col gap-2 px-4">
{[
- { icon: Envelope, value: referral.email },
- { icon: OfficeBuilding, value: referral.company },
+ { icon: Envelope, value: lead.email },
+ { icon: OfficeBuilding, value: lead.company },
].map(({ icon: Icon, value }, index) => (
<div
key={index}
@@ -95,16 +101,16 @@ export function ReferralLeadDetails({
<div className="mt-4 border-t border-neutral-200 p-4">
<div className="text-content-emphasis mb-2 text-base font-semibold">
- Referral stage
+ Lead stage
</div>
{isInteractive ? (
- <ReferralStatusDropdown
- referral={referral as ReferralProps}
+ <SubmittedLeadStatusDropdown
+ lead={lead as SubmittedLeadProps}
selectedStatus={selectedStatus}
onStatusChange={handleStatusChange}
/>
) : (
- <ReferralStatusBadge status={referral.status} />
+ <SubmittedLeadStatusBadge status={lead.status} />
)}
</div>
</div>
diff --git a/apps/web/ui/referrals/referral-details.tsx b/apps/web/ui/submitted-leads/submitted-lead-details.tsx
similarity index 69%
rename from apps/web/ui/referrals/referral-details.tsx
rename to apps/web/ui/submitted-leads/submitted-lead-details.tsx
index 4e2a618ae8..78dd3f9822 100644
--- a/apps/web/ui/referrals/referral-details.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-details.tsx
@@ -1,13 +1,13 @@
-import { ReferralFormDataField, ReferralProps } from "@/lib/types";
-import { formatFormDataValue } from "./referral-utils";
+import { SubmittedLeadFormDataField, SubmittedLeadProps } from "@/lib/types";
+import { formatFormDataValue } from "./submitted-lead-utils";
-interface ReferralDetailsProps {
- referral: Pick<ReferralProps, "formData">;
+interface SubmittedLeadDetailsProps {
+ lead: Pick<SubmittedLeadProps, "formData">;
}
-export function ReferralDetails({ referral }: ReferralDetailsProps) {
- const formData = referral.formData as
- | ReferralFormDataField[]
+export function SubmittedLeadDetails({ lead }: SubmittedLeadDetailsProps) {
+ const formData = lead.formData as
+ | SubmittedLeadFormDataField[]
| null
| undefined;
@@ -22,9 +22,6 @@ export function ReferralDetails({ referral }: ReferralDetailsProps) {
return (
<div className="@3xl/sheet:order-1">
<div className="border-border-subtle overflow-hidden rounded-xl border bg-white p-4">
- <h3 className="text-content-emphasis mb-4 text-lg font-semibold">
- Referral details
- </h3>
<div className="grid grid-cols-1 gap-4 text-sm text-neutral-600">
{displayFormData?.map((field) => (
<div key={field.key}>
diff --git a/apps/web/ui/referrals/referral-partner-details.tsx b/apps/web/ui/submitted-leads/submitted-lead-partner-details.tsx
similarity index 68%
rename from apps/web/ui/referrals/referral-partner-details.tsx
rename to apps/web/ui/submitted-leads/submitted-lead-partner-details.tsx
index a13824839f..ad493dd20d 100644
--- a/apps/web/ui/referrals/referral-partner-details.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-partner-details.tsx
@@ -1,15 +1,15 @@
-import { ReferralProps } from "@/lib/types";
+import { SubmittedLeadProps } from "@/lib/types";
import { PartnerAvatar } from "@/ui/partners/partner-avatar";
import Link from "next/link";
import { useParams } from "next/navigation";
-interface ReferralPartnerDetailsProps {
- referral: ReferralProps;
+interface SubmittedLeadPartnerDetailsProps {
+ lead: SubmittedLeadProps;
}
-export function ReferralPartnerDetails({
- referral,
-}: ReferralPartnerDetailsProps) {
+export function SubmittedLeadPartnerDetails({
+ lead,
+}: SubmittedLeadPartnerDetailsProps) {
const { slug } = useParams();
return (
@@ -18,16 +18,16 @@ export function ReferralPartnerDetails({
Partner
</h3>
<Link
- href={`/${slug}/program/partners/${referral.partner.id}`}
+ href={`/${slug}/program/partners/${lead.partner.id}`}
target="_blank"
className="flex items-center gap-2 transition-opacity hover:opacity-80"
>
<PartnerAvatar
- partner={referral.partner}
+ partner={lead.partner}
className="size-5 border border-neutral-100"
/>
<div className="text-content-emphasis cursor-alias text-sm font-semibold decoration-dotted hover:underline">
- {referral.partner.name}
+ {lead.partner.name}
</div>
</Link>
</div>
diff --git a/apps/web/ui/referrals/partner-referral-sheet.tsx b/apps/web/ui/submitted-leads/submitted-lead-sheet.tsx
similarity index 68%
rename from apps/web/ui/referrals/partner-referral-sheet.tsx
rename to apps/web/ui/submitted-leads/submitted-lead-sheet.tsx
index e8831b8e53..f09a40ec96 100644
--- a/apps/web/ui/referrals/partner-referral-sheet.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-sheet.tsx
@@ -1,7 +1,7 @@
-import { ReferralProps } from "@/lib/types";
-import { useConfirmReferralStatusChangeModal } from "@/ui/modals/confirm-referral-status-change-modal";
+import { SubmittedLeadProps } from "@/lib/types";
+import { useConfirmSubmittedLeadStatusChangeModal } from "@/ui/modals/confirm-submitted-lead-status-change-modal";
import { X } from "@/ui/shared/icons";
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import {
Button,
ChevronLeft,
@@ -11,37 +11,36 @@ import {
useRouterStuff,
} from "@dub/ui";
import { Dispatch, SetStateAction, useState } from "react";
-import { ReferralActivitySection } from "../activity-logs/referral-activity-section";
-import { ReferralDetails } from "./referral-details";
-import { ReferralLeadDetails } from "./referral-lead-details";
-import { ReferralPartnerDetails } from "./referral-partner-details";
+import { SubmittedLeadActivitySection } from "../activity-logs/submitted-lead-activity-section";
+import { SubmittedLeadContactDetails } from "./submitted-lead-contact-details";
+import { SubmittedLeadDetails } from "./submitted-lead-details";
+import { SubmittedLeadPartnerDetails } from "./submitted-lead-partner-details";
-type ReferralSheetProps = {
- referral: ReferralProps;
+type SubmittedLeadSheetProps = {
+ lead: SubmittedLeadProps;
onNext?: () => void;
onPrevious?: () => void;
setIsOpen: Dispatch<SetStateAction<boolean>>;
};
-function ReferralSheetContent({
- referral,
+function SubmittedLeadSheetContent({
+ lead,
onPrevious,
onNext,
setIsOpen,
-}: ReferralSheetProps) {
- const [pendingStatus, setPendingStatus] = useState<ReferralStatus | null>(
- null,
- );
+}: SubmittedLeadSheetProps) {
+ const [pendingStatus, setPendingStatus] =
+ useState<SubmittedLeadStatus | null>(null);
const {
- ConfirmReferralStatusChangeModal,
- openConfirmReferralStatusChangeModal,
- } = useConfirmReferralStatusChangeModal({
+ ConfirmSubmittedLeadStatusChangeModal,
+ openConfirmSubmittedLeadStatusChangeModal,
+ } = useConfirmSubmittedLeadStatusChangeModal({
onClose: () => setPendingStatus(null),
});
const hasPendingStatusChange =
- pendingStatus !== null && pendingStatus !== referral.status;
+ pendingStatus !== null && pendingStatus !== lead.status;
// right arrow key onNext
useKeyboardShortcut(
@@ -74,23 +73,23 @@ function ReferralSheetContent({
{ sheet: true },
);
- const handleStatusChange = (newStatus: ReferralStatus) => {
- setPendingStatus(newStatus === referral.status ? null : newStatus);
+ const handleStatusChange = (newStatus: SubmittedLeadStatus) => {
+ setPendingStatus(newStatus === lead.status ? null : newStatus);
};
const handleSaveStatusChange = () => {
if (pendingStatus !== null) {
- openConfirmReferralStatusChangeModal(referral, pendingStatus);
+ openConfirmSubmittedLeadStatusChangeModal(lead, pendingStatus);
}
};
return (
<>
- {ConfirmReferralStatusChangeModal}
+ {ConfirmSubmittedLeadStatusChangeModal}
<div className="flex size-full flex-col">
<div className="flex h-16 shrink-0 items-center justify-between border-b border-neutral-200 px-6 py-4">
<Sheet.Title className="text-lg font-semibold">
- Partner referral
+ Submitted lead
</Sheet.Title>
<div className="flex items-center gap-4">
<div className="flex items-center">
@@ -122,20 +121,20 @@ function ReferralSheetContent({
</div>
<div className="@3xl/sheet:grid-cols-[minmax(440px,1fr)_minmax(0,360px)] scrollbar-hide grid min-h-0 grow grid-cols-1 gap-x-6 gap-y-4 overflow-y-auto p-4 sm:p-6">
- {/* Left side - Referral details */}
+ {/* Left side - Lead details */}
<div className="flex flex-col gap-6">
- <ReferralDetails referral={{ formData: referral.formData }} />
- <ReferralActivitySection referralId={referral.id} />
+ <SubmittedLeadDetails lead={{ formData: lead.formData }} />
+ <SubmittedLeadActivitySection leadId={lead.id} />
</div>
{/* Right side - Two cards */}
<div className="@3xl/sheet:order-2 flex flex-col gap-4">
- <ReferralLeadDetails
- referral={referral}
- selectedStatus={pendingStatus ?? referral.status}
+ <SubmittedLeadContactDetails
+ lead={lead}
+ selectedStatus={pendingStatus ?? lead.status}
onStatusChange={handleStatusChange}
/>
- <ReferralPartnerDetails referral={referral} />
+ <SubmittedLeadPartnerDetails lead={lead} />
</div>
</div>
@@ -164,11 +163,11 @@ function ReferralSheetContent({
);
}
-export function ReferralSheet({
+export function SubmittedLeadSheet({
isOpen,
nested,
...rest
-}: ReferralSheetProps & {
+}: SubmittedLeadSheetProps & {
isOpen: boolean;
nested?: boolean;
}) {
@@ -177,14 +176,14 @@ export function ReferralSheet({
<Sheet
open={isOpen}
onOpenChange={rest.setIsOpen}
- onClose={() => queryParams({ del: "referralId", scroll: false })}
+ onClose={() => queryParams({ del: "leadId", scroll: false })}
nested={nested}
contentProps={{
// 540px - 1170px width based on viewport
className: "md:w-[max(min(calc(100vw-334px),1170px),540px)]",
}}
>
- <ReferralSheetContent {...rest} />
+ <SubmittedLeadSheetContent {...rest} />
</Sheet>
);
}
diff --git a/apps/web/ui/submitted-leads/submitted-lead-status-badge.tsx b/apps/web/ui/submitted-leads/submitted-lead-status-badge.tsx
new file mode 100644
index 0000000000..259d551ce3
--- /dev/null
+++ b/apps/web/ui/submitted-leads/submitted-lead-status-badge.tsx
@@ -0,0 +1,25 @@
+import { SubmittedLeadStatus } from "@dub/prisma/client";
+import { StatusBadge } from "@dub/ui";
+import { SubmittedLeadStatusBadges } from "./submitted-lead-status-badges";
+
+interface SubmittedLeadStatusBadgeProps {
+ status: SubmittedLeadStatus;
+ className?: string;
+}
+
+export function SubmittedLeadStatusBadge({
+ status,
+ className,
+}: SubmittedLeadStatusBadgeProps) {
+ const badge = SubmittedLeadStatusBadges[status];
+
+ return (
+ <StatusBadge
+ variant={badge.variant}
+ icon={null}
+ className={`border-0 ${badge.className} ${className || ""}`}
+ >
+ {badge.label}
+ </StatusBadge>
+ );
+}
diff --git a/apps/web/ui/referrals/referral-status-badges.ts b/apps/web/ui/submitted-leads/submitted-lead-status-badges.ts
similarity index 90%
rename from apps/web/ui/referrals/referral-status-badges.ts
rename to apps/web/ui/submitted-leads/submitted-lead-status-badges.ts
index d020bbf8fe..987f79c212 100644
--- a/apps/web/ui/referrals/referral-status-badges.ts
+++ b/apps/web/ui/submitted-leads/submitted-lead-status-badges.ts
@@ -1,8 +1,8 @@
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { CircleCheck, CircleHalfDottedClock, CircleXmark } from "@dub/ui/icons";
-export const ReferralStatusBadges: Record<
- ReferralStatus,
+export const SubmittedLeadStatusBadges: Record<
+ SubmittedLeadStatus,
{
label: string;
variant: "new" | "success" | "pending" | "error" | "neutral";
diff --git a/apps/web/ui/referrals/referral-status-dropdown.tsx b/apps/web/ui/submitted-leads/submitted-lead-status-dropdown.tsx
similarity index 74%
rename from apps/web/ui/referrals/referral-status-dropdown.tsx
rename to apps/web/ui/submitted-leads/submitted-lead-status-dropdown.tsx
index ef1f3a18fe..8cee45226a 100644
--- a/apps/web/ui/referrals/referral-status-dropdown.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-status-dropdown.tsx
@@ -1,32 +1,34 @@
"use client";
-import { ReferralProps } from "@/lib/types";
-import { ReferralStatus } from "@dub/prisma/client";
+import { SubmittedLeadProps } from "@/lib/types";
+import { SubmittedLeadStatus } from "@dub/prisma/client";
import { Popover } from "@dub/ui";
import { cn } from "@dub/utils";
import { Check, ChevronDown } from "lucide-react";
import { useState } from "react";
-import { ReferralStatusBadges } from "./referral-status-badges";
+import { SubmittedLeadStatusBadges } from "./submitted-lead-status-badges";
-interface ReferralStatusDropdownProps {
- referral: ReferralProps;
- selectedStatus?: ReferralStatus;
- onStatusChange: (newStatus: ReferralStatus) => void;
+interface SubmittedLeadStatusDropdownProps {
+ lead: SubmittedLeadProps;
+ selectedStatus?: SubmittedLeadStatus;
+ onStatusChange: (newStatus: SubmittedLeadStatus) => void;
}
-export function ReferralStatusDropdown({
- referral,
+export function SubmittedLeadStatusDropdown({
+ lead,
selectedStatus,
onStatusChange,
-}: ReferralStatusDropdownProps) {
+}: SubmittedLeadStatusDropdownProps) {
const [openStatusDropdown, setOpenStatusDropdown] = useState(false);
- const displayStatus = selectedStatus ?? referral.status;
- const currentBadge = ReferralStatusBadges[displayStatus];
- const allStatuses = Object.keys(ReferralStatusBadges) as ReferralStatus[];
+ const displayStatus = selectedStatus ?? lead.status;
+ const currentBadge = SubmittedLeadStatusBadges[displayStatus];
+ const allStatuses = Object.keys(
+ SubmittedLeadStatusBadges,
+ ) as SubmittedLeadStatus[];
- const handleStatusChange = (newStatus: ReferralStatus) => {
- if (newStatus !== referral.status) {
+ const handleStatusChange = (newStatus: SubmittedLeadStatus) => {
+ if (newStatus !== lead.status) {
onStatusChange(newStatus);
}
setOpenStatusDropdown(false);
@@ -40,7 +42,7 @@ export function ReferralStatusDropdown({
content={
<div className="w-full p-2">
{allStatuses.map((status) => {
- const badge = ReferralStatusBadges[status];
+ const badge = SubmittedLeadStatusBadges[status];
const isSelected = status === displayStatus;
return (
<button
diff --git a/apps/web/ui/referrals/partner-referral-table.tsx b/apps/web/ui/submitted-leads/submitted-lead-table.tsx
similarity index 62%
rename from apps/web/ui/referrals/partner-referral-table.tsx
rename to apps/web/ui/submitted-leads/submitted-lead-table.tsx
index 4298f87926..261736dad0 100644
--- a/apps/web/ui/referrals/partner-referral-table.tsx
+++ b/apps/web/ui/submitted-leads/submitted-lead-table.tsx
@@ -1,7 +1,7 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import { referralSchema } from "@/lib/zod/schemas/referrals";
+import { submittedLeadSchema } from "@/lib/zod/schemas/submitted-leads";
import { PartnerRowItem } from "@/ui/partners/partner-row-item";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { SearchBoxPersisted } from "@/ui/shared/search-box";
@@ -21,38 +21,38 @@ import { Row } from "@tanstack/react-table";
import { useEffect, useMemo, useState } from "react";
import useSWR from "swr";
import * as z from "zod/v4";
-import { useProgramReferralsCount } from "../../lib/swr/use-program-referrals-count";
-import { ReferralSheet } from "./partner-referral-sheet";
-import { ReferralStatusBadges } from "./referral-status-badges";
-import { getCompanyLogoUrl } from "./referral-utils";
-import { useProgramReferralsFilters } from "./use-program-referral-filters";
+import { useProgramSubmittedLeadsCount } from "../../lib/swr/use-program-submitted-leads-count";
+import { SubmittedLeadSheet } from "./submitted-lead-sheet";
+import { SubmittedLeadStatusBadges } from "./submitted-lead-status-badges";
+import { getCompanyLogoUrl } from "./submitted-lead-utils";
+import { useProgramSubmittedLeadFilters } from "./use-program-submitted-lead-filters";
-type PartnerReferralProps = z.infer<typeof referralSchema>;
+type SubmittedLeadItem = z.infer<typeof submittedLeadSchema>;
-export function PartnerReferralTable() {
+export function SubmittedLeadTable() {
const { getQueryString, queryParams, searchParams } = useRouterStuff();
const { pagination, setPagination } = usePagination();
const { id: workspaceId, defaultProgramId } = useWorkspace();
- const referralIdFromUrl = searchParams.get("referralId");
+ const leadIdFromUrl = searchParams.get("leadId");
const [detailsSheetState, setDetailsSheetState] = useState<{
- referralId: string | null;
+ leadId: string | null;
open: boolean;
}>({
- referralId: referralIdFromUrl,
- open: !!referralIdFromUrl,
+ leadId: leadIdFromUrl,
+ open: !!leadIdFromUrl,
});
- const { data: referralsCount, error: countError } =
- useProgramReferralsCount();
+ const { data: leadsCount, error: countError } =
+ useProgramSubmittedLeadsCount();
const {
- data: referrals,
+ data: leads,
error,
isLoading,
- } = useSWR<PartnerReferralProps[]>(
- `/api/programs/${defaultProgramId}/referrals${getQueryString({
+ } = useSWR<SubmittedLeadItem[]>(
+ `/api/programs/${defaultProgramId}/submitted-leads${getQueryString({
workspaceId,
})}`,
fetcher,
@@ -61,14 +61,14 @@ export function PartnerReferralTable() {
},
);
- const referralsColumns = {
+ const leadsColumns = {
all: ["lead", "company", "partner", "submitted", "status"],
defaultVisible: ["lead", "company", "partner", "submitted", "status"],
};
const { columnVisibility, setColumnVisibility } = useColumnVisibility(
- "partner-referrals-table-columns",
- referralsColumns,
+ "partner-submitted-leads-table-columns",
+ leadsColumns,
);
const columns = [
@@ -77,19 +77,19 @@ export function PartnerReferralTable() {
header: "Lead",
enableHiding: false,
minSize: 250,
- cell: ({ row }: { row: Row<PartnerReferralProps> }) => {
- const referral = row.original;
- const companyLogoUrl = getCompanyLogoUrl(referral.email);
+ cell: ({ row }: { row: Row<SubmittedLeadItem> }) => {
+ const lead = row.original;
+ const companyLogoUrl = getCompanyLogoUrl(lead.email);
return (
<div className="flex items-center gap-2 truncate">
<img
- alt={referral.email}
- src={companyLogoUrl || `${OG_AVATAR_URL}${referral.id}`}
+ alt={lead.email}
+ src={companyLogoUrl || `${OG_AVATAR_URL}${lead.id}`}
className="size-5 shrink-0 rounded-full border border-neutral-200"
/>
- <span className="truncate" title={referral.email}>
- {referral.email}
+ <span className="truncate" title={lead.email}>
+ {lead.email}
</span>
</div>
);
@@ -100,7 +100,7 @@ export function PartnerReferralTable() {
header: "Company",
accessorKey: "company",
minSize: 150,
- cell: ({ row }: { row: Row<PartnerReferralProps> }) => {
+ cell: ({ row }: { row: Row<SubmittedLeadItem> }) => {
return (
<span className="min-w-0 truncate" title={row.original.company}>
{row.original.company}
@@ -112,7 +112,7 @@ export function PartnerReferralTable() {
id: "partner",
header: "Partner",
minSize: 200,
- cell: ({ row }: { row: Row<PartnerReferralProps> }) => {
+ cell: ({ row }: { row: Row<SubmittedLeadItem> }) => {
return (
<PartnerRowItem
partner={row.original.partner}
@@ -125,7 +125,7 @@ export function PartnerReferralTable() {
{
id: "submitted",
header: "Submitted",
- cell: ({ row }: { row: Row<PartnerReferralProps> }) => (
+ cell: ({ row }: { row: Row<SubmittedLeadItem> }) => (
<TimestampTooltip
timestamp={row.original.createdAt}
rows={["local"]}
@@ -140,9 +140,9 @@ export function PartnerReferralTable() {
id: "status",
header: "Status",
accessorKey: "status",
- cell: ({ row }: { row: Row<PartnerReferralProps> }) => {
+ cell: ({ row }: { row: Row<SubmittedLeadItem> }) => {
const status = row.original.status;
- const badge = ReferralStatusBadges[status];
+ const badge = SubmittedLeadStatusBadges[status];
return (
<StatusBadge
@@ -155,10 +155,10 @@ export function PartnerReferralTable() {
);
},
},
- ].filter((c) => referralsColumns.all.includes(c.id));
+ ].filter((c) => leadsColumns.all.includes(c.id));
const { table, ...tableProps } = useTable({
- data: referrals || [],
+ data: leads || [],
columns,
pagination,
onPaginationChange: setPagination,
@@ -166,91 +166,89 @@ export function PartnerReferralTable() {
onColumnVisibilityChange: setColumnVisibility,
thClassName: "border-l-0",
tdClassName: "border-l-0",
- resourceName: (p) => `partner referral${p ? "s" : ""}`,
- rowCount: referralsCount || 0,
+ resourceName: (p) => `submitted lead${p ? "s" : ""}`,
+ rowCount: leadsCount || 0,
loading: isLoading,
- error: error || countError ? "Failed to load referrals" : undefined,
+ error: error || countError ? "Failed to load submitted leads" : undefined,
onRowClick: (row) => {
queryParams({
- set: { referralId: row.original.id },
+ set: { leadId: row.original.id },
scroll: false,
});
setDetailsSheetState({
- referralId: row.original.id,
+ leadId: row.original.id,
open: true,
});
},
});
- const currentReferral = useMemo(() => {
- if (!referrals || !detailsSheetState.referralId) return null;
- return referrals.find((r) => r.id === detailsSheetState.referralId) || null;
- }, [referrals, detailsSheetState.referralId]);
+ const currentLead = useMemo(() => {
+ if (!leads || !detailsSheetState.leadId) return null;
+ return leads.find((l) => l.id === detailsSheetState.leadId) || null;
+ }, [leads, detailsSheetState.leadId]);
- const [previousReferralId, nextReferralId] = useMemo(() => {
- if (!referrals || !detailsSheetState.referralId) return [null, null];
+ const [previousLeadId, nextLeadId] = useMemo(() => {
+ if (!leads || !detailsSheetState.leadId) return [null, null];
- const currentIndex = referrals.findIndex(
- ({ id }) => id === detailsSheetState.referralId,
+ const currentIndex = leads.findIndex(
+ ({ id }) => id === detailsSheetState.leadId,
);
if (currentIndex === -1) return [null, null];
return [
- currentIndex > 0 ? referrals[currentIndex - 1].id : null,
- currentIndex < referrals.length - 1
- ? referrals[currentIndex + 1].id
- : null,
+ currentIndex > 0 ? leads[currentIndex - 1].id : null,
+ currentIndex < leads.length - 1 ? leads[currentIndex + 1].id : null,
];
- }, [referrals, detailsSheetState.referralId]);
+ }, [leads, detailsSheetState.leadId]);
// Sync state with URL params
useEffect(() => {
- const urlReferralId = searchParams.get("referralId");
- if (urlReferralId && urlReferralId !== detailsSheetState.referralId) {
+ const urlLeadId = searchParams.get("leadId");
+ if (urlLeadId && urlLeadId !== detailsSheetState.leadId) {
setDetailsSheetState({
- referralId: urlReferralId,
+ leadId: urlLeadId,
open: true,
});
- } else if (!urlReferralId && detailsSheetState.referralId) {
+ } else if (!urlLeadId && detailsSheetState.leadId) {
setDetailsSheetState({
- referralId: null,
+ leadId: null,
open: false,
});
}
- }, [searchParams, detailsSheetState.referralId]);
+ }, [searchParams, detailsSheetState.leadId]);
return (
<div className="flex flex-col gap-3">
- {detailsSheetState.referralId && currentReferral && (
- <ReferralSheet
+ {detailsSheetState.leadId && currentLead && (
+ <SubmittedLeadSheet
isOpen={detailsSheetState.open}
setIsOpen={(open) =>
setDetailsSheetState((s) => ({ ...s, open }) as any)
}
- referral={currentReferral}
+ lead={currentLead}
onPrevious={
- previousReferralId
+ previousLeadId
? () => {
queryParams({
- set: { referralId: previousReferralId },
+ set: { leadId: previousLeadId },
scroll: false,
});
setDetailsSheetState({
- referralId: previousReferralId,
+ leadId: previousLeadId,
open: true,
});
}
: undefined
}
onNext={
- nextReferralId
+ nextLeadId
? () => {
queryParams({
- set: { referralId: nextReferralId },
+ set: { leadId: nextLeadId },
scroll: false,
});
setDetailsSheetState({
- referralId: nextReferralId,
+ leadId: nextLeadId,
open: true,
});
}
@@ -259,13 +257,13 @@ export function PartnerReferralTable() {
/>
)}
<div>
- <PartnerReferralFilters />
+ <SubmittedLeadFilters />
</div>
- {referrals?.length !== 0 ? (
+ {leads?.length !== 0 ? (
<Table {...tableProps} table={table} />
) : (
<AnimatedEmptyState
- title="No referrals submitted"
+ title="No leads submitted"
description="Allow partners to submit leads and track their progress through the sales process."
learnMoreHref="https://dub.co/help/article/partner-rewards"
cardContent={
@@ -279,7 +277,7 @@ export function PartnerReferralTable() {
);
}
-function PartnerReferralFilters() {
+function SubmittedLeadFilters() {
const {
filters,
activeFilters,
@@ -288,7 +286,7 @@ function PartnerReferralFilters() {
onRemoveAll,
setSearch,
setSelectedFilter,
- } = useProgramReferralsFilters({});
+ } = useProgramSubmittedLeadFilters({});
return (
<>
diff --git a/apps/web/ui/referrals/referral-utils.ts b/apps/web/ui/submitted-leads/submitted-lead-utils.ts
similarity index 100%
rename from apps/web/ui/referrals/referral-utils.ts
rename to apps/web/ui/submitted-leads/submitted-lead-utils.ts
diff --git a/apps/web/ui/referrals/use-program-referral-filters.tsx b/apps/web/ui/submitted-leads/use-program-submitted-lead-filters.tsx
similarity index 88%
rename from apps/web/ui/referrals/use-program-referral-filters.tsx
rename to apps/web/ui/submitted-leads/use-program-submitted-lead-filters.tsx
index 2bd2ec65bf..09a6d51c24 100644
--- a/apps/web/ui/referrals/use-program-referral-filters.tsx
+++ b/apps/web/ui/submitted-leads/use-program-submitted-lead-filters.tsx
@@ -2,19 +2,19 @@ import usePartners from "@/lib/swr/use-partners";
import useWorkspace from "@/lib/swr/use-workspace";
import { EnrolledPartnerProps } from "@/lib/types";
import {
- partnerReferralsCountByPartnerIdSchema,
- partnerReferralsCountByStatusSchema,
-} from "@/lib/zod/schemas/referrals";
+ submittedLeadsCountByPartnerSchema,
+ submittedLeadsCountByStatusSchema,
+} from "@/lib/zod/schemas/submitted-leads";
import { CircleDotted, useRouterStuff } from "@dub/ui";
import { Users } from "@dub/ui/icons";
import { cn, nFormatter, OG_AVATAR_URL } from "@dub/utils";
import { useCallback, useMemo, useState } from "react";
import { useDebounce } from "use-debounce";
import * as z from "zod/v4";
-import { useProgramReferralsCount } from "../../lib/swr/use-program-referrals-count";
-import { ReferralStatusBadges } from "./referral-status-badges";
+import { useProgramSubmittedLeadsCount } from "../../lib/swr/use-program-submitted-leads-count";
+import { SubmittedLeadStatusBadges } from "./submitted-lead-status-badges";
-export function useProgramReferralsFilters(
+export function useProgramSubmittedLeadFilters(
extraSearchParams: Record<string, string>,
) {
const [search, setSearch] = useState("");
@@ -27,16 +27,16 @@ export function useProgramReferralsFilters(
selectedFilter === "partnerId" ? debouncedSearch : "",
);
- const { data: statusCount } = useProgramReferralsCount<
- z.infer<typeof partnerReferralsCountByStatusSchema>[] | undefined
+ const { data: statusCount } = useProgramSubmittedLeadsCount<
+ z.infer<typeof submittedLeadsCountByStatusSchema>[] | undefined
>({
query: {
groupBy: "status",
},
});
- const { data: partnersCount } = useProgramReferralsCount<
- z.infer<typeof partnerReferralsCountByPartnerIdSchema>[] | undefined
+ const { data: partnersCount } = useProgramSubmittedLeadsCount<
+ z.infer<typeof submittedLeadsCountByPartnerSchema>[] | undefined
>({
query: {
groupBy: "partnerId",
@@ -81,7 +81,7 @@ export function useProgramReferralsFilters(
label: "Status",
options:
statusCount?.map(({ status, _count }) => {
- const badge = ReferralStatusBadges[status];
+ const badge = SubmittedLeadStatusBadges[status];
const Icon = badge.icon;
return {
diff --git a/packages/email/src/templates/referral-status-update.tsx b/packages/email/src/templates/lead-status-updated.tsx
similarity index 88%
rename from packages/email/src/templates/referral-status-update.tsx
rename to packages/email/src/templates/lead-status-updated.tsx
index 67da27e30e..40e48ea35b 100644
--- a/packages/email/src/templates/referral-status-update.tsx
+++ b/packages/email/src/templates/lead-status-updated.tsx
@@ -13,7 +13,7 @@ import {
} from "@react-email/components";
import { Footer } from "../components/footer";
-export default function ReferralStatusUpdate({
+export default function LeadStatusUpdated({
partner = {
name: "John Doe",
@@ -22,7 +22,7 @@ export default function ReferralStatusUpdate({
name: "Acme",
slug: "acme",
},
- referral = {
+ lead = {
name: "Jane Smith",
company: "Acme Corp",
@@ -33,7 +33,7 @@ export default function ReferralStatusUpdate({
}: {
partner: { name: string; email: string };
program: { name: string; slug: string };
- referral: {
+ lead: {
name: string;
email: string;
company: string;
@@ -46,7 +46,7 @@ export default function ReferralStatusUpdate({
<Html>
<Head />
<Preview>
- Your referral {referral.name} has been updated to {referral.status}.
+ Your submitted lead {lead.name} has been updated to {lead.status}.
</Preview>
<Tailwind>
<Body className="mx-auto my-auto bg-white font-sans">
@@ -56,13 +56,12 @@ export default function ReferralStatusUpdate({
</Section>
<Heading className="mx-0 p-0 text-lg font-medium text-neutral-800">
- Referral status update
+ Submitted lead status update
</Heading>
<Text className="text-sm leading-6 text-neutral-600">
- Your submitted referral has changed to{" "}
- <strong>{referral.status}</strong> by{" "}
- <strong>{program.name}</strong>.
+ Your submitted lead has changed to <strong>{lead.status}</strong>{" "}
+ by <strong>{program.name}</strong>.
</Text>
{notes && (
@@ -81,18 +80,16 @@ export default function ReferralStatusUpdate({
<Container className="w-full rounded-lg border border-solid border-neutral-100 bg-neutral-50 p-6">
<div>
<Img
- src={
- referral.image || `${OG_AVATAR_URL}${referral.email}`
- }
+ src={lead.image || `${OG_AVATAR_URL}${lead.email}`}
width="48"
height="48"
- alt={referral.name}
+ alt={lead.name}
className="rounded-full"
/>
<div>
<Text className="m-0 mt-3 p-0 text-lg font-medium text-neutral-900">
- {referral.name}
+ {lead.name}
</Text>
<table
cellPadding="0"
@@ -122,7 +119,7 @@ export default function ReferralStatusUpdate({
color: "#737373",
}}
>
- {referral.email}
+ {lead.email}
</td>
</tr>
</table>
@@ -154,7 +151,7 @@ export default function ReferralStatusUpdate({
color: "#737373",
}}
>
- {referral.company}
+ {lead.company}
</td>
</tr>
</table>
diff --git a/packages/email/src/templates/partner-referral-submitted.tsx b/packages/email/src/templates/new-lead-submitted.tsx
similarity index 90%
rename from packages/email/src/templates/partner-referral-submitted.tsx
rename to packages/email/src/templates/new-lead-submitted.tsx
index 162768a29c..c9f6d4bdb9 100644
--- a/packages/email/src/templates/partner-referral-submitted.tsx
+++ b/packages/email/src/templates/new-lead-submitted.tsx
@@ -14,12 +14,12 @@ import {
} from "@react-email/components";
import { Footer } from "../components/footer";
-export default function PartnerReferralSubmitted({
+export default function NewLeadSubmitted({
email = "[email protected]",
workspace = {
slug: "acme",
},
- referral = {
+ lead = {
id: "ref_1234567890",
name: "Jane Smith",
@@ -27,7 +27,7 @@ export default function PartnerReferralSubmitted({
image: null,
formData: [
{
- label: "How did you meet this referral?",
+ label: "How did you meet this lead?",
value: "Met at a conference last month.",
},
{
@@ -44,7 +44,7 @@ export default function PartnerReferralSubmitted({
}: {
email: string;
workspace: { slug: string };
- referral: {
+ lead: {
id: string;
name: string;
email: string;
@@ -58,14 +58,13 @@ export default function PartnerReferralSubmitted({
image: string | null;
};
}) {
- const referralUrl = `https://app.dub.co/${workspace.slug}/program/customers/referrals?referralId=${referral.id}`;
+ const leadUrl = `https://app.dub.co/${workspace.slug}/program/customers/leads?leadId=${lead.id}`;
return (
<Html>
<Head />
<Preview>
- New partner referral from {referral.name} ({referral.email}) at{" "}
- {referral.company}.
+ New lead from {lead.name} ({lead.email}) at {lead.company}.
</Preview>
<Tailwind>
<Body className="mx-auto my-auto bg-white font-sans">
@@ -75,13 +74,13 @@ export default function PartnerReferralSubmitted({
</Section>
<Heading className="mx-0 p-0 text-lg font-medium text-neutral-800">
- New partner referral
+ New lead
</Heading>
<Text className="text-sm leading-6 text-neutral-600">
- You have a new partner referral to review, view the{" "}
+ You have a new lead to review, view the{" "}
<Link
- href={referralUrl}
+ href={leadUrl}
className="text-neutral-600 underline underline-offset-4"
>
full details on Dub
@@ -94,18 +93,16 @@ export default function PartnerReferralSubmitted({
<Container className="w-full rounded-lg border border-solid border-neutral-100 bg-neutral-50 p-5">
<div>
<Img
- src={
- referral.image || `${OG_AVATAR_URL}${referral.email}`
- }
+ src={lead.image || `${OG_AVATAR_URL}${lead.email}`}
width="48"
height="48"
- alt={referral.name}
+ alt={lead.name}
className="rounded-full"
/>
<div>
<Text className="m-0 mt-3 p-0 text-lg font-medium text-neutral-900">
- {referral.name}
+ {lead.name}
</Text>
<table
cellPadding="0"
@@ -135,7 +132,7 @@ export default function PartnerReferralSubmitted({
color: "#737373",
}}
>
- {referral.email}
+ {lead.email}
</td>
</tr>
</table>
@@ -167,7 +164,7 @@ export default function PartnerReferralSubmitted({
color: "#737373",
}}
>
- {referral.company}
+ {lead.company}
</td>
</tr>
</table>
@@ -251,9 +248,9 @@ export default function PartnerReferralSubmitted({
</table>
</Container>
- {referral.formData && referral.formData.length > 0 && (
+ {lead.formData && lead.formData.length > 0 && (
<Section className="px-4 pt-4">
- {referral.formData.map((field) => (
+ {lead.formData.map((field) => (
<Section key={field.label} className="mb-4">
<Text className="m-0 mb-2 p-0 text-base font-medium text-neutral-900">
{field.label}
@@ -270,7 +267,7 @@ export default function PartnerReferralSubmitted({
<Section className="mb-8 mt-8 text-center">
<Link
- href={referralUrl}
+ href={leadUrl}
className="box-border block w-full rounded-lg bg-black px-0 py-4 text-center text-sm font-semibold leading-none text-white no-underline"
>
Review on Dub
diff --git a/packages/prisma/client.ts b/packages/prisma/client.ts
index b487f5b27e..d0641ff247 100644
--- a/packages/prisma/client.ts
+++ b/packages/prisma/client.ts
@@ -36,6 +36,7 @@ export {
ProgramPayoutMode,
RewardStructure,
SalesChannel,
+ SubmittedLeadStatus,
WebhookReceiver,
WorkflowTrigger,
WorkspaceRole,
diff --git a/packages/prisma/schema/customer.prisma b/packages/prisma/schema/customer.prisma
index 45d94383a8..918a4db85b 100644
--- a/packages/prisma/schema/customer.prisma
+++ b/packages/prisma/schema/customer.prisma
@@ -32,7 +32,7 @@ model Customer {
programEnrollment ProgramEnrollment? @relation(fields: [programId, partnerId], references: [programId, partnerId])
commissions Commission[]
fraudEvents FraudEvent[]
- referrals PartnerReferral[]
+ submittedLeads SubmittedLead[]
@@unique([projectId, externalId])
@@unique([projectConnectId, externalId])
diff --git a/packages/prisma/schema/lead.prisma b/packages/prisma/schema/lead.prisma
new file mode 100644
index 0000000000..66b1c4fc35
--- /dev/null
+++ b/packages/prisma/schema/lead.prisma
@@ -0,0 +1,33 @@
+enum SubmittedLeadStatus {
+ pending
+ qualified
+ meeting
+ negotiation
+ unqualified
+ closedWon
+ closedLost
+}
+
+model SubmittedLead {
+ id String @id @default(cuid())
+ programId String
+ partnerId String
+ customerId String?
+ name String
+ email String
+ company String
+ formData Json? @db.Json
+ status SubmittedLeadStatus @default(pending)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ program Program @relation(fields: [programId], references: [id])
+ partner Partner @relation(fields: [partnerId], references: [id])
+ programEnrollment ProgramEnrollment @relation(fields: [programId, partnerId], references: [programId, partnerId])
+ customer Customer? @relation(fields: [customerId], references: [id])
+
+ @@index([programId, partnerId])
+ @@index(partnerId)
+ @@index(customerId)
+ @@fulltext([email, name])
+}
diff --git a/packages/prisma/schema/partner.prisma b/packages/prisma/schema/partner.prisma
index b3726b6860..88ee744ff8 100644
--- a/packages/prisma/schema/partner.prisma
+++ b/packages/prisma/schema/partner.prisma
@@ -107,8 +107,8 @@ model Partner {
fraudAlerts FraudAlert[]
partnerRewinds PartnerRewind[]
platforms PartnerPlatform[]
- referrals PartnerReferral[]
referredApplications ProgramApplicationEvent[]
+ submittedLeads SubmittedLead[]
@@index(country)
@@index(networkStatus)
diff --git a/packages/prisma/schema/program.prisma b/packages/prisma/schema/program.prisma
index 6c767ff6cb..5924b948c8 100644
--- a/packages/prisma/schema/program.prisma
+++ b/packages/prisma/schema/program.prisma
@@ -89,9 +89,9 @@ model Program {
fraudEventGroups FraudEventGroup[]
sourceFraudEvents FraudEvent[] @relation("SourceFraudEvents")
fraudAlerts FraudAlert[]
- referrals PartnerReferral[]
partnerTags PartnerTag[]
programPartnerTags ProgramPartnerTag[]
+ submittedLeads SubmittedLead[]
@@index(workspaceId)
@@index(addedToMarketplaceAt)
@@ -152,10 +152,10 @@ model ProgramEnrollment {
commissions Commission[]
payouts Payout[]
fraudEventGroups FraudEventGroup[]
- referrals PartnerReferral[]
fraudAlerts FraudAlert[]
discoveredPartner DiscoveredPartner?
programPartnerTags ProgramPartnerTag[]
+ submittedLeads SubmittedLead[]
// unique constraints
@@unique([partnerId, programId])
diff --git a/packages/prisma/schema/referral.prisma b/packages/prisma/schema/referral.prisma
index 2d2820352c..afe1b02269 100644
--- a/packages/prisma/schema/referral.prisma
+++ b/packages/prisma/schema/referral.prisma
@@ -21,13 +21,8 @@ model PartnerReferral {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- program Program @relation(fields: [programId], references: [id])
- partner Partner @relation(fields: [partnerId], references: [id])
- programEnrollment ProgramEnrollment @relation(fields: [programId, partnerId], references: [programId, partnerId])
- customer Customer? @relation(fields: [customerId], references: [id])
-
@@index([programId, partnerId])
@@index(partnerId)
@@index(customerId)
@@fulltext([email, name])
-}
+}
\ No newline at end of file