feat: logo et favicon, confirmation modale, fil d'ariane, e-mails sombres (#4)
CD — Déploiement / deploy (push) Failing after 25s
CD — Déploiement / deploy (push) Failing after 25s
- logo embarque dans les e-mails (CID) et gabarit repense en mode sombre - favicon multi-tailles + icone PNG, logo a gauche du titre (app et auth) - modale de confirmation animee a la place de window.confirm - bouton retour et fil d'ariane dans l'explorateur --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #4 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #4.
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
import { useState } from "react";
|
||||
import { NavLink, Outlet } from "react-router-dom";
|
||||
import { Button, cn } from "../ui/index.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
CloseIcon,
|
||||
FolderIcon,
|
||||
HardDriveIcon,
|
||||
ImageIcon,
|
||||
LogoutIcon,
|
||||
MenuIcon,
|
||||
SearchNavIcon,
|
||||
SettingsIcon,
|
||||
ShieldIcon,
|
||||
TrashIcon,
|
||||
} from "./icons.js";
|
||||
|
||||
interface NavItem {
|
||||
to: string;
|
||||
label: string;
|
||||
icon: typeof FolderIcon;
|
||||
}
|
||||
|
||||
const NAV: NavItem[] = [
|
||||
{ to: "/files", label: "Fichiers", icon: FolderIcon },
|
||||
{ to: "/search", label: "Recherche", icon: SearchNavIcon },
|
||||
{ to: "/gallery", label: "Galerie", icon: ImageIcon },
|
||||
{ to: "/trash", label: "Corbeille", icon: TrashIcon },
|
||||
];
|
||||
|
||||
const ADMIN_NAV: NavItem[] = [
|
||||
{ to: "/admin/comptes", label: "Comptes", icon: ShieldIcon },
|
||||
{ to: "/admin/stockage", label: "Stockage", icon: HardDriveIcon },
|
||||
{ to: "/admin/audit", label: "Journal", icon: ActivityIcon },
|
||||
];
|
||||
|
||||
const ACCOUNT_NAV: NavItem = { to: "/profile", label: "Mon compte", icon: SettingsIcon };
|
||||
|
||||
const initials = (first: string, last: string): string =>
|
||||
`${first.charAt(0)}${last.charAt(0)}`.toUpperCase() || "?";
|
||||
|
||||
const navClass = ({ isActive }: { isActive: boolean }) =>
|
||||
cn(
|
||||
"flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors",
|
||||
isActive
|
||||
? "bg-accent/10 text-accent"
|
||||
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
);
|
||||
|
||||
export const AppShell = () => {
|
||||
const { user, logout } = useSession();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
if (!user) return null;
|
||||
|
||||
const isAdmin = user.role_slug === "admin";
|
||||
const allNav = [...NAV, ...(isAdmin ? ADMIN_NAV : []), ACCOUNT_NAV];
|
||||
|
||||
const brand = (
|
||||
<NavLink to="/files" className="flex items-center gap-2" onClick={() => setMenuOpen(false)}>
|
||||
<img
|
||||
src="/icon.png"
|
||||
alt=""
|
||||
className="h-7 w-7 shrink-0 rounded-md ring-1 ring-black/5"
|
||||
/>
|
||||
<span className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</span>
|
||||
<span className="text-border" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
<span className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
Cloud
|
||||
</span>
|
||||
</NavLink>
|
||||
);
|
||||
|
||||
const renderLink = (item: NavItem) => {
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<NavLink key={item.to} to={item.to} className={navClass} onClick={() => setMenuOpen(false)}>
|
||||
<Icon className="h-4 w-4" />
|
||||
{item.label}
|
||||
</NavLink>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-dvh bg-background">
|
||||
<aside className="hidden w-60 shrink-0 flex-col gap-1 border-r border-border bg-surface p-3 lg:flex">
|
||||
<div className="px-1 py-2">{brand}</div>
|
||||
{NAV.map(renderLink)}
|
||||
{isAdmin ? (
|
||||
<>
|
||||
<p className="mt-3 px-3 py-1 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Administration
|
||||
</p>
|
||||
{ADMIN_NAV.map(renderLink)}
|
||||
</>
|
||||
) : null}
|
||||
<div className="mt-auto pt-3">{renderLink(ACCOUNT_NAV)}</div>
|
||||
</aside>
|
||||
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
<header className="sticky top-0 z-20 border-b border-border bg-surface">
|
||||
<div className="mx-auto flex w-full max-w-5xl items-center justify-between gap-4 px-4 py-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
className="text-muted-foreground lg:hidden"
|
||||
aria-label={menuOpen ? "Fermer le menu" : "Ouvrir le menu"}
|
||||
aria-expanded={menuOpen}
|
||||
onClick={() => setMenuOpen((value) => !value)}
|
||||
>
|
||||
{menuOpen ? <CloseIcon className="h-5 w-5" /> : <MenuIcon className="h-5 w-5" />}
|
||||
</button>
|
||||
<span className="lg:hidden">{brand}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="hidden text-right sm:block">
|
||||
<p className="text-xs font-medium text-foreground">
|
||||
{user.first_name} {user.last_name}
|
||||
</p>
|
||||
<p className="text-[0.6875rem] uppercase tracking-label text-subtle-foreground">
|
||||
{user.role_name}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-border bg-surface text-xs font-semibold text-foreground"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{initials(user.first_name, user.last_name)}
|
||||
</span>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<LogoutIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => void logout()}
|
||||
>
|
||||
<span className="hidden sm:inline">Déconnexion</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{menuOpen ? (
|
||||
<nav className="flex flex-col gap-1 border-t border-border px-3 py-2 lg:hidden">
|
||||
{allNav.map(renderLink)}
|
||||
</nav>
|
||||
) : null}
|
||||
</header>
|
||||
|
||||
<main className="mx-auto w-full max-w-5xl flex-1 px-4 py-6">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { Spinner, cn } from "../ui/index.js";
|
||||
|
||||
export const IconAction = ({
|
||||
label,
|
||||
icon,
|
||||
onClick,
|
||||
isLoading = false,
|
||||
tone = "neutral",
|
||||
}: {
|
||||
label: string;
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
isLoading?: boolean;
|
||||
tone?: "neutral" | "danger";
|
||||
}) => (
|
||||
<button
|
||||
type="button"
|
||||
title={label}
|
||||
aria-label={label}
|
||||
disabled={isLoading}
|
||||
onClick={onClick}
|
||||
className={cn(
|
||||
"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors",
|
||||
"hover:bg-surface-hover hover:text-foreground disabled:pointer-events-none disabled:opacity-50",
|
||||
tone === "danger" && "hover:text-destructive",
|
||||
)}
|
||||
>
|
||||
{isLoading ? <Spinner size="xs" /> : icon}
|
||||
</button>
|
||||
);
|
||||
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { Button } from "../ui/index.js";
|
||||
import { Modal } from "./feedback.js";
|
||||
|
||||
export interface ConfirmOptions {
|
||||
/** Titre de la modale. */
|
||||
title?: string;
|
||||
/** Corps du message ; accepte du balisage pour mettre un nom en valeur. */
|
||||
message: ReactNode;
|
||||
confirmLabel?: string;
|
||||
cancelLabel?: string;
|
||||
/** `danger` reserve l'action a une operation destructive. */
|
||||
tone?: "default" | "danger";
|
||||
}
|
||||
|
||||
type ConfirmFn = (options: ConfirmOptions) => Promise<boolean>;
|
||||
|
||||
interface PendingConfirm {
|
||||
options: ConfirmOptions;
|
||||
resolve: (value: boolean) => void;
|
||||
}
|
||||
|
||||
const ConfirmContext = createContext<ConfirmFn | null>(null);
|
||||
|
||||
/**
|
||||
* Remplace `window.confirm` par une modale maison aux couleurs de l'app.
|
||||
* `useConfirm()` renvoie une promesse resolue a `true` (confirme) ou `false`.
|
||||
*/
|
||||
export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [pending, setPending] = useState<PendingConfirm | null>(null);
|
||||
|
||||
const confirm = useCallback<ConfirmFn>(
|
||||
(options) => new Promise<boolean>((resolve) => setPending({ options, resolve })),
|
||||
[],
|
||||
);
|
||||
|
||||
const answer = (value: boolean) => {
|
||||
if (pending) pending.resolve(value);
|
||||
setPending(null);
|
||||
};
|
||||
|
||||
const tone = pending?.options.tone ?? "default";
|
||||
|
||||
return (
|
||||
<ConfirmContext.Provider value={confirm}>
|
||||
{children}
|
||||
<Modal
|
||||
open={pending !== null}
|
||||
title={pending?.options.title ?? "Confirmation"}
|
||||
onClose={() => answer(false)}
|
||||
>
|
||||
<div className="flex flex-col gap-5">
|
||||
<p className="text-sm leading-relaxed text-muted-foreground">
|
||||
{pending?.options.message}
|
||||
</p>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={() => answer(false)}>
|
||||
{pending?.options.cancelLabel ?? "Annuler"}
|
||||
</Button>
|
||||
<Button
|
||||
variant={tone === "danger" ? "destructive" : "primary"}
|
||||
size="md"
|
||||
autoFocus
|
||||
onClick={() => answer(true)}
|
||||
>
|
||||
{pending?.options.confirmLabel ?? "Confirmer"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</ConfirmContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useConfirm = (): ConfirmFn => {
|
||||
const context = useContext(ConfirmContext);
|
||||
if (!context) throw new Error("useConfirm doit etre utilise sous ConfirmProvider");
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,381 @@
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Input, cn } from "../ui/index.js";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
formatDate,
|
||||
type Folder,
|
||||
type FolderPermission,
|
||||
} from "../lib/api.js";
|
||||
import { Alert, Modal } from "./feedback.js";
|
||||
import { TrashIcon } from "./icons.js";
|
||||
|
||||
const LEVELS = ["read", "write", "admin"] as const;
|
||||
const LEVEL_LABEL: Record<string, string> = {
|
||||
read: "Lecture",
|
||||
write: "Écriture",
|
||||
admin: "Administration",
|
||||
};
|
||||
|
||||
const messageOf = (caught: unknown, fallback: string): string =>
|
||||
caught instanceof ApiError ? caught.message : fallback;
|
||||
|
||||
interface Target {
|
||||
type: "folder" | "file";
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const CreateFolderDialog = ({
|
||||
parentId,
|
||||
onClose,
|
||||
onCreated,
|
||||
}: {
|
||||
parentId: string | null;
|
||||
onClose: () => void;
|
||||
onCreated: () => void;
|
||||
}) => {
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.createFolder(name, parentId, description.trim() || undefined);
|
||||
onCreated();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Création impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title="Nouveau dossier" onClose={onClose}>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nom"
|
||||
required
|
||||
maxLength={255}
|
||||
autoFocus
|
||||
placeholder="Contrats 2026"
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Description (optionnelle)"
|
||||
maxLength={2000}
|
||||
value={description}
|
||||
onChange={(event) => setDescription(event.target.value)}
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={onClose}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button type="submit" size="md" isLoading={busy}>
|
||||
Créer
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const RenameDialog = ({
|
||||
target,
|
||||
onClose,
|
||||
onDone,
|
||||
}: {
|
||||
target: Target;
|
||||
onClose: () => void;
|
||||
onDone: () => void;
|
||||
}) => {
|
||||
const [name, setName] = useState(target.name);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
if (target.type === "folder") await api.updateFolder(target.id, { name });
|
||||
else await api.renameFile(target.id, name);
|
||||
onDone();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Renommage impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title="Renommer" onClose={onClose}>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nom"
|
||||
required
|
||||
maxLength={255}
|
||||
autoFocus
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={onClose}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button type="submit" size="md" isLoading={busy}>
|
||||
Enregistrer
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
interface TreeEntry {
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
const loadTree = async (): Promise<TreeEntry[]> => {
|
||||
const entries: TreeEntry[] = [];
|
||||
const walk = async (parentId: string | null, prefix: string, depth: number): Promise<void> => {
|
||||
if (depth > 6) return;
|
||||
const { folders } = await api.folders(parentId);
|
||||
for (const folder of folders) {
|
||||
entries.push({ id: folder.id, label: `${prefix}${folder.name}` });
|
||||
await walk(folder.id, `${prefix}${folder.name} / `, depth + 1);
|
||||
}
|
||||
};
|
||||
await walk(null, "", 0);
|
||||
return entries;
|
||||
};
|
||||
|
||||
export const MoveDialog = ({
|
||||
target,
|
||||
onClose,
|
||||
onDone,
|
||||
}: {
|
||||
target: Target;
|
||||
onClose: () => void;
|
||||
onDone: () => void;
|
||||
}) => {
|
||||
const [entries, setEntries] = useState<TreeEntry[] | null>(null);
|
||||
const [destination, setDestination] = useState<string>("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadTree()
|
||||
.then(setEntries)
|
||||
.catch((caught: unknown) => setError(messageOf(caught, "Chargement des dossiers impossible.")));
|
||||
}, []);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
const parentId = destination === "" ? null : destination;
|
||||
try {
|
||||
if (target.type === "folder") await api.moveFolder(target.id, parentId);
|
||||
else await api.moveFile(target.id, parentId);
|
||||
onDone();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Déplacement impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title="Déplacer" onClose={onClose}>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Destination de <span className="font-medium text-foreground">{target.name}</span>.
|
||||
</p>
|
||||
{entries === null && !error ? (
|
||||
<Alert tone="info">Chargement des dossiers…</Alert>
|
||||
) : (
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Destination
|
||||
</span>
|
||||
<select
|
||||
value={destination}
|
||||
onChange={(event) => setDestination(event.target.value)}
|
||||
className={cn(
|
||||
"h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground",
|
||||
"focus-visible:ring-ring focus-visible:border-border-strong focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none",
|
||||
)}
|
||||
>
|
||||
<option value="">Racine</option>
|
||||
{(entries ?? [])
|
||||
.filter((entry) => entry.id !== target.id)
|
||||
.map((entry) => (
|
||||
<option key={entry.id} value={entry.id}>
|
||||
{entry.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={onClose}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button type="submit" size="md" isLoading={busy} disabled={entries === null}>
|
||||
Déplacer
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const ShareDialog = ({
|
||||
folder,
|
||||
onClose,
|
||||
}: {
|
||||
folder: Folder;
|
||||
onClose: () => void;
|
||||
}) => {
|
||||
const [permissions, setPermissions] = useState<FolderPermission[] | null>(null);
|
||||
const [email, setEmail] = useState("");
|
||||
const [level, setLevel] = useState<string>("read");
|
||||
const [expiresAt, setExpiresAt] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
const { permissions: list } = await api.folderPermissions(folder.id);
|
||||
setPermissions(list);
|
||||
setError(null);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement des partages impossible."));
|
||||
setPermissions([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [folder.id]);
|
||||
|
||||
const grant = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const iso = expiresAt ? new Date(expiresAt).toISOString() : null;
|
||||
await api.grantPermission(folder.id, email, level, expiresAt ? iso : null);
|
||||
setEmail("");
|
||||
setExpiresAt("");
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Partage impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const revoke = async (userId: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
await api.revokePermission(folder.id, userId);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Révocation impossible."));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title={`Partager « ${folder.name} »`} onClose={onClose}>
|
||||
<div className="flex flex-col gap-5">
|
||||
<form className="flex flex-col gap-3" onSubmit={(event) => void grant(event)}>
|
||||
<Input
|
||||
label="Adresse e-mail du membre"
|
||||
type="email"
|
||||
required
|
||||
autoFocus
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Niveau
|
||||
</span>
|
||||
<select
|
||||
value={level}
|
||||
onChange={(event) => setLevel(event.target.value)}
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground focus-visible:ring-ring focus-visible:border-border-strong focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none"
|
||||
>
|
||||
{LEVELS.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{LEVEL_LABEL[value]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<Input
|
||||
label="Expire le"
|
||||
type="date"
|
||||
value={expiresAt}
|
||||
onChange={(event) => setExpiresAt(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="md" isLoading={busy}>
|
||||
Autoriser
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<h3 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Accès accordés
|
||||
</h3>
|
||||
{permissions === null ? (
|
||||
<Alert tone="info">Chargement…</Alert>
|
||||
) : permissions.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">Aucun partage pour ce dossier.</p>
|
||||
) : (
|
||||
<ul className="flex flex-col divide-y divide-border rounded-md border border-border">
|
||||
{permissions.map((permission) => (
|
||||
<li key={permission.user_id} className="flex items-center gap-3 px-3 py-2">
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-xs font-medium text-foreground">
|
||||
{permission.first_name} {permission.last_name}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{permission.email} · {LEVEL_LABEL[permission.level] ?? permission.level}
|
||||
{permission.expires_at ? ` · jusqu'au ${formatDate(permission.expires_at)}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Révoquer ${permission.email}`}
|
||||
onClick={() => void revoke(permission.user_id)}
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-destructive"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,150 @@
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
import { cn } from "../ui/index.js";
|
||||
import { CloseIcon } from "./icons.js";
|
||||
|
||||
export const Modal = ({
|
||||
open,
|
||||
title,
|
||||
onClose,
|
||||
children,
|
||||
}: {
|
||||
open: boolean;
|
||||
title: string;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
}) => {
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
const previousOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
document.body.style.overflow = previousOverflow;
|
||||
};
|
||||
}, [open, onClose]);
|
||||
|
||||
if (!open) return null;
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
||||
<div
|
||||
className="animate-overlay-in absolute inset-0 bg-black/40 backdrop-blur-[2px]"
|
||||
onClick={onClose}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={title}
|
||||
className="animate-panel-in relative w-full max-w-md rounded-lg border border-border bg-surface p-4 shadow-lg"
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between gap-4">
|
||||
<h2 className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
{title}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
aria-label="Fermer"
|
||||
className="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<CloseIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const Alert = ({
|
||||
children,
|
||||
tone = "error",
|
||||
className,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
tone?: "error" | "success" | "info";
|
||||
className?: string;
|
||||
}) => (
|
||||
<p
|
||||
role="alert"
|
||||
className={cn(
|
||||
"rounded-md border px-3 py-2 text-xs leading-relaxed",
|
||||
tone === "error" && "border-destructive/40 bg-destructive/10 text-destructive",
|
||||
tone === "success" && "border-accent/40 bg-accent/10 text-accent",
|
||||
tone === "info" && "border-border bg-surface text-muted-foreground",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</p>
|
||||
);
|
||||
|
||||
export const PageHeader = ({
|
||||
title,
|
||||
description,
|
||||
actions,
|
||||
}: {
|
||||
title: string;
|
||||
description?: string;
|
||||
actions?: ReactNode;
|
||||
}) => (
|
||||
<header className="mb-6 flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div>
|
||||
<h1 className="font-display text-base font-semibold uppercase tracking-label text-foreground">
|
||||
{title}
|
||||
</h1>
|
||||
{description ? (
|
||||
<p className="mt-1 max-w-2xl text-sm leading-relaxed text-muted-foreground">{description}</p>
|
||||
) : null}
|
||||
</div>
|
||||
{actions ? <div className="flex flex-wrap items-center gap-2">{actions}</div> : null}
|
||||
</header>
|
||||
);
|
||||
|
||||
export const EmptyState = ({
|
||||
icon,
|
||||
title,
|
||||
description,
|
||||
action,
|
||||
}: {
|
||||
icon?: ReactNode;
|
||||
title: string;
|
||||
description?: string;
|
||||
action?: ReactNode;
|
||||
}) => (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border-control py-16 text-center">
|
||||
{icon ? <span className="text-subtle-foreground">{icon}</span> : null}
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
{title}
|
||||
</p>
|
||||
{description ? (
|
||||
<p className="max-w-xs text-sm leading-relaxed text-muted-foreground">{description}</p>
|
||||
) : null}
|
||||
{action}
|
||||
</div>
|
||||
);
|
||||
|
||||
export const Badge = ({
|
||||
children,
|
||||
tone = "neutral",
|
||||
}: {
|
||||
children: ReactNode;
|
||||
tone?: "neutral" | "accent" | "warning" | "danger";
|
||||
}) => (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center rounded-sm border px-1.5 py-0.5 font-display text-[0.625rem] font-semibold uppercase tracking-label",
|
||||
tone === "neutral" && "border-border-strong text-muted-foreground",
|
||||
tone === "accent" && "border-accent/50 bg-accent/10 text-accent",
|
||||
tone === "warning" && "border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-400",
|
||||
tone === "danger" && "border-destructive/40 bg-destructive/10 text-destructive",
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
@@ -0,0 +1,166 @@
|
||||
import type { SVGProps } from "react";
|
||||
|
||||
type IconProps = SVGProps<SVGSVGElement>;
|
||||
|
||||
const base = (props: IconProps) => ({
|
||||
viewBox: "0 0 24 24",
|
||||
fill: "none",
|
||||
stroke: "currentColor",
|
||||
strokeWidth: 1.6,
|
||||
strokeLinecap: "round" as const,
|
||||
strokeLinejoin: "round" as const,
|
||||
"aria-hidden": true,
|
||||
...props,
|
||||
});
|
||||
|
||||
export const FolderIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M3 7.5A1.5 1.5 0 0 1 4.5 6h4l2 2.5h7A1.5 1.5 0 0 1 19 10v7.5A1.5 1.5 0 0 1 17.5 19h-13A1.5 1.5 0 0 1 3 17.5Z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const FileIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M6 3.5h7l5 5v12A1.5 1.5 0 0 1 16.5 22h-10A1.5 1.5 0 0 1 5 20.5v-16A1.5 1.5 0 0 1 6 3Z" />
|
||||
<path d="M13 3.5v5h5" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ImageIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<circle cx="8.5" cy="9.5" r="1.5" />
|
||||
<path d="m4 17 4.5-4.5a1.5 1.5 0 0 1 2.1 0L15 17m1.5-2 1.2-1.2a1.5 1.5 0 0 1 2.1 0L21 15" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const UploadIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M12 16V4m0 0L7.5 8.5M12 4l4.5 4.5M4 17v1.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V17" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const DownloadIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M12 4v12m0 0-4.5-4.5M12 16l4.5-4.5M4 17v1.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V17" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const PlusIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const TrashIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M4 7h16M9 7V5.5A1.5 1.5 0 0 1 10.5 4h3A1.5 1.5 0 0 1 15 5.5V7m-8 0 .7 11.1A1.5 1.5 0 0 0 9.2 19.6h5.6a1.5 1.5 0 0 0 1.5-1.5L17 7" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const RestoreIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M4 12a8 8 0 1 0 2.3-5.6M4 4v4h4" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const StarIcon = ({ filled, ...props }: IconProps & { filled?: boolean }) => (
|
||||
<svg {...base(props)} fill={filled ? "currentColor" : "none"}>
|
||||
<path d="m12 3.5 2.6 5.3 5.9.9-4.2 4.1 1 5.8L12 20.8l-5.3 2.8 1-5.8L3.5 14l5.9-.9Z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const SearchIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<circle cx="11" cy="11" r="7" />
|
||||
<path d="m20 20-3.5-3.5" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const UsersIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<circle cx="9" cy="8" r="3.5" />
|
||||
<path d="M3.5 20a5.5 5.5 0 0 1 11 0M16 5.5a3 3 0 0 1 0 6M16.5 20a5.5 1.5 0 0 0-2.2-4.3" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const SettingsIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
<path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-2.9 1.2 2 2 0 1 1-4 0 1.7 1.7 0 0 0-2.9-1.2l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.7 1.7 0 0 0 2.6 15a2 2 0 1 1 0-4 1.7 1.7 0 0 0 1.2-2.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.7 1.7 0 0 0 9 4.6a2 2 0 1 1 4 0 1.7 1.7 0 0 0 2.9 1.2l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0 1.2 2.9 2 2 0 1 1 0 4 1.7 1.7 0 0 0-1.5 1Z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const LogoutIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M15 4h2.5A1.5 1.5 0 0 1 19 5.5v13a1.5 1.5 0 0 1-1.5 1.5H15M10 8l-4 4 4 4M6 12h9" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ShieldIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M12 3 5 6v5c0 4.3 3 8.2 7 9.5 4-1.3 7-5.2 7-9.5V6Z" />
|
||||
<path d="m9 12 2 2 4-4" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const HardDriveIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M3 14h18M7 17h.01M11 17h.01" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ActivityIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M3 12h4l3 8 4-16 3 8h4" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const SearchNavIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<circle cx="11" cy="11" r="7" />
|
||||
<path d="m20 20-3.5-3.5" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ShareIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<circle cx="18" cy="5" r="2.5" />
|
||||
<circle cx="6" cy="12" r="2.5" />
|
||||
<circle cx="18" cy="19" r="2.5" />
|
||||
<path d="m8.2 10.8 7.6-4.6M8.2 13.2l7.6 4.6" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const MenuIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M4 7h16M4 12h16M4 17h16" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const CloseIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M6 6l12 12M18 6 6 18" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ArrowLeftIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M19 12H5M11 18l-6-6 6-6" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const PenIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M4 20h4L18.5 9.5a2.1 2.1 0 0 0-3-3L5 17v3Z" />
|
||||
<path d="m13.5 6.5 3 3" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const MoveIcon = (props: IconProps) => (
|
||||
<svg {...base(props)}>
|
||||
<path d="M12 4v16M4 12h16" />
|
||||
<path d="m9 7 3-3 3 3M9 17l3 3 3-3M7 9l-3 3 3 3M17 9l3 3-3 3" />
|
||||
</svg>
|
||||
);
|
||||
Reference in New Issue
Block a user