The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Shareable images
Tim Wilson3e73dcfcaa8c
diff --git a/apps/web/app/(ee)/api/partner-profile/rewind/image/route.tsx b/apps/web/app/(ee)/api/partner-profile/rewind/image/route.tsxindex 0b6b4e28d9..ab4e8463fa 100644--- a/apps/web/app/(ee)/api/partner-profile/rewind/image/route.tsx+++ b/apps/web/app/(ee)/api/partner-profile/rewind/image/route.tsx@@ -120,6 +120,7 @@ const CURRENT_YEAR = 2025;async function getPartnerRewind(rewindId: string) {const rewinds = await prismaEdge.$queryRaw<{+ id: string;totalClicks: number;totalLeads: number;totalRevenue: number;@@ -131,6 +132,7 @@ async function getPartnerRewind(rewindId: string) {}[]>`SELECT+ pr.id,pr.year,pr.totalClicks,pr.totalLeads,diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsxindex 7982ac32aa..1397182bdb 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx@@ -1,15 +1,21 @@import { PartnerRewindProps } from "@/lib/types";-import { AnimatedSizeContainer, ChevronLeft, ChevronRight } from "@dub/ui";+import {+ AnimatedSizeContainer,+ ChevronLeft,+ ChevronRight,+ ReferredVia,+} from "@dub/ui";import { cn } from "@dub/utils/src";import NumberFlow from "@number-flow/react";import { AnimatePresence, motion } from "motion/react";import { CSSProperties, useEffect, useMemo, useState } from "react";import { REWIND_ASSETS_PATH, REWIND_STEPS } from "./constants";+import { useShareRewindModal } from "./share-rewind-modal";const STEP_DELAY_MS = 8_000;export const navButtonClassName =- "bg-neutral-200 text-content-subtle disabled:opacity-50 hover:bg-neutral-300 ease-out flex size-8 items-center justify-center rounded-lg transition-[background-color,transform] active:scale-95";+ "bg-neutral-200 text-content-subtle disabled:opacity-50 hover:bg-neutral-300 ease-out flex size-8 items-center text-sm font-medium gap-2 justify-center rounded-lg transition-[background-color,transform] active:scale-95";export function Rewind({partnerRewind,@@ -50,8 +56,14 @@ export function Rewind({return () => clearTimeout(timeout);}, [steps, currentStepIndex, isPaused]);+ const { ShareRewindModal, setShowShareRewindModal } = useShareRewindModal({+ rewindId: partnerRewind.id,+ step: steps[currentStepIndex].id,+ });+return (<div className="flex w-full flex-col items-center">+ <ShareRewindModal /><div className="flex items-center gap-0.5">{steps.map((step, index) => (<button@@ -119,6 +131,17 @@ export function Rewind({><ChevronLeft className="size-3 [&_*]:stroke-2" /></button>+ <button+ type="button"+ onClick={() => {+ setIsPaused(true);+ setShowShareRewindModal(true);+ }}+ className={cn(navButtonClassName, "text-content-emphasis w-fit px-3")}+ >+ Share+ <ReferredVia className="size-3.5" />+ </button><buttontype="button"onClick={() => {diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/share-rewind-modal.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/share-rewind-modal.tsxnew file mode 100644index 0000000000..17a34f3ed8--- /dev/null+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/share-rewind-modal.tsx@@ -0,0 +1,135 @@+import { Button, LoadingSpinner, Modal } from "@dub/ui";+import slugify from "@sindresorhus/slugify";+import { useCallback, useEffect, useMemo, useState } from "react";+import { toast } from "sonner";+import { REWIND_STEPS } from "./constants";++type ShareRewindModalInnerProps = {+ rewindId: string;+ step: string;+};++type ShareRewindModalProps = {+ showModal: boolean;+ setShowModal: (showModal: boolean) => void;+} & ShareRewindModalInnerProps;++function ShareRewindModal(props: ShareRewindModalProps) {+ return (+ <Modal {...props} className="max-w-[500px] xl:max-w-[600px]">+ <ShareRewindModalInner {...props} />+ </Modal>+ );+}++function ShareRewindModalInner({ rewindId, step }: ShareRewindModalProps) {+ const imageUrl = `/api/partner-profile/rewind/image?${new URLSearchParams({ rewindId, step }).toString()}`;++ const [isLoading, setIsLoading] = useState(false);+ const [blob, setBlob] = useState<Blob | null>(null);++ useEffect(() => {+ setIsLoading(true);+ fetch(imageUrl)+ .then((res) =>+ res.blob().then((blob) => {+ setBlob(blob);+ setIsLoading(false);+ }),+ )+ .catch(() => {+ toast.error("Failed to prepare rewind image for sharing");+ });+ }, [imageUrl]);++ return (+ <div className="flex flex-col gap-5 p-4 sm:px-6">+ <h3 className="text-lg font-medium">Share rewind</h3>++ <div className="border-border-subtle scrollbar-hide max-h-[calc(100dvh-200px)] overflow-y-auto rounded-xl border">+ <div className="relative aspect-[1084/994] w-full">+ <div className="absolute inset-0 flex items-center justify-center">+ <LoadingSpinner />+ </div>+ <img+ src={`/api/partner-profile/rewind/image?${new URLSearchParams({ rewindId, step }).toString()}`}+ alt="share rewind image"+ className="relative size-full"+ />+ </div>+ </div>++ <div className="flex items-center justify-end gap-2">+ <Button+ text="Copy"+ variant="secondary"+ disabled={isLoading}+ onClick={async () => {+ if (!blob) return;++ try {+ const clipboardItem = new ClipboardItem({+ [blob.type]: blob,+ });++ await navigator.clipboard.write([clipboardItem]);++ toast.success("Copied to clipboard");+ } catch (err) {+ console.error("Failed to copy image: ", err.name, err.message);+ toast.error("Failed to copy image to clipboard");+ }+ }}+ className="h-9 w-fit rounded-lg"+ />+ <Button+ text="Download"+ disabled={isLoading}+ onClick={() => {+ if (!blob) return;++ const blobUrl = URL.createObjectURL(blob);++ // Create an anchor element+ const link = document.createElement("a");+ link.href = blobUrl;+ link.download = `rewind-${slugify(REWIND_STEPS.find((s) => s.id === step)?.label || "").toLowerCase()}.png`;++ // Append the link to the body (necessary for some browsers)+ document.body.appendChild(link);++ // Programmatically click the link to trigger the download+ link.click();++ // Clean up by removing the link and revoking the object URL+ document.body.removeChild(link);+ URL.revokeObjectURL(blobUrl);+ }}+ className="h-9 w-fit rounded-lg"+ />+ </div>+ </div>+ );+}++export function useShareRewindModal(props: ShareRewindModalInnerProps) {+ const [showShareRewindModal, setShowShareRewindModal] = useState(false);++ const ShareRewindModalCallback = useCallback(() => {+ return (+ <ShareRewindModal+ showModal={showShareRewindModal}+ setShowModal={setShowShareRewindModal}+ {...props}+ />+ );+ }, [showShareRewindModal, setShowShareRewindModal, props]);++ return useMemo(+ () => ({+ setShowShareRewindModal,+ ShareRewindModal: ShareRewindModalCallback,+ }),+ [setShowShareRewindModal, ShareRewindModalCallback],+ );+}diff --git a/apps/web/app/api/og/partner-rewind/route.tsx b/apps/web/app/api/og/partner-rewind/route.tsxdeleted file mode 100644index 0b6b4e28d9..0000000000--- a/apps/web/app/api/og/partner-rewind/route.tsx+++ /dev/null@@ -1,169 +0,0 @@-import { PartnerRewindSchema } from "@/lib/zod/schemas/partners";-import { prismaEdge } from "@dub/prisma/edge";-import { cn, nFormatter } from "@dub/utils";-import {- REWIND_ASSETS_PATH,- REWIND_STEPS,-} from "app/(ee)/partners.dub.co/(dashboard)/rewind/2025/constants";-import { ImageResponse } from "next/og";-import { NextRequest } from "next/server";--export const runtime = "edge";--export async function GET(req: NextRequest) {- // Use only Inter-Semibold to reduce bundle size (~300KB savings)- const [interSemibold, satoshiBold] = await Promise.all([- fetch(new URL("@/styles/Inter-Semibold.ttf", import.meta.url)).then((res) =>- res.arrayBuffer(),- ),- fetch(new URL("@/styles/Satoshi-Bold.ttf", import.meta.url)).then((res) =>- res.arrayBuffer(),- ),- ]);-- const rewindId = req.nextUrl.searchParams.get("rewindId");- const stepRaw = req.nextUrl.searchParams.get("step");-- const step = REWIND_STEPS.find((step) => step.id === stepRaw);-- if (!rewindId || !step)- return new Response("Missing 'rewindId' or 'step' parameter", {- status: 400,- });-- const rewind = await getPartnerRewind(rewindId);-- if (!rewind)- return new Response("Partner rewind not found", {- status: 404,- });-- const isTop10 = rewind[step.percentileId] >= 90;-- const value =- step.valueType === "currency"- ? Math.floor(rewind[step.id] / 100)- : Math.floor(rewind[step.id]);-- return new ImageResponse(- (- <div- tw="flex flex-col bg-neutral-50 w-full h-full items-center justify-between"- style={{ fontFamily: "Inter Semibold" }}- >- <div- tw="bg-white border-neutral-200 flex w-full max-w-screen-sm flex-col rounded-2xl border p-10 shadow-sm mt-16"- style={{ transform: "scale(1.5)", transformOrigin: "top center" }}- >- <div tw="flex grow flex-col">- <span tw="text-neutral-900 text-lg font-semibold">- {step.label}- </span>-- <div tw="flex pt-2">- <span tw="text-neutral-900 text-8xl font-bold">- {step.valueType === "currency" && "$"}- {nFormatter(value, { full: value <= 9999999 })}- </span>- </div>-- <div tw={cn("mt-5 flex items-center", !isTop10 && "opacity-0")}>- <img- src={`https://assets.dub.co/misc/partner-rewind-2025/top-medallion.png`}- tw="w-6 h-6 mr-2.5"- />- <span tw="text-neutral-900 text-base font-semibold">- Top 10% of all partners- </span>- </div>- </div>-- <div tw="flex items-end justify-between">- <span- tw="text-neutral-900 max-w-[180px] text-3xl leading-8 font-bold"- style={{ fontFamily: "Satoshi Bold" }}- >- Dub Partner Rewind ’25- </span>-- <img- tw="-mb-4 -mr-1 -mt-8 flex h-[280px]"- src={`${REWIND_ASSETS_PATH}/${step.image}`}- />- </div>- </div>-- <img src="https://assets.dub.co/wordmark.svg" tw="h-16 mb-18" />- </div>- ),- {- width: 1084,- height: 994,- fonts: [- {- name: "Inter Semibold",- data: interSemibold,- },- {- name: "Satoshi Bold",- data: satoshiBold,- },- ],- },- );-}--// Mostly copied from `getPartnerRewind` in `lib/api/partners/get-partner-rewind.ts`,-// but couldn't get that to work with dynamic client + conditional Prisma.sql-const CURRENT_YEAR = 2025;--async function getPartnerRewind(rewindId: string) {- const rewinds = await prismaEdge.$queryRaw<- {- totalClicks: number;- totalLeads: number;- totalRevenue: number;- totalEarnings: number;- clicksPercentile: any; // Decimal- leadsPercentile: any; // Decimal- revenuePercentile: any; // Decimal- earningsPercentile: any; // Decimal- }[]- >`- SELECT- pr.year,- pr.totalClicks,- pr.totalLeads,- pr.totalRevenue,- pr.totalEarnings,- CASE WHEN pr.totalClicks > 0 THEN ROUND(- 100 - 100 * (SELECT COUNT(*) FROM PartnerRewind c WHERE c.year = pr.year AND c.totalClicks >= pr.totalClicks)- / (SELECT COUNT(*) FROM PartnerRewind WHERE year = pr.year)- ) ELSE 0 END AS clicksPercentile,- CASE WHEN pr.totalLeads > 0 THEN ROUND(- 100 - 100 * (SELECT COUNT(*) FROM PartnerRewind c WHERE c.year = pr.year AND c.totalLeads >= pr.totalLeads)- / (SELECT COUNT(*) FROM PartnerRewind WHERE year = pr.year)- ) ELSE 0 END AS leadsPercentile,- CASE WHEN pr.totalRevenue > 0 THEN ROUND(- 100 - 100 * (SELECT COUNT(*) FROM PartnerRewind c WHERE c.year = pr.year AND c.totalRevenue >= pr.totalRevenue)- / (SELECT COUNT(*) FROM PartnerRewind WHERE year = pr.year)- ) ELSE 0 END AS revenuePercentile,- CASE WHEN pr.totalEarnings > 0 THEN ROUND(- 100 - 100 * (SELECT COUNT(*) FROM PartnerRewind c WHERE c.year = pr.year AND c.totalEarnings >= pr.totalEarnings)- / (SELECT COUNT(*) FROM PartnerRewind WHERE year = pr.year)- ) ELSE 0 END AS earningsPercentile- FROM PartnerRewind pr- WHERE- pr.id = ${rewindId}- AND pr.year = ${CURRENT_YEAR}`;-- if (!rewinds.length) return null;-- return PartnerRewindSchema.parse({- ...rewinds[0],- clicksPercentile: Number(rewinds[0].clicksPercentile),- leadsPercentile: Number(rewinds[0].leadsPercentile),- revenuePercentile: Number(rewinds[0].revenuePercentile),- earningsPercentile: Number(rewinds[0].earningsPercentile),- });-}diff --git a/apps/web/lib/api/partners/get-partner-rewind.ts b/apps/web/lib/api/partners/get-partner-rewind.tsindex 0e9fc99514..d2a99b49de 100644--- a/apps/web/lib/api/partners/get-partner-rewind.ts+++ b/apps/web/lib/api/partners/get-partner-rewind.ts@@ -29,6 +29,7 @@ export async function getPartnerRewind({}[]>`SELECT+ pr.id,pr.year,pr.totalClicks,pr.totalLeads,diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex 1b9a058196..00dfcd5640 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -343,6 +343,7 @@ export const PartnerWithProfileSchema =PartnerSchema.merge(PartnerProfileSchema);export const PartnerRewindSchema = z.object({+ id: z.string(),year: z.number(),totalClicks: z.number().default(0),totalLeads: z.number().default(0),