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.

Update rewards display UI for referral embed and partner program overview

Tim Wilson7e50d845ab9d
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/route.ts
index d094032247..e4ea8f4883 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/route.ts
@@ -14,12 +14,24 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
const { partnerId, programId } = programEnrollment;
- const [reward, discount] = await Promise.all([
- determinePartnerReward({
- event: "sale",
- partnerId,
- programId,
- }),
+ const [rewards, discount] = await Promise.all([
+ Promise.all([
+ determinePartnerReward({
+ event: "click",
+ partnerId,
+ programId,
+ }),
+ determinePartnerReward({
+ event: "lead",
+ partnerId,
+ programId,
+ }),
+ determinePartnerReward({
+ event: "sale",
+ partnerId,
+ programId,
+ }),
+ ]),
determinePartnerDiscount({
partnerId,
@@ -30,7 +42,7 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {
return NextResponse.json(
ProgramEnrollmentSchema.parse({
...programEnrollment,
- reward,
+ rewards: rewards.filter((reward) => reward !== null),
discount,
}),
);
diff --git a/apps/web/app/app.dub.co/embed/referrals/page-client.tsx b/apps/web/app/app.dub.co/embed/referrals/page-client.tsx
index 0bca8dd8d9..9150829e76 100644
--- a/apps/web/app/app.dub.co/embed/referrals/page-client.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/page-client.tsx
@@ -2,13 +2,12 @@
import { DiscountProps, RewardProps } from "@/lib/types";
import { HeroBackground } from "@/ui/partners/hero-background";
-import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
+import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { Link, PayoutStatus, Program } from "@dub/prisma/client";
import {
Button,
Check,
Copy,
- MoneyBill,
ToggleGroup,
useCopyToClipboard,
Wordmark,
@@ -30,7 +29,7 @@ const tabs = ["Quickstart", "Earnings", "Leaderboard", "FAQ"];
export function ReferralsEmbedPageClient({
program,
links,
- reward,
+ rewards,
discount,
payouts,
stats,
@@ -38,7 +37,7 @@ export function ReferralsEmbedPageClient({
}: {
program: Program;
links: Link[];
- reward: RewardProps | null;
+ rewards: RewardProps[];
discount?: DiscountProps | null;
payouts: {
status: PayoutStatus;
@@ -65,23 +64,20 @@ export function ReferralsEmbedPageClient({
>
<div className="relative z-0 p-5">
<div className="border-border-default relative flex flex-col overflow-hidden rounded-lg border p-4 md:p-6">
- <HeroBackground logo={program.logo} color={program.brandColor} />
- <span className="text-content-subtle flex items-center gap-2 text-sm">
- <MoneyBill className="size-4" />
- Refer and earn
- </span>
- <div className="text-content-emphasis relative mt-16 text-lg sm:max-w-[50%]">
- <ProgramRewardDescription reward={reward} discount={discount} />
- </div>
- <span className="text-content-default mb-1.5 mt-6 block text-sm">
+ <HeroBackground
+ logo={program.logo}
+ color={program.brandColor}
+ embed
+ />
+ <span className="text-base font-semibold text-neutral-800">
Referral link
</span>
- <div className="xs:flex-row relative flex flex-col items-center gap-2">
+ <div className="xs:flex-row xs:items-center relative mt-3 flex flex-col gap-2 sm:max-w-[50%]">
<input
type="text"
readOnly
value={getPrettyUrl(links[0].shortLink)}
- className="xs:w-auto border-border-default text-content-default focus:border-border-emphasis bg-bg-default h-10 w-full rounded-md border px-3 text-sm focus:outline-none focus:ring-neutral-500 lg:min-w-64 xl:min-w-72"
+ className="border-border-default text-content-default focus:border-border-emphasis bg-bg-default h-10 min-w-0 shrink grow rounded-md border px-3 text-sm focus:outline-none focus:ring-neutral-500"
/>
<Button
icon={
@@ -109,6 +105,12 @@ export function ReferralsEmbedPageClient({
onClick={() => copyToClipboard(links[0].shortLink)}
/>
</div>
+ <span className="mt-12 text-base font-semibold text-neutral-800">
+ Rewards
+ </span>
+ <div className="text-content-emphasis relative mt-2 text-lg sm:max-w-[50%]">
+ <ProgramRewardList rewards={rewards} discount={discount} />
+ </div>
<div className="mt-4 flex justify-center md:absolute md:bottom-3 md:right-3 md:mt-0">
<a
href="https://dub.partners"
@@ -153,7 +155,7 @@ export function ReferralsEmbedPageClient({
) : selectedTab === "Leaderboard" ? (
<ReferralsEmbedLeaderboard />
) : selectedTab === "FAQ" ? (
- <ReferralsEmbedFAQ program={program} reward={reward} />
+ <ReferralsEmbedFAQ program={program} reward={rewards[0]} />
) : null}
</AnimatePresence>
</div>
diff --git a/apps/web/app/app.dub.co/embed/referrals/page.tsx b/apps/web/app/app.dub.co/embed/referrals/page.tsx
index f8dca42dbe..d07a0d0a4b 100644
--- a/apps/web/app/app.dub.co/embed/referrals/page.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/page.tsx
@@ -1,5 +1,5 @@
import { HeroBackground } from "@/ui/partners/hero-background";
-import { Button, Copy, MoneyBill, Wordmark } from "@dub/ui";
+import { Button, Copy, Wordmark } from "@dub/ui";
import { Suspense } from "react";
import { ReferralsEmbedPageClient } from "./page-client";
import { parseThemeOptions, ThemeOptions } from "./theme-options";
@@ -48,11 +48,7 @@ function EmbedInlineLoading({ themeOptions }: { themeOptions: ThemeOptions }) {
<div className="p-5">
<div className="border-border-default relative flex flex-col overflow-hidden rounded-lg border p-4 md:p-6">
<HeroBackground color="#737373" />
- <span className="text-content-subtle flex items-center gap-2 text-sm">
- <MoneyBill className="size-4" />
- Refer and earn
- </span>
- <div className="relative mt-16 flex flex-col gap-2">
+ <div className="relative flex flex-col gap-2">
<div className="bg-bg-muted h-6 w-60 rounded-md" />
<div className="bg-bg-muted h-6 w-40 rounded-md" />
</div>
diff --git a/apps/web/app/app.dub.co/embed/referrals/utils.ts b/apps/web/app/app.dub.co/embed/referrals/utils.ts
index c5ffb04589..423c7e31c9 100644
--- a/apps/web/app/app.dub.co/embed/referrals/utils.ts
+++ b/apps/web/app/app.dub.co/embed/referrals/utils.ts
@@ -28,12 +28,24 @@ export const getReferralsEmbedData = async (token: string) => {
notFound();
}
- const [reward, discount, payouts] = await Promise.all([
- determinePartnerReward({
- programId,
- partnerId,
- event: "sale",
- }),
+ const [rewards, discount, payouts] = await Promise.all([
+ Promise.all([
+ determinePartnerReward({
+ programId,
+ partnerId,
+ event: "click",
+ }),
+ determinePartnerReward({
+ programId,
+ partnerId,
+ event: "lead",
+ }),
+ determinePartnerReward({
+ programId,
+ partnerId,
+ event: "sale",
+ }),
+ ]),
determinePartnerDiscount({
programId,
@@ -57,7 +69,7 @@ export const getReferralsEmbedData = async (token: string) => {
return {
program,
links,
- reward,
+ rewards: rewards.filter((reward) => reward !== null),
discount,
payouts: payouts.map((payout) => ({
status: payout.status,
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx
index ffda2d0387..cc3611e2aa 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/page-client.tsx
@@ -8,7 +8,7 @@ import usePartnerAnalytics from "@/lib/swr/use-partner-analytics";
import { usePartnerEarningsTimeseries } from "@/lib/swr/use-partner-earnings-timeseries";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import { HeroBackground } from "@/ui/partners/hero-background";
-import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
+import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
import {
Button,
@@ -24,7 +24,7 @@ import {
TimeSeriesChart,
XAxis,
} from "@dub/ui/charts";
-import { Check, Copy, LoadingSpinner, MoneyBill } from "@dub/ui/icons";
+import { Check, Copy, LoadingSpinner } from "@dub/ui/icons";
import { cn, currencyFormatter, getPrettyUrl, nFormatter } from "@dub/utils";
import NumberFlow, { NumberFlowGroup } from "@number-flow/react";
import { LinearGradient } from "@visx/gradient";
@@ -98,30 +98,16 @@ export default function ProgramPageClient() {
color={program.brandColor}
/>
)}
- <span className="mt-2 flex items-center gap-2 text-sm text-neutral-500">
- <MoneyBill className="size-4" />
- Refer and earn
- </span>
- <div className="relative mt-24 text-lg text-neutral-900 sm:max-w-[50%]">
- {program ? (
- <ProgramRewardDescription
- reward={programEnrollment?.reward}
- discount={programEnrollment?.discount}
- />
- ) : (
- <div className="h-7 w-5/6 animate-pulse rounded-md bg-neutral-200" />
- )}
- </div>
- <span className="mb-1.5 mt-6 block text-sm text-neutral-800">
+ <span className="text-base font-semibold text-neutral-800">
Referral link
</span>
- <div className="xs:flex-row relative flex flex-col items-center gap-2">
+ <div className="xs:flex-row xs:items-center relative mt-3 flex flex-col gap-2 md:max-w-[50%]">
{masterLink ? (
<input
type="text"
readOnly
value={getPrettyUrl(masterLink.shortLink)}
- className="xs:w-auto h-10 w-full rounded-md border border-neutral-300 px-3 text-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 lg:min-w-64 xl:min-w-72"
+ className="border-border-default text-content-default focus:border-border-emphasis bg-bg-default h-10 min-w-0 shrink grow rounded-md border px-3 text-sm focus:outline-none focus:ring-neutral-500"
/>
) : (
<div className="h-10 w-16 animate-pulse rounded-md bg-neutral-200 lg:w-72" />
@@ -157,6 +143,19 @@ export default function ProgramPageClient() {
}}
/>
</div>
+ <span className="mt-12 text-base font-semibold text-neutral-800">
+ Rewards
+ </span>
+ <div className="relative mt-2 text-lg text-neutral-900 md:max-w-[50%]">
+ {program && programEnrollment?.rewards ? (
+ <ProgramRewardList
+ rewards={programEnrollment?.rewards}
+ discount={programEnrollment?.discount}
+ />
+ ) : (
+ <div className="h-7 w-5/6 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
</div>
</motion.div>
)}
diff --git a/apps/web/lib/api/sales/construct-reward-amount.ts b/apps/web/lib/api/sales/construct-reward-amount.ts
index 0eb56091dd..13e5211a38 100644
--- a/apps/web/lib/api/sales/construct-reward-amount.ts
+++ b/apps/web/lib/api/sales/construct-reward-amount.ts
@@ -10,7 +10,13 @@ export const constructRewardAmount = ({
}) => {
return type === "percentage"
? `${amount}%`
- : currencyFormatter(amount / 100, {
- maximumFractionDigits: 2,
- });
+ : currencyFormatter(
+ amount / 100,
+ amount % 100 === 0
+ ? undefined
+ : {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ },
+ );
};
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index dfb9581910..3775efe552 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -66,7 +66,7 @@ export const ProgramEnrollmentSchema = z.object({
program: ProgramSchema,
status: z.nativeEnum(ProgramEnrollmentStatus),
links: z.array(ProgramPartnerLinkSchema).nullable(),
- reward: RewardSchema.nullish(),
+ rewards: z.array(RewardSchema).nullish(),
discount: DiscountSchema.nullish(),
createdAt: z.date(),
});
diff --git a/apps/web/ui/partners/constants.ts b/apps/web/ui/partners/constants.ts
index 82dee37547..5dbfc33644 100644
--- a/apps/web/ui/partners/constants.ts
+++ b/apps/web/ui/partners/constants.ts
@@ -1,5 +1,4 @@
-import { CursorRays, MoneyBill } from "@dub/ui/icons";
-import { UserPlus } from "lucide-react";
+import { CursorRays, InvoiceDollar, UserPlus } from "@dub/ui/icons";
export const REWARD_EVENTS = {
click: {
@@ -17,7 +16,7 @@ export const REWARD_EVENTS = {
eventName: "signup",
},
sale: {
- icon: MoneyBill,
+ icon: InvoiceDollar,
text: "Sale reward",
event: "sale",
shortcut: "S",
diff --git a/apps/web/ui/partners/hero-background.tsx b/apps/web/ui/partners/hero-background.tsx
index 8d73c60d06..21c3df971c 100644
--- a/apps/web/ui/partners/hero-background.tsx
+++ b/apps/web/ui/partners/hero-background.tsx
@@ -9,9 +9,11 @@ const BG_INVERTED = "rgb(var(--bg-inverted))";
export function HeroBackground({
logo,
color,
+ embed = false,
}: {
logo?: string | null;
color?: string | null;
+ embed?: boolean;
}) {
const id = useId();
@@ -40,7 +42,10 @@ export function HeroBackground({
height="258"
fill="none"
viewBox="0 0 718 258"
- className="pointer-events-none absolute right-0 top-0 hidden h-full w-auto md:block"
+ className={cn(
+ "pointer-events-none absolute right-0 top-0 hidden h-full w-auto",
+ embed ? "md:block" : "lg:block",
+ )}
>
<mask
id={`${id}-grid-mask`}
@@ -324,7 +329,10 @@ export function HeroBackground({
"absolute right-4 top-4 block size-6 min-[300px]:size-8",
// Position based on cqh to adjust for container height
- "md:right-[62cqh] md:top-1/2 md:size-[32cqh] md:-translate-y-1/2 md:translate-x-1/2",
+ "",
+ embed
+ ? "md:right-[62cqh] md:top-1/2 md:size-[32cqh] md:-translate-y-1/2 md:translate-x-1/2"
+ : "lg:right-[62cqh] lg:top-1/2 lg:size-[32cqh] lg:-translate-y-1/2 lg:translate-x-1/2",
"drop-shadow-[0_0_15px_rgb(from_var(--brand-dark,#000)_r_g_b/0.4)]",
)}
diff --git a/apps/web/ui/partners/program-reward-list.tsx b/apps/web/ui/partners/program-reward-list.tsx
new file mode 100644
index 0000000000..67b08c0f24
--- /dev/null
+++ b/apps/web/ui/partners/program-reward-list.tsx
@@ -0,0 +1,69 @@
+import { constructRewardAmount } from "@/lib/api/sales/construct-reward-amount";
+import { DiscountProps, RewardProps } from "@/lib/types";
+import { Gift, Icon } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { PropsWithChildren } from "react";
+import { REWARD_EVENTS } from "./constants";
+
+export function ProgramRewardList({
+ rewards,
+ discount,
+ className,
+}: {
+ rewards: RewardProps[];
+ discount?: DiscountProps | null;
+ className?: string;
+}) {
+ const sortedFilteredRewards = rewards.filter((r) => r.amount >= 0);
+
+ return (
+ <ul
+ className={cn(
+ "flex flex-col gap-4 rounded-md border border-neutral-200 bg-white p-4",
+ className,
+ )}
+ >
+ {sortedFilteredRewards.map((reward) => (
+ <Item key={reward.id} icon={REWARD_EVENTS[reward.event].icon}>
+ {constructRewardAmount({
+ amount: reward.amount,
+ type: reward.type,
+ })}{" "}
+ per {reward.event}
+ {reward.maxDuration === null ? (
+ <> for the customer's lifetime</>
+ ) : reward.maxDuration && reward.maxDuration > 1 ? (
+ <>, and again every month for {reward.maxDuration} months</>
+ ) : null}
+ </Item>
+ ))}
+ {discount && (
+ <Item icon={Gift}>
+ {" "}
+ Users get{" "}
+ {constructRewardAmount({
+ amount: discount.amount,
+ type: discount.type,
+ })}{" "}
+ off{" "}
+ {discount.maxDuration === null ? (
+ <> for their lifetime</>
+ ) : discount.maxDuration && discount.maxDuration > 1 ? (
+ <>for {discount.maxDuration} months</>
+ ) : (
+ <>for their first purchase</>
+ )}
+ </Item>
+ )}
+ </ul>
+ );
+}
+
+const Item = ({ icon: Icon, children }: PropsWithChildren<{ icon: Icon }>) => {
+ return (
+ <li className="flex items-center gap-2 text-sm text-neutral-600">
+ <Icon className="size-4" />
+ <div>{children}</div>
+ </li>
+ );
+};
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 85557ac649..9bf8a019d4 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -172,6 +172,7 @@ export * from "./ui-card";
export * from "./user";
export * from "./user-check";
export * from "./user-crown";
+export * from "./user-plus";
export * from "./users";
export * from "./users-settings";
export * from "./users2";
diff --git a/packages/ui/src/icons/nucleo/user-plus.tsx b/packages/ui/src/icons/nucleo/user-plus.tsx
new file mode 100644
index 0000000000..b2ebf2c214
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/user-plus.tsx
@@ -0,0 +1,56 @@
+import { SVGProps } from "react";
+
+export function UserPlus(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <circle
+ cx="9"
+ cy="4.5"
+ fill="none"
+ r="2.75"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="17.25"
+ x2="12.25"
+ y1="14.75"
+ y2="14.75"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="14.75"
+ x2="14.75"
+ y1="12.25"
+ y2="17.25"
+ />
+ <path
+ d="M12.633,10.932c-1.024-.738-2.274-1.182-3.633-1.182-2.551,0-4.739,1.53-5.709,3.72-.365,.825,.087,1.774,.947,2.045,1.225,.386,2.846,.734,4.762,.734,.422,0,.824-.023,1.217-.053"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}