The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Display "All links" folder at the beginning of the folders list
Kiran Kd685fd8ca160
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/page-client.tsxindex dee660d179..3ccfe1475d 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/folders/page-client.tsx@@ -1,5 +1,6 @@"use client";+import { FolderWithRole } from "@/lib/link-folder/types";import useFolders from "@/lib/swr/use-folders";import useLinksCount from "@/lib/swr/use-links-count";import { FolderCard } from "@/ui/folders/folder-card";@@ -10,6 +11,15 @@ import { TooltipContent } from "@dub/ui";import { Folder } from "@dub/ui/src/icons";import { InfoTooltip } from "@dub/ui/src/tooltip";+const allLinkFolder: FolderWithRole = {+ id: "all-links",+ name: "All links",+ accessLevel: null,+ role: null,+ createdAt: new Date(),+ updatedAt: new Date(),+};+export const FoldersPageClient = () => {const { folders, isLoading } = useFolders();const { AddFolderButton, AddFolderModal } = useAddFolderModal();@@ -55,6 +65,8 @@ export const FoldersPageClient = () => {)}<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">+ <FolderCard folder={allLinkFolder} linksCount={linksCount} />+{isLoading? Array.from({ length: 6 }).map((_, idx) => (<FolderCardPlaceholder key={idx} />diff --git a/apps/web/lib/swr/use-folders.ts b/apps/web/lib/swr/use-folders.tsindex 165182cd1b..aef1be6773 100644--- a/apps/web/lib/swr/use-folders.ts+++ b/apps/web/lib/swr/use-folders.ts@@ -1,7 +1,6 @@-import { FolderProps } from "@/lib/types";import { fetcher } from "@dub/utils";-import { FolderUserRole } from "@prisma/client";import useSWR from "swr";+import { FolderWithRole } from "../link-folder/types";import useWorkspace from "./use-workspace";export default function useFolders() {@@ -11,7 +10,7 @@ export default function useFolders() {data: folders,isValidating,isLoading,- } = useSWR<(FolderProps & { role: FolderUserRole })[]>(+ } = useSWR<FolderWithRole[]>(id && `/api/folders?workspaceId=${id}`,fetcher,{diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex aae010b013..47e7a49594 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -260,5 +260,3 @@ export type TrackCustomerResponse = z.infer<typeof trackCustomerResponseSchema>;export type TrackLeadResponse = z.infer<typeof trackLeadResponseSchema>;export type TrackSaleResponse = z.infer<typeof trackSaleResponseSchema>;--export type FolderProps = z.infer<typeof folderSchema>;diff --git a/apps/web/ui/folders/folder-card.tsx b/apps/web/ui/folders/folder-card.tsxindex f4f8a57c9e..707c994fe0 100644--- a/apps/web/ui/folders/folder-card.tsx+++ b/apps/web/ui/folders/folder-card.tsx@@ -1,12 +1,11 @@"use client";import { getFolderPermissions } from "@/lib/link-folder/permissions";+import { FolderWithRole } from "@/lib/link-folder/types";import useWorkspace from "@/lib/swr/use-workspace";-import { FolderProps } from "@/lib/types";import { Button, PenWriting, Popover, Users } from "@dub/ui";import { Globe } from "@dub/ui/src/icons";import { cn, nFormatter } from "@dub/utils";-import { FolderUserRole } from "@prisma/client";import { FolderIcon } from "lucide-react";import { useRouter } from "next/navigation";import { useState } from "react";@@ -21,7 +20,7 @@ interface LinksCount {}interface FolderCardProps {- folder: FolderProps & { role: FolderUserRole | null };+ folder: FolderWithRole;linksCount: LinksCount[] | undefined;}@@ -40,6 +39,9 @@ export const FolderCard = ({ folder, linksCount }: FolderCardProps) => {linksCount?.find((link) => link.folderId === folder.id)?.count || 0;const folderPermissions = getFolderPermissions(folder.role);+ const canUpdateFolder = folderPermissions.includes("folders.write");+ const canMoveLinks = folderPermissions.includes("folders.links.write");+ const isAllLinksFolder = folder.id === "all-links";return (<>@@ -52,69 +54,72 @@ export const FolderCard = ({ folder, linksCount }: FolderCardProps) => {<FolderIcon className="size-3" /></div></div>- <div className="flex items-center gap-2">- {!folderPermissions.includes("folders.links.write") && (- <AskToEditButton folder={folder} workspaceId={workspaceId!} />- )}- <Popover- content={- <div className="grid w-full gap-px p-2 sm:w-48">- {folderPermissions.includes("folders.write") && (- <Button- text="Rename"- variant="outline"- onClick={() => {- setOpenPopover(false);- setShowRenameFolderModal(true);- }}- icon={<PenWriting className="h-4 w-4" />}- shortcut="R"- className="h-9 px-2 font-medium"- />- )}+ {!isAllLinksFolder && (+ <div className="flex items-center gap-2">+ {!canMoveLinks && (+ <AskToEditButton folder={folder} workspaceId={workspaceId!} />+ )}- <Button- text="Members"- variant="outline"- onClick={() => {- setOpenPopover(false);- router.push(`/settings/folders/${folder.id}/members`);- }}- icon={<Users className="h-4 w-4" />}- shortcut="M"- className="h-9 px-2 font-medium"- />+ <Popover+ content={+ <div className="grid w-full gap-px p-2 sm:w-48">+ {canUpdateFolder && (+ <Button+ text="Rename"+ variant="outline"+ onClick={() => {+ setOpenPopover(false);+ setShowRenameFolderModal(true);+ }}+ icon={<PenWriting className="h-4 w-4" />}+ shortcut="R"+ className="h-9 px-2 font-medium"+ />+ )}- {folderPermissions.includes("folders.write") && (<Button- text="Delete"- variant="danger-outline"+ text="Members"+ variant="outline"onClick={() => {setOpenPopover(false);- setShowDeleteFolderModal(true);+ router.push(`/settings/folders/${folder.id}/members`);}}- icon={<Delete className="h-4 w-4" />}- shortcut="X"+ icon={<Users className="h-4 w-4" />}+ shortcut="M"className="h-9 px-2 font-medium"/>++ {canUpdateFolder && (+ <Button+ text="Delete"+ variant="danger-outline"+ onClick={() => {+ setOpenPopover(false);+ setShowDeleteFolderModal(true);+ }}+ icon={<Delete className="h-4 w-4" />}+ shortcut="X"+ className="h-9 px-2 font-medium"+ />+ )}+ </div>+ }+ align="end"+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ >+ <Button+ variant="secondary"+ className={cn(+ "h-8 px-1 outline-none transition-all duration-200",+ "border-transparent data-[state=open]:border-gray-500 sm:group-hover/card:data-[state=closed]:border-gray-200",)}- </div>- }- align="end"- openPopover={openPopover}- setOpenPopover={setOpenPopover}- >- <Button- variant="secondary"- className={cn(- "h-8 px-1 outline-none transition-all duration-200",- "border-transparent data-[state=open]:border-gray-500 sm:group-hover/card:data-[state=closed]:border-gray-200",- )}- icon={<ThreeDots className="h-4 w-4 shrink-0" />}- />- </Popover>- </div>+ icon={<ThreeDots className="h-4 w-4 shrink-0" />}+ />+ </Popover>+ </div>+ )}</div><div className="sm:mt-6">