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,766 @@
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import { Button, Input, Spinner } from "../ui/index.js";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
formatDate,
|
||||
type AdminStats,
|
||||
type AdminUser,
|
||||
type AuditEntry,
|
||||
type StorageLocation,
|
||||
} from "../lib/api.js";
|
||||
import { Alert, Badge, EmptyState, Modal, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
HardDriveIcon,
|
||||
PlusIcon,
|
||||
TrashIcon,
|
||||
UsersIcon,
|
||||
} from "../components/icons.js";
|
||||
|
||||
const GB = 1024 ** 3;
|
||||
const MB = 1024 ** 2;
|
||||
|
||||
const messageOf = (caught: unknown, fallback: string): string =>
|
||||
caught instanceof ApiError ? caught.message : fallback;
|
||||
|
||||
const toGb = (bytes: number): string =>
|
||||
(bytes / GB).toLocaleString("fr-FR", { maximumFractionDigits: 1 });
|
||||
|
||||
const StatCard = ({ label, value }: { label: string; value: string }) => (
|
||||
<div className="rounded-lg border border-border bg-surface p-3">
|
||||
<p className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
{label}
|
||||
</p>
|
||||
<p className="mt-1 text-lg font-semibold text-foreground">{value}</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const AdminUsers = () => {
|
||||
const confirm = useConfirm();
|
||||
const [users, setUsers] = useState<AdminUser[] | null>(null);
|
||||
const [stats, setStats] = useState<AdminStats | null>(null);
|
||||
const [q, setQ] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [edit, setEdit] = useState<AdminUser | null>(null);
|
||||
const [credentials, setCredentials] = useState<{ email: string; password: string } | null>(null);
|
||||
const termRef = useRef("");
|
||||
|
||||
const load = async (term: string) => {
|
||||
termRef.current = term;
|
||||
setError(null);
|
||||
try {
|
||||
const { users: list } = await api.adminUsers(term || undefined);
|
||||
setUsers(list);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setUsers([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void load("");
|
||||
api
|
||||
.adminStats()
|
||||
.then(setStats)
|
||||
.catch(() => undefined);
|
||||
}, []);
|
||||
|
||||
const toggleActive = async (user: AdminUser) => {
|
||||
setBusy(user.id);
|
||||
setError(null);
|
||||
try {
|
||||
await api.adminUpdateUser(user.id, { is_active: !user.is_active });
|
||||
await load(termRef.current);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Mise à jour impossible."));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
};
|
||||
|
||||
const resetPassword = async (user: AdminUser) => {
|
||||
setBusy(user.id);
|
||||
setError(null);
|
||||
try {
|
||||
const { password } = await api.adminResetPassword(user.id);
|
||||
setCredentials({ email: user.email, password });
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Réinitialisation impossible."));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
};
|
||||
|
||||
const removeUser = async (user: AdminUser) => {
|
||||
const ok = await confirm({
|
||||
title: "Supprimer le membre",
|
||||
message: (
|
||||
<>
|
||||
Supprimer définitivement <span className="font-semibold text-foreground">{user.email}</span>{" "}
|
||||
ainsi que ses fichiers ? Cette action est irréversible.
|
||||
</>
|
||||
),
|
||||
confirmLabel: "Supprimer",
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(user.id);
|
||||
setError(null);
|
||||
try {
|
||||
await api.adminDeleteUser(user.id);
|
||||
await load(termRef.current);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Suppression impossible."));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Comptes"
|
||||
description="Créez des membres, ajustez leurs quotas et gérez les accès."
|
||||
actions={
|
||||
<Button
|
||||
size="sm"
|
||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
Nouveau membre
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
{stats ? (
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<StatCard label="Membres" value={String(stats.users)} />
|
||||
<StatCard label="Fichiers" value={String(stats.files)} />
|
||||
<StatCard label="Stockage" value={`${toGb(stats.usedBytes)} Go`} />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<form
|
||||
className="flex items-end gap-2"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void load(q);
|
||||
}}
|
||||
>
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
label="Rechercher"
|
||||
type="search"
|
||||
placeholder="nom ou e-mail"
|
||||
value={q}
|
||||
onChange={(event) => setQ(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" size="md" variant="secondary">
|
||||
Filtrer
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{users === null ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : users.length === 0 ? (
|
||||
<EmptyState icon={<UsersIcon className="h-8 w-8" />} title="Aucun membre" />
|
||||
) : (
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{users.map((user) => (
|
||||
<li key={user.id} className="flex flex-wrap items-center gap-3 px-3 py-3">
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="truncate text-sm font-medium text-foreground">
|
||||
{user.first_name} {user.last_name}
|
||||
</span>
|
||||
{user.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
||||
{!user.is_active ? <Badge tone="danger">Inactif</Badge> : null}
|
||||
{user.must_change_password ? <Badge tone="warning">À changer</Badge> : null}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{user.email} · {toGb(user.used_bytes)} / {toGb(user.quota_bytes)} Go ·{" "}
|
||||
{user.last_login_at
|
||||
? `vu le ${formatDate(user.last_login_at)}`
|
||||
: "jamais connecté"}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<Button variant="ghost" size="sm" onClick={() => setEdit(user)}>
|
||||
Modifier
|
||||
</Button>
|
||||
<IconAction
|
||||
label={user.is_active ? "Désactiver" : "Réactiver"}
|
||||
icon={<HardDriveIcon className="h-4 w-4" />}
|
||||
isLoading={busy === user.id}
|
||||
onClick={() => void toggleActive(user)}
|
||||
/>
|
||||
<IconAction
|
||||
label="Réinitialiser le mot de passe"
|
||||
icon={<ActivityIcon className="h-4 w-4" />}
|
||||
isLoading={busy === user.id}
|
||||
onClick={() => void resetPassword(user)}
|
||||
/>
|
||||
<IconAction
|
||||
label="Supprimer"
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
tone="danger"
|
||||
isLoading={busy === user.id}
|
||||
onClick={() => void removeUser(user)}
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{createOpen ? (
|
||||
<CreateUserDialog
|
||||
onClose={() => setCreateOpen(false)}
|
||||
onCreated={(email, password) => {
|
||||
setCreateOpen(false);
|
||||
setCredentials({ email, password });
|
||||
void load(termRef.current);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{edit ? (
|
||||
<EditUserDialog
|
||||
user={edit}
|
||||
onClose={() => setEdit(null)}
|
||||
onSaved={() => {
|
||||
setEdit(null);
|
||||
void load(termRef.current);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<CredentialsModal credentials={credentials} onClose={() => setCredentials(null)} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const CredentialsModal = ({
|
||||
credentials,
|
||||
onClose,
|
||||
}: {
|
||||
credentials: { email: string; password: string } | null;
|
||||
onClose: () => void;
|
||||
}) => {
|
||||
if (!credentials) return null;
|
||||
return (
|
||||
<Modal open title="Identifiants générés" onClose={onClose}>
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert tone="success">
|
||||
Transmettez ces informations par un canal sûr : le mot de passe ne sera plus affiché.
|
||||
</Alert>
|
||||
<dl className="flex flex-col gap-2 text-xs">
|
||||
<div>
|
||||
<dt className="text-subtle-foreground">Adresse</dt>
|
||||
<dd className="font-medium text-foreground">{credentials.email}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-subtle-foreground">Mot de passe</dt>
|
||||
<dd className="break-all font-mono text-foreground">{credentials.password}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<div className="flex justify-end">
|
||||
<Button size="md" onClick={onClose}>
|
||||
Terminé
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
const CreateUserDialog = ({
|
||||
onClose,
|
||||
onCreated,
|
||||
}: {
|
||||
onClose: () => void;
|
||||
onCreated: (email: string, password: string) => void;
|
||||
}) => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [firstName, setFirstName] = useState("");
|
||||
const [lastName, setLastName] = useState("");
|
||||
const [role, setRole] = useState("user");
|
||||
const [quotaGb, setQuotaGb] = useState("");
|
||||
const [maxFileMb, setMaxFileMb] = 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 {
|
||||
const { user, password } = await api.adminCreateUser({
|
||||
email: email.trim(),
|
||||
first_name: firstName.trim(),
|
||||
last_name: lastName.trim(),
|
||||
role_slug: role,
|
||||
quota_bytes: quotaGb ? Math.round(Number(quotaGb) * GB) : null,
|
||||
max_file_bytes: maxFileMb ? Math.round(Number(maxFileMb) * MB) : null,
|
||||
});
|
||||
onCreated(user.email, password);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Création impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title="Nouveau membre" onClose={onClose}>
|
||||
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
type="email"
|
||||
required
|
||||
autoFocus
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Prénom"
|
||||
required
|
||||
value={firstName}
|
||||
onChange={(event) => setFirstName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom"
|
||||
required
|
||||
value={lastName}
|
||||
onChange={(event) => setLastName(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Rôle
|
||||
</span>
|
||||
<select
|
||||
value={role}
|
||||
onChange={(event) => setRole(event.target.value)}
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground"
|
||||
>
|
||||
<option value="user">Utilisateur</option>
|
||||
<option value="admin">Administrateur</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Quota (Go, optionnel)"
|
||||
type="number"
|
||||
min={1}
|
||||
value={quotaGb}
|
||||
onChange={(event) => setQuotaGb(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fichier max (Mo)"
|
||||
type="number"
|
||||
min={1}
|
||||
value={maxFileMb}
|
||||
onChange={(event) => setMaxFileMb(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{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>
|
||||
);
|
||||
};
|
||||
|
||||
const EditUserDialog = ({
|
||||
user,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
user: AdminUser;
|
||||
onClose: () => void;
|
||||
onSaved: () => void;
|
||||
}) => {
|
||||
const [firstName, setFirstName] = useState(user.first_name);
|
||||
const [lastName, setLastName] = useState(user.last_name);
|
||||
const [role, setRole] = useState(user.role_slug);
|
||||
const [quotaGb, setQuotaGb] = useState(String(Math.round(user.quota_bytes / GB)));
|
||||
const [maxFileMb, setMaxFileMb] = useState(String(Math.round(user.max_file_bytes / MB)));
|
||||
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.adminUpdateUser(user.id, {
|
||||
first_name: firstName.trim(),
|
||||
last_name: lastName.trim(),
|
||||
role_slug: role,
|
||||
quota_bytes: Math.round(Number(quotaGb) * GB),
|
||||
max_file_bytes: Math.round(Number(maxFileMb) * MB),
|
||||
});
|
||||
onSaved();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Enregistrement impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title="Modifier le membre" onClose={onClose}>
|
||||
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Prénom"
|
||||
required
|
||||
value={firstName}
|
||||
onChange={(event) => setFirstName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom"
|
||||
required
|
||||
value={lastName}
|
||||
onChange={(event) => setLastName(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Rôle
|
||||
</span>
|
||||
<select
|
||||
value={role}
|
||||
onChange={(event) => setRole(event.target.value)}
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground"
|
||||
>
|
||||
<option value="user">Utilisateur</option>
|
||||
<option value="admin">Administrateur</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Quota (Go)"
|
||||
type="number"
|
||||
min={1}
|
||||
value={quotaGb}
|
||||
onChange={(event) => setQuotaGb(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fichier max (Mo)"
|
||||
type="number"
|
||||
min={1}
|
||||
value={maxFileMb}
|
||||
onChange={(event) => setMaxFileMb(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{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>
|
||||
);
|
||||
};
|
||||
|
||||
export const AdminStorage = () => {
|
||||
const [locations, setLocations] = useState<StorageLocation[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
|
||||
const load = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
const { locations: list } = await api.adminStorageLocations();
|
||||
setLocations(list);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setLocations([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, []);
|
||||
|
||||
const toggle = async (location: StorageLocation) => {
|
||||
setError(null);
|
||||
try {
|
||||
await api.adminUpdateStorageLocation(location.id, { is_active: !location.is_active });
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Mise à jour impossible."));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Emplacements de stockage"
|
||||
description="Volumes montés utilisés pour stocker les fichiers."
|
||||
actions={
|
||||
<Button
|
||||
size="sm"
|
||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
Nouvel emplacement
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{locations === null ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : locations.length === 0 ? (
|
||||
<EmptyState icon={<HardDriveIcon className="h-8 w-8" />} title="Aucun emplacement" />
|
||||
) : (
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{locations.map((location) => (
|
||||
<li key={location.id} className="flex flex-wrap items-center gap-3 px-3 py-3">
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="truncate text-sm font-medium text-foreground">
|
||||
{location.name}
|
||||
</span>
|
||||
{!location.is_active ? <Badge tone="danger">Inactif</Badge> : null}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{location.slug} · {location.mount_path} ·{" "}
|
||||
{location.quota_bytes
|
||||
? `${toGb(location.used_bytes)} / ${toGb(location.quota_bytes)} Go`
|
||||
: `${toGb(location.used_bytes)} Go utilisés`}
|
||||
</span>
|
||||
</span>
|
||||
<Button variant="ghost" size="sm" onClick={() => void toggle(location)}>
|
||||
{location.is_active ? "Désactiver" : "Réactiver"}
|
||||
</Button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{createOpen ? (
|
||||
<CreateLocationDialog
|
||||
onClose={() => setCreateOpen(false)}
|
||||
onCreated={() => {
|
||||
setCreateOpen(false);
|
||||
void load();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const CreateLocationDialog = ({
|
||||
onClose,
|
||||
onCreated,
|
||||
}: {
|
||||
onClose: () => void;
|
||||
onCreated: () => void;
|
||||
}) => {
|
||||
const [name, setName] = useState("");
|
||||
const [slug, setSlug] = useState("");
|
||||
const [mountPath, setMountPath] = useState("");
|
||||
const [quotaGb, setQuotaGb] = 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.adminCreateStorageLocation({
|
||||
name: name.trim(),
|
||||
slug: slug.trim(),
|
||||
mount_path: mountPath.trim(),
|
||||
quota_bytes: quotaGb ? Math.round(Number(quotaGb) * GB) : null,
|
||||
});
|
||||
onCreated();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Création impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal open title="Nouvel emplacement" onClose={onClose}>
|
||||
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nom"
|
||||
required
|
||||
autoFocus
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Identifiant technique"
|
||||
required
|
||||
placeholder="principal"
|
||||
pattern="[a-z0-9][a-z0-9-]*"
|
||||
value={slug}
|
||||
onChange={(event) => setSlug(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Chemin de montage"
|
||||
required
|
||||
placeholder="/data/cloud"
|
||||
value={mountPath}
|
||||
onChange={(event) => setMountPath(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Quota (Go, optionnel)"
|
||||
type="number"
|
||||
min={1}
|
||||
value={quotaGb}
|
||||
onChange={(event) => setQuotaGb(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 AdminAudit = () => {
|
||||
const [entries, setEntries] = useState<AuditEntry[] | null>(null);
|
||||
const [action, setAction] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loadingMore, setLoadingMore] = useState(false);
|
||||
|
||||
const load = async (term: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
const { entries: list } = await api.adminAudit(100, 0, term || undefined);
|
||||
setEntries(list);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setEntries([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void load("");
|
||||
}, []);
|
||||
|
||||
const loadMore = async () => {
|
||||
if (!entries) return;
|
||||
setLoadingMore(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { entries: more } = await api.adminAudit(100, entries.length, action || undefined);
|
||||
setEntries((previous) => [...(previous ?? []), ...more]);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
} finally {
|
||||
setLoadingMore(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader title="Journal d'activité" description="Dernières actions enregistrées." />
|
||||
|
||||
<form
|
||||
className="flex items-end gap-2"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void load(action);
|
||||
}}
|
||||
>
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
label="Filtrer par action"
|
||||
placeholder="auth.login, file.upload…"
|
||||
value={action}
|
||||
onChange={(event) => setAction(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" variant="secondary" size="md">
|
||||
Filtrer
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{entries === null ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : entries.length === 0 ? (
|
||||
<EmptyState icon={<ActivityIcon className="h-8 w-8" />} title="Aucune entrée" />
|
||||
) : (
|
||||
<>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{entries.map((entry) => (
|
||||
<li key={entry.id} className="flex flex-wrap items-center gap-3 px-3 py-2.5">
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{entry.action}
|
||||
<span className="ml-2 font-normal text-subtle-foreground">
|
||||
{entry.resource}
|
||||
{entry.resource_id ? ` · ${entry.resource_id}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{entry.user_email ?? "système"} · {formatDate(entry.created_at)}
|
||||
{entry.ip_address ? ` · ${entry.ip_address}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{entries.length >= 100 ? (
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="md"
|
||||
isLoading={loadingMore}
|
||||
onClick={() => void loadMore()}
|
||||
>
|
||||
Charger plus
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,476 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Button, Card, Spinner } from "../ui/index.js";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
formatBytes,
|
||||
type Folder,
|
||||
type UploadedFile,
|
||||
} from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { Alert, Badge, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
import {
|
||||
CreateFolderDialog,
|
||||
MoveDialog,
|
||||
RenameDialog,
|
||||
ShareDialog,
|
||||
} from "../components/dialogs.js";
|
||||
import {
|
||||
ArrowLeftIcon,
|
||||
DownloadIcon,
|
||||
FileIcon,
|
||||
FolderIcon,
|
||||
MoveIcon,
|
||||
PenIcon,
|
||||
PlusIcon,
|
||||
ShareIcon,
|
||||
StarIcon,
|
||||
TrashIcon,
|
||||
UploadIcon,
|
||||
} from "../components/icons.js";
|
||||
|
||||
interface Crumb {
|
||||
id: string | null;
|
||||
name: string;
|
||||
}
|
||||
|
||||
type Target = { type: "folder" | "file"; id: string; name: string };
|
||||
|
||||
type Dialog =
|
||||
| { kind: "create" }
|
||||
| { kind: "rename"; target: Target }
|
||||
| { kind: "move"; target: Target }
|
||||
| { kind: "share"; folder: Folder }
|
||||
| null;
|
||||
|
||||
const isImage = (file: UploadedFile): boolean =>
|
||||
(file.mime_type ?? "").toLowerCase().startsWith("image/");
|
||||
|
||||
export const Browser = () => {
|
||||
const { user, refresh } = useSession();
|
||||
const confirm = useConfirm();
|
||||
const [path, setPath] = useState<Crumb[]>([{ id: null, name: "Racine" }]);
|
||||
const [folders, setFolders] = useState<Folder[]>([]);
|
||||
const [files, setFiles] = useState<UploadedFile[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [removing, setRemoving] = useState<string | null>(null);
|
||||
const [dialog, setDialog] = useState<Dialog>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const current = path[path.length - 1] ?? { id: null, name: "Racine" };
|
||||
|
||||
const load = useCallback(async (parentId: string | null) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const [folderResult, fileResult] = await Promise.all([
|
||||
api.folders(parentId),
|
||||
api.files(parentId),
|
||||
]);
|
||||
setFolders(folderResult.folders);
|
||||
setFiles(fileResult.files);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setFolders([]);
|
||||
setFiles([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void load(current.id);
|
||||
}, [current.id, load]);
|
||||
|
||||
const reload = useCallback(() => load(current.id), [current.id, load]);
|
||||
|
||||
const open = (folder: Folder) => {
|
||||
setPath((previous) => [...previous, { id: folder.id, name: folder.name }]);
|
||||
};
|
||||
|
||||
const goTo = (index: number) => setPath((previous) => previous.slice(0, index + 1));
|
||||
|
||||
const upload = async (selected: FileList | null) => {
|
||||
if (!selected || selected.length === 0) return;
|
||||
setUploading(true);
|
||||
setError(null);
|
||||
try {
|
||||
for (const file of Array.from(selected)) {
|
||||
await api.uploadFile(file, current.id);
|
||||
}
|
||||
void refresh();
|
||||
await reload();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
} finally {
|
||||
setUploading(false);
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
}
|
||||
};
|
||||
|
||||
const removeTarget = async (target: Target) => {
|
||||
const label = target.type === "folder" ? "ce dossier" : "ce fichier";
|
||||
const ok = await confirm({
|
||||
title: "Mettre à la corbeille",
|
||||
message: (
|
||||
<>
|
||||
Placer <span className="font-semibold text-foreground">{target.name}</span> ({label}) dans la
|
||||
corbeille ?
|
||||
</>
|
||||
),
|
||||
confirmLabel: "Corbeille",
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
setRemoving(target.id);
|
||||
setError(null);
|
||||
try {
|
||||
if (target.type === "folder") {
|
||||
await api.deleteFolder(target.id);
|
||||
} else {
|
||||
await api.deleteFile(target.id);
|
||||
void refresh();
|
||||
}
|
||||
await reload();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
} finally {
|
||||
setRemoving(null);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleStar = async (file: UploadedFile) => {
|
||||
setError(null);
|
||||
try {
|
||||
const { file: updated } = await api.starFile(file.id);
|
||||
setFiles((previous) => previous.map((item) => (item.id === updated.id ? updated : item)));
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
||||
}
|
||||
};
|
||||
|
||||
const canWrite = user?.role_slug === "admin" || user?.role_slug === "user";
|
||||
const empty = folders.length === 0 && files.length === 0;
|
||||
const quotaPercent =
|
||||
user && user.quota_bytes > 0
|
||||
? Math.min(100, Math.round((user.used_bytes / user.quota_bytes) * 100))
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title={current.name}
|
||||
description="Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier."
|
||||
/>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{path.length > 1 ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(path.length - 2)}
|
||||
className="inline-flex items-center gap-1.5 rounded-sm border border-border-control bg-surface px-2.5 py-1.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors duration-fast hover:bg-surface-hover focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<ArrowLeftIcon className="h-3.5 w-3.5" />
|
||||
Retour
|
||||
</button>
|
||||
) : null}
|
||||
|
||||
<nav aria-label="Fil d'Ariane" className="min-w-0">
|
||||
<ol className="flex flex-wrap items-center gap-1.5 text-xs">
|
||||
{path.map((crumb, index) => (
|
||||
<li key={`${crumb.id ?? "root"}-${index}`} className="flex items-center gap-1.5">
|
||||
{index > 0 ? (
|
||||
<span className="text-border" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
) : null}
|
||||
{index === path.length - 1 ? (
|
||||
<span className="font-medium text-foreground" aria-current="page">
|
||||
{crumb.name}
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(index)}
|
||||
className="text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
|
||||
>
|
||||
{crumb.name}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<div className="flex flex-col gap-3 p-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<span className="text-xs font-medium text-foreground">Espace utilisé</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{formatBytes(user?.used_bytes ?? 0)} sur {formatBytes(user?.quota_bytes ?? 0)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-surface-muted">
|
||||
<div
|
||||
className="h-full rounded-full bg-accent-graphic transition-[width] duration-300"
|
||||
style={{ width: `${Math.max(quotaPercent, 1)}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{canWrite ? (
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
className="sr-only"
|
||||
onChange={(event) => void upload(event.target.files)}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<UploadIcon className="h-3.5 w-3.5" />}
|
||||
isLoading={uploading}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
>
|
||||
Envoyer
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setDialog({ kind: "create" })}
|
||||
>
|
||||
Nouveau dossier
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : empty ? (
|
||||
<EmptyState
|
||||
icon={<FolderIcon className="h-8 w-8" />}
|
||||
title="Emplacement vide"
|
||||
description="Créez un sous-dossier ou envoyez un fichier pour commencer."
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6">
|
||||
{folders.length > 0 ? (
|
||||
<section aria-label="Dossiers">
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Dossiers
|
||||
</h2>
|
||||
<ul className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{folders.map((folder) => (
|
||||
<li
|
||||
key={folder.id}
|
||||
className="flex items-center gap-1 rounded-lg border border-border bg-surface p-2 transition-colors hover:border-border-strong hover:bg-surface-hover"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open(folder)}
|
||||
className="flex min-w-0 flex-1 items-center gap-3 rounded-sm p-1 text-left focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<span className="shrink-0 text-accent">
|
||||
<FolderIcon className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{folder.name}
|
||||
</span>
|
||||
<span className="mt-0.5 flex items-center gap-2">
|
||||
{folder.is_system ? <Badge>Système</Badge> : null}
|
||||
{folder.access_type === "public" ? (
|
||||
<Badge tone="accent">Public</Badge>
|
||||
) : null}
|
||||
<span className="text-[0.6875rem] text-subtle-foreground">
|
||||
{new Date(folder.created_at).toLocaleDateString("fr-FR")}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
{canWrite ? (
|
||||
<div className="flex shrink-0 items-center gap-0.5">
|
||||
<IconAction
|
||||
label={`Partager ${folder.name}`}
|
||||
icon={<ShareIcon className="h-4 w-4" />}
|
||||
onClick={() => setDialog({ kind: "share", folder })}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Renommer ${folder.name}`}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "rename",
|
||||
target: { type: "folder", id: folder.id, name: folder.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Déplacer ${folder.name}`}
|
||||
icon={<MoveIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "move",
|
||||
target: { type: "folder", id: folder.id, name: folder.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer ${folder.name}`}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === folder.id}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void removeTarget({ type: "folder", id: folder.id, name: folder.name })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{files.length > 0 ? (
|
||||
<section aria-label="Fichiers">
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Fichiers
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{files.map((file) => (
|
||||
<li key={file.id} className="flex items-center gap-2 px-3 py-2.5">
|
||||
<span className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-sm border border-border bg-surface-muted text-muted-foreground">
|
||||
{isImage(file) ? (
|
||||
<img
|
||||
src={api.thumbnailUrl(file.id)}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<FileIcon className="h-5 w-5" />
|
||||
)}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(file.size_bytes)} ·{" "}
|
||||
{new Date(file.created_at).toLocaleDateString("fr-FR")}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<IconAction
|
||||
label={file.is_starred ? `Retirer l'étoile de ${file.name}` : `Étoiler ${file.name}`}
|
||||
icon={
|
||||
<StarIcon className="h-4 w-4" {...(file.is_starred ? { filled: true } : {})} />
|
||||
}
|
||||
onClick={() => void toggleStar(file)}
|
||||
/>
|
||||
|
||||
<a
|
||||
href={api.downloadUrl(file.id)}
|
||||
download={file.name}
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-sm border border-border-strong bg-surface px-3 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors hover:bg-surface-hover"
|
||||
>
|
||||
<DownloadIcon className="h-3.5 w-3.5" />
|
||||
<span className="hidden sm:inline">Télécharger</span>
|
||||
</a>
|
||||
|
||||
{canWrite ? (
|
||||
<>
|
||||
<IconAction
|
||||
label={`Renommer ${file.name}`}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "rename",
|
||||
target: { type: "file", id: file.id, name: file.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Déplacer ${file.name}`}
|
||||
icon={<MoveIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "move",
|
||||
target: { type: "file", id: file.id, name: file.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer ${file.name}`}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === file.id}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void removeTarget({ type: "file", id: file.id, name: file.name })
|
||||
}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{dialog?.kind === "create" ? (
|
||||
<CreateFolderDialog
|
||||
parentId={current.id}
|
||||
onClose={() => setDialog(null)}
|
||||
onCreated={() => {
|
||||
setDialog(null);
|
||||
void reload();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{dialog?.kind === "rename" ? (
|
||||
<RenameDialog
|
||||
target={dialog.target}
|
||||
onClose={() => setDialog(null)}
|
||||
onDone={() => {
|
||||
setDialog(null);
|
||||
void reload();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{dialog?.kind === "move" ? (
|
||||
<MoveDialog
|
||||
target={dialog.target}
|
||||
onClose={() => setDialog(null)}
|
||||
onDone={() => {
|
||||
setDialog(null);
|
||||
void reload();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{dialog?.kind === "share" ? (
|
||||
<ShareDialog folder={dialog.folder} onClose={() => setDialog(null)} />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,117 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
|
||||
export const ChangePassword = () => {
|
||||
const { user, refresh, logout } = useSession();
|
||||
const navigate = useNavigate();
|
||||
const [current, setCurrent] = useState("");
|
||||
const [next, setNext] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (next !== confirm) {
|
||||
setError("Les deux mots de passe ne correspondent pas.");
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.changePassword(current, next);
|
||||
await refresh();
|
||||
navigate("/files", { replace: true });
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Changement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<img
|
||||
src="/icon.png"
|
||||
alt=""
|
||||
className="h-12 w-12 rounded-xl ring-1 ring-black/5"
|
||||
/>
|
||||
<div className="text-left">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Nouveau mot de passe
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
Bienvenue {user?.first_name ?? ""}. Ce mot de passe a été défini par un
|
||||
administrateur : choisissez le vôtre.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Changement requis</CardTitle>
|
||||
<CardDescription>
|
||||
Les autres sessions ouvertes sur ce compte seront fermées.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Mot de passe actuel"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
autoFocus
|
||||
value={current}
|
||||
onChange={(event) => setCurrent(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nouveau mot de passe"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
hint="8 caractères minimum."
|
||||
value={next}
|
||||
onChange={(event) => setNext(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Confirmation"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
value={confirm}
|
||||
onChange={(event) => setConfirm(event.target.value)}
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Enregistrer
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="md"
|
||||
fullWidth
|
||||
onClick={() => void logout()}
|
||||
>
|
||||
Se déconnecter
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Spinner } from "../ui/index.js";
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
|
||||
export const ConfirmEmail = () => {
|
||||
const [params] = useSearchParams();
|
||||
const token = params.get("token") ?? "";
|
||||
const { refresh } = useSession();
|
||||
const [state, setState] = useState<"loading" | "success" | "error">("loading");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const started = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (started.current) return;
|
||||
started.current = true;
|
||||
if (!token) {
|
||||
setState("error");
|
||||
setError("Ce lien est incomplet ou invalide.");
|
||||
return;
|
||||
}
|
||||
api
|
||||
.confirmEmailChange(token)
|
||||
.then(() => {
|
||||
setState("success");
|
||||
void refresh();
|
||||
})
|
||||
.catch((caught: unknown) => {
|
||||
setState("error");
|
||||
setError(caught instanceof ApiError ? caught.message : "Confirmation impossible.");
|
||||
});
|
||||
}, [token, refresh]);
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<img
|
||||
src="/icon.png"
|
||||
alt=""
|
||||
className="h-12 w-12 rounded-xl ring-1 ring-black/5"
|
||||
/>
|
||||
<div className="text-left">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Changement d'adresse
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Confirmation</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{state === "loading" ? (
|
||||
<div className="flex justify-center py-4">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : state === "success" ? (
|
||||
<>
|
||||
<Alert tone="success">Votre adresse e-mail a été mise à jour.</Alert>
|
||||
<Link to="/files">
|
||||
<Button size="lg" fullWidth>
|
||||
Accéder à mes fichiers
|
||||
</Button>
|
||||
</Link>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Alert>{error}</Alert>
|
||||
<Link to="/profile">
|
||||
<Button size="lg" fullWidth>
|
||||
Mon compte
|
||||
</Button>
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,100 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
|
||||
export const ForgotPassword = () => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
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.forgotPassword(email);
|
||||
setSent(true);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Demande impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<img
|
||||
src="/icon.png"
|
||||
alt=""
|
||||
className="h-12 w-12 rounded-xl ring-1 ring-black/5"
|
||||
/>
|
||||
<div className="text-left">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Mot de passe oublié
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Réinitialisation</CardTitle>
|
||||
<CardDescription>
|
||||
Nous vous enverrons un lien valable une heure.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{sent ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert tone="success">
|
||||
Si cette adresse correspond à un compte, un message contenant le lien de
|
||||
réinitialisation vient d'être envoyé.
|
||||
</Alert>
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Retour à la connexion
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<form
|
||||
className="flex flex-col gap-4"
|
||||
onSubmit={(event) => void submit(event)}
|
||||
>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
autoFocus
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Envoyer le lien
|
||||
</Button>
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Retour à la connexion
|
||||
</Link>
|
||||
</form>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,142 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Button, Spinner, cn } from "../ui/index.js";
|
||||
import { ApiError, api, formatBytes, type MediaItem } from "../lib/api.js";
|
||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { FileIcon, ImageIcon } from "../components/icons.js";
|
||||
|
||||
const KINDS = [
|
||||
{ value: "", label: "Tout" },
|
||||
{ value: "image", label: "Images" },
|
||||
{ value: "video", label: "Vidéos" },
|
||||
{ value: "audio", label: "Audio" },
|
||||
{ value: "document", label: "Documents" },
|
||||
{ value: "archive", label: "Archives" },
|
||||
{ value: "other", label: "Autres" },
|
||||
] as const;
|
||||
|
||||
const PAGE = 60;
|
||||
|
||||
export const Gallery = () => {
|
||||
const [kind, setKind] = useState<string>("image");
|
||||
const [items, setItems] = useState<MediaItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadingMore, setLoadingMore] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
void api
|
||||
.gallery(kind, PAGE, 0)
|
||||
.then(({ items: first }) => {
|
||||
setItems(first);
|
||||
setError(null);
|
||||
})
|
||||
.catch((caught: unknown) => {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setItems([]);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, [kind]);
|
||||
|
||||
const loadMore = useCallback(async () => {
|
||||
setLoadingMore(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { items: more } = await api.gallery(kind, PAGE, items.length);
|
||||
setItems((previous) => [...previous, ...more]);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
} finally {
|
||||
setLoadingMore(false);
|
||||
}
|
||||
}, [kind, items.length]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Galerie"
|
||||
description="Parcourez les médias auxquels vous avez accès."
|
||||
/>
|
||||
|
||||
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label="Filtrer par type">
|
||||
{KINDS.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={kind === option.value}
|
||||
onClick={() => {
|
||||
setKind(option.value);
|
||||
setItems([]);
|
||||
}}
|
||||
className={cn(
|
||||
"rounded-sm border px-3 py-1.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label transition-colors",
|
||||
kind === option.value
|
||||
? "border-accent/50 bg-accent/10 text-accent"
|
||||
: "border-border-control text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : items.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<ImageIcon className="h-8 w-8" />}
|
||||
title="Aucun média"
|
||||
description="Rien à afficher pour ce filtre."
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{items.map((item) => (
|
||||
<li key={item.id}>
|
||||
<a
|
||||
href={api.downloadUrl(item.id)}
|
||||
download={item.name}
|
||||
className="group flex flex-col overflow-hidden rounded-lg border border-border bg-surface transition-colors hover:border-border-strong"
|
||||
>
|
||||
<span className="flex aspect-square items-center justify-center overflow-hidden bg-surface-muted text-muted-foreground">
|
||||
{item.kind === "image" && item.has_thumbnail ? (
|
||||
<img
|
||||
src={api.thumbnailUrl(item.id)}
|
||||
alt={item.name}
|
||||
loading="lazy"
|
||||
className="h-full w-full object-cover transition-transform duration-fast group-hover:scale-[1.02]"
|
||||
/>
|
||||
) : (
|
||||
<FileIcon className="h-8 w-8" />
|
||||
)}
|
||||
</span>
|
||||
<span className="flex flex-col gap-0.5 p-2">
|
||||
<span className="truncate text-xs font-medium text-foreground">
|
||||
{item.name}
|
||||
</span>
|
||||
<span className="text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(item.size_bytes)}
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
{items.length >= PAGE ? (
|
||||
<div className="flex justify-center">
|
||||
<Button variant="secondary" size="md" isLoading={loadingMore} onClick={() => void loadMore()}>
|
||||
Charger plus
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,100 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Link, Navigate, useNavigate } from "react-router-dom";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
|
||||
export const Login = () => {
|
||||
const { user, setUser } = useSession();
|
||||
const navigate = useNavigate();
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
if (user) return <Navigate to="/files" replace />;
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { user: current } = await api.login(email, password);
|
||||
setUser(current);
|
||||
navigate(current.must_change_password ? "/change-password" : "/files", { replace: true });
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Connexion impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<img
|
||||
src="/icon.png"
|
||||
alt=""
|
||||
className="h-12 w-12 rounded-xl ring-1 ring-black/5"
|
||||
/>
|
||||
<div className="text-left">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Cloud
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
Connectez-vous pour accéder à vos fichiers.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Connexion</CardTitle>
|
||||
<CardDescription>Votre session reste ouverte 14 jours.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
required
|
||||
autoFocus
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mot de passe"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
{...(error ? { error } : {})}
|
||||
/>
|
||||
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Se connecter
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<p className="mt-4 text-center text-xs text-muted-foreground">
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Mot de passe oublié ?
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,325 @@
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Spinner } from "../ui/index.js";
|
||||
import { ApiError, api, formatDate, type SessionInfo } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { Alert, Badge, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.js";
|
||||
import { TrashIcon } from "../components/icons.js";
|
||||
|
||||
export const Profile = () => {
|
||||
const { user, refresh } = useSession();
|
||||
const confirm = useConfirm();
|
||||
|
||||
const [firstName, setFirstName] = useState(user?.first_name ?? "");
|
||||
const [lastName, setLastName] = useState(user?.last_name ?? "");
|
||||
const [profileMessage, setProfileMessage] = useState<string | null>(null);
|
||||
const [profileError, setProfileError] = useState<string | null>(null);
|
||||
const [savingProfile, setSavingProfile] = useState(false);
|
||||
|
||||
const [avatarNonce, setAvatarNonce] = useState(0);
|
||||
const [avatarError, setAvatarError] = useState<string | null>(null);
|
||||
const avatarInput = useRef<HTMLInputElement>(null);
|
||||
|
||||
const [password, setPassword] = useState("");
|
||||
const [newEmail, setNewEmail] = useState("");
|
||||
const [emailMessage, setEmailMessage] = useState<string | null>(null);
|
||||
const [emailError, setEmailError] = useState<string | null>(null);
|
||||
const [sendingEmail, setSendingEmail] = useState(false);
|
||||
|
||||
const [sessions, setSessions] = useState<SessionInfo[] | null>(null);
|
||||
const [sessionsError, setSessionsError] = useState<string | null>(null);
|
||||
const [revoking, setRevoking] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
setFirstName((current) => (current === "" ? user.first_name : current));
|
||||
setLastName((current) => (current === "" ? user.last_name : current));
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const loadSessions = async () => {
|
||||
setSessionsError(null);
|
||||
try {
|
||||
const { sessions: list } = await api.sessions();
|
||||
setSessions(list);
|
||||
} catch (caught) {
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setSessions([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void loadSessions();
|
||||
}, []);
|
||||
|
||||
const saveProfile = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setSavingProfile(true);
|
||||
setProfileError(null);
|
||||
setProfileMessage(null);
|
||||
try {
|
||||
await api.updateProfile(firstName.trim(), lastName.trim());
|
||||
await refresh();
|
||||
setProfileMessage("Informations enregistrées.");
|
||||
} catch (caught) {
|
||||
setProfileError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setSavingProfile(false);
|
||||
}
|
||||
};
|
||||
|
||||
const requestEmail = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setSendingEmail(true);
|
||||
setEmailError(null);
|
||||
setEmailMessage(null);
|
||||
try {
|
||||
await api.requestEmailChange(password, newEmail.trim());
|
||||
setPassword("");
|
||||
setNewEmail("");
|
||||
setEmailMessage("Un e-mail de confirmation a été envoyé à la nouvelle adresse.");
|
||||
} catch (caught) {
|
||||
setEmailError(caught instanceof ApiError ? caught.message : "Demande impossible.");
|
||||
} finally {
|
||||
setSendingEmail(false);
|
||||
}
|
||||
};
|
||||
|
||||
const changeAvatar = async (file: File | undefined) => {
|
||||
if (!file) return;
|
||||
setAvatarError(null);
|
||||
try {
|
||||
await api.uploadAvatar(file);
|
||||
setAvatarNonce((value) => value + 1);
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
} finally {
|
||||
if (avatarInput.current) avatarInput.current.value = "";
|
||||
}
|
||||
};
|
||||
|
||||
const removeAvatar = async () => {
|
||||
setAvatarError(null);
|
||||
try {
|
||||
await api.deleteAvatar();
|
||||
setAvatarNonce((value) => value + 1);
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
}
|
||||
};
|
||||
|
||||
const revokeSession = async (session: SessionInfo) => {
|
||||
if (session.current) {
|
||||
const ok = await confirm({
|
||||
title: "Fermer la session",
|
||||
message: "Fermer la session en cours vous déconnectera immédiatement.",
|
||||
confirmLabel: "Fermer",
|
||||
});
|
||||
if (!ok) return;
|
||||
}
|
||||
setRevoking(session.id);
|
||||
setSessionsError(null);
|
||||
try {
|
||||
await api.revokeSession(session.id);
|
||||
if (session.current) {
|
||||
await refresh();
|
||||
return;
|
||||
}
|
||||
setSessions((previous) => (previous ?? []).filter((item) => item.id !== session.id));
|
||||
} catch (caught) {
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : "Révocation impossible.");
|
||||
} finally {
|
||||
setRevoking(null);
|
||||
}
|
||||
};
|
||||
|
||||
const revokeOthers = async () => {
|
||||
setSessionsError(null);
|
||||
try {
|
||||
await api.revokeOtherSessions();
|
||||
setSessions((previous) => (previous ?? []).filter((item) => item.current));
|
||||
} catch (caught) {
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : "Révocation impossible.");
|
||||
}
|
||||
};
|
||||
|
||||
if (!user) {
|
||||
return (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<PageHeader title="Mon compte" description="Profil, photo, adresse e-mail et sessions ouvertes." />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Identité</CardTitle>
|
||||
<CardDescription>Informations affichées dans l'interface.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void saveProfile(event)}>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<Input
|
||||
label="Prénom"
|
||||
required
|
||||
maxLength={255}
|
||||
value={firstName}
|
||||
onChange={(event) => setFirstName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom"
|
||||
required
|
||||
maxLength={255}
|
||||
value={lastName}
|
||||
onChange={(event) => setLastName(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{profileError ? <Alert>{profileError}</Alert> : null}
|
||||
{profileMessage ? <Alert tone="success">{profileMessage}</Alert> : null}
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="md" isLoading={savingProfile}>
|
||||
Enregistrer
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Photo de profil</CardTitle>
|
||||
<CardDescription>Image carrée, format PNG ou JPEG.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex items-center gap-4">
|
||||
<span className="flex h-16 w-16 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface-muted">
|
||||
<img
|
||||
src={`${api.avatarUrl(user.id)}?v=${avatarNonce}`}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
onError={(event) => {
|
||||
event.currentTarget.style.display = "none";
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
<div className="flex flex-col gap-2">
|
||||
<input
|
||||
ref={avatarInput}
|
||||
type="file"
|
||||
accept="image/png,image/jpeg,image/webp"
|
||||
className="sr-only"
|
||||
onChange={(event) => void changeAvatar(event.target.files?.[0])}
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="secondary" size="sm" onClick={() => avatarInput.current?.click()}>
|
||||
Choisir une image
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={() => void removeAvatar()}>
|
||||
Retirer
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-[0.6875rem] text-subtle-foreground">
|
||||
Si aucune image n'est définie, vos initiales sont affichées.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{avatarError ? <Alert>{avatarError}</Alert> : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Adresse e-mail</CardTitle>
|
||||
<CardDescription>Adresse actuelle : {user.email}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void requestEmail(event)}>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Input
|
||||
label="Nouvelle adresse"
|
||||
type="email"
|
||||
required
|
||||
value={newEmail}
|
||||
onChange={(event) => setNewEmail(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mot de passe actuel"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{emailError ? <Alert>{emailError}</Alert> : null}
|
||||
{emailMessage ? <Alert tone="success">{emailMessage}</Alert> : null}
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="md" isLoading={sendingEmail}>
|
||||
Demander le changement
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Sessions ouvertes</CardTitle>
|
||||
<CardDescription>Appareils actuellement connectés à votre compte.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{sessionsError ? <Alert>{sessionsError}</Alert> : null}
|
||||
{sessions === null ? (
|
||||
<div className="flex justify-center py-6">
|
||||
<Spinner size="sm" />
|
||||
</div>
|
||||
) : sessions.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">Aucune session active.</p>
|
||||
) : (
|
||||
<ul className="flex flex-col divide-y divide-border rounded-md border border-border">
|
||||
{sessions.map((session) => (
|
||||
<li key={session.id} className="flex items-center gap-3 px-3 py-2.5">
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="truncate text-xs font-medium text-foreground">
|
||||
{session.user_agent ? session.user_agent.slice(0, 60) : "Appareil inconnu"}
|
||||
</span>
|
||||
{session.current ? <Badge tone="accent">Cette session</Badge> : null}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{session.ip_address ?? "IP inconnue"} · vue le {formatDate(session.last_seen_at)}
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Fermer cette session"
|
||||
disabled={revoking === session.id}
|
||||
onClick={() => void revokeSession(session)}
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-destructive disabled:opacity-50"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<TrashIcon className="h-3.5 w-3.5" />}
|
||||
disabled={sessions === null || sessions.length <= 1}
|
||||
onClick={() => void revokeOthers()}
|
||||
>
|
||||
Fermer les autres sessions
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
|
||||
export const ResetPassword = () => {
|
||||
const [params] = useSearchParams();
|
||||
const token = params.get("token") ?? "";
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [done, setDone] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (password !== confirm) {
|
||||
setError("Les deux mots de passe ne correspondent pas.");
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.resetPassword(token, password);
|
||||
setDone(true);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Réinitialisation impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<img
|
||||
src="/icon.png"
|
||||
alt=""
|
||||
className="h-12 w-12 rounded-xl ring-1 ring-black/5"
|
||||
/>
|
||||
<div className="text-left">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Nouveau mot de passe
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Réinitialisation</CardTitle>
|
||||
<CardDescription>Choisissez un mot de passe robuste.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{!token ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert>Ce lien est incomplet ou invalide.</Alert>
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Demander un nouveau lien
|
||||
</Link>
|
||||
</div>
|
||||
) : done ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert tone="success">
|
||||
Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.
|
||||
</Alert>
|
||||
<Link to="/login">
|
||||
<Button size="lg" fullWidth>
|
||||
Se connecter
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nouveau mot de passe"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
autoFocus
|
||||
hint="8 caractères minimum."
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Confirmation"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
value={confirm}
|
||||
onChange={(event) => setConfirm(event.target.value)}
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Réinitialiser
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,138 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Button, Input, Spinner } from "../ui/index.js";
|
||||
import { ApiError, api, formatBytes, type Folder, type UploadedFile } from "../lib/api.js";
|
||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { DownloadIcon, FileIcon, FolderIcon, SearchIcon } from "../components/icons.js";
|
||||
|
||||
interface Results {
|
||||
folders: Folder[];
|
||||
files: UploadedFile[];
|
||||
}
|
||||
|
||||
export const Search = () => {
|
||||
const [q, setQ] = useState("");
|
||||
const [results, setResults] = useState<Results | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const query = q.trim();
|
||||
if (query.length < 2) {
|
||||
setError("Saisissez au moins deux caractères.");
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { folders, files } = await api.search(query);
|
||||
setResults({ folders, files });
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Recherche impossible.");
|
||||
setResults(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const total = results ? results.folders.length + results.files.length : 0;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Recherche"
|
||||
description="Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès."
|
||||
/>
|
||||
|
||||
<form className="flex items-end gap-2" onSubmit={(event) => void submit(event)}>
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
label="Terme recherché"
|
||||
type="search"
|
||||
autoFocus
|
||||
placeholder="facture, rapport…"
|
||||
value={q}
|
||||
onChange={(event) => setQ(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
size="md"
|
||||
isLoading={loading}
|
||||
iconLeading={<SearchIcon className="h-3.5 w-3.5" />}
|
||||
>
|
||||
Rechercher
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : results === null ? null : total === 0 ? (
|
||||
<EmptyState
|
||||
icon={<SearchIcon className="h-8 w-8" />}
|
||||
title="Aucun résultat"
|
||||
description={`Rien ne correspond à « ${q.trim()} ».`}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6">
|
||||
{results.folders.length > 0 ? (
|
||||
<section aria-label="Dossiers">
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Dossiers
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{results.folders.map((folder) => (
|
||||
<li key={folder.id} className="flex items-center gap-3 px-3 py-2.5">
|
||||
<span className="shrink-0 text-accent">
|
||||
<FolderIcon className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
||||
{folder.name}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{results.files.length > 0 ? (
|
||||
<section aria-label="Fichiers">
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Fichiers
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{results.files.map((file) => (
|
||||
<li key={file.id} className="flex items-center gap-3 px-3 py-2.5">
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
<FileIcon className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(file.size_bytes)}
|
||||
</span>
|
||||
</span>
|
||||
<a
|
||||
href={api.downloadUrl(file.id)}
|
||||
download={file.name}
|
||||
aria-label={`Télécharger ${file.name}`}
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-surface-hover hover:text-foreground"
|
||||
>
|
||||
<DownloadIcon className="h-4 w-4" />
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,209 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Button, Spinner } from "../ui/index.js";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
formatBytes,
|
||||
formatDate,
|
||||
type TrashFile,
|
||||
type TrashFolder,
|
||||
} from "../lib/api.js";
|
||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
import { FileIcon, FolderIcon, RestoreIcon, TrashIcon } from "../components/icons.js";
|
||||
|
||||
interface TrashData {
|
||||
retentionDays: number;
|
||||
folders: TrashFolder[];
|
||||
files: TrashFile[];
|
||||
}
|
||||
|
||||
export const Trash = () => {
|
||||
const confirm = useConfirm();
|
||||
const [data, setData] = useState<TrashData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
setData(await api.trash());
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setData(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
const run = async (key: string, action: () => Promise<unknown>) => {
|
||||
setBusy(key);
|
||||
setError(null);
|
||||
try {
|
||||
await action();
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
};
|
||||
|
||||
const emptyTrash = async () => {
|
||||
const ok = await confirm({
|
||||
title: "Vider la corbeille",
|
||||
message: "Tous les éléments seront définitivement supprimés. Cette action est irréversible.",
|
||||
confirmLabel: "Vider",
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
void run("empty", () => api.emptyTrash());
|
||||
};
|
||||
|
||||
const purge = async (key: string, name: string, action: () => Promise<unknown>) => {
|
||||
const ok = await confirm({
|
||||
title: "Supprimer définitivement",
|
||||
message: (
|
||||
<>
|
||||
Supprimer définitivement <span className="font-semibold text-foreground">{name}</span> ?
|
||||
Cette action est irréversible.
|
||||
</>
|
||||
),
|
||||
confirmLabel: "Supprimer",
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
void run(key, action);
|
||||
};
|
||||
|
||||
const empty = data !== null && data.folders.length === 0 && data.files.length === 0;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Corbeille"
|
||||
description={
|
||||
data
|
||||
? `Les éléments sont définitivement supprimés après ${data.retentionDays} jours.`
|
||||
: "Éléments supprimés récemment."
|
||||
}
|
||||
actions={
|
||||
data && !empty ? (
|
||||
<Button variant="destructive" size="sm" isLoading={busy === "empty"} onClick={emptyTrash}>
|
||||
Vider la corbeille
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-16">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : empty ? (
|
||||
<EmptyState
|
||||
icon={<TrashIcon className="h-8 w-8" />}
|
||||
title="Corbeille vide"
|
||||
description="Aucun élément supprimé pour le moment."
|
||||
/>
|
||||
) : data ? (
|
||||
<div className="flex flex-col gap-6">
|
||||
{data.folders.length > 0 ? (
|
||||
<section aria-label="Dossiers supprimés">
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Dossiers
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{data.folders.map((folder) => (
|
||||
<li key={folder.id} className="flex items-center gap-3 px-3 py-2.5">
|
||||
<span className="shrink-0 text-accent">
|
||||
<FolderIcon className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{folder.name}
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
Supprimé le {formatDate(folder.deleted_at)}
|
||||
</span>
|
||||
</span>
|
||||
<IconAction
|
||||
label={`Restaurer ${folder.name}`}
|
||||
icon={<RestoreIcon className="h-4 w-4" />}
|
||||
isLoading={busy === `restore-${folder.id}`}
|
||||
onClick={() =>
|
||||
void run(`restore-${folder.id}`, () => api.restoreFolder(folder.id))
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer définitivement ${folder.name}`}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
tone="danger"
|
||||
isLoading={busy === `purge-${folder.id}`}
|
||||
onClick={() =>
|
||||
void purge(`purge-${folder.id}`, folder.name, () =>
|
||||
api.purgeFolder(folder.id),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{data.files.length > 0 ? (
|
||||
<section aria-label="Fichiers supprimés">
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Fichiers
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{data.files.map((file) => (
|
||||
<li key={file.id} className="flex items-center gap-3 px-3 py-2.5">
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
<FileIcon className="h-5 w-5" />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(file.size_bytes)} · supprimé le {formatDate(file.deleted_at)}
|
||||
</span>
|
||||
</span>
|
||||
<IconAction
|
||||
label={`Restaurer ${file.name}`}
|
||||
icon={<RestoreIcon className="h-4 w-4" />}
|
||||
isLoading={busy === `restore-${file.id}`}
|
||||
onClick={() =>
|
||||
void run(`restore-${file.id}`, () => api.restoreFile(file.id))
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer définitivement ${file.name}`}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={busy === `purge-${file.id}`}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void purge(`purge-${file.id}`, file.name, () => api.purgeFile(file.id))
|
||||
}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user