Skip to content

Commit 7b218d5

Browse files
committed
Feat: introduce self files tab in the file manager
1 parent 0f26fb2 commit 7b218d5

File tree

20 files changed

+456
-216
lines changed

20 files changed

+456
-216
lines changed

package-lock.json

Lines changed: 26 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(dashboard)/dashboard/files/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ async function FilesPage() {
2424
}
2525

2626
export default withPermissions(FilesPage, {
27-
requiredPermissions: ["files.index"],
27+
requiredPermissions: ["files.index", "self.files.index"],
2828
});
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import {revalidatePath} from "next/cache";
44
import {APP_PATHS} from "@/lib/app-paths";
5-
import {deleteFile} from "@/dal/private/files";
5+
import {addNewFile, deleteFile} from "@/dal/private/files";
6+
7+
export async function addFileAction(formData: FormData): Promise<any> {
8+
await addNewFile(formData);
9+
}
610

711
export async function deleteFileAction(formData: FormData) {
812
const fileId = formData.get("id")?.toString();
@@ -12,3 +16,4 @@ export async function deleteFileAction(formData: FormData) {
1216
await deleteFile(fileId);
1317
revalidatePath(APP_PATHS.dashboard.files);
1418
}
19+

src/components/files-explorer/add-file-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {useState, useRef, useId} from "react";
44
import {Tooltip, ActionIcon, Loader} from "@mantine/core";
55
import {IconPlus} from "@tabler/icons-react";
6-
import {addFileAction} from "@/features/files/actions";
6+
import {addFileAction} from "./actions";
77

88
type Props = {
99
onAdd: () => void;

src/components/files-explorer/file-card.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from "@mantine/core";
1818
import {IconEye, IconTrash, IconCheck} from "@tabler/icons-react";
1919
import {FILES_PUBLIC_URL} from "@/constants/envs";
20-
import {deleteFileAction} from "@/features/files/actions";
20+
import {deleteFileAction} from "./actions";
2121
import {mimeToIcon, defaultIcon} from "./mimetype-mapping";
2222
import classes from "./file-card.module.css";
2323

@@ -30,7 +30,7 @@ type File = {
3030
type Props = {
3131
file: File;
3232
isSelected?: boolean;
33-
onDelete: (id: string) => void;
33+
onDelete?: (id: string) => void;
3434
onSelect?: (id: string) => void;
3535
};
3636

@@ -39,7 +39,7 @@ export function FileCard({file, isSelected, onDelete, onSelect}: Props) {
3939
mutationKey: ["file-delete"],
4040
mutationFn: deleteFileAction,
4141
onSuccess: () => {
42-
onDelete(file.uuid);
42+
onDelete?.(file.uuid);
4343
handleClose();
4444
},
4545
});
@@ -58,6 +58,7 @@ export function FileCard({file, isSelected, onDelete, onSelect}: Props) {
5858
};
5959

6060
const handleDelete = async () => {
61+
if (!onDelete) return;
6162
const fd = new FormData();
6263
fd.set("id", file.uuid);
6364
mutate(fd);
@@ -128,16 +129,18 @@ export function FileCard({file, isSelected, onDelete, onSelect}: Props) {
128129
>
129130
<IconEye />
130131
</ActionIcon>
131-
<ActionIcon
132-
size={"lg"}
133-
color="red"
134-
onClick={(e) => {
135-
e.stopPropagation();
136-
setShowDeleteConfirm(true);
137-
}}
138-
>
139-
<IconTrash />
140-
</ActionIcon>
132+
{onDelete !== undefined && (
133+
<ActionIcon
134+
size={"lg"}
135+
color="red"
136+
onClick={(e) => {
137+
e.stopPropagation();
138+
setShowDeleteConfirm(true);
139+
}}
140+
>
141+
<IconTrash />
142+
</ActionIcon>
143+
)}
141144
</ActionIconGroup>
142145
</Box>
143146
</Overlay>

0 commit comments

Comments
 (0)