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.

Remove old files

Tim Wilson81d00689a6b9
diff --git a/apps/web/ui/layout/nav-tabs.tsx b/apps/web/ui/layout/nav-tabs.tsx
deleted file mode 100644
index d523126d7e..0000000000
--- a/apps/web/ui/layout/nav-tabs.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-"use client";
-
-import useWorkspace from "@/lib/swr/use-workspace";
-import { useScroll } from "@dub/ui";
-import { cn } from "@dub/utils";
-import { motion } from "framer-motion";
-import Link from "next/link";
-import { useParams, usePathname } from "next/navigation";
-import { useMemo } from "react";
-
-export default function NavTabs() {
- const pathname = usePathname();
- const { slug } = useParams() as { slug?: string };
- const { error, flags } = useWorkspace();
-
- const tabs = useMemo(
- () => [
- { name: "Links", href: `/${slug}` },
- { name: "Analytics", href: `/${slug}/analytics` },
- { name: "Events", href: `/${slug}/events` },
- { name: "Settings", href: `/${slug}/settings` },
- ],
- [flags],
- );
-
- const scrolled = useScroll(80);
-
- if (!slug || error) return null;
-
- return (
- <div
- className={cn(
- "scrollbar-hide relative flex gap-x-2 overflow-x-auto transition-all",
- scrolled && "sm:translate-x-9",
- )}
- >
- {tabs.map(({ name, href }) => {
- const isActive =
- href === `/${slug}` ? pathname === href : pathname.startsWith(href);
-
- return (
- <Link key={href} href={href} className="relative">
- <div className="mx-1 my-1.5 rounded-md px-3 py-1.5 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200">
- <p className="text-sm text-gray-600 hover:text-black">{name}</p>
- </div>
- {isActive && (
- <motion.div
- layoutId="indicator"
- transition={{
- duration: 0.25,
- }}
- className="absolute bottom-0 w-full px-1.5"
- >
- <div className="h-0.5 bg-black" />
- </motion.div>
- )}
- </Link>
- );
- })}
- </div>
- );
-}
diff --git a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
index 6dacc5b30d..a1b0db0e20 100644
--- a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
@@ -71,7 +71,7 @@ export function WorkspaceDropdown() {
const [openPopover, setOpenPopover] = useState(false);
if (!workspaces || status === "loading") {
- return <WorkspaceSwitcherPlaceholder />;
+ return <WorkspaceDropdownPlaceholder />;
}
return (
@@ -127,7 +127,7 @@ export function WorkspaceDropdown() {
);
}
-function WorkspaceSwitcherPlaceholder() {
+function WorkspaceDropdownPlaceholder() {
return (
<div className="flex w-full animate-pulse items-center gap-x-1.5 rounded-lg p-1.5">
<div className="size-7 animate-pulse rounded-full bg-gray-200" />
diff --git a/apps/web/ui/layout/upgrade-banner.tsx b/apps/web/ui/layout/upgrade-banner.tsx
deleted file mode 100644
index 66c932dd00..0000000000
--- a/apps/web/ui/layout/upgrade-banner.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-"use client";
-
-import useWorkspace from "@/lib/swr/use-workspace";
-import { useMediaQuery } from "@dub/ui";
-import Cookies from "js-cookie";
-import Link from "next/link";
-import { useParams } from "next/navigation";
-import { useEffect, useState } from "react";
-import ProBanner from "../workspaces/pro-banner";
-
-export default function UpgradeBanner() {
- const { slug } = useParams() as { slug?: string };
-
- const { id, name, plan, stripeId, createdAt } = useWorkspace();
- const [showProBanner, setShowProBanner] = useState<boolean | null>(null);
-
- const { isMobile } = useMediaQuery();
-
- useEffect(() => {
- if (plan) {
- /* show pro banner if:
- - free plan
- - not hidden by user for this workspace
- - workspace is created more than 24 hours ago
- */
- if (
- plan === "free" &&
- Cookies.get("hideProBanner") !== slug &&
- createdAt &&
- Date.now() - new Date(createdAt).getTime() > 24 * 60 * 60 * 1000
- ) {
- setShowProBanner(true);
- } else {
- setShowProBanner(false);
- }
- } else {
- setShowProBanner(false);
- }
- }, [plan, id, name, slug, stripeId, createdAt]);
-
- return (
- <>
- {!isMobile && showProBanner && (
- <ProBanner setShowProBanner={setShowProBanner} />
- )}
- {plan === "free" && (isMobile || showProBanner === false) && (
- <Link
- href={`/${slug}/upgrade`}
- className="transition-all duration-75 active:scale-95"
- >
- <span className="bg-gradient-to-r from-violet-600 to-pink-600 bg-clip-text text-sm text-transparent">
- Upgrade
- </span>
- </Link>
- )}
- </>
- );
-}
diff --git a/apps/web/ui/layout/user-dropdown.tsx b/apps/web/ui/layout/user-dropdown.tsx
deleted file mode 100644
index 604125df87..0000000000
--- a/apps/web/ui/layout/user-dropdown.tsx
+++ /dev/null
@@ -1,117 +0,0 @@
-"use client";
-
-import { Avatar, Badge, IconMenu, Popover } from "@dub/ui";
-import Cookies from "js-cookie";
-import { Edit3, HelpCircle, LogOut, Settings } from "lucide-react";
-import { signOut, useSession } from "next-auth/react";
-import Link from "next/link";
-import { useEffect, useState } from "react";
-
-export default function UserDropdown() {
- const { data: session } = useSession();
- const [openPopover, setOpenPopover] = useState(false);
-
- const [unreadChangelogs, setUnreadChangelogs] = useState(0);
- useEffect(() => {
- const lastReadChangelog = Cookies.get("lastReadChangelog");
- if (!lastReadChangelog) {
- setUnreadChangelogs(2);
- }
- }, []);
-
- return (
- <div className="relative inline-block pt-1.5">
- <Popover
- content={
- <div className="flex w-full flex-col space-y-px rounded-md bg-white p-3 sm:w-56">
- {session?.user ? (
- <Link
- href="/"
- className="p-2"
- onClick={() => setOpenPopover(false)}
- >
- <p className="truncate text-sm font-medium text-gray-900">
- {session.user.name || session.user.email?.split("@")[0]}
- </p>
- <p className="truncate text-sm text-gray-500">
- {session.user.email}
- </p>
- </Link>
- ) : (
- <div className="grid gap-2 px-2 py-3">
- <div className="h-3 w-12 animate-pulse rounded-full bg-gray-200" />
- <div className="h-3 w-20 animate-pulse rounded-full bg-gray-200" />
- </div>
- )}
- <Link
- href="https://dub.co/help"
- onClick={() => setOpenPopover(false)}
- target="_blank"
- className="w-full rounded-md p-2 text-sm transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
- >
- <IconMenu
- text="Help Center"
- icon={<HelpCircle className="h-4 w-4" />}
- />
- </Link>
- <Link
- href="/account/settings"
- onClick={() => setOpenPopover(false)}
- className="block w-full rounded-md p-2 text-sm transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
- >
- <IconMenu
- text="Settings"
- icon={<Settings className="h-4 w-4" />}
- />
- </Link>
- <Link
- href="https://dub.co/changelog"
- target="_blank"
- rel="noopener noreferrer"
- onClick={() => {
- Cookies.set("lastReadChangelog", new Date().toISOString());
- setOpenPopover(false);
- }}
- className="flex w-full justify-between rounded-md p-2 text-sm transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
- >
- <IconMenu text="Changelog" icon={<Edit3 className="h-4 w-4" />} />
- {unreadChangelogs > 0 && (
- <Badge variant="blue">{unreadChangelogs}</Badge>
- )}
- </Link>
- <button
- className="w-full rounded-md p-2 text-sm transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
- onClick={() => {
- signOut({
- callbackUrl: "/login",
- });
- }}
- >
- <IconMenu text="Logout" icon={<LogOut className="h-4 w-4" />} />
- </button>
- </div>
- }
- align="end"
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- >
- <button
- onClick={() => setOpenPopover(!openPopover)}
- className="group relative"
- >
- {session?.user ? (
- <Avatar
- user={session.user}
- className="h-9 w-9 transition-all duration-75 group-focus:outline-none group-active:scale-95 sm:h-10 sm:w-10"
- />
- ) : (
- <div className="h-9 w-9 animate-pulse rounded-full border border-gray-300 bg-gray-100 sm:h-10 sm:w-10" />
- )}
- {unreadChangelogs > 0 && (
- <div className="absolute -bottom-0.5 -right-0.5 h-4 w-4 rounded-full border-2 border-white bg-blue-500" />
- )}
- </button>
- </Popover>
- </div>
- );
-}
diff --git a/apps/web/ui/layout/workspace-switcher.tsx b/apps/web/ui/layout/workspace-switcher.tsx
deleted file mode 100644
index 24467efffb..0000000000
--- a/apps/web/ui/layout/workspace-switcher.tsx
+++ /dev/null
@@ -1,201 +0,0 @@
-"use client";
-
-import useWorkspaces from "@/lib/swr/use-workspaces";
-import { PlanProps, WorkspaceProps } from "@/lib/types";
-import { ModalContext } from "@/ui/modals/modal-provider";
-import PlanBadge from "@/ui/workspaces/plan-badge";
-import { BlurImage, getUserAvatarUrl, Popover, Tick } from "@dub/ui";
-import { OfficeBuilding } from "@dub/ui/src/icons";
-import { DICEBEAR_AVATAR_URL } from "@dub/utils";
-import { ChevronsUpDown } from "lucide-react";
-import { useSession } from "next-auth/react";
-import Link from "next/link";
-import { useParams, usePathname } from "next/navigation";
-import { useCallback, useContext, useMemo, useState } from "react";
-
-export default function WorkspaceSwitcher() {
- const { workspaces } = useWorkspaces();
- const { data: session, status } = useSession();
- const { slug, key } = useParams() as {
- slug?: string;
- key?: string;
- };
-
- const selected = useMemo(() => {
- const selectedWorkspace = workspaces?.find(
- (workspace) => workspace.slug === slug,
- );
-
- if (slug && workspaces && selectedWorkspace) {
- return {
- ...selectedWorkspace,
- image:
- selectedWorkspace.logo ||
- `${DICEBEAR_AVATAR_URL}${selectedWorkspace.name}`,
- };
-
- // return personal account selector if there's no workspace or error (user doesn't have access to workspace)
- } else {
- return {
- name: session?.user?.name || session?.user?.email,
- slug: "/",
- image: getUserAvatarUrl(session?.user),
- plan: "free",
- };
- }
- }, [slug, workspaces, session]) as {
- id?: string;
- name: string;
- slug: string;
- image: string;
- plan: PlanProps;
- };
-
- const [openPopover, setOpenPopover] = useState(false);
-
- if (!workspaces || status === "loading") {
- return <WorkspaceSwitcherPlaceholder />;
- }
-
- return (
- <div>
- <Popover
- content={
- <WorkspaceList
- selected={selected}
- workspaces={workspaces}
- setOpenPopover={setOpenPopover}
- />
- }
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- >
- <button
- onClick={() => setOpenPopover(!openPopover)}
- className="flex items-center justify-between rounded-lg bg-white p-1.5 text-left text-sm transition-all duration-75 hover:bg-gray-100 focus:outline-none active:bg-gray-200"
- >
- <div className="flex items-center space-x-3 pr-2">
- <BlurImage
- src={selected.image}
- referrerPolicy="no-referrer"
- width={20}
- height={20}
- alt={selected.id || selected.name}
- className="h-8 w-8 flex-none overflow-hidden rounded-full"
- />
- <div
- className={`${
- key ? "hidden" : "flex"
- } items-center space-x-3 sm:flex`}
- >
- <span className="inline-block max-w-[100px] truncate text-sm font-medium sm:max-w-[200px]">
- {selected.name}
- </span>
- {selected.slug !== "/" && <PlanBadge plan={selected.plan} />}
- </div>
- </div>
- <ChevronsUpDown
- className="h-4 w-4 text-gray-400"
- aria-hidden="true"
- />
- </button>
- </Popover>
- </div>
- );
-}
-
-function WorkspaceList({
- selected,
- workspaces,
- setOpenPopover,
-}: {
- selected: {
- name: string;
- slug: string;
- image: string;
- plan: PlanProps;
- };
- workspaces: WorkspaceProps[];
- setOpenPopover: (open: boolean) => void;
-}) {
- const { setShowAddWorkspaceModal } = useContext(ModalContext);
- const { domain, key } = useParams() as { domain?: string; key?: string };
- const pathname = usePathname();
-
- const href = useCallback(
- (slug: string) => {
- if (domain || key || selected.slug === "/") {
- // if we're on a link page, navigate back to the workspace root
- return `/${slug}`;
- } else {
- // else, we keep the path but remove all query params
- return pathname?.replace(selected.slug, slug).split("?")[0] || "/";
- }
- },
- [domain, key, pathname, selected.slug],
- );
-
- 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="flex items-center justify-between px-2 pb-1">
- <p className="text-xs text-gray-500">My Workspaces</p>
- </div>
- {workspaces.map(({ id, name, slug, logo }) => {
- return (
- <Link
- key={slug}
- className={`relative flex w-full items-center gap-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)}
- >
- <BlurImage
- src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
- width={20}
- height={20}
- alt={id}
- className="size-7 shrink-0 overflow-hidden rounded-full"
- />
- <span
- className={`block truncate text-sm sm:max-w-[140px] ${
- selected.slug === slug ? "font-medium" : "font-normal"
- }`}
- >
- {name}
- </span>
- {selected.slug === slug ? (
- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
- <Tick className="size-5" aria-hidden="true" />
- </span>
- ) : null}
- </Link>
- );
- })}
- <button
- key="add"
- onClick={() => {
- setOpenPopover(false);
- setShowAddWorkspaceModal(true);
- }}
- className="group flex w-full cursor-pointer items-center gap-x-2 rounded-md p-2 transition-all duration-75 hover:bg-gray-100"
- >
- <div className="flex size-7 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100 group-hover:bg-white">
- <OfficeBuilding className="size-4 text-gray-700" />
- </div>
- <span className="block truncate">Create new workspace</span>
- </button>
- </div>
- );
-}
-
-function WorkspaceSwitcherPlaceholder() {
- return (
- <div className="flex animate-pulse items-center space-x-1.5 rounded-lg px-1.5 py-2 sm:w-60">
- <div className="h-8 w-8 animate-pulse rounded-full bg-gray-200" />
- <div className="hidden h-8 w-28 animate-pulse rounded-md bg-gray-200 sm:block sm:w-40" />
- <ChevronsUpDown className="h-4 w-4 text-gray-400" aria-hidden="true" />
- </div>
- );
-}
diff --git a/apps/web/ui/workspaces/pro-banner.tsx b/apps/web/ui/workspaces/pro-banner.tsx
deleted file mode 100644
index 11658dc13e..0000000000
--- a/apps/web/ui/workspaces/pro-banner.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import { Button, buttonVariants } from "@dub/ui";
-import { cn } from "@dub/utils";
-import Cookies from "js-cookie";
-import Link from "next/link";
-import { useParams } from "next/navigation";
-import posthog from "posthog-js";
-import { Dispatch, SetStateAction } from "react";
-
-export default function ProBanner({
- setShowProBanner,
-}: {
- setShowProBanner: Dispatch<SetStateAction<boolean>>;
-}) {
- const { slug } = useParams() as { slug: string };
-
- return (
- <div className="fixed bottom-24 z-10 mx-5 flex flex-col space-y-3 rounded-lg border border-gray-200 bg-white p-5 shadow-lg sm:right-5 sm:mx-auto sm:max-w-sm">
- <h3 className="text-lg font-semibold">Upgrade to Pro</h3>
- <p className="text-sm text-gray-500">
- It looks like you're currently on our Free plan. Please consider
- upgrading to Pro to enjoy higher limits and extra features.
- </p>
- <div className="grid grid-cols-2 gap-4">
- <Button
- variant="secondary"
- text="Don't show again"
- onClick={() => {
- setShowProBanner(false);
- posthog.capture("pro_banner_hidden", {
- workspace: slug,
- });
- Cookies.set("hideProBanner", slug, { expires: 180 });
- }}
- />
- <Link
- href={`/${slug}/upgrade`}
- className={cn(
- buttonVariants(),
- "flex w-full items-center justify-center whitespace-nowrap rounded-md border text-sm",
- )}
- >
- Benefits of Pro
- </Link>
- </div>
- </div>
- );
-}