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 info modal with arrow

Steven Teye954316839fc
diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.ts
index 71001fc077..a0793a6050 100644
--- a/apps/web/app/api/user/route.ts
+++ b/apps/web/app/api/user/route.ts
@@ -1,8 +1,22 @@
import { withSession } from "@/lib/auth";
import prisma from "@/lib/prisma";
+import { redis } from "@/lib/upstash";
import cloudinary from "cloudinary";
import { NextResponse } from "next/server";
+// GET /api/user – get a specific user
+export const GET = withSession(async ({ session }) => {
+ const migratedProject = await redis.hget(
+ "migrated_links_users",
+ session.user.id,
+ );
+
+ return NextResponse.json({
+ ...session.user,
+ migratedProject,
+ });
+});
+
// PUT /api/user – edit a specific user
export const PUT = withSession(async ({ req, session }) => {
let { name, email, image } = await req.json();
diff --git a/apps/web/ui/layout/project-select.tsx b/apps/web/ui/layout/project-select.tsx
index 88368d54df..f048c5e408 100644
--- a/apps/web/ui/layout/project-select.tsx
+++ b/apps/web/ui/layout/project-select.tsx
@@ -4,7 +4,7 @@ import { PlanProps, ProjectWithDomainProps } from "@/lib/types";
import { ModalContext } from "@/ui/modals/provider";
import PlanBadge from "@/ui/projects/plan-badge";
import { Popover, Tick } from "@dub/ui";
-import { GOOGLE_FAVICON_URL } from "@dub/utils";
+import { GOOGLE_FAVICON_URL, SHORT_DOMAIN } from "@dub/utils";
import { ChevronsUpDown, PlusCircle } from "lucide-react";
import { useSession } from "next-auth/react";
import Link from "next/link";
@@ -28,7 +28,9 @@ export default function ProjectSelect() {
...selectedProject,
image:
selectedProject?.logo ||
- `${GOOGLE_FAVICON_URL}${selectedProject?.primaryDomain?.slug}`,
+ `${GOOGLE_FAVICON_URL}${
+ selectedProject?.primaryDomain?.slug || SHORT_DOMAIN
+ }`,
};
// return personal account selector if there's no project or error (user doesn't have access to project)
@@ -115,7 +117,6 @@ function ProjectList({
projects: ProjectWithDomainProps[];
setOpenPopover: (open: boolean) => void;
}) {
- const { data: session } = useSession();
const { setShowAddProjectModal } = useContext(ModalContext);
const { domain, key } = useParams() as { domain?: string; key?: string };
const pathname = usePathname();
@@ -136,35 +137,40 @@ function ProjectList({
return (
<div className="relative mt-1 max-h-72 w-full space-y-0.5 overflow-auto rounded-md bg-white p-2 text-base sm:w-60 sm:text-sm sm:shadow-lg">
<div className="p-2 text-xs text-gray-500">My Projects</div>
- {projects.map(({ id, name, slug, logo, primaryDomain }) => (
- <Link
- key={slug}
- className={`relative flex w-full items-center space-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${
- selected.slug === slug ? "font-medium" : ""
- } transition-all duration-75`}
- href={href(slug)}
- shallow={false}
- onClick={() => setOpenPopover(false)}
- >
- <img
- src={logo || `${GOOGLE_FAVICON_URL}${primaryDomain?.slug}`}
- alt={id}
- className="h-7 w-7 overflow-hidden rounded-full"
- />
- <span
- className={`block truncate text-sm ${
- selected.slug === slug ? "font-medium" : "font-normal"
- }`}
+ {projects.map(({ id, name, slug, logo, primaryDomain, metadata }) => {
+ return (
+ <Link
+ key={slug}
+ className={`relative flex w-full items-center space-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${
+ selected.slug === slug ? "font-medium" : ""
+ } transition-all duration-75`}
+ href={href(slug)}
+ shallow={false}
+ onClick={() => setOpenPopover(false)}
>
- {name}
- </span>
- {selected.slug === slug ? (
- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
- <Tick className="h-5 w-5" aria-hidden="true" />
+ <img
+ src={
+ logo ||
+ `${GOOGLE_FAVICON_URL}${primaryDomain?.slug || SHORT_DOMAIN}`
+ }
+ alt={id}
+ className="h-7 w-7 overflow-hidden rounded-full"
+ />
+ <span
+ className={`block truncate text-sm ${
+ selected.slug === slug ? "font-medium" : "font-normal"
+ }`}
+ >
+ {name}
</span>
- ) : null}
- </Link>
- ))}
+ {selected.slug === slug ? (
+ <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
+ <Tick className="h-5 w-5" aria-hidden="true" />
+ </span>
+ ) : null}
+ </Link>
+ );
+ })}
<button
key="add"
onClick={() => {
diff --git a/apps/web/ui/projects/project-arrow.tsx b/apps/web/ui/projects/project-arrow.tsx
new file mode 100644
index 0000000000..8c52df372c
--- /dev/null
+++ b/apps/web/ui/projects/project-arrow.tsx
@@ -0,0 +1,59 @@
+export default function ProjectArrow({ className }: { className?: string }) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ direction="ltr"
+ width="118.74"
+ height="113.35"
+ viewBox="686.76 370.89 118.74 113.35"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ >
+ <g transform="matrix(1, 0, 0, 1, 841.69, 473.12)" opacity="1">
+ <g>
+ <defs>
+ <mask id="shape_DMhXIOleLZoVYRbAUpH5t_clip">
+ <rect
+ x="-222.934999821233"
+ y="-170.22265625"
+ width="254.74"
+ height="249.35"
+ fill="white"
+ />
+ <path
+ d="M -128.12074054893105 -61.43422831638357 L -122.375 -70.22265625 L -117.63686842462491 -60.85248500426316"
+ fill="none"
+ stroke="none"
+ />
+ </mask>
+ </defs>
+ <g mask="url(#shape_DMhXIOleLZoVYRbAUpH5t_clip)">
+ <rect
+ x="-100"
+ y="-100"
+ width="254.74"
+ height="249.35"
+ fill="transparent"
+ stroke="none"
+ />
+ <path
+ d="M-68.1875,-22.86328125 A41.88122170338541 41.88 0 0 1 -122.375,-70.22265625"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="3.5"
+ strokeDasharray="none"
+ strokeDashoffset="none"
+ />
+ </g>
+ <path
+ d="M -128.12074054893105 -61.43422831638357 L -122.375 -70.22265625 L -117.63686842462491 -60.85248500426316"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="3.5"
+ />
+ </g>
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/projects/project-card.tsx b/apps/web/ui/projects/project-card.tsx
index 0d68adeddf..088b359677 100644
--- a/apps/web/ui/projects/project-card.tsx
+++ b/apps/web/ui/projects/project-card.tsx
@@ -3,18 +3,22 @@
import { DomainProps, ProjectWithDomainProps } from "@/lib/types";
import { BlurImage } from "@/ui/shared/blur-image";
import { CheckCircleFill, XCircleFill } from "@/ui/shared/icons";
-import { Badge, NumberTooltip, Tooltip } from "@dub/ui";
+import { Badge, InlineSnippet, NumberTooltip, Tooltip } from "@dub/ui";
import {
DUB_DOMAINS,
GOOGLE_FAVICON_URL,
- SHORT_DOMAIN,
+ HOME_DOMAIN,
+ cn,
fetcher,
nFormatter,
} from "@dub/utils";
import { BarChart2, ExternalLink, Globe, Link2 } from "lucide-react";
import Link from "next/link";
import useSWR from "swr";
+import useSWRImmutable from "swr/immutable";
import PlanBadge from "./plan-badge";
+import { Session } from "@/lib/auth";
+import ProjectArrow from "./project-arrow";
export default function ProjectCard({
id,
@@ -24,14 +28,20 @@ export default function ProjectCard({
usage,
plan,
domains: projectDomains,
- metadata,
primaryDomain: projectPrimaryDomain,
+ metadata,
}: ProjectWithDomainProps) {
const { data: count } = useSWR<number>(
`/api/links/count?projectSlug=${slug}`,
fetcher,
);
+ const { data: user } = useSWRImmutable<
+ Session["user"] & { migratedProject: string | null }
+ >(`/api/user`, fetcher);
+
+ const isMigratedProject = user?.migratedProject === id;
+
const defaultDomains = metadata?.defaultDomains
? DUB_DOMAINS.filter((d) => metadata?.defaultDomains?.includes(d.slug))
: DUB_DOMAINS;
@@ -41,86 +51,112 @@ export default function ProjectCard({
const primaryDomain = projectPrimaryDomain || defaultDomains[0];
return (
- <Link
- key={slug}
- href={`/${slug}`}
- className="flex flex-col justify-between space-y-10 rounded-lg border border-gray-100 bg-white p-6 shadow transition-all hover:shadow-lg"
- >
- <div className="flex items-start justify-between">
- <div className="flex items-center space-x-3">
- <BlurImage
- src={logo || `${GOOGLE_FAVICON_URL}${primaryDomain?.slug}`}
- alt={id}
- className="h-10 w-10 flex-shrink-0 overflow-hidden rounded-full"
- width={48}
- height={48}
- />
- <div>
- <h2 className="text-lg font-medium text-gray-700">{name}</h2>
- <div className="flex items-center">
- <p className="text-gray-500">{primaryDomain?.slug}</p>
- <Tooltip
- content={
- <DomainsTooltip
- domains={domains}
- title={
- primaryDomain?.verified === false
- ? "Please verify your domain to start adding links."
- : "Here are all the domains for this project."
- }
- cta={
- primaryDomain?.verified === false
- ? "Verify Domain"
- : "Manage Domain"
- }
- href={`/${slug}/domains`}
- />
- }
- >
- <div className="ml-1 flex items-center">
- {domains.length > 1 ? (
- <Badge variant="gray">+{domains.length - 1}</Badge>
- ) : primaryDomain?.verified ? (
- <CheckCircleFill className="h-5 w-5 text-blue-500" />
- ) : primaryDomain?.verified === false ? (
- <XCircleFill className="h-5 w-5 text-gray-300" />
- ) : null}
- </div>
- </Tooltip>
+ <div className="group relative">
+ {isMigratedProject && (
+ <>
+ <div className="absolute -inset-1 rounded-lg bg-gradient-to-r from-red-600 to-violet-600 opacity-25 blur-lg transition duration-1000 group-hover:opacity-75 group-hover:duration-200" />
+ <ProjectArrow className="absolute -bottom-20 right-0 z-10 text-violet-600" />
+ <div className="absolute -bottom-28 -right-56 z-10 w-full max-w-[16rem] rounded-lg border border-gray-200 bg-white p-3 text-center text-sm shadow">
+ <p>
+ Your <InlineSnippet>dub.sh</InlineSnippet> links have been
+ migrated to a custom project.
+ </p>
+ <a
+ href={`${HOME_DOMAIN}/changelog/projects`}
+ target="_blank"
+ className="mt-1 block text-gray-500 underline underline-offset-4 hover:text-gray-800"
+ >
+ Read the changelog.
+ </a>
+ </div>
+ </>
+ )}
+ <Link
+ key={slug}
+ href={`/${slug}`}
+ className={cn(
+ "relative flex flex-col justify-between space-y-10 rounded-lg border border-gray-100 bg-white p-6 shadow transition-all hover:shadow-lg",
+ {
+ "border-violet-600": isMigratedProject,
+ },
+ )}
+ >
+ <div className="flex items-start justify-between">
+ <div className="flex items-center space-x-3">
+ <BlurImage
+ src={logo || `${GOOGLE_FAVICON_URL}${primaryDomain?.slug}`}
+ alt={id}
+ className="h-10 w-10 flex-shrink-0 overflow-hidden rounded-full"
+ width={48}
+ height={48}
+ />
+ <div>
+ <h2 className="text-lg font-medium text-gray-700">{name}</h2>
+ <div className="flex items-center">
+ <p className="text-gray-500">{primaryDomain?.slug}</p>
+ <Tooltip
+ content={
+ <DomainsTooltip
+ domains={domains}
+ title={
+ primaryDomain?.verified === false
+ ? "Please verify your domain to start adding links."
+ : "Here are all the domains for this project."
+ }
+ cta={
+ primaryDomain?.verified === false
+ ? "Verify Domain"
+ : "Manage Domain"
+ }
+ href={`/${slug}/domains`}
+ />
+ }
+ >
+ <div className="ml-1 flex items-center">
+ {domains.length > 1 ? (
+ <Badge variant="gray">+{domains.length - 1}</Badge>
+ ) : primaryDomain?.verified ? (
+ <CheckCircleFill className="h-5 w-5 text-blue-500" />
+ ) : primaryDomain?.verified === false ? (
+ <XCircleFill className="h-5 w-5 text-gray-300" />
+ ) : null}
+ </div>
+ </Tooltip>
+ </div>
</div>
</div>
+ <PlanBadge plan={plan} />
</div>
- <PlanBadge plan={plan} />
- </div>
- <div className="flex items-center space-x-4">
- <div className="flex items-center space-x-1 text-gray-500">
- <Globe className="h-4 w-4" />
- <h2 className="whitespace-nowrap text-sm">
- {nFormatter(domains.length)} domain{domains.length != 1 && "s"}
- </h2>
- </div>
- <div className="flex items-center space-x-1 text-gray-500">
- <Link2 className="h-4 w-4" />
- {count || count === 0 ? (
- <NumberTooltip value={count} unit="links">
+ <div className="flex items-center space-x-4">
+ <div className="flex items-center space-x-1 text-gray-500">
+ <Globe className="h-4 w-4" />
+ <h2 className="whitespace-nowrap text-sm">
+ {nFormatter(domains.length)} domain{domains.length != 1 && "s"}
+ </h2>
+ </div>
+ <div className="flex items-center space-x-1 text-gray-500">
+ <Link2 className="h-4 w-4" />
+ {count || count === 0 ? (
+ <NumberTooltip value={count} unit="links">
+ <h2 className="whitespace-nowrap text-sm">
+ {nFormatter(count)} link{count != 1 && "s"}
+ </h2>
+ </NumberTooltip>
+ ) : (
+ <div className="h-4 w-8 animate-pulse rounded-md bg-gray-200" />
+ )}
+ </div>
+ <div className="flex items-center space-x-1 text-gray-500">
+ <BarChart2 className="h-4 w-4" />
+ <NumberTooltip value={usage}>
<h2 className="whitespace-nowrap text-sm">
- {nFormatter(count)} link{count != 1 && "s"}
+ {nFormatter(usage)} click{usage != 1 && "s"}
</h2>
</NumberTooltip>
- ) : (
- <div className="h-4 w-8 animate-pulse rounded-md bg-gray-200" />
- )}
- </div>
- <div className="flex items-center space-x-1 text-gray-500">
- <BarChart2 className="h-4 w-4" />
- <NumberTooltip value={usage}>
- <h2 className="whitespace-nowrap text-sm">
- {nFormatter(usage)} click{usage != 1 && "s"}
- </h2>
- </NumberTooltip>
+ </div>
</div>
- </div>
- </Link>
+ </Link>
+ </div>
);
}