The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Year in Review card
Steven Teycf0957b7d268
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.tsindex f620cf1878..defa1f7935 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts@@ -15,25 +15,37 @@ import { NextResponse } from "next/server";// GET /api/workspaces/[idOrSlug] – get a specific workspace by id or slugexport const GET = withWorkspace(async ({ workspace, headers }) => {- const domains = await prisma.domain.findMany({- where: {- projectId: workspace.id,- },- select: {- slug: true,- primary: true,- },- });+ const [domains, yearInReviews] = await Promise.all([+ prisma.domain.findMany({+ where: {+ projectId: workspace.id,+ },+ select: {+ slug: true,+ primary: true,+ },+ take: 100,+ }),+ prisma.yearInReview.findMany({+ where: {+ workspaceId: workspace.id,+ year: 2024,+ },+ }),+ ]);return NextResponse.json(- WorkspaceSchema.parse({- ...workspace,- id: `ws_${workspace.id}`,- domains,- flags: await getFeatureFlags({- workspaceId: workspace.id,+ {+ ...WorkspaceSchema.parse({+ ...workspace,+ id: `ws_${workspace.id}`,+ domains,+ flags: await getFeatureFlags({+ workspaceId: workspace.id,+ }),}),- }),+ yearInReview: yearInReviews.length > 0 ? yearInReviews[0] : null,+ },{ headers },);},diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/wrapped/[year]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/wrapped/[year]/page.tsxnew file mode 100644index 0000000000..c4cc53f948--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/wrapped/[year]/page.tsx@@ -0,0 +1,152 @@+import { prisma } from "@dub/prisma";+import { DUB_WORDMARK, smartTruncate } from "@dub/utils";+import { COUNTRIES } from "@dub/utils/src/constants/countries";+import NumberFlow from "@number-flow/react";+import { redirect } from "next/navigation";++export default function WrappedPage({+ params,+}: {+ params: { slug: string; year: string };+}) {+ return <WrappedPageRSC {...params} />;+}++async function WrappedPageRSC({ slug, year }: { slug: string; year: string }) {+ const workspace = await prisma.project.findUnique({+ where: {+ slug,+ },+ select: {+ name: true,+ logo: true,+ yearInReviews: {+ where: {+ year: parseInt(year),+ },+ },+ },+ });++ if (!workspace?.yearInReviews?.length) {+ redirect(`/${slug}`);+ }++ const { totalLinks, totalClicks, topLinks, topCountries } =+ workspace.yearInReviews[0];++ const stats = {+ "Total Links": totalLinks,+ "Total Clicks": totalClicks,+ };++ return (+ <div className="mx-auto my-10 max-w-lg bg-white px-10 py-5">+ <div className="mt-8 sm:hidden">+ <img src={DUB_WORDMARK} alt="Dub" className="h-8" />+ </div>+ <h1 className="mx-0 mb-4 mt-8 p-0 text-xl font-semibold text-black">+ Dub {year} Year in Review 🎊+ </h1>+ <p className="text-sm leading-6 text-black">+ As we put a wrap on {year}, we wanted to say thank you for your support!+ Here's a look back at your activity in {year}:+ </p>++ <div className="my-8 rounded-lg border border-neutral-200 p-2 shadow-md">+ <div+ className="flex h-24 flex-col items-center justify-center rounded-lg"+ style={{+ backgroundImage: `url(https://assets.dub.co/misc/year-in-review-header.jpg)`,+ backgroundSize: "cover",+ backgroundPosition: "center",+ }}+ >+ {workspace.logo && (+ <img+ src={workspace.logo}+ alt={workspace.name}+ className="h-8 rounded-lg"+ />+ )}+ <h2 className="mt-1 text-xl font-semibold">{workspace.name}</h2>+ </div>+ <div className="grid w-full grid-cols-2 gap-2 p-4">+ {Object.entries(stats).map(([key, value]) => (+ <StatCard key={key} title={key} value={value} />+ ))}+ </div>+ <div className="grid gap-2 p-4">+ <StatTable+ title="Top Links"+ value={topLinks as { item: string; count: number }[]}+ workspaceSlug={slug}+ />+ <StatTable+ title="Top Countries"+ value={topCountries as { item: string; count: number }[]}+ workspaceSlug={slug}+ />+ </div>+ </div>+ </div>+ );+}++const StatCard = ({ title, value }: { title: string; value: number }) => {+ return (+ <div className="text-center">+ <h3 className="font-medium text-neutral-400">{title}</h3>+ <NumberFlow value={value} className="text-lg font-medium text-black" />+ </div>+ );+};++const StatTable = ({+ title,+ value,+ workspaceSlug,+}: {+ title: string;+ value: { item: string; count: number }[];+ workspaceSlug: string;+}) => {+ return (+ <div className="mb-2">+ <h3 className="mb-2 font-medium text-neutral-500">{title}</h3>+ <div className="grid divide-y divide-neutral-200 text-sm">+ {value.map(({ item, count }, index) => {+ const [domain, ...pathParts] = item.split("/");+ const path = pathParts.join("/") || "_root";+ return (+ <div key={index} className="flex justify-between py-1.5">+ <div className="flex items-center gap-2">+ {title === "Top Countries" && (+ <img+ src={`https://hatscripts.github.io/circle-flags/flags/${item.toLowerCase()}.svg`}+ alt={COUNTRIES[item]}+ className="size-4"+ />+ )}+ <div className="text-left font-medium text-black">+ {title === "Top Links" ? (+ <a+ href={`https://app.dub.co/${workspaceSlug}/analytics?domain=${domain}&key=${path}&interval=1y`}+ target="_blank"+ className="underline-offset-2 hover:underline"+ >+ {smartTruncate(item, 33)} ↗+ </a>+ ) : (+ <p>{COUNTRIES[item]}</p>+ )}+ </div>+ </div>+ <NumberFlow value={count} className="text-neutral-600" />+ </div>+ );+ })}+ </div>+ </div>+ );+};diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsxindex 49d9d10504..940888bd24 100644--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx@@ -1,8 +1,8 @@import { MainNav } from "@/ui/layout/main-nav";import { AppSidebarNav } from "@/ui/layout/sidebar/app-sidebar-nav";import { HelpButtonRSC } from "@/ui/layout/sidebar/help-button-rsc";-import { NewsRSC } from "@/ui/layout/sidebar/news-rsc";import { ReferButton } from "@/ui/layout/sidebar/refer-button";+import { YearEndReviewCard } from "@/ui/layout/sidebar/year-end-review-card";import Toolbar from "@/ui/layout/toolbar/toolbar";import { constructMetadata } from "@dub/utils";import { ReactNode } from "react";@@ -22,7 +22,7 @@ export default async function Layout({ children }: { children: ReactNode }) {<HelpButtonRSC /></>}- newsContent={<NewsRSC />}+ newsContent={<YearEndReviewCard />}>{children}</MainNav>diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex ad7553dca0..f6bf6cbee5 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -9,6 +9,7 @@ import {SaleStatus,UtmTemplate,Webhook,+ YearInReview,} from "@dub/prisma/client";import { WEBHOOK_TRIGGER_DESCRIPTIONS } from "./webhook/constants";import { clickEventResponseSchema } from "./zod/schemas/clicks";@@ -139,6 +140,7 @@ export type ExpandedWorkspaceProps = WorkspaceProps & {id: string;name: string;}[];+ yearInReview: YearInReview | null;};export type WorkspaceWithUsers = Omit<WorkspaceProps, "domains">;diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsxindex 4d7f199b08..94c586b403 100644--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx@@ -106,7 +106,7 @@ const NAV_AREAS: SidebarNavAreas<{href: `/${slug}/programs/${programs[0].id}/resources`,},{- name: "Settings",+ name: "Configuration",href: `/${slug}/programs/${programs[0].id}/settings`,},],diff --git a/apps/web/ui/layout/sidebar/year-end-review-card.tsx b/apps/web/ui/layout/sidebar/year-end-review-card.tsxnew file mode 100644index 0000000000..b9819093ba--- /dev/null+++ b/apps/web/ui/layout/sidebar/year-end-review-card.tsx@@ -0,0 +1,49 @@+"use client";++import useWorkspace from "@/lib/swr/use-workspace";+import { cn } from "@dub/utils";+import Image from "next/image";+import Link from "next/link";+import { usePathname } from "next/navigation";++export function YearEndReviewCard() {+ const pathname = usePathname();+ const { slug, yearInReview } = useWorkspace();++ if (!yearInReview) return null;++ return (+ <Link+ href={`/${slug}/wrapped/2024`}+ className={cn(+ "group m-3 mt-8 h-44 select-none gap-2 overflow-hidden rounded-lg border border-neutral-200 bg-white p-3 text-[0.8125rem] transition-[height] duration-200 hover:h-52",+ pathname.endsWith("/wrapped/2024") && "h-52",+ )}+ >+ <div className="flex flex-col gap-1">+ <span className="line-clamp-1 font-medium text-neutral-900">+ Dub 2024 Year in Review 🎊+ </span>+ <p className="line-clamp-2 h-10 leading-5 text-neutral-500">+ As we put a bow on 2024, we want to say thank you for your support!+ </p>+ </div>+ <div className="relative mt-3 aspect-[16/9] w-full shrink-0 overflow-hidden rounded border border-neutral-200 bg-neutral-100">+ <div+ className={cn(+ "absolute z-10 h-36 w-full bg-gradient-to-b from-transparent to-white transition-[opacity] duration-200 group-hover:opacity-0",+ pathname.endsWith("/wrapped/2024") && "opacity-0",+ )}+ />+ <Image+ src="https://assets.dub.co/misc/dub-confetti.jpg"+ alt="Dub logo with confetti"+ fill+ sizes="10vw"+ className="rounded object-cover object-center"+ draggable={false}+ />+ </div>+ </Link>+ );+}