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.

folder fixes

Kiran K74beae1dc055
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 7e3a8bfedb..9321cd8798 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -88,12 +88,19 @@ export const PATCH = withWorkspace(
: null;
if (defaultFolderId) {
- await verifyFolderAccess({
+ const folder = await verifyFolderAccess({
workspace,
userId: session.user.id,
folderId: defaultFolderId,
- requiredPermission: "folders.write",
+ requiredPermission: "folders.read",
});
+
+ if (folder.accessLevel === null) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "Only folder with workspace access can be set as default.",
+ });
+ }
}
try {
diff --git a/apps/web/app/api/workspaces/[workspaceId]/default-folder/route.ts b/apps/web/app/api/workspaces/[workspaceId]/default-folder/route.ts
deleted file mode 100644
index 0519ecba6e..0000000000
--- a/apps/web/app/api/workspaces/[workspaceId]/default-folder/route.ts
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx
index 8d2c17160c..b787fc040e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/folders/page-client.tsx
@@ -1,5 +1,6 @@
"use client";
+import { unsortedLinks } from "@/lib/folder/constants";
import useFolders from "@/lib/swr/use-folders";
import useFoldersCount from "@/lib/swr/use-folders-count";
import useWorkspace from "@/lib/swr/use-workspace";
@@ -13,13 +14,10 @@ import { PaginationControls, usePagination, useRouterStuff } from "@dub/ui";
import { useRouter, useSearchParams } from "next/navigation";
const allLinkFolder: Folder = {
- id: "unsorted",
- name: "Links",
type: "default",
- accessLevel: null,
- linkCount: 0,
createdAt: new Date(),
updatedAt: new Date(),
+ ...unsortedLinks,
};
export const FoldersPageClient = () => {
diff --git a/apps/web/lib/folder/constants.ts b/apps/web/lib/folder/constants.ts
index 425249fb92..cdd85e5ac1 100644
--- a/apps/web/lib/folder/constants.ts
+++ b/apps/web/lib/folder/constants.ts
@@ -44,6 +44,7 @@ export const FOLDER_USER_ROLE_TO_PERMISSIONS: Record<
export const unsortedLinks: FolderSummary = {
id: "unsorted",
name: "Links",
- accessLevel: null,
+ accessLevel: "write",
linkCount: -1,
-};
+
+};
\ No newline at end of file
diff --git a/apps/web/ui/folders/folder-actions.tsx b/apps/web/ui/folders/folder-actions.tsx
index 25687f56fa..7aaa6dfdd3 100644
--- a/apps/web/ui/folders/folder-actions.tsx
+++ b/apps/web/ui/folders/folder-actions.tsx
@@ -22,6 +22,10 @@ import { useRenameFolderModal } from "../modals/rename-folder-modal";
import { Chart, Delete, ThreeDots } from "../shared/icons";
import { useFolderPermissionsPanel } from "./folder-permissions-panel";
+// TODO:
+// If no actions button exists, then hide the popover
+// Re-render when default folder changes
+
export const FolderActions = ({
folder,
onDelete,
@@ -100,9 +104,11 @@ export const FolderActions = ({
},
);
- const unsortedLinks = folder.id === "unsorted";
- const isDefault = defaultFolderId && folder.id === defaultFolderId;
- const canMakeDefault = !isDefault;
+ const folderId = folder.id === "unsorted" ? null : folder.id;
+ const unsortedLinks = folderId === null;
+ const isDefault = Boolean(defaultFolderId) && defaultFolderId === folderId;
+ const canMakeDefault =
+ !isDefault && !permissionsError && folder.accessLevel != null;
return (
<>
diff --git a/apps/web/ui/modals/default-folder-modal.tsx b/apps/web/ui/modals/default-folder-modal.tsx
index 312359dd7b..48f591696d 100644
--- a/apps/web/ui/modals/default-folder-modal.tsx
+++ b/apps/web/ui/modals/default-folder-modal.tsx
@@ -1,4 +1,3 @@
-import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { FolderSummary } from "@/lib/types";
import { Button, Modal } from "@dub/ui";
@@ -22,13 +21,8 @@ function DefaultFolderModal({
setShowDefaultFolderModal: Dispatch<SetStateAction<boolean>>;
folder: FolderSummary;
}) {
+ const { id: workspaceId } = useWorkspace();
const [loading, setLoading] = useState(false);
- const { id: workspaceId, role, defaultFolderId } = useWorkspace();
-
- const permissionsError = clientAccessCheck({
- action: "workspaces.write",
- role,
- }).error;
const setDefault = async () => {
setLoading(true);
@@ -54,11 +48,6 @@ function DefaultFolderModal({
}
};
- const canMakeDefault = folder.accessLevel != null || folder.id === "unsorted";
- const isDefault =
- (defaultFolderId && folder.id === defaultFolderId) ||
- (folder.id === "unsorted" && !defaultFolderId);
-
return (
<Modal
showModal={showDefaultFolderModal}
@@ -88,16 +77,7 @@ function DefaultFolderModal({
}
autoFocus
loading={loading}
- text={
- isDefault ? "This is the default folder" : "Set as default folder"
- }
- disabled={isDefault}
- disabledTooltip={
- permissionsError ||
- (!canMakeDefault &&
- "Only folder with workspace access can be set as default.") ||
- undefined
- }
+ text="Set as default folder"
/>
</div>
</Modal>