import { useState } from "react"; import { del, post, put } from "../../api"; import { useFetch } from "../../hooks"; import { useT } from "../../i18n"; import type { User } from "../../types"; import { confirmDialog, promptDialog, toast } from "../../dialogs"; interface Folder { id: string; path: string; users: string[]; } /** Admin: folders inside the workspace shared with selected users. */ export function Folders() { const t = useT(); const { data, reload } = useFetch<{ workspace: string; folders: Folder[] }>("/folders"); const users = (useFetch("/users").data ?? []).filter((u) => u.role !== "admin"); const [path, setPath] = useState(""); const [notice, setNotice] = useState<{ ok: boolean; text: string }>(); const run = async (fn: () => Promise) => { try { await fn(); setNotice({ ok: true, text: t("settings.saved") }); reload(); } catch (e: any) { setNotice({ ok: false, text: e.message }); } }; const toggle = (f: Folder, userId: string) => { const next = f.users.includes(userId) ? f.users.filter((u) => u !== userId) : [...f.users, userId]; void run(() => put(`/folders/${f.id}/access`, { users: next })); }; const ws = data?.workspace ?? ""; return ( <>
{t("folders.intro")}
{notice &&
{notice.text}
} {data?.folders.length === 0 &&
{t("folders.none")}
} {data?.folders.map((f) => (

📁 {f.path.slice(ws.length) || "/"}

{users.length === 0 &&
{t("folders.noUsers")}
} {users.map((u) => ( ))}
))}

{t("folders.add")}

{ws}/ setPath(e.target.value)} placeholder="team/project" style={{ flex: 1, minWidth: 160 }} />
{t("folders.addHint")}
); }