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.

WIP partner sheet

Tim Wilson382181bc7243
diff --git a/apps/web/app/(ee)/api/network/partners/count/route.ts b/apps/web/app/(ee)/api/network/partners/count/route.ts
index 4beba611de..37548d9549 100644
--- a/apps/web/app/(ee)/api/network/partners/count/route.ts
+++ b/apps/web/app/(ee)/api/network/partners/count/route.ts
@@ -9,6 +9,7 @@ export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
const {
+ partnerIds,
status,
groupBy,
country,
@@ -20,6 +21,9 @@ export const GET = withWorkspace(
const commonWhere = {
discoverableAt: { not: null },
+ ...(partnerIds && {
+ id: { in: partnerIds },
+ }),
...(country && {
country,
}),
diff --git a/apps/web/app/(ee)/api/network/partners/route.ts b/apps/web/app/(ee)/api/network/partners/route.ts
index a0f3552d57..4be289687f 100644
--- a/apps/web/app/(ee)/api/network/partners/route.ts
+++ b/apps/web/app/(ee)/api/network/partners/route.ts
@@ -15,6 +15,7 @@ export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
const {
+ partnerIds,
status,
page,
pageSize,
@@ -71,6 +72,7 @@ export const GET = withWorkspace(
) salesChannels ON salesChannels.partnerId = p.id
WHERE
p.discoverableAt IS NOT NULL
+ ${partnerIds && partnerIds.length > 0 ? Prisma.sql`AND p.id IN (${Prisma.join(partnerIds)})` : Prisma.sql``}
${country ? Prisma.sql`AND p.country = ${country}` : Prisma.sql``}
${
status === "discover"
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx
index 97fced5f9d..3a27b2e01f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/directory/page-client.tsx
@@ -8,19 +8,16 @@ import {
} from "@/lib/partners/partner-profile";
import usePartnerNetworkPartnersCount from "@/lib/swr/use-partner-network-partners-count";
import useWorkspace from "@/lib/swr/use-workspace";
-import { DiscoverablePartnerProps } from "@/lib/types";
-import {
- PARTNER_CONVERSION_SCORES,
- PARTNER_CONVERSION_SCORE_RATES,
- PARTNER_NETWORK_PARTNERS_MAX_PAGE_SIZE,
-} from "@/lib/zod/schemas/partner-network";
+import { PartnerNetworkPartnerProps } from "@/lib/types";
+import { PARTNER_NETWORK_PARTNERS_MAX_PAGE_SIZE } from "@/lib/zod/schemas/partner-network";
import { ConversionScoreIcon } from "@/ui/partners/conversion-score-icon";
+import { PartnerNetworkPartnerSheet } from "@/ui/partners/partner-network-partner-sheet";
+import { ConversionScoreTooltip } from "@/ui/partners/partner-network/conversion-score-tooltip";
import {
AnimatedSizeContainer,
BadgeCheck2Fill,
Button,
ChartActivity2,
- DynamicTooltipWrapper,
Filter,
PaginationControls,
Switch,
@@ -39,6 +36,7 @@ import {
cn,
fetcher,
formatDate,
+ isClickOnInteractiveChild,
timeAgo,
} from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
@@ -79,7 +77,7 @@ export function ProgramPartnersDirectoryPageClient() {
error,
mutate: mutatePartners,
isValidating,
- } = useSWR<DiscoverablePartnerProps[]>(
+ } = useSWR<PartnerNetworkPartnerProps[]>(
workspaceId &&
`/api/network/partners${getQueryString(
{
@@ -103,8 +101,65 @@ export function ProgramPartnersDirectoryPageClient() {
const { filters, activeFilters, onSelect, onRemove, onRemoveAll } =
usePartnerNetworkFilters({ status });
+ const [detailsSheetState, setDetailsSheetState] = useState<
+ | { open: false; partnerId: string | null }
+ | { open: true; partnerId: string }
+ >({ open: false, partnerId: null });
+
+ useEffect(() => {
+ const partnerId = searchParams.get("partnerId");
+ if (partnerId) setDetailsSheetState({ open: true, partnerId });
+ }, [searchParams]);
+
+ const { currentPartner, isLoading: isCurrentPartnerLoading } =
+ useCurrentPartner({
+ partners,
+ partnerId: detailsSheetState.partnerId,
+ });
+
+ const [previousPartnerId, nextPartnerId] = useMemo(() => {
+ if (!partners || !detailsSheetState.partnerId) return [null, null];
+
+ const currentIndex = partners.findIndex(
+ ({ id }) => id === detailsSheetState.partnerId,
+ );
+ if (currentIndex === -1) return [null, null];
+
+ return [
+ currentIndex > 0 ? partners[currentIndex - 1].id : null,
+ currentIndex < partners.length - 1 ? partners[currentIndex + 1].id : null,
+ ];
+ }, [partners, detailsSheetState.partnerId]);
+
return (
<div className="flex flex-col gap-6">
+ {detailsSheetState.partnerId && currentPartner && (
+ <PartnerNetworkPartnerSheet
+ isOpen={detailsSheetState.open}
+ setIsOpen={(open) =>
+ setDetailsSheetState((s) => ({ ...s, open }) as any)
+ }
+ partner={currentPartner}
+ onPrevious={
+ previousPartnerId
+ ? () =>
+ queryParams({
+ set: { partnerId: previousPartnerId },
+ scroll: false,
+ })
+ : undefined
+ }
+ onNext={
+ nextPartnerId
+ ? () =>
+ queryParams({
+ set: { partnerId: nextPartnerId },
+ scroll: false,
+ })
+ : undefined
+ }
+ />
+ )}
<div className="grid grid-cols-3 gap-2">
{tabs.map((tab) => {
const isActive = status === tab.id;
@@ -268,9 +323,11 @@ function PartnerCard({
partner,
onToggleStarred,
}: {
- partner?: DiscoverablePartnerProps;
+ partner?: PartnerNetworkPartnerProps;
onToggleStarred?: (starred: boolean) => void;
}) {
+ const { queryParams } = useRouterStuff();
+
const basicFields = useMemo(
() => [
{
@@ -304,6 +361,7 @@ function PartnerCard({
? `${capitalize(partner.conversionScore)} conversion`
: "Unknown conversion"
: undefined,
+ wrapper: ConversionScoreTooltip,
},
],
[partner],
@@ -322,7 +380,17 @@ function PartnerCard({
);
return (
- <div className="border-border-subtle rounded-xl border p-4">
+ <div
+ className={cn(
+ "border-border-subtle rounded-xl border bg-white p-4",
+ partner?.id && "cursor-pointer hover:drop-shadow-sm",
+ )}
+ onClick={(e) => {
+ if (!partner?.id || isClickOnInteractiveChild(e)) return;
+
+ queryParams({ set: { partnerId: partner.id } });
+ }}
+ >
<div className="flex justify-between gap-4">
{/* Avatar + country icon */}
<div className="relative w-fit">
@@ -378,65 +446,8 @@ function PartnerCard({
<div className="flex flex-col items-start gap-1">
{basicFields
.filter(({ text }) => text !== null)
- .map(({ id, icon, text }) => (
- <DynamicTooltipWrapper
- key={id}
- tooltipProps={
- id === "conversion"
- ? {
- content: (
- <div className="max-w-60 p-2.5 text-xs">
- <div className="flex flex-col gap-2.5">
- {PARTNER_CONVERSION_SCORES.map((score, idx) => (
- <div
- key={score}
- className="flex items-center gap-1.5"
- >
- <ConversionScoreIcon
- score={score}
- className="size-3.5 shrink-0"
- />
- <span className="text-content-default font-semibold">
- {capitalize(score)}{" "}
- <span className="text-content-subtle font-medium">
- (
- {idx <
- PARTNER_CONVERSION_SCORES.length - 1 ? (
- <>
- {PARTNER_CONVERSION_SCORE_RATES[
- score
- ] * 100}
- -
- {PARTNER_CONVERSION_SCORE_RATES[
- PARTNER_CONVERSION_SCORES[idx + 1]
- ] * 100}
- </>
- ) : (
- <>
- &gt;
- {PARTNER_CONVERSION_SCORE_RATES[
- score
- ] * 100}
- </>
- )}
- %)
- </span>
- </span>
- </div>
- ))}
- </div>
- <p className="text-content-subtle mt-4 font-medium">
- This score is an average for all Dub programs the
- partner is enrolled in.
- </p>
- </div>
- ),
- side: "right",
- align: "end",
- }
- : undefined
- }
- >
+ .map(({ id, icon, text, wrapper: Wrapper = "div" }) => (
+ <Wrapper key={id}>
<div className="text-content-subtle flex cursor-default items-center gap-1">
{text !== undefined ? (
<>
@@ -447,7 +458,7 @@ function PartnerCard({
<div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
)}
</div>
- </DynamicTooltipWrapper>
+ </Wrapper>
))}
</div>
@@ -639,3 +650,36 @@ function ListPill({ icon: Icon, label }: { icon?: Icon; label: string }) {
</div>
);
}
+
+/** Gets the current partner from the loaded partners array if available, or a separate fetch if not */
+function useCurrentPartner({
+ partners,
+ partnerId,
+}: {
+ partners?: PartnerNetworkPartnerProps[];
+ partnerId: string | null;
+}) {
+ const { id: workspaceId } = useWorkspace();
+
+ let currentPartner = partnerId
+ ? partners?.find(({ id }) => id === partnerId)
+ : null;
+
+ const fetchPartnerId =
+ partners && partnerId && !currentPartner ? partnerId : null;
+
+ const { data: fetchedPartners, isLoading } =
+ useSWR<PartnerNetworkPartnerProps>(
+ fetchPartnerId &&
+ `/api/network/partners?workspaceId=${workspaceId}&partnerIds=${fetchPartnerId}`,
+ fetcher,
+ {
+ keepPreviousData: true,
+ },
+ );
+
+ if (!currentPartner && fetchedPartners?.[0]?.id === partnerId)
+ currentPartner = fetchedPartners[0];
+
+ return { currentPartner, isLoading };
+}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index e787a5c1f4..ae2fa0c41e 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -46,6 +46,7 @@ import {
import { dashboardSchema } from "./zod/schemas/dashboard";
import { DiscountSchema } from "./zod/schemas/discount";
import { FolderSchema } from "./zod/schemas/folders";
+import { GroupWithProgramSchema } from "./zod/schemas/group-with-program";
import {
additionalPartnerLinkSchema,
GroupSchema,
@@ -53,7 +54,6 @@ import {
GroupWithFormDataSchema,
PartnerGroupDefaultLinkSchema,
} from "./zod/schemas/groups";
-import { GroupWithProgramSchema } from "./zod/schemas/group-with-program";
import { integrationSchema } from "./zod/schemas/integration";
import { InvoiceSchema } from "./zod/schemas/invoices";
import {
@@ -83,6 +83,11 @@ import {
PayoutResponseSchema,
PayoutSchema,
} from "./zod/schemas/payouts";
+import {
+ programApplicationFormDataWithValuesSchema,
+ programApplicationFormFieldWithValuesSchema,
+ programApplicationFormSchema,
+} from "./zod/schemas/program-application-form";
import { programLanderSchema } from "./zod/schemas/program-lander";
import { programDataSchema } from "./zod/schemas/program-onboarding";
import {
@@ -121,7 +126,6 @@ import {
workflowConditionSchema,
} from "./zod/schemas/workflows";
import { workspacePreferencesSchema } from "./zod/schemas/workspace-preferences";
-import { programApplicationFormDataWithValuesSchema, programApplicationFormFieldWithValuesSchema, programApplicationFormSchema } from "./zod/schemas/program-application-form";
export type LinkProps = Link;
@@ -445,7 +449,7 @@ export type PartnerProfileLinkProps = z.infer<typeof PartnerProfileLinkSchema>;
export type EnrolledPartnerProps = z.infer<typeof EnrolledPartnerSchema>;
-export type DiscoverablePartnerProps = z.infer<
+export type PartnerNetworkPartnerProps = z.infer<
typeof PartnerNetworkPartnerSchema
>;
@@ -467,11 +471,17 @@ export type ProgramWithLanderDataProps = z.infer<
typeof ProgramWithLanderDataSchema
>;
-export type ProgramApplicationFormData = z.infer<typeof programApplicationFormSchema>;
+export type ProgramApplicationFormData = z.infer<
+ typeof programApplicationFormSchema
+>;
-export type ProgramApplicationFormDataWithValues = z.infer<typeof programApplicationFormDataWithValuesSchema>;
+export type ProgramApplicationFormDataWithValues = z.infer<
+ typeof programApplicationFormDataWithValuesSchema
+>;
-export type ProgramApplicationFormFieldWithValues = z.infer<typeof programApplicationFormFieldWithValuesSchema>;
+export type ProgramApplicationFormFieldWithValues = z.infer<
+ typeof programApplicationFormFieldWithValuesSchema
+>;
export type ProgramInviteProps = z.infer<typeof ProgramInviteSchema>;
@@ -564,7 +574,7 @@ export type LeadEventTB = z.infer<typeof leadEventSchemaTB>;
export type SaleEventTB = z.infer<typeof saleEventSchemaTB>;
-export type GroupProps = z.infer<typeof GroupSchema>
+export type GroupProps = z.infer<typeof GroupSchema>;
export type GroupWithFormDataProps = z.infer<typeof GroupWithFormDataSchema>;
diff --git a/apps/web/lib/zod/schemas/partner-network.ts b/apps/web/lib/zod/schemas/partner-network.ts
index c598129a40..83b6a3bf37 100644
--- a/apps/web/lib/zod/schemas/partner-network.ts
+++ b/apps/web/lib/zod/schemas/partner-network.ts
@@ -41,6 +41,10 @@ export const getPartnerNetworkPartnersQuerySchema = z
status: partnerNetworkPartnersStatusSchema.default("discover"),
country: z.string().optional(),
starred: booleanQuerySchema.nullish(),
+ partnerIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(",")))
+ .optional(),
industryInterests: z
.preprocess(
(v) => (typeof v === "string" ? v.split(",") : v),
diff --git a/apps/web/ui/partners/change-group-modal.tsx b/apps/web/ui/partners/change-group-modal.tsx
index 4f1d4399bc..f5faf9db1a 100644
--- a/apps/web/ui/partners/change-group-modal.tsx
+++ b/apps/web/ui/partners/change-group-modal.tsx
@@ -18,7 +18,8 @@ import { GroupSelector } from "./groups/group-selector";
type ChangeGroupModalProps = {
showChangeGroupModal: boolean;
setShowChangeGroupModal: Dispatch<SetStateAction<boolean>>;
- partners: EnrolledPartnerProps[];
+ partners: (Pick<EnrolledPartnerProps, "id" | "groupId" | "name" | "image"> &
+ Partial<Pick<EnrolledPartnerProps, "email">>)[];
/** Called when the selection is confirmed. Return false to prevent persisting the group change. */
onChangeGroup?: (groupId: string) => void | boolean;
@@ -79,9 +80,11 @@ function ChangeGroupModal({
<h4 className="truncate text-sm font-medium text-neutral-900">
{partners[0].name}
</h4>
- <p className="truncate text-xs text-neutral-500">
- {partners[0].email}
- </p>
+ {partners[0].email && (
+ <p className="truncate text-xs text-neutral-500">
+ {partners[0].email}
+ </p>
+ )}
</div>
</div>
) : (
diff --git a/apps/web/ui/partners/online-presence-summary.tsx b/apps/web/ui/partners/online-presence-summary.tsx
index abf6cbf6db..f205fd244d 100644
--- a/apps/web/ui/partners/online-presence-summary.tsx
+++ b/apps/web/ui/partners/online-presence-summary.tsx
@@ -10,7 +10,23 @@ export function OnlinePresenceSummary({
className,
emptyClassName,
}: {
- partner: EnrolledPartnerExtendedProps;
+ partner: Pick<
+ EnrolledPartnerExtendedProps,
+ | "website"
+ | "websiteVerifiedAt"
+ | "youtube"
+ | "youtubeSubscriberCount"
+ | "youtubeVerifiedAt"
+ | "youtubeViewCount"
+ | "twitter"
+ | "twitterVerifiedAt"
+ | "linkedin"
+ | "linkedinVerifiedAt"
+ | "instagram"
+ | "instagramVerifiedAt"
+ | "tiktok"
+ | "tiktokVerifiedAt"
+ >;
showLabels?: boolean;
className?: string;
emptyClassName?: string;
diff --git a/apps/web/ui/partners/partner-about.tsx b/apps/web/ui/partners/partner-about.tsx
index ee7212cbfb..254b1e8ac9 100644
--- a/apps/web/ui/partners/partner-about.tsx
+++ b/apps/web/ui/partners/partner-about.tsx
@@ -14,7 +14,28 @@ export function PartnerAbout({
partner,
error,
}: {
- partner?: EnrolledPartnerExtendedProps;
+ partner?: Pick<
+ EnrolledPartnerExtendedProps,
+ | "description"
+ | "industryInterests"
+ | "salesChannels"
+ | "preferredEarningStructures"
+ | "monthlyTraffic"
+ | "website"
+ | "websiteVerifiedAt"
+ | "youtube"
+ | "youtubeSubscriberCount"
+ | "youtubeVerifiedAt"
+ | "youtubeViewCount"
+ | "twitter"
+ | "twitterVerifiedAt"
+ | "linkedin"
+ | "linkedinVerifiedAt"
+ | "instagram"
+ | "instagramVerifiedAt"
+ | "tiktok"
+ | "tiktokVerifiedAt"
+ >;
error?: any;
}) {
return partner ? (
diff --git a/apps/web/ui/partners/partner-application-sheet.tsx b/apps/web/ui/partners/partner-application-sheet.tsx
index a54bc272a0..3b338ef869 100644
--- a/apps/web/ui/partners/partner-application-sheet.tsx
+++ b/apps/web/ui/partners/partner-application-sheet.tsx
@@ -21,9 +21,9 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { toast } from "sonner";
import { PartnerAbout } from "./partner-about";
import { PartnerApplicationDetails } from "./partner-application-details";
-import { PartnerApplicationTabs } from "./partner-application-tabs";
import { PartnerComments } from "./partner-comments";
import { PartnerInfoCards } from "./partner-info-cards";
+import { PartnerSheetTabs } from "./partner-sheet-tabs";
type PartnerApplicationSheetProps = {
partner: EnrolledPartnerProps;
@@ -109,7 +109,7 @@ function PartnerApplicationSheetContent({
</div>
<div className="@3xl/sheet:order-1">
<div className="border-border-subtle overflow-hidden rounded-xl border bg-neutral-100">
- <PartnerApplicationTabs
+ <PartnerSheetTabs
partnerId={partner.id}
currentTabId={currentTabId}
setCurrentTabId={setCurrentTabId}
diff --git a/apps/web/ui/partners/partner-info-cards.tsx b/apps/web/ui/partners/partner-info-cards.tsx
index 4941d0b45a..467854050c 100644
--- a/apps/web/ui/partners/partner-info-cards.tsx
+++ b/apps/web/ui/partners/partner-info-cards.tsx
@@ -1,11 +1,10 @@
-"use client";
-
import { sortRewardsByEventOrder } from "@/lib/partners/sort-rewards-by-event-order";
import useGroup from "@/lib/swr/use-group";
import useWorkspace from "@/lib/swr/use-workspace";
import {
BountyListProps,
EnrolledPartnerExtendedProps,
+ PartnerNetworkPartnerProps,
RewardProps,
} from "@/lib/types";
import { DEFAULT_PARTNER_GROUP } from "@/lib/zod/schemas/groups";
@@ -22,37 +21,49 @@ import {
import {
COUNTRIES,
OG_AVATAR_URL,
+ capitalize,
fetcher,
formatDate,
timeAgo,
} from "@dub/utils";
import Link from "next/link";
import useSWR from "swr";
+import { ConversionScoreIcon } from "./conversion-score-icon";
import { PartnerInfoGroup } from "./partner-info-group";
+import { ConversionScoreTooltip } from "./partner-network/conversion-score-tooltip";
import { PartnerStatusBadges } from "./partner-status-badges";
import { ProgramRewardList } from "./program-reward-list";
-export function PartnerInfoCards({
- partner,
- hideStatuses = [],
- selectedGroupId,
- setSelectedGroupId,
-}: {
- partner?: EnrolledPartnerExtendedProps;
-
+type PartnerInfoCardsProps = {
/** Partner statuses to hide badges for */
hideStatuses?: EnrolledPartnerExtendedProps["status"][];
// Only used for a controlled group selector that doesn't persist the selection itself
selectedGroupId?: string | null;
setSelectedGroupId?: (groupId: string) => void;
-}) {
+} & (
+ | { type?: "enrolled"; partner: EnrolledPartnerExtendedProps }
+ | { type: "network"; partner: PartnerNetworkPartnerProps }
+);
+
+export function PartnerInfoCards({
+ type,
+ partner,
+ hideStatuses = [],
+ selectedGroupId,
+ setSelectedGroupId,
+}: PartnerInfoCardsProps) {
const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
+ const isEnrolled = type === "enrolled" || type === undefined;
+ const isNetwork = type === "network";
+
const { group } = useGroup(
{
groupIdOrSlug: partner
- ? selectedGroupId || partner.groupId || DEFAULT_PARTNER_GROUP.slug
+ ? selectedGroupId ||
+ ("groupId" in partner ? partner.groupId : null) ||
+ DEFAULT_PARTNER_GROUP.slug
: undefined,
},
{ keepPreviousData: false },
@@ -65,42 +76,80 @@ export function PartnerInfoCards({
fetcher,
);
- const basicFields = [
- ...(partner?.status === "approved"
+ const basicFields = isEnrolled
+ ? [
+ ...(partner.status === "approved"
+ ? [
+ {
+ id: "lastLeadAt",
+ icon: <ChartActivity2 className="size-3.5" />,
+ text: partner.lastLeadAt
+ ? `Last lead event ${timeAgo(new Date(partner.lastLeadAt), { withAgo: true })}`
+ : null,
+ },
+ {
+ id: "lastConversionAt",
+ icon: <ChartActivity2 className="size-3.5" />,
+ text: partner.lastConversionAt
+ ? `Last conversion event ${timeAgo(new Date(partner.lastConversionAt), { withAgo: true })}`
+ : null,
+ },
+ ]
+ : []),
+ {
+ id: "companyName",
+ icon: <OfficeBuilding className="size-3.5" />,
+ text: partner ? partner.companyName || null : undefined,
+ },
+ {
+ id: "createdAt",
+ icon: <CalendarIcon className="size-3.5" />,
+ text: partner
+ ? `${partner.status === "approved" ? "Partner since" : "Applied"} ${formatDate(partner.createdAt)}`
+ : undefined,
+ },
+ ]
+ : isNetwork
? [
{
- id: "lastLeadAt",
- icon: <ChartActivity2 className="size-3.5" />,
- text: partner.lastLeadAt
- ? `Last lead event ${timeAgo(new Date(partner.lastLeadAt), { withAgo: true })}`
- : null,
+ id: "conversion",
+ icon: (
+ <ConversionScoreIcon
+ score={partner?.conversionScore || null}
+ className="size-3.5 shrink-0"
+ />
+ ),
+ text: partner
+ ? partner.conversionScore
+ ? `${capitalize(partner.conversionScore)} conversion`
+ : "Unknown conversion"
+ : undefined,
+ wrapper: ConversionScoreTooltip,
},
{
id: "lastConversionAt",
icon: <ChartActivity2 className="size-3.5" />,
text: partner.lastConversionAt
- ? `Last conversion event ${timeAgo(new Date(partner.lastConversionAt), { withAgo: true })}`
- : null,
+ ? `Last conversion ${timeAgo(partner.lastConversionAt, { withAgo: true })}`
+ : "No conversions yet",
+ },
+ {
+ id: "companyName",
+ icon: <OfficeBuilding className="size-3.5" />,
+ text: partner ? partner.companyName || null : undefined,
+ },
+ {
+ id: "listedAt",
+ icon: <CalendarIcon className="size-3.5" />,
+ text: partner
+ ? `Listed ${formatDate(partner.discoverableAt!)}`
+ : undefined,
},
]
- : []),
-
- {
- id: "companyName",
- icon: <OfficeBuilding className="size-3.5" />,
- text: partner ? partner.companyName || null : undefined,
- },
- {
- id: "createdAt",
- icon: <CalendarIcon className="size-3.5" />,
- text: partner
- ? `${partner.status === "approved" ? "Partner since" : "Applied"} ${formatDate(partner.createdAt)}`
- : undefined,
- },
- ];
+ : [];
const badge =
- partner && !hideStatuses.includes(partner.status)
+ isEnrolled && !hideStatuses.includes(partner.status)
? PartnerStatusBadges[partner.status]
: null;
@@ -146,41 +195,41 @@ export function PartnerInfoCards({
<div className="h-7 w-24 animate-pulse rounded bg-neutral-200" />
)}
</div>
- {partner ? (
- partner.email && (
- <div className="mt-0.5 flex items-center gap-1">
- <span className="text-sm font-medium text-neutral-500">
- {partner.email}
- </span>
- <CopyButton
- value={partner.email}
- variant="neutral"
- className="p-1 [&>*]:h-3 [&>*]:w-3"
- successMessage="Copied email to clipboard!"
- />
- </div>
- )
- ) : (
- <div className="mt-0.5 h-5 w-32 animate-pulse rounded bg-neutral-200" />
- )}
+ {isEnrolled &&
+ (partner ? (
+ partner.email && (
+ <div className="mt-0.5 flex items-center gap-1">
+ <span className="text-sm font-medium text-neutral-500">
+ {partner.email}
+ </span>
+ <CopyButton
+ value={partner.email}
+ variant="neutral"
+ className="p-1 [&>*]:h-3 [&>*]:w-3"
+ successMessage="Copied email to clipboard!"
+ />
+ </div>
+ )
+ ) : (
+ <div className="mt-0.5 h-5 w-32 animate-pulse rounded bg-neutral-200" />
+ ))}
<div className="mt-3 flex flex-col gap-2">
{basicFields
.filter(({ text }) => text !== null)
- .map(({ id, icon, text }) => (
- <div
- key={id}
- className="text-content-subtle flex items-center gap-1"
- >
- {text !== undefined ? (
- <>
- {icon}
- <span className="text-xs font-medium">{text}</span>
- </>
- ) : (
- <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
- )}
- </div>
+ .map(({ id, icon, text, wrapper: Wrapper = "div" }) => (
+ <Wrapper key={id}>
+ <div className="text-content-subtle flex items-center gap-1">
+ {text !== undefined ? (
+ <>
+ {icon}
+ <span className="text-xs font-medium">{text}</span>
+ </>
+ ) : (
+ <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
+ )}
+ </div>
+ </Wrapper>
))}
</div>
</div>
@@ -238,7 +287,7 @@ export function PartnerInfoCards({
</div>
{/* Eligible bounties */}
- {partner?.status === "approved" && (
+ {isEnrolled && partner?.status === "approved" && (
<div className="flex flex-col gap-2">
<h3 className="text-content-emphasis text-xs font-semibold">
Eligible Bounties
diff --git a/apps/web/ui/partners/partner-info-group.tsx b/apps/web/ui/partners/partner-info-group.tsx
index a694d2407a..1ea34c4232 100644
--- a/apps/web/ui/partners/partner-info-group.tsx
+++ b/apps/web/ui/partners/partner-info-group.tsx
@@ -16,7 +16,8 @@ export function PartnerInfoGroup({
selectedGroupId,
setSelectedGroupId,
}: {
- partner: EnrolledPartnerProps;
+ partner: Pick<EnrolledPartnerProps, "id" | "groupId" | "name" | "image"> &
+ Partial<Pick<EnrolledPartnerProps, "email">>;
changeButtonText?: string;
className?: string;
diff --git a/apps/web/ui/partners/partner-network-partner-sheet.tsx b/apps/web/ui/partners/partner-network-partner-sheet.tsx
new file mode 100644
index 0000000000..a7d997a9d1
--- /dev/null
+++ b/apps/web/ui/partners/partner-network-partner-sheet.tsx
@@ -0,0 +1,282 @@
+import { approvePartnerAction } from "@/lib/actions/partners/approve-partner";
+import { rejectPartnerAction } from "@/lib/actions/partners/reject-partner";
+import { mutatePrefix } from "@/lib/swr/mutate";
+import useProgram from "@/lib/swr/use-program";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { PartnerNetworkPartnerProps } from "@/lib/types";
+import { useConfirmModal } from "@/ui/modals/confirm-modal";
+import { X } from "@/ui/shared/icons";
+import {
+ Button,
+ ChevronLeft,
+ ChevronRight,
+ Sheet,
+ useKeyboardShortcut,
+ useRouterStuff,
+} from "@dub/ui";
+import { useAction } from "next-safe-action/hooks";
+import { Dispatch, SetStateAction, useState } from "react";
+import { toast } from "sonner";
+import { PartnerAbout } from "./partner-about";
+import { PartnerComments } from "./partner-comments";
+import { PartnerInfoCards } from "./partner-info-cards";
+import { PartnerSheetTabs } from "./partner-sheet-tabs";
+
+type PartnerNetworkPartnerSheetProps = {
+ partner: PartnerNetworkPartnerProps;
+ onNext?: () => void;
+ onPrevious?: () => void;
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
+};
+
+function PartnerNetworkPartnerSheetContent({
+ partner,
+ onPrevious,
+ onNext,
+ setIsOpen,
+}: PartnerNetworkPartnerSheetProps) {
+ const { slug: workspaceSlug } = useWorkspace();
+ const [currentTabId, setCurrentTabId] = useState<string>("about");
+
+ const [selectedGroupId, setSelectedGroupId] = useState<string | null>(null);
+
+ return (
+ <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 discovery
+ </Sheet.Title>
+ <div className="flex items-center gap-4">
+ <div className="flex items-center">
+ <Button
+ type="button"
+ disabled={!onPrevious}
+ onClick={onPrevious}
+ variant="secondary"
+ className="size-9 rounded-l-lg rounded-r-none p-0"
+ icon={<ChevronLeft className="size-3.5" />}
+ />
+ <Button
+ type="button"
+ disabled={!onNext}
+ onClick={onNext}
+ variant="secondary"
+ className="-ml-px size-9 rounded-l-none rounded-r-lg p-0"
+ icon={<ChevronRight className="size-3.5" />}
+ />
+ </div>
+ <Sheet.Close asChild>
+ <Button
+ variant="outline"
+ icon={<X className="size-5" />}
+ className="h-auto w-fit p-1"
+ />
+ </Sheet.Close>
+ </div>
+ </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">
+ <div className="@3xl/sheet:order-2">
+ <PartnerInfoCards
+ type="network"
+ partner={partner}
+ hideStatuses={["pending"]}
+ selectedGroupId={selectedGroupId}
+ setSelectedGroupId={setSelectedGroupId}
+ />
+ </div>
+ <div className="@3xl/sheet:order-1">
+ <div className="border-border-subtle overflow-hidden rounded-xl border bg-neutral-100">
+ <PartnerSheetTabs
+ partnerId={partner.id}
+ currentTabId={currentTabId}
+ setCurrentTabId={setCurrentTabId}
+ />
+ <div className="border-border-subtle -mx-px -mb-px rounded-xl border bg-white p-4">
+ {currentTabId === "about" && (
+ <div className="grid grid-cols-1 gap-5 text-sm text-neutral-600">
+ <PartnerAbout partner={partner} />
+ </div>
+ )}
+ {currentTabId === "comments" && (
+ <div>
+ <h3 className="text-content-emphasis text-lg font-semibold">
+ Comments
+ </h3>
+ <PartnerComments partnerId={partner.id} />
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div className="shrink-0 border-t border-neutral-200 p-5">
+ {/* <PartnerApproval
+ key={partner.id} // Reset when navigating between partners to avoid memoized action callback issues
+ partner={partner}
+ groupId={
+ partner.status === "rejected" ? selectedGroupId : partner.groupId
+ }
+ setIsOpen={setIsOpen}
+ onNext={onNext}
+ /> */}
+ </div>
+ </div>
+ );
+}
+
+export function PartnerNetworkPartnerSheet({
+ isOpen,
+ nested,
+ ...rest
+}: PartnerNetworkPartnerSheetProps & {
+ isOpen: boolean;
+ nested?: boolean;
+}) {
+ const { queryParams } = useRouterStuff();
+ return (
+ <Sheet
+ open={isOpen}
+ onOpenChange={rest.setIsOpen}
+ onClose={() => queryParams({ del: "partnerId", scroll: false })}
+ nested={nested}
+ contentProps={{
+ // 540px - 1170px width based on viewport
+ className: "md:w-[max(min(calc(100vw-334px),1170px),540px)]",
+ }}
+ >
+ <PartnerNetworkPartnerSheetContent {...rest} />
+ </Sheet>
+ );
+}
+
+function PartnerApproval({
+ partner,
+ groupId,
+ setIsOpen,
+ onNext,
+}: {
+ partner: PartnerNetworkPartnerProps;
+ groupId?: string | null;
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
+ onNext?: () => void;
+}) {
+ const { id: workspaceId } = useWorkspace();
+ const { program } = useProgram();
+
+ const { executeAsync, isPending } = useAction(approvePartnerAction, {
+ onSuccess: () => {
+ onNext ? onNext() : setIsOpen(false);
+ toast.success(`Successfully approved ${partner.name} to your program.`);
+ mutatePrefix("/api/partners");
+ },
+ onError({ error }) {
+ toast.error(error.serverError || "Failed to approve partner.");
+ },
+ });
+
+ const { setShowConfirmModal, confirmModal } = useConfirmModal({
+ title: "Approve Partner",
+ description: "Are you sure you want to approve this partner application?",
+ confirmText: "Approve",
+ confirmShortcut: "a",
+ confirmShortcutOptions: { sheet: true, modal: true },
+ onConfirm: async () => {
+ if (!program || !workspaceId) return;
+
+ await executeAsync({
+ workspaceId: workspaceId,
+ partnerId: partner.id,
+ groupId,
+ });
+ },
+ });
+
+ useKeyboardShortcut("a", () => setShowConfirmModal(true), { sheet: true });
+
+ return (
+ <>
+ {confirmModal}
+ <div className="flex justify-end gap-2">
+ <div className="flex-shrink-0">
+ <PartnerRejectButton
+ partner={partner}
+ setIsOpen={setIsOpen}
+ onNext={onNext}
+ />
+ </div>
+ <Button
+ type="button"
+ variant="primary"
+ text="Approve"
+ shortcut="A"
+ loading={isPending}
+ onClick={() => setShowConfirmModal(true)}
+ className="w-fit shrink-0"
+ />
+ </div>
+ </>
+ );
+}
+
+function PartnerRejectButton({
+ partner,
+ setIsOpen,
+ onNext,
+}: {
+ partner: PartnerNetworkPartnerProps;
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
+ onNext?: () => void;
+}) {
+ const { id: workspaceId } = useWorkspace();
+
+ const { executeAsync: rejectPartner, isPending } = useAction(
+ rejectPartnerAction,
+ {
+ onSuccess: () => {
+ onNext ? onNext() : setIsOpen(false);
+ toast.success(
+ `Partner ${partner.name} has been rejected from your program.`,
+ );
+ mutatePrefix("/api/partners");
+ },
+ onError({ error }) {
+ toast.error(error.serverError || "Failed to reject partner.");
+ },
+ },
+ );
+
+ const { setShowConfirmModal, confirmModal } = useConfirmModal({
+ title: "Reject Application",
+ description: "Are you sure you want to reject this partner application?",
+ confirmText: "Reject",
+ confirmShortcut: "r",
+ confirmShortcutOptions: { sheet: true, modal: true },
+ onConfirm: async () => {
+ await rejectPartner({
+ workspaceId: workspaceId!,
+ partnerId: partner.id,
+ });
+ },
+ });
+
+ useKeyboardShortcut("r", () => setShowConfirmModal(true), { sheet: true });
+
+ return (
+ <>
+ {confirmModal}
+ <Button
+ type="button"
+ variant="secondary"
+ text={isPending ? "" : "Reject"}
+ loading={isPending}
+ shortcut="R"
+ onClick={() => {
+ setShowConfirmModal(true);
+ }}
+ className="px-4"
+ />
+ </>
+ );
+}
diff --git a/apps/web/ui/partners/partner-network/conversion-score-tooltip.tsx b/apps/web/ui/partners/partner-network/conversion-score-tooltip.tsx
new file mode 100644
index 0000000000..118e048e72
--- /dev/null
+++ b/apps/web/ui/partners/partner-network/conversion-score-tooltip.tsx
@@ -0,0 +1,66 @@
+import {
+ PARTNER_CONVERSION_SCORES,
+ PARTNER_CONVERSION_SCORE_RATES,
+} from "@/lib/zod/schemas/partner-network";
+import { DynamicTooltipWrapper } from "@dub/ui";
+import { capitalize } from "@dub/utils";
+import { PropsWithChildren } from "react";
+import { ConversionScoreIcon } from "../conversion-score-icon";
+
+export function ConversionScoreTooltip({
+ enabled = true,
+ children,
+}: PropsWithChildren<{ enabled?: boolean }>) {
+ return (
+ <DynamicTooltipWrapper
+ tooltipProps={
+ enabled
+ ? {
+ content: (
+ <div className="max-w-60 p-2.5 text-xs">
+ <div className="flex flex-col gap-2.5">
+ {PARTNER_CONVERSION_SCORES.map((score, idx) => (
+ <div key={score} className="flex items-center gap-1.5">
+ <ConversionScoreIcon
+ score={score}
+ className="size-3.5 shrink-0"
+ />
+ <span className="text-content-default font-semibold">
+ {capitalize(score)}{" "}
+ <span className="text-content-subtle font-medium">
+ (
+ {idx < PARTNER_CONVERSION_SCORES.length - 1 ? (
+ <>
+ {PARTNER_CONVERSION_SCORE_RATES[score] * 100}-
+ {PARTNER_CONVERSION_SCORE_RATES[
+ PARTNER_CONVERSION_SCORES[idx + 1]
+ ] * 100}
+ </>
+ ) : (
+ <>
+ &gt;
+ {PARTNER_CONVERSION_SCORE_RATES[score] * 100}
+ </>
+ )}
+ %)
+ </span>
+ </span>
+ </div>
+ ))}
+ </div>
+ <p className="text-content-subtle mt-4 font-medium">
+ This score is an average for all Dub programs the partner is
+ enrolled in.
+ </p>
+ </div>
+ ),
+ side: "right",
+ align: "end",
+ }
+ : undefined
+ }
+ >
+ {children}
+ </DynamicTooltipWrapper>
+ );
+}
diff --git a/apps/web/ui/partners/partner-application-tabs.tsx b/apps/web/ui/partners/partner-sheet-tabs.tsx
similarity index 98%
rename from apps/web/ui/partners/partner-application-tabs.tsx
rename to apps/web/ui/partners/partner-sheet-tabs.tsx
index 43ce44bfb5..5332ed527f 100644
--- a/apps/web/ui/partners/partner-application-tabs.tsx
+++ b/apps/web/ui/partners/partner-sheet-tabs.tsx
@@ -4,7 +4,7 @@ import { cn } from "@dub/utils";
import { LayoutGroup, motion } from "motion/react";
import { Dispatch, SetStateAction, useId, useMemo } from "react";
-export function PartnerApplicationTabs({
+export function PartnerSheetTabs({
partnerId,
currentTabId,
setCurrentTabId,