Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add resources to referral embed

Tim Wilson6c209ac8eb45
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..529a89eaf9 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
@@ -1,32 +1,36 @@
"use client";
import { DiscountProps, RewardProps } from "@/lib/types";
+import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
import { HeroBackground } from "@/ui/partners/hero-background";
import { ProgramRewardDescription } from "@/ui/partners/program-reward-description";
+import { ThreeDots } from "@/ui/shared/icons";
import { Link, PayoutStatus, Program } from "@dub/prisma/client";
import {
Button,
Check,
Copy,
+ Directions,
MoneyBill,
- ToggleGroup,
+ Popover,
+ TabSelect,
useCopyToClipboard,
+ useLocalStorage,
Wordmark,
} from "@dub/ui";
import { cn, getPrettyUrl } from "@dub/utils";
import { AnimatePresence } from "framer-motion";
-import { useState } from "react";
+import { useEffect, useMemo, useState } from "react";
import { ReferralsEmbedActivity } from "./activity";
import { ReferralsEmbedEarnings } from "./earnings";
import { ReferralsEmbedFAQ } from "./faq";
import { ReferralsEmbedLeaderboard } from "./leaderboard";
import { ReferralsEmbedPayouts } from "./payouts";
import { ReferralsEmbedQuickstart } from "./quickstart";
+import { ReferralsEmbedResources } from "./resources";
import { ThemeOptions } from "./theme-options";
import { ReferralsReferralsEmbedToken } from "./token";
-const tabs = ["Quickstart", "Earnings", "Leaderboard", "FAQ"];
-
export function ReferralsEmbedPageClient({
program,
links,
@@ -51,9 +55,39 @@ export function ReferralsEmbedPageClient({
};
themeOptions: ThemeOptions;
}) {
+ const resources = programResourcesSchema.parse(
+ program.resources ?? { logos: [], colors: [], files: [] },
+ );
+
+ const hasResources =
+ resources &&
+ ["logos", "colors", "files"].some(
+ (resource) => resources?.[resource]?.length,
+ );
+
+ const [showQuickstart, setShowQuickstart] = useLocalStorage(
+ "referral-embed-show-quickstart",
+ true,
+ );
+
+ const tabs = useMemo(
+ () => [
+ ...(showQuickstart ? ["Quickstart"] : []),
+ "Earnings",
+ "Leaderboard",
+ "FAQ",
+ ...(hasResources ? ["Resources"] : []),
+ ],
+ [showQuickstart, hasResources],
+ );
+
const [copied, copyToClipboard] = useCopyToClipboard();
const [selectedTab, setSelectedTab] = useState(tabs[0]);
+ useEffect(() => {
+ if (!tabs.includes(selectedTab)) setSelectedTab(tabs[0]);
+ }, [tabs, selectedTab]);
+
return (
<div
style={
@@ -131,29 +165,48 @@ export function ReferralsEmbedPageClient({
<ReferralsEmbedPayouts payouts={payouts} />
</div>
<div className="mt-4">
- <ToggleGroup
- options={tabs.map((tab) => ({
- label: tab,
- value: tab,
- }))}
- selected={selectedTab}
- selectAction={(option) => {
- setSelectedTab(option);
- }}
- className="bg-bg-muted w-full rounded-lg"
- optionClassName="w-full flex justify-center py-1.5"
- indicatorClassName="bg-bg-default"
- />
+ <div className="flex items-center border-b border-neutral-200">
+ <TabSelect
+ options={tabs.map((tab) => ({
+ id: tab,
+ label: tab,
+ }))}
+ selected={selectedTab}
+ onSelect={(option) => {
+ console.log("onSelect", option);
+ setSelectedTab(option);
+ }}
+ className="scrollbar-hide min-w-0 grow overflow-x-auto"
+ />
+
+ <div className="shrink">
+ <Menu
+ showQuickstart={showQuickstart}
+ setShowQuickstart={(show) => {
+ setShowQuickstart(show);
+ if (show) setSelectedTab("Quickstart");
+ }}
+ />
+ </div>
+ </div>
<div className="my-4">
<AnimatePresence mode="wait">
{selectedTab === "Quickstart" ? (
- <ReferralsEmbedQuickstart program={program} link={links[0]} />
+ <ReferralsEmbedQuickstart
+ program={program}
+ link={links[0]}
+ onViewResources={
+ hasResources ? () => setSelectedTab("Resources") : undefined
+ }
+ />
) : selectedTab === "Earnings" ? (
<ReferralsEmbedEarnings salesCount={stats.sales} />
) : selectedTab === "Leaderboard" ? (
<ReferralsEmbedLeaderboard />
) : selectedTab === "FAQ" ? (
<ReferralsEmbedFAQ program={program} reward={reward} />
+ ) : selectedTab === "Resources" ? (
+ <ReferralsEmbedResources resources={resources} />
) : null}
</AnimatePresence>
</div>
@@ -163,3 +216,47 @@ export function ReferralsEmbedPageClient({
</div>
);
}
+
+function Menu({
+ showQuickstart,
+ setShowQuickstart,
+}: {
+ showQuickstart: boolean;
+ setShowQuickstart: (value: boolean) => void;
+}) {
+ const [openPopover, setOpenPopover] = useState(false);
+
+ return (
+ <Popover
+ content={
+ <div className="grid w-full grid-cols-1 gap-px p-2 sm:w-48">
+ <Button
+ text={`${showQuickstart ? "Hide" : "Show"} starting guide`}
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowQuickstart(!showQuickstart);
+ }}
+ icon={<Directions className="size-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <Button
+ variant="secondary"
+ className={cn(
+ "h-8 px-1.5 text-neutral-500 outline-none transition-all duration-200",
+ "border-transparent data-[state=open]:border-neutral-500 sm:group-hover/card:data-[state=closed]:border-neutral-200",
+ )}
+ icon={<ThreeDots className="size-4 shrink-0" />}
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ />
+ </Popover>
+ );
+}
diff --git a/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx b/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx
index f74221149f..a5b77426b1 100644
--- a/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx
@@ -18,9 +18,11 @@ const BUTTON_CLASSNAME = "h-9 rounded-lg bg-bg-inverted hover:bg-neutral-800";
export function ReferralsEmbedQuickstart({
program,
link,
+ onViewResources,
}: {
program: Program;
link: Link;
+ onViewResources?: () => void;
}) {
const [copied, copyToClipboard] = useCopyToClipboard();
const { isMobile } = useMediaQuery();
@@ -64,7 +66,14 @@ export function ReferralsEmbedQuickstart({
description:
"Make sure you get setup for success with the official brand files and supportive content and documents.",
illustration: <SuccessKit logo={program.logo ?? DUB_LOGO} />,
- cta: <Button className="h-9 rounded-lg" text="Coming soon" disabled />,
+ cta: (
+ <Button
+ className="h-9 rounded-lg"
+ text={onViewResources ? "View resources" : "No resources"}
+ disabled={!onViewResources}
+ onClick={onViewResources}
+ />
+ ),
},
{
title: "Receive earnings",
diff --git a/apps/web/app/app.dub.co/embed/referrals/resources.tsx b/apps/web/app/app.dub.co/embed/referrals/resources.tsx
new file mode 100644
index 0000000000..77a400c8ba
--- /dev/null
+++ b/apps/web/app/app.dub.co/embed/referrals/resources.tsx
@@ -0,0 +1,80 @@
+import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
+import { ResourceCard } from "@/ui/partners/resources/resource-card";
+import { ResourceSection } from "@/ui/partners/resources/resource-section";
+import { FileContent } from "@dub/ui";
+import { formatFileSize, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/utils";
+import { motion } from "framer-motion";
+import { z } from "zod";
+
+export function ReferralsEmbedResources({
+ resources,
+}: {
+ resources: z.infer<typeof programResourcesSchema>;
+}) {
+ return (
+ <motion.div
+ className="flex flex-col gap-4"
+ {...TAB_ITEM_ANIMATION_SETTINGS}
+ >
+ {!!resources?.logos?.length && (
+ <ResourceSection resource="logo" title="Brand logos">
+ {resources?.logos?.map((logo) => (
+ <ResourceCard
+ key={logo.id}
+ resourceType="logo"
+ icon={
+ <div className="relative size-8 overflow-hidden">
+ <img
+ src={logo.url}
+ alt="thumbnail"
+ className="size-full object-contain"
+ />
+ </div>
+ }
+ title={logo.name || "Logo"}
+ description={formatFileSize(logo.size, 0)}
+ downloadUrl={logo.url}
+ />
+ ))}
+ </ResourceSection>
+ )}
+ {!!resources?.colors?.length && (
+ <ResourceSection resource="color" title="Colors">
+ {resources?.colors?.map((color) => (
+ <ResourceCard
+ key={color.id}
+ resourceType="color"
+ icon={
+ <div
+ className="size-full"
+ style={{ backgroundColor: color.color }}
+ />
+ }
+ title={color.name || "Color"}
+ description={color.color.toUpperCase()}
+ copyText={color.color.toUpperCase()}
+ />
+ ))}
+ </ResourceSection>
+ )}
+ {!!resources?.files?.length && (
+ <ResourceSection resource="file" title="Additional files">
+ {resources?.files?.map((file) => (
+ <ResourceCard
+ key={file.id}
+ resourceType="file"
+ icon={
+ <div className="flex size-full items-center justify-center bg-neutral-50">
+ <FileContent className="size-4 text-neutral-800" />
+ </div>
+ }
+ title={file.name || "File"}
+ description={formatFileSize(file.size, 0)}
+ downloadUrl={file.url}
+ />
+ ))}
+ </ResourceSection>
+ )}
+ </motion.div>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/directions.tsx b/packages/ui/src/icons/nucleo/directions.tsx
new file mode 100644
index 0000000000..4b77cbdb77
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/directions.tsx
@@ -0,0 +1,54 @@
+import { SVGProps } from "react";
+
+export function Directions(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">
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="9"
+ x2="9"
+ y1="1.75"
+ y2="16.25"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="5.75"
+ x2="12.25"
+ y1="16.25"
+ y2="16.25"
+ />
+ <path
+ d="M9,6.25H3.884c-.247,0-.485-.091-.669-.257l-1.389-1.25c-.441-.397-.441-1.089,0-1.487l1.389-1.25c.184-.165,.422-.257,.669-.257h5.116"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M11.495,10.75h2.616c.247,0,.485-.091,.669-.257l1.389-1.25c.441-.397,.441-1.089,0-1.487l-1.389-1.25c-.184-.165-.422-.257-.669-.257h-2.616"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 2cdc89882f..9a91e25fb2 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -64,6 +64,7 @@ export * from "./cursor-rays";
export * from "./database-key";
export * from "./desktop";
export * from "./diamond-turn-right";
+export * from "./directions";
export * from "./discount";
export * from "./dots";
export * from "./download";