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.

Fix folder dropdown with optional auto-redirect and improved folder selection

Kiran Kef4ba4f603e7
diff --git a/apps/web/lib/plan-capabilities.ts b/apps/web/lib/plan-capabilities.ts
index aa8a8d286f..c16dcf4685 100644
--- a/apps/web/lib/plan-capabilities.ts
+++ b/apps/web/lib/plan-capabilities.ts
@@ -1,6 +1,6 @@
import { WorkspaceProps } from "@/lib/types";
-// Get the capabilities of the folder based on the workspace plan
+// Get the capabilities of a workspace based on the plan
export const getPlanCapabilities = (
plan: WorkspaceProps["plan"] | undefined | string,
) => {
diff --git a/apps/web/ui/folders/folder-dropdown.tsx b/apps/web/ui/folders/folder-dropdown.tsx
index beb8c925c3..30de2462d6 100644
--- a/apps/web/ui/folders/folder-dropdown.tsx
+++ b/apps/web/ui/folders/folder-dropdown.tsx
@@ -7,7 +7,7 @@ import { Button, Popover, Tick, TooltipContent } from "@dub/ui";
import { cn } from "@dub/utils";
import { ChevronsUpDown } from "lucide-react";
import Link from "next/link";
-import { useSearchParams } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { useAddFolderModal } from "../modals/add-folder-modal";
import { FolderIcon } from "./folder-icon";
@@ -17,6 +17,7 @@ interface FolderDropdownProps {
hideViewAll?: boolean;
hideFolderIcon?: boolean;
textClassName?: string;
+ disableAutoRedirect?: boolean; // decide if we should auto redirect to the folder after it's created
}
export const FolderDropdown = ({
@@ -24,20 +25,32 @@ export const FolderDropdown = ({
hideViewAll = false,
hideFolderIcon = false,
textClassName,
+ disableAutoRedirect = false,
}: FolderDropdownProps) => {
+ const router = useRouter();
const { slug, plan } = useWorkspace();
-
const searchParams = useSearchParams();
const { folders, loading } = useFolders();
const [openPopover, setOpenPopover] = useState(false);
+
const [selectedFolder, setSelectedFolder] = useState<FolderSummary | null>(
unsortedLinks,
);
+
const folderId = searchParams.get("folderId");
const { AddFolderModal, setShowAddFolderModal } = useAddFolderModal({
onSuccess: (folder) => {
setSelectedFolder(folder);
+ onFolderSelect?.(folder);
+
+ if (!disableAutoRedirect) {
+ if (folder.id !== "unsorted") {
+ router.push(`/${slug}?folderId=${folder.id}`);
+ } else {
+ router.push(`/${slug}`);
+ }
+ }
},
});
@@ -45,6 +58,7 @@ export const FolderDropdown = ({
if (folders) {
const folder = folders.find((f) => f.id === folderId) || unsortedLinks;
setSelectedFolder(folder);
+ onFolderSelect?.(folder);
}
}, [folderId, folders]);
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index 1acc33d6fe..2b265230bd 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -349,6 +349,7 @@ function LinkBuilderInner({
<>
<FolderDropdown
hideViewAll={true}
+ disableAutoRedirect={true}
onFolderSelect={(folder) => {
setValue("folderId", folder.id, { shouldDirty: true });
}}