feat(frontend): i18n, theming and account/browser/admin UI updates
- add French-keyed i18n with an English dictionary, plus theme and locale helpers, applied across all pages and components - account page: theme and language selectors and a two-column layout - browser: per-folder media type filters and unread chat badges - admin: audit log filtered by user and action through dropdowns - global API and type updates to match the new backend endpoints
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
(function () {
|
(function () {
|
||||||
try {
|
try {
|
||||||
var stored = localStorage.getItem("cohaise-theme");
|
var stored = localStorage.getItem("cohaise-theme");
|
||||||
|
var theme = stored === "light" || stored === "dark" ? stored : "system";
|
||||||
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||||
var theme = stored || (prefersDark ? "dark" : "light");
|
var dark = theme === "dark" || (theme === "system" && prefersDark);
|
||||||
if (theme === "dark") document.documentElement.classList.add("dark");
|
document.documentElement.classList.toggle("dark", dark);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
void error;
|
void error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState } from "react";
|
|||||||
import { NavLink, Outlet } from "react-router-dom";
|
import { NavLink, Outlet } from "react-router-dom";
|
||||||
import { Button, cn } from "../ui/index.js";
|
import { Button, cn } from "../ui/index.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
import { Avatar } from "./Avatar.js";
|
import { Avatar } from "./Avatar.js";
|
||||||
import {
|
import {
|
||||||
ActivityIcon,
|
ActivityIcon,
|
||||||
@@ -50,6 +51,7 @@ const navClass = ({ isActive }: { isActive: boolean }) =>
|
|||||||
|
|
||||||
export const AppShell = () => {
|
export const AppShell = () => {
|
||||||
const { user, logout } = useSession();
|
const { user, logout } = useSession();
|
||||||
|
const { t } = useI18n();
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
|
||||||
@@ -80,7 +82,7 @@ export const AppShell = () => {
|
|||||||
return (
|
return (
|
||||||
<NavLink key={item.to} to={item.to} className={navClass} onClick={() => setMenuOpen(false)}>
|
<NavLink key={item.to} to={item.to} className={navClass} onClick={() => setMenuOpen(false)}>
|
||||||
<Icon className="h-4 w-4" />
|
<Icon className="h-4 w-4" />
|
||||||
{item.label}
|
{t(item.label)}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -93,7 +95,7 @@ export const AppShell = () => {
|
|||||||
{isAdmin ? (
|
{isAdmin ? (
|
||||||
<>
|
<>
|
||||||
<p className="mt-3 px-3 py-1 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<p className="mt-3 px-3 py-1 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Administration
|
{t("Administration")}
|
||||||
</p>
|
</p>
|
||||||
{ADMIN_NAV.map(renderLink)}
|
{ADMIN_NAV.map(renderLink)}
|
||||||
</>
|
</>
|
||||||
@@ -108,7 +110,7 @@ export const AppShell = () => {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="text-muted-foreground lg:hidden"
|
className="text-muted-foreground lg:hidden"
|
||||||
aria-label={menuOpen ? "Fermer le menu" : "Ouvrir le menu"}
|
aria-label={menuOpen ? t("Fermer le menu") : t("Ouvrir le menu")}
|
||||||
aria-expanded={menuOpen}
|
aria-expanded={menuOpen}
|
||||||
onClick={() => setMenuOpen((value) => !value)}
|
onClick={() => setMenuOpen((value) => !value)}
|
||||||
>
|
>
|
||||||
@@ -139,7 +141,7 @@ export const AppShell = () => {
|
|||||||
iconLeading={<LogoutIcon className="h-3.5 w-3.5" />}
|
iconLeading={<LogoutIcon className="h-3.5 w-3.5" />}
|
||||||
onClick={() => void logout()}
|
onClick={() => void logout()}
|
||||||
>
|
>
|
||||||
<span className="hidden sm:inline">Déconnexion</span>
|
<span className="hidden sm:inline">{t("Déconnexion")}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
} from "react";
|
} from "react";
|
||||||
import { Button, Spinner, cn } from "../ui/index.js";
|
import { Button, Spinner, cn } from "../ui/index.js";
|
||||||
import { ApiError, api, formatDate, type ChatMember, type ChatMessage } from "../lib/api.js";
|
import { ApiError, api, formatDate, type ChatMember, type ChatMessage } from "../lib/api.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
import { getLocale } from "../lib/locale.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
import { useConfirm } from "./confirm.js";
|
import { useConfirm } from "./confirm.js";
|
||||||
import { Avatar } from "./Avatar.js";
|
import { Avatar } from "./Avatar.js";
|
||||||
@@ -22,10 +24,10 @@ const POLL_MEMBERS_MS = 30_000;
|
|||||||
const GROUP_WINDOW_MS = 5 * 60 * 1000;
|
const GROUP_WINDOW_MS = 5 * 60 * 1000;
|
||||||
|
|
||||||
const timeOf = (value: string): string =>
|
const timeOf = (value: string): string =>
|
||||||
new Date(value).toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" });
|
new Date(value).toLocaleTimeString(getLocale(), { hour: "2-digit", minute: "2-digit" });
|
||||||
|
|
||||||
const dayOf = (value: string): string =>
|
const dayOf = (value: string): string =>
|
||||||
new Date(value).toLocaleDateString("fr-FR", {
|
new Date(value).toLocaleDateString(getLocale(), {
|
||||||
weekday: "long",
|
weekday: "long",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
month: "long",
|
month: "long",
|
||||||
@@ -34,8 +36,10 @@ const dayOf = (value: string): string =>
|
|||||||
const isSameDay = (a: string, b: string): boolean =>
|
const isSameDay = (a: string, b: string): boolean =>
|
||||||
new Date(a).toDateString() === new Date(b).toDateString();
|
new Date(a).toDateString() === new Date(b).toDateString();
|
||||||
|
|
||||||
const fullName = (member: { first_name: string | null; last_name: string | null }): string =>
|
const fullName = (
|
||||||
`${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || "Compte supprimé";
|
member: { first_name: string | null; last_name: string | null },
|
||||||
|
fallback: string,
|
||||||
|
): string => `${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || fallback;
|
||||||
|
|
||||||
const MAX_ID = (list: ChatMessage[]): number =>
|
const MAX_ID = (list: ChatMessage[]): number =>
|
||||||
list.reduce((max, message) => Math.max(max, message.id), 0);
|
list.reduce((max, message) => Math.max(max, message.id), 0);
|
||||||
@@ -52,6 +56,7 @@ export interface ChatFolder {
|
|||||||
* chaque requete, l'interface ne fait que l'afficher.
|
* chaque requete, l'interface ne fait que l'afficher.
|
||||||
*/
|
*/
|
||||||
export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: () => void }) => {
|
export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: () => void }) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const { user } = useSession();
|
const { user } = useSession();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
const folderId = folder.id;
|
const folderId = folder.id;
|
||||||
@@ -114,7 +119,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
setError(null);
|
setError(null);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
if (!active) return;
|
if (!active) return;
|
||||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
if (active) {
|
if (active) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -189,7 +194,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
mergeMessages([message]);
|
mergeMessages([message]);
|
||||||
setDraft("");
|
setDraft("");
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Envoi impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setSending(false);
|
setSending(false);
|
||||||
}
|
}
|
||||||
@@ -198,9 +203,9 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
const remove = async (message: ChatMessage) => {
|
const remove = async (message: ChatMessage) => {
|
||||||
if (
|
if (
|
||||||
!(await confirm({
|
!(await confirm({
|
||||||
title: "Supprimer le message",
|
title: t("Supprimer le message"),
|
||||||
message: "Ce message sera retiré du salon pour tout le monde.",
|
message: t("Ce message sera retiré du salon pour tout le monde."),
|
||||||
confirmLabel: "Supprimer",
|
confirmLabel: t("Supprimer"),
|
||||||
tone: "danger",
|
tone: "danger",
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
@@ -210,7 +215,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
await api.chatDeleteMessage(folderId, message.id);
|
await api.chatDeleteMessage(folderId, message.id);
|
||||||
setMessages((previous) => previous.filter((item) => item.id !== message.id));
|
setMessages((previous) => previous.filter((item) => item.id !== message.id));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Suppression impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingId(null);
|
setDeletingId(null);
|
||||||
}
|
}
|
||||||
@@ -249,11 +254,11 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
"absolute inset-y-0 left-0 z-20 flex w-64 flex-col border-r border-border bg-surface transition-transform md:static md:z-auto md:translate-x-0",
|
"absolute inset-y-0 left-0 z-20 flex w-64 flex-col border-r border-border bg-surface transition-transform md:static md:z-auto md:translate-x-0",
|
||||||
membersOpen ? "translate-x-0 shadow-lg md:shadow-none" : "-translate-x-full",
|
membersOpen ? "translate-x-0 shadow-lg md:shadow-none" : "-translate-x-full",
|
||||||
)}
|
)}
|
||||||
aria-label="Membres du dossier"
|
aria-label={t("Membres du dossier")}
|
||||||
>
|
>
|
||||||
<div className="flex shrink-0 items-center justify-between gap-2 border-b border-border px-4 py-3">
|
<div className="flex shrink-0 items-center justify-between gap-2 border-b border-border px-4 py-3">
|
||||||
<span className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
<span className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||||
Membres
|
{t("Membres")}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-subtle-foreground">{members.length}</span>
|
<span className="text-xs text-subtle-foreground">{members.length}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -270,15 +275,17 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
/>
|
/>
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<p className="flex items-center gap-1.5 truncate text-xs font-medium text-foreground">
|
<p className="flex items-center gap-1.5 truncate text-xs font-medium text-foreground">
|
||||||
{fullName(member)}
|
{fullName(member, t("Compte supprimé"))}
|
||||||
{member.is_self ? (
|
{member.is_self ? (
|
||||||
<span className="text-subtle-foreground">(vous)</span>
|
<span className="text-subtle-foreground">{t("(vous)")}</span>
|
||||||
) : null}
|
) : null}
|
||||||
</p>
|
</p>
|
||||||
<p className="truncate text-[0.6875rem] text-subtle-foreground">
|
<p className="truncate text-[0.6875rem] text-subtle-foreground">
|
||||||
{member.last_login_at
|
{member.last_login_at
|
||||||
? `Dernière connexion le ${formatDate(member.last_login_at)}`
|
? t("Dernière connexion le {date}", {
|
||||||
: "Jamais connecté"}
|
date: formatDate(member.last_login_at),
|
||||||
|
})
|
||||||
|
: t("Jamais connecté")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{member.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
{member.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
||||||
@@ -300,7 +307,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="text-muted-foreground md:hidden"
|
className="text-muted-foreground md:hidden"
|
||||||
aria-label={membersOpen ? "Masquer les membres" : "Afficher les membres"}
|
aria-label={membersOpen ? t("Masquer les membres") : t("Afficher les membres")}
|
||||||
aria-expanded={membersOpen}
|
aria-expanded={membersOpen}
|
||||||
onClick={() => setMembersOpen((value) => !value)}
|
onClick={() => setMembersOpen((value) => !value)}
|
||||||
>
|
>
|
||||||
@@ -308,16 +315,16 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
</button>
|
</button>
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<h1 className="truncate font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
<h1 className="truncate font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
||||||
Discussion · {folder.name}
|
{t("Discussion · {name}", { name: folder.name })}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-[0.6875rem] text-subtle-foreground">
|
<p className="text-[0.6875rem] text-subtle-foreground">
|
||||||
Membres ayant accès à ce dossier
|
{t("Membres ayant accès à ce dossier")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
aria-label="Fermer la discussion"
|
aria-label={t("Fermer la discussion")}
|
||||||
className="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
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" />
|
<CloseIcon className="h-5 w-5" />
|
||||||
@@ -342,8 +349,10 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
) : messages.length === 0 ? (
|
) : messages.length === 0 ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={<ChatIcon className="h-8 w-8" />}
|
icon={<ChatIcon className="h-8 w-8" />}
|
||||||
title="Aucun message"
|
title={t("Aucun message")}
|
||||||
description="Lancez la discussion : les membres du dossier verront votre message."
|
description={t(
|
||||||
|
"Lancez la discussion : les membres du dossier verront votre message.",
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ol className="flex flex-col gap-1">
|
<ol className="flex flex-col gap-1">
|
||||||
@@ -382,7 +391,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
<span
|
<span
|
||||||
className={cn("font-medium", own ? "text-accent" : "text-foreground")}
|
className={cn("font-medium", own ? "text-accent" : "text-foreground")}
|
||||||
>
|
>
|
||||||
{fullName(message)}
|
{fullName(message, t("Compte supprimé"))}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-[0.6875rem] text-subtle-foreground">
|
<span className="text-[0.6875rem] text-subtle-foreground">
|
||||||
{timeOf(message.created_at)}
|
{timeOf(message.created_at)}
|
||||||
@@ -396,7 +405,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
{canDelete ? (
|
{canDelete ? (
|
||||||
<span className="opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
<span className="opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||||
<IconAction
|
<IconAction
|
||||||
label="Supprimer le message"
|
label={t("Supprimer le message")}
|
||||||
tone="danger"
|
tone="danger"
|
||||||
isLoading={deletingId === message.id}
|
isLoading={deletingId === message.id}
|
||||||
icon={<TrashIcon className="h-3.5 w-3.5" />}
|
icon={<TrashIcon className="h-3.5 w-3.5" />}
|
||||||
@@ -421,8 +430,10 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
onKeyDown={onComposerKeyDown}
|
onKeyDown={onComposerKeyDown}
|
||||||
rows={1}
|
rows={1}
|
||||||
maxLength={MAX_LENGTH}
|
maxLength={MAX_LENGTH}
|
||||||
placeholder="Écrire un message… (Entrée pour envoyer, Maj+Entrée pour retour à la ligne)"
|
placeholder={t(
|
||||||
aria-label="Votre message"
|
"Écrire un message… (Entrée pour envoyer, Maj+Entrée pour retour à la ligne)",
|
||||||
|
)}
|
||||||
|
aria-label={t("Votre message")}
|
||||||
className="max-h-40 min-h-[2.5rem] flex-1 resize-y rounded-sm border border-border-control bg-surface px-3 py-2 text-sm text-foreground placeholder:text-subtle-foreground focus-visible:border-border-strong focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none"
|
className="max-h-40 min-h-[2.5rem] flex-1 resize-y rounded-sm border border-border-control bg-surface px-3 py-2 text-sm text-foreground placeholder:text-subtle-foreground focus-visible:border-border-strong focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
@@ -432,7 +443,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
|||||||
disabled={draft.trim().length === 0}
|
disabled={draft.trim().length === 0}
|
||||||
iconLeading={<SendIcon className="h-4 w-4" />}
|
iconLeading={<SendIcon className="h-4 w-4" />}
|
||||||
>
|
>
|
||||||
<span className="hidden sm:inline">Envoyer</span>
|
<span className="hidden sm:inline">{t("Envoyer")}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ export const IconAction = ({
|
|||||||
onClick,
|
onClick,
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
tone = "neutral",
|
tone = "neutral",
|
||||||
|
badge = 0,
|
||||||
}: {
|
}: {
|
||||||
label: string;
|
label: string;
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
tone?: "neutral" | "danger";
|
tone?: "neutral" | "danger";
|
||||||
|
badge?: number;
|
||||||
}) => (
|
}) => (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -21,11 +23,19 @@ export const IconAction = ({
|
|||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors",
|
"relative 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",
|
"hover:bg-surface-hover hover:text-foreground disabled:pointer-events-none disabled:opacity-50",
|
||||||
tone === "danger" && "hover:text-destructive",
|
tone === "danger" && "hover:text-destructive",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{isLoading ? <Spinner size="xs" /> : icon}
|
{isLoading ? <Spinner size="xs" /> : icon}
|
||||||
|
{badge > 0 ? (
|
||||||
|
<span
|
||||||
|
aria-hidden="true"
|
||||||
|
className="pointer-events-none absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-accent-graphic px-1 font-display text-[0.625rem] font-semibold leading-none text-accent-foreground"
|
||||||
|
>
|
||||||
|
{badge > 99 ? "99+" : badge}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { cn } from "../ui/index.js";
|
import { cn } from "../ui/index.js";
|
||||||
import { api } from "../lib/api.js";
|
import { api } from "../lib/api.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, DownloadIcon, FileIcon } from "./icons.js";
|
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, DownloadIcon, FileIcon } from "./icons.js";
|
||||||
|
|
||||||
export interface MediaViewerItem {
|
export interface MediaViewerItem {
|
||||||
@@ -29,6 +30,7 @@ const actionClass =
|
|||||||
"inline-flex items-center gap-2 rounded-md border border-white/20 bg-white/10 px-3.5 py-2 text-sm font-medium text-white transition-colors hover:bg-white/20";
|
"inline-flex items-center gap-2 rounded-md border border-white/20 bg-white/10 px-3.5 py-2 text-sm font-medium text-white transition-colors hover:bg-white/20";
|
||||||
|
|
||||||
const TextViewer = ({ id }: { id: string }) => {
|
const TextViewer = ({ id }: { id: string }) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [text, setText] = useState<string | null>(null);
|
const [text, setText] = useState<string | null>(null);
|
||||||
const [failed, setFailed] = useState(false);
|
const [failed, setFailed] = useState(false);
|
||||||
|
|
||||||
@@ -49,8 +51,8 @@ const TextViewer = ({ id }: { id: string }) => {
|
|||||||
};
|
};
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
if (failed) return <p className="text-sm text-white/70">Lecture impossible.</p>;
|
if (failed) return <p className="text-sm text-white/70">{t("Lecture impossible.")}</p>;
|
||||||
if (text === null) return <p className="text-sm text-white/70">Chargement…</p>;
|
if (text === null) return <p className="text-sm text-white/70">{t("Chargement…")}</p>;
|
||||||
return (
|
return (
|
||||||
<pre className="max-h-full w-full max-w-3xl overflow-auto rounded-md bg-black/60 p-4 text-left text-sm whitespace-pre-wrap text-white/90">
|
<pre className="max-h-full w-full max-w-3xl overflow-auto rounded-md bg-black/60 p-4 text-left text-sm whitespace-pre-wrap text-white/90">
|
||||||
{text}
|
{text}
|
||||||
@@ -66,33 +68,37 @@ const Panel = ({
|
|||||||
item: MediaViewerItem;
|
item: MediaViewerItem;
|
||||||
message: string;
|
message: string;
|
||||||
openable: boolean;
|
openable: boolean;
|
||||||
}) => (
|
}) => {
|
||||||
<div className="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-white/10 bg-black/40 p-8 text-center">
|
const { t } = useI18n();
|
||||||
<FileIcon className="h-12 w-12 text-white/60" />
|
return (
|
||||||
<div className="min-w-0">
|
<div className="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-white/10 bg-black/40 p-8 text-center">
|
||||||
<p className="truncate text-sm font-medium text-white">{item.name}</p>
|
<FileIcon className="h-12 w-12 text-white/60" />
|
||||||
<p className="mt-1 text-xs text-white/60">{message}</p>
|
<div className="min-w-0">
|
||||||
</div>
|
<p className="truncate text-sm font-medium text-white">{item.name}</p>
|
||||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
<p className="mt-1 text-xs text-white/60">{message}</p>
|
||||||
{openable ? (
|
</div>
|
||||||
<a
|
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||||
href={api.previewUrl(item.id)}
|
{openable ? (
|
||||||
target="_blank"
|
<a
|
||||||
rel="noopener noreferrer"
|
href={api.previewUrl(item.id)}
|
||||||
className={actionClass}
|
target="_blank"
|
||||||
>
|
rel="noopener noreferrer"
|
||||||
Ouvrir
|
className={actionClass}
|
||||||
|
>
|
||||||
|
{t("Ouvrir")}
|
||||||
|
</a>
|
||||||
|
) : null}
|
||||||
|
<a href={api.downloadUrl(item.id)} download={item.name} className={actionClass}>
|
||||||
|
<DownloadIcon className="h-4 w-4" />
|
||||||
|
{t("Télécharger")}
|
||||||
</a>
|
</a>
|
||||||
) : null}
|
</div>
|
||||||
<a href={api.downloadUrl(item.id)} download={item.name} className={actionClass}>
|
|
||||||
<DownloadIcon className="h-4 w-4" />
|
|
||||||
Télécharger
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
};
|
||||||
|
|
||||||
const Body = ({ item }: { item: MediaViewerItem }) => {
|
const Body = ({ item }: { item: MediaViewerItem }) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const kind = kindOf(item.mime_type);
|
const kind = kindOf(item.mime_type);
|
||||||
if (kind === "image") {
|
if (kind === "image") {
|
||||||
return (
|
return (
|
||||||
@@ -124,11 +130,11 @@ const Body = ({ item }: { item: MediaViewerItem }) => {
|
|||||||
}
|
}
|
||||||
if (kind === "text") return <TextViewer id={item.id} />;
|
if (kind === "text") return <TextViewer id={item.id} />;
|
||||||
if (kind === "pdf") {
|
if (kind === "pdf") {
|
||||||
return (
|
return <Panel item={item} message={t("Le PDF s'ouvre dans un nouvel onglet.")} openable />;
|
||||||
<Panel item={item} message="Le PDF s'ouvre dans un nouvel onglet." openable />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return <Panel item={item} message="Aperçu indisponible pour ce format." openable={false} />;
|
return (
|
||||||
|
<Panel item={item} message={t("Aperçu indisponible pour ce format.")} openable={false} />
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MediaViewer = ({
|
export const MediaViewer = ({
|
||||||
@@ -140,6 +146,7 @@ export const MediaViewer = ({
|
|||||||
startIndex: number;
|
startIndex: number;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [index, setIndex] = useState(startIndex);
|
const [index, setIndex] = useState(startIndex);
|
||||||
const current = items[index];
|
const current = items[index];
|
||||||
|
|
||||||
@@ -169,11 +176,11 @@ export const MediaViewer = ({
|
|||||||
href={api.downloadUrl(current.id)}
|
href={api.downloadUrl(current.id)}
|
||||||
download={current.name}
|
download={current.name}
|
||||||
className={controlClass}
|
className={controlClass}
|
||||||
aria-label="Télécharger"
|
aria-label={t("Télécharger")}
|
||||||
>
|
>
|
||||||
<DownloadIcon className="h-4 w-4" />
|
<DownloadIcon className="h-4 w-4" />
|
||||||
</a>
|
</a>
|
||||||
<button type="button" onClick={onClose} className={controlClass} aria-label="Fermer">
|
<button type="button" onClick={onClose} className={controlClass} aria-label={t("Fermer")}>
|
||||||
<CloseIcon className="h-4 w-4" />
|
<CloseIcon className="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -190,7 +197,7 @@ export const MediaViewer = ({
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={() => setIndex((value) => value - 1)}
|
onClick={() => setIndex((value) => value - 1)}
|
||||||
className={cn(controlClass, "absolute left-4 z-10")}
|
className={cn(controlClass, "absolute left-4 z-10")}
|
||||||
aria-label="Fichier précédent"
|
aria-label={t("Fichier précédent")}
|
||||||
>
|
>
|
||||||
<ArrowLeftIcon className="h-5 w-5" />
|
<ArrowLeftIcon className="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
@@ -203,7 +210,7 @@ export const MediaViewer = ({
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={() => setIndex((value) => value + 1)}
|
onClick={() => setIndex((value) => value + 1)}
|
||||||
className={cn(controlClass, "absolute right-4 z-10")}
|
className={cn(controlClass, "absolute right-4 z-10")}
|
||||||
aria-label="Fichier suivant"
|
aria-label={t("Fichier suivant")}
|
||||||
>
|
>
|
||||||
<ArrowRightIcon className="h-5 w-5" />
|
<ArrowRightIcon className="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
type ReactNode,
|
type ReactNode,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { Button } from "../ui/index.js";
|
import { Button } from "../ui/index.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
import { Modal } from "./feedback.js";
|
import { Modal } from "./feedback.js";
|
||||||
|
|
||||||
export interface ConfirmOptions {
|
export interface ConfirmOptions {
|
||||||
@@ -33,6 +34,7 @@ const ConfirmContext = createContext<ConfirmFn | null>(null);
|
|||||||
* `useConfirm()` renvoie une promesse resolue a `true` (confirme) ou `false`.
|
* `useConfirm()` renvoie une promesse resolue a `true` (confirme) ou `false`.
|
||||||
*/
|
*/
|
||||||
export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [pending, setPending] = useState<PendingConfirm | null>(null);
|
const [pending, setPending] = useState<PendingConfirm | null>(null);
|
||||||
|
|
||||||
const confirm = useCallback<ConfirmFn>(
|
const confirm = useCallback<ConfirmFn>(
|
||||||
@@ -52,7 +54,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
{children}
|
{children}
|
||||||
<Modal
|
<Modal
|
||||||
open={pending !== null}
|
open={pending !== null}
|
||||||
title={pending?.options.title ?? "Confirmation"}
|
title={pending?.options.title ?? t("Confirmation")}
|
||||||
onClose={() => answer(false)}
|
onClose={() => answer(false)}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
@@ -61,7 +63,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
</p>
|
</p>
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={() => answer(false)}>
|
<Button variant="ghost" size="md" onClick={() => answer(false)}>
|
||||||
{pending?.options.cancelLabel ?? "Annuler"}
|
{pending?.options.cancelLabel ?? t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant={tone === "danger" ? "destructive" : "primary"}
|
variant={tone === "danger" ? "destructive" : "primary"}
|
||||||
@@ -69,7 +71,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
autoFocus
|
autoFocus
|
||||||
onClick={() => answer(true)}
|
onClick={() => answer(true)}
|
||||||
>
|
>
|
||||||
{pending?.options.confirmLabel ?? "Confirmer"}
|
{pending?.options.confirmLabel ?? t("Confirmer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import {
|
|||||||
ApiError,
|
ApiError,
|
||||||
api,
|
api,
|
||||||
formatDate,
|
formatDate,
|
||||||
|
type DirectoryUser,
|
||||||
type Folder,
|
type Folder,
|
||||||
type FolderPermission,
|
type FolderPermission,
|
||||||
} from "../lib/api.js";
|
} from "../lib/api.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
import { Alert, Modal } from "./feedback.js";
|
import { Alert, Modal } from "./feedback.js";
|
||||||
import { TrashIcon } from "./icons.js";
|
import { TrashIcon } from "./icons.js";
|
||||||
|
|
||||||
@@ -35,8 +37,8 @@ export const CreateFolderDialog = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onCreated: () => void;
|
onCreated: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [description, setDescription] = useState("");
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
@@ -45,40 +47,34 @@ export const CreateFolderDialog = ({
|
|||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
await api.createFolder(name, parentId, description.trim() || undefined);
|
await api.createFolder(name, parentId);
|
||||||
onCreated();
|
onCreated();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Création impossible."));
|
setError(messageOf(caught, t("Création impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title="Nouveau dossier" onClose={onClose}>
|
<Modal open title={t("Nouveau dossier")} onClose={onClose}>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label={t("Nom")}
|
||||||
required
|
required
|
||||||
maxLength={255}
|
maxLength={255}
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder="Contrats 2026"
|
placeholder={t("Contrats 2026")}
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(event) => setName(event.target.value)}
|
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}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={onClose}>
|
<Button variant="ghost" size="md" onClick={onClose}>
|
||||||
Annuler
|
{t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" size="md" isLoading={busy}>
|
<Button type="submit" size="md" isLoading={busy}>
|
||||||
Créer
|
{t("Créer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -95,6 +91,7 @@ export const RenameDialog = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onDone: () => void;
|
onDone: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [name, setName] = useState(target.name);
|
const [name, setName] = useState(target.name);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
@@ -104,21 +101,21 @@ export const RenameDialog = ({
|
|||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
if (target.type === "folder") await api.updateFolder(target.id, { name });
|
if (target.type === "folder") await api.updateFolder(target.id, name);
|
||||||
else await api.renameFile(target.id, name);
|
else await api.renameFile(target.id, name);
|
||||||
onDone();
|
onDone();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Renommage impossible."));
|
setError(messageOf(caught, t("Renommage impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title="Renommer" onClose={onClose}>
|
<Modal open title={t("Renommer")} onClose={onClose}>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label={t("Nom")}
|
||||||
required
|
required
|
||||||
maxLength={255}
|
maxLength={255}
|
||||||
autoFocus
|
autoFocus
|
||||||
@@ -128,10 +125,10 @@ export const RenameDialog = ({
|
|||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={onClose}>
|
<Button variant="ghost" size="md" onClick={onClose}>
|
||||||
Annuler
|
{t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" size="md" isLoading={busy}>
|
<Button type="submit" size="md" isLoading={busy}>
|
||||||
Enregistrer
|
{t("Enregistrer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -167,6 +164,7 @@ export const MoveDialog = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onDone: () => void;
|
onDone: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [entries, setEntries] = useState<TreeEntry[] | null>(null);
|
const [entries, setEntries] = useState<TreeEntry[] | null>(null);
|
||||||
const [destination, setDestination] = useState<string>("");
|
const [destination, setDestination] = useState<string>("");
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -175,7 +173,7 @@ export const MoveDialog = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadTree()
|
loadTree()
|
||||||
.then(setEntries)
|
.then(setEntries)
|
||||||
.catch((caught: unknown) => setError(messageOf(caught, "Chargement des dossiers impossible.")));
|
.catch((caught: unknown) => setError(messageOf(caught, t("Chargement des dossiers impossible."))));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
@@ -188,24 +186,24 @@ export const MoveDialog = ({
|
|||||||
else await api.moveFile(target.id, parentId);
|
else await api.moveFile(target.id, parentId);
|
||||||
onDone();
|
onDone();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Déplacement impossible."));
|
setError(messageOf(caught, t("Déplacement impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title="Déplacer" onClose={onClose}>
|
<Modal open title={t("Déplacer")} onClose={onClose}>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
Destination de <span className="font-medium text-foreground">{target.name}</span>.
|
{t("Destination de {name}.", { name: target.name })}
|
||||||
</p>
|
</p>
|
||||||
{entries === null && !error ? (
|
{entries === null && !error ? (
|
||||||
<Alert tone="info">Chargement des dossiers…</Alert>
|
<Alert tone="info">{t("Chargement des dossiers…")}</Alert>
|
||||||
) : (
|
) : (
|
||||||
<label className="flex flex-col gap-1.5">
|
<label className="flex flex-col gap-1.5">
|
||||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
Destination
|
{t("Destination")}
|
||||||
</span>
|
</span>
|
||||||
<select
|
<select
|
||||||
value={destination}
|
value={destination}
|
||||||
@@ -215,7 +213,7 @@ export const MoveDialog = ({
|
|||||||
"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",
|
"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>
|
<option value="">{t("Racine")}</option>
|
||||||
{(entries ?? [])
|
{(entries ?? [])
|
||||||
.filter((entry) => entry.id !== target.id)
|
.filter((entry) => entry.id !== target.id)
|
||||||
.map((entry) => (
|
.map((entry) => (
|
||||||
@@ -229,10 +227,10 @@ export const MoveDialog = ({
|
|||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={onClose}>
|
<Button variant="ghost" size="md" onClick={onClose}>
|
||||||
Annuler
|
{t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" size="md" isLoading={busy} disabled={entries === null}>
|
<Button type="submit" size="md" isLoading={busy} disabled={entries === null}>
|
||||||
Déplacer
|
{t("Déplacer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -247,7 +245,9 @@ export const ShareDialog = ({
|
|||||||
folder: Folder;
|
folder: Folder;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [permissions, setPermissions] = useState<FolderPermission[] | null>(null);
|
const [permissions, setPermissions] = useState<FolderPermission[] | null>(null);
|
||||||
|
const [members, setMembers] = useState<DirectoryUser[] | null>(null);
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [level, setLevel] = useState<string>("read");
|
const [level, setLevel] = useState<string>("read");
|
||||||
const [expiresAt, setExpiresAt] = useState("");
|
const [expiresAt, setExpiresAt] = useState("");
|
||||||
@@ -256,12 +256,17 @@ export const ShareDialog = ({
|
|||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
try {
|
try {
|
||||||
const { permissions: list } = await api.folderPermissions(folder.id);
|
const [{ permissions: list }, { users }] = await Promise.all([
|
||||||
|
api.folderPermissions(folder.id),
|
||||||
|
api.directory(),
|
||||||
|
]);
|
||||||
setPermissions(list);
|
setPermissions(list);
|
||||||
|
setMembers(users);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Chargement des partages impossible."));
|
setError(messageOf(caught, t("Chargement des partages impossible.")));
|
||||||
setPermissions([]);
|
setPermissions([]);
|
||||||
|
setMembers([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -270,6 +275,10 @@ export const ShareDialog = ({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [folder.id]);
|
}, [folder.id]);
|
||||||
|
|
||||||
|
const candidates = (members ?? []).filter(
|
||||||
|
(member) => !(permissions ?? []).some((permission) => permission.user_id === member.id),
|
||||||
|
);
|
||||||
|
|
||||||
const grant = async (event: FormEvent<HTMLFormElement>) => {
|
const grant = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
@@ -281,7 +290,7 @@ export const ShareDialog = ({
|
|||||||
setExpiresAt("");
|
setExpiresAt("");
|
||||||
await load();
|
await load();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Partage impossible."));
|
setError(messageOf(caught, t("Partage impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
@@ -293,26 +302,43 @@ export const ShareDialog = ({
|
|||||||
await api.revokePermission(folder.id, userId);
|
await api.revokePermission(folder.id, userId);
|
||||||
await load();
|
await load();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Révocation impossible."));
|
setError(messageOf(caught, t("Révocation impossible.")));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title={`Partager « ${folder.name} »`} onClose={onClose}>
|
<Modal open title={t("Partager « {name} »", { name: folder.name })} onClose={onClose}>
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<form className="flex flex-col gap-3" onSubmit={(event) => void grant(event)}>
|
<form className="flex flex-col gap-3" onSubmit={(event) => void grant(event)}>
|
||||||
<Input
|
<label className="flex flex-col gap-1.5">
|
||||||
label="Adresse e-mail du membre"
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
type="email"
|
{t("Membre")}
|
||||||
required
|
</span>
|
||||||
autoFocus
|
<select
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(event) => setEmail(event.target.value)}
|
autoFocus
|
||||||
/>
|
required
|
||||||
|
disabled={candidates.length === 0}
|
||||||
|
onChange={(event) => setEmail(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"
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
{t("Choisir un membre")}
|
||||||
|
</option>
|
||||||
|
{candidates.map((member) => (
|
||||||
|
<option key={member.id} value={member.email}>
|
||||||
|
{member.first_name} {member.last_name} ({member.email})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
{members !== null && candidates.length === 0 && permissions !== null ? (
|
||||||
|
<p className="text-xs text-muted-foreground">{t("Aucun autre membre à ajouter.")}</p>
|
||||||
|
) : null}
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<label className="flex flex-col gap-1.5">
|
<label className="flex flex-col gap-1.5">
|
||||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
Niveau
|
{t("Niveau")}
|
||||||
</span>
|
</span>
|
||||||
<select
|
<select
|
||||||
value={level}
|
value={level}
|
||||||
@@ -321,13 +347,13 @@ export const ShareDialog = ({
|
|||||||
>
|
>
|
||||||
{LEVELS.map((value) => (
|
{LEVELS.map((value) => (
|
||||||
<option key={value} value={value}>
|
<option key={value} value={value}>
|
||||||
{LEVEL_LABEL[value]}
|
{t(LEVEL_LABEL[value] ?? value)}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
label="Expire le"
|
label={t("Expire le")}
|
||||||
type="date"
|
type="date"
|
||||||
value={expiresAt}
|
value={expiresAt}
|
||||||
onChange={(event) => setExpiresAt(event.target.value)}
|
onChange={(event) => setExpiresAt(event.target.value)}
|
||||||
@@ -335,20 +361,20 @@ export const ShareDialog = ({
|
|||||||
</div>
|
</div>
|
||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button type="submit" size="md" isLoading={busy}>
|
<Button type="submit" size="md" isLoading={busy} disabled={candidates.length === 0}>
|
||||||
Autoriser
|
{t("Autoriser")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h3 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h3 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Accès accordés
|
{t("Accès accordés")}
|
||||||
</h3>
|
</h3>
|
||||||
{permissions === null ? (
|
{permissions === null ? (
|
||||||
<Alert tone="info">Chargement…</Alert>
|
<Alert tone="info">{t("Chargement…")}</Alert>
|
||||||
) : permissions.length === 0 ? (
|
) : permissions.length === 0 ? (
|
||||||
<p className="text-xs text-muted-foreground">Aucun partage pour ce dossier.</p>
|
<p className="text-xs text-muted-foreground">{t("Aucun partage pour ce dossier.")}</p>
|
||||||
) : (
|
) : (
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-md border border-border">
|
<ul className="flex flex-col divide-y divide-border rounded-md border border-border">
|
||||||
{permissions.map((permission) => (
|
{permissions.map((permission) => (
|
||||||
@@ -358,13 +384,18 @@ export const ShareDialog = ({
|
|||||||
{permission.first_name} {permission.last_name}
|
{permission.first_name} {permission.last_name}
|
||||||
</span>
|
</span>
|
||||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||||
{permission.email} · {LEVEL_LABEL[permission.level] ?? permission.level}
|
{permission.email} ·{" "}
|
||||||
{permission.expires_at ? ` · jusqu'au ${formatDate(permission.expires_at)}` : ""}
|
{permission.expires_at
|
||||||
|
? t("{level} · jusqu'au {date}", {
|
||||||
|
level: t(LEVEL_LABEL[permission.level] ?? permission.level),
|
||||||
|
date: formatDate(permission.expires_at),
|
||||||
|
})
|
||||||
|
: t(LEVEL_LABEL[permission.level] ?? permission.level)}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
aria-label={`Révoquer ${permission.email}`}
|
aria-label={t("Révoquer {email}", { email: permission.email })}
|
||||||
onClick={() => void revoke(permission.user_id)}
|
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"
|
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-destructive"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, type ReactNode } from "react";
|
import { useEffect, type ReactNode } from "react";
|
||||||
import { cn } from "../ui/index.js";
|
import { cn } from "../ui/index.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
import { CloseIcon } from "./icons.js";
|
import { CloseIcon } from "./icons.js";
|
||||||
|
|
||||||
export const Modal = ({
|
export const Modal = ({
|
||||||
@@ -13,6 +14,8 @@ export const Modal = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
const onKeyDown = (event: KeyboardEvent) => {
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
@@ -48,7 +51,7 @@ export const Modal = ({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
aria-label="Fermer"
|
aria-label={t("Fermer")}
|
||||||
className="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
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" />
|
<CloseIcon className="h-5 w-5" />
|
||||||
|
|||||||
+36
-12
@@ -1,3 +1,8 @@
|
|||||||
|
import { getLanguage, getLocale } from "./locale";
|
||||||
|
|
||||||
|
export type Theme = "system" | "light" | "dark";
|
||||||
|
export type Language = "fr" | "en";
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
@@ -9,6 +14,8 @@ export interface User {
|
|||||||
used_bytes: number;
|
used_bytes: number;
|
||||||
max_file_bytes: number;
|
max_file_bytes: number;
|
||||||
must_change_password: boolean;
|
must_change_password: boolean;
|
||||||
|
theme: Theme;
|
||||||
|
language: Language;
|
||||||
has_avatar: boolean;
|
has_avatar: boolean;
|
||||||
avatar_updated_at: string | null;
|
avatar_updated_at: string | null;
|
||||||
}
|
}
|
||||||
@@ -17,7 +24,6 @@ export interface Folder {
|
|||||||
id: string;
|
id: string;
|
||||||
parent_id: string | null;
|
parent_id: string | null;
|
||||||
name: string;
|
name: string;
|
||||||
description: string | null;
|
|
||||||
owner_id: string | null;
|
owner_id: string | null;
|
||||||
access_type: string;
|
access_type: string;
|
||||||
is_system: boolean;
|
is_system: boolean;
|
||||||
@@ -67,7 +73,6 @@ export interface TrashFolder {
|
|||||||
id: string;
|
id: string;
|
||||||
parent_id: string | null;
|
parent_id: string | null;
|
||||||
name: string;
|
name: string;
|
||||||
description: string | null;
|
|
||||||
owner_id: string | null;
|
owner_id: string | null;
|
||||||
access_type: string;
|
access_type: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
@@ -171,6 +176,15 @@ export interface ChatMessage {
|
|||||||
avatar_updated_at: string | null;
|
avatar_updated_at: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DirectoryUser {
|
||||||
|
id: string;
|
||||||
|
first_name: string;
|
||||||
|
last_name: string;
|
||||||
|
email: string;
|
||||||
|
has_avatar: boolean;
|
||||||
|
avatar_updated_at: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
readonly status: number;
|
readonly status: number;
|
||||||
|
|
||||||
@@ -268,6 +282,9 @@ export const api = {
|
|||||||
// --- Compte ------------------------------------------------------------
|
// --- Compte ------------------------------------------------------------
|
||||||
updateProfile: (first_name: string, last_name: string) =>
|
updateProfile: (first_name: string, last_name: string) =>
|
||||||
patch<{ ok: boolean }>("/account/profile", { first_name, last_name }),
|
patch<{ ok: boolean }>("/account/profile", { first_name, last_name }),
|
||||||
|
preferences: () => request<{ theme: Theme; language: Language }>("/account/preferences"),
|
||||||
|
updatePreferences: (theme: Theme, language: Language) =>
|
||||||
|
patch<{ theme: Theme; language: Language }>("/account/preferences", { theme, language }),
|
||||||
sessions: () => request<{ sessions: SessionInfo[] }>("/account/sessions"),
|
sessions: () => request<{ sessions: SessionInfo[] }>("/account/sessions"),
|
||||||
revokeSession: (id: string) => del<{ ok: boolean }>(`/account/sessions/${encodeURIComponent(id)}`),
|
revokeSession: (id: string) => del<{ ok: boolean }>(`/account/sessions/${encodeURIComponent(id)}`),
|
||||||
revokeOtherSessions: () => del<{ ok: boolean }>("/account/sessions"),
|
revokeOtherSessions: () => del<{ ok: boolean }>("/account/sessions"),
|
||||||
@@ -275,15 +292,16 @@ export const api = {
|
|||||||
uploadAvatar: (file: File) => putBinary<{ ok: boolean }>("/account/avatar", file, file.type),
|
uploadAvatar: (file: File) => putBinary<{ ok: boolean }>("/account/avatar", file, file.type),
|
||||||
deleteAvatar: () => del<{ ok: boolean }>("/account/avatar"),
|
deleteAvatar: () => del<{ ok: boolean }>("/account/avatar"),
|
||||||
|
|
||||||
|
directory: () => request<{ users: DirectoryUser[] }>("/directory"),
|
||||||
// --- Dossiers ----------------------------------------------------------
|
// --- Dossiers ----------------------------------------------------------
|
||||||
folders: (parentId?: string | null) =>
|
folders: (parentId?: string | null) =>
|
||||||
request<{ parentId: string | null; folders: Folder[] }>(
|
request<{ parentId: string | null; folders: Folder[] }>(
|
||||||
`/folders${query({ parentId })}`,
|
`/folders${query({ parentId })}`,
|
||||||
),
|
),
|
||||||
createFolder: (name: string, parentId?: string | null, description?: string) =>
|
createFolder: (name: string, parentId?: string | null) =>
|
||||||
post<{ folder: Folder }>("/folders", { name, parentId: parentId ?? null, description }),
|
post<{ folder: Folder }>("/folders", { name, parentId: parentId ?? null }),
|
||||||
updateFolder: (id: string, payload: { name?: string; description?: string | null }) =>
|
updateFolder: (id: string, name: string) =>
|
||||||
patch<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}`, payload),
|
patch<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}`, { name }),
|
||||||
moveFolder: (id: string, parentId: string | null) =>
|
moveFolder: (id: string, parentId: string | null) =>
|
||||||
post<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}/move`, { parentId }),
|
post<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}/move`, { parentId }),
|
||||||
deleteFolder: (id: string) => del<{ ok: boolean }>(`/folders/${encodeURIComponent(id)}`),
|
deleteFolder: (id: string) => del<{ ok: boolean }>(`/folders/${encodeURIComponent(id)}`),
|
||||||
@@ -352,6 +370,7 @@ export const api = {
|
|||||||
post<{ message: ChatMessage }>(`/folders/${encodeURIComponent(folderId)}/chat/messages`, { body }),
|
post<{ message: ChatMessage }>(`/folders/${encodeURIComponent(folderId)}/chat/messages`, { body }),
|
||||||
chatDeleteMessage: (folderId: string, id: number) =>
|
chatDeleteMessage: (folderId: string, id: number) =>
|
||||||
del<{ ok: boolean }>(`/folders/${encodeURIComponent(folderId)}/chat/messages/${id}`),
|
del<{ ok: boolean }>(`/folders/${encodeURIComponent(folderId)}/chat/messages/${id}`),
|
||||||
|
chatUnread: () => request<{ unread: Record<string, number> }>("/chat/unread"),
|
||||||
|
|
||||||
// --- Administration ----------------------------------------------------
|
// --- Administration ----------------------------------------------------
|
||||||
adminStats: () => request<AdminStats>("/admin/stats"),
|
adminStats: () => request<AdminStats>("/admin/stats"),
|
||||||
@@ -391,22 +410,27 @@ export const api = {
|
|||||||
id: number,
|
id: number,
|
||||||
payload: { name?: string; quota_bytes?: number | null; is_active?: boolean },
|
payload: { name?: string; quota_bytes?: number | null; is_active?: boolean },
|
||||||
) => patch<{ ok: boolean }>(`/admin/storage-locations/${id}`, payload),
|
) => patch<{ ok: boolean }>(`/admin/storage-locations/${id}`, payload),
|
||||||
adminAudit: (limit = 100, offset = 0, action?: string) =>
|
adminAudit: (limit = 100, offset = 0, action?: string, userId?: string) =>
|
||||||
request<{ entries: AuditEntry[] }>(`/admin/audit${query({ limit, offset, action })}`),
|
request<{ entries: AuditEntry[] }>(`/admin/audit${query({ limit, offset, action, userId })}`),
|
||||||
|
adminAuditFilters: () =>
|
||||||
|
request<{ actions: string[]; users: { id: string; email: string | null }[] }>(
|
||||||
|
"/admin/audit/filters",
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Octets en lecture humaine, sans precision inutile. */
|
/** Octets en lecture humaine, sans precision inutile. */
|
||||||
export const formatBytes = (bytes: number): string => {
|
export const formatBytes = (bytes: number): string => {
|
||||||
if (bytes < 1024) return `${bytes} o`;
|
const english = getLanguage() === "en";
|
||||||
const units = ["Ko", "Mo", "Go", "To"];
|
if (bytes < 1024) return `${bytes} ${english ? "B" : "o"}`;
|
||||||
|
const units = english ? ["KB", "MB", "GB", "TB"] : ["Ko", "Mo", "Go", "To"];
|
||||||
let value = bytes;
|
let value = bytes;
|
||||||
let index = -1;
|
let index = -1;
|
||||||
do {
|
do {
|
||||||
value /= 1024;
|
value /= 1024;
|
||||||
index += 1;
|
index += 1;
|
||||||
} while (value >= 1024 && index < units.length - 1);
|
} while (value >= 1024 && index < units.length - 1);
|
||||||
return `${value.toLocaleString("fr-FR", { maximumFractionDigits: value < 10 ? 1 : 0 })} ${units[index]}`;
|
return `${value.toLocaleString(getLocale(), { maximumFractionDigits: value < 10 ? 1 : 0 })} ${units[index]}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDate = (value: string | null): string =>
|
export const formatDate = (value: string | null): string =>
|
||||||
value ? new Date(value).toLocaleString("fr-FR", { dateStyle: "medium", timeStyle: "short" }) : "—";
|
value ? new Date(value).toLocaleString(getLocale(), { dateStyle: "medium", timeStyle: "short" }) : "—";
|
||||||
|
|||||||
@@ -0,0 +1,375 @@
|
|||||||
|
import {
|
||||||
|
createContext,
|
||||||
|
useCallback,
|
||||||
|
useContext,
|
||||||
|
useMemo,
|
||||||
|
type ReactNode,
|
||||||
|
} from "react";
|
||||||
|
import type { Language } from "./api.js";
|
||||||
|
import { setLanguage } from "./locale.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Traduction par clef de source : la chaine francaise sert de clef, le
|
||||||
|
* dictionnaire anglais fournit la variante. Une clef absente retombe sur le
|
||||||
|
* francais, donc un oubli ne casse jamais l'interface.
|
||||||
|
*/
|
||||||
|
const en: Record<string, string> = {
|
||||||
|
// --- Commun ------------------------------------------------------------
|
||||||
|
"Annuler": "Cancel",
|
||||||
|
"Enregistrer": "Save",
|
||||||
|
"Créer": "Create",
|
||||||
|
"Supprimer": "Delete",
|
||||||
|
"Confirmer": "Confirm",
|
||||||
|
"Fermer": "Close",
|
||||||
|
"Retour": "Back",
|
||||||
|
"Filtrer": "Filter",
|
||||||
|
"Tous les utilisateurs": "All users",
|
||||||
|
"Toutes les actions": "All actions",
|
||||||
|
"Type d'action": "Action type",
|
||||||
|
"Charger plus": "Load more",
|
||||||
|
"Chargement…": "Loading…",
|
||||||
|
"Chargement impossible.": "Unable to load.",
|
||||||
|
"Action impossible.": "Action failed.",
|
||||||
|
"Envoi impossible.": "Upload failed.",
|
||||||
|
"Suppression impossible.": "Deletion failed.",
|
||||||
|
"Enregistrement impossible.": "Saving failed.",
|
||||||
|
"Création impossible.": "Creation failed.",
|
||||||
|
"Mise à jour impossible.": "Update failed.",
|
||||||
|
"Réinitialisation impossible.": "Reset failed.",
|
||||||
|
"Révocation impossible.": "Revocation failed.",
|
||||||
|
"Déplacement impossible.": "Move failed.",
|
||||||
|
"Renommage impossible.": "Rename failed.",
|
||||||
|
"Partage impossible.": "Sharing failed.",
|
||||||
|
"Demande impossible.": "Request failed.",
|
||||||
|
"Confirmation impossible.": "Confirmation failed.",
|
||||||
|
"Recherche impossible.": "Search failed.",
|
||||||
|
"Changement impossible.": "Change failed.",
|
||||||
|
"Connexion impossible.": "Unable to sign in.",
|
||||||
|
"Chargement des dossiers impossible.": "Unable to load folders.",
|
||||||
|
"Chargement des dossiers…": "Loading folders…",
|
||||||
|
"Chargement des partages impossible.": "Unable to load shares.",
|
||||||
|
|
||||||
|
// --- Navigation / coque ------------------------------------------------
|
||||||
|
"Fichiers": "Files",
|
||||||
|
"Favoris": "Favorites",
|
||||||
|
"Recherche": "Search",
|
||||||
|
"Galerie": "Gallery",
|
||||||
|
"Corbeille": "Trash",
|
||||||
|
"Comptes": "Accounts",
|
||||||
|
"Stockage": "Storage",
|
||||||
|
"Journal": "Log",
|
||||||
|
"Mon compte": "My account",
|
||||||
|
"Administration": "Administration",
|
||||||
|
"Déconnexion": "Sign out",
|
||||||
|
"Fermer le menu": "Close menu",
|
||||||
|
"Ouvrir le menu": "Open menu",
|
||||||
|
|
||||||
|
// --- Connexion ---------------------------------------------------------
|
||||||
|
"Connectez-vous pour accéder à vos fichiers.": "Sign in to access your files.",
|
||||||
|
"Connexion": "Sign in",
|
||||||
|
"Votre session reste ouverte 14 jours.": "Your session stays open for 14 days.",
|
||||||
|
"Adresse e-mail": "Email address",
|
||||||
|
"Mot de passe": "Password",
|
||||||
|
"Se connecter": "Sign in",
|
||||||
|
"Mot de passe oublié ?": "Forgot your password?",
|
||||||
|
|
||||||
|
// --- Mot de passe oublié ----------------------------------------------
|
||||||
|
"Mot de passe oublié": "Forgot password",
|
||||||
|
"Réinitialisation": "Reset",
|
||||||
|
"Nous vous enverrons un lien valable une heure.": "We will email you a link valid for one hour.",
|
||||||
|
"Si cette adresse correspond à un compte, un message contenant le lien de réinitialisation vient d'être envoyé.":
|
||||||
|
"If this address matches an account, a message with the reset link has just been sent.",
|
||||||
|
"Retour à la connexion": "Back to sign in",
|
||||||
|
"Envoyer le lien": "Send link",
|
||||||
|
|
||||||
|
// --- Réinitialisation --------------------------------------------------
|
||||||
|
"Nouveau mot de passe": "New password",
|
||||||
|
"Choisissez un mot de passe robuste.": "Choose a strong password.",
|
||||||
|
"Ce lien est incomplet ou invalide.": "This link is incomplete or invalid.",
|
||||||
|
"Demander un nouveau lien": "Request a new link",
|
||||||
|
"Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.":
|
||||||
|
"Your password has been reset. You can now sign in.",
|
||||||
|
"Confirmation": "Confirmation",
|
||||||
|
"8 caractères minimum.": "At least 8 characters.",
|
||||||
|
"Réinitialiser": "Reset",
|
||||||
|
"Les deux mots de passe ne correspondent pas.": "The two passwords do not match.",
|
||||||
|
|
||||||
|
// --- Changement d'adresse ---------------------------------------------
|
||||||
|
"Changement d'adresse": "Email change",
|
||||||
|
"Votre adresse e-mail a été mise à jour.": "Your email address has been updated.",
|
||||||
|
"Accéder à mes fichiers": "Go to my files",
|
||||||
|
|
||||||
|
// --- Changement de mot de passe ---------------------------------------
|
||||||
|
"Bienvenue {name}. Ce mot de passe a été défini par un administrateur : choisissez le vôtre.":
|
||||||
|
"Welcome {name}. This password was set by an administrator: choose your own.",
|
||||||
|
"Changement requis": "Change required",
|
||||||
|
"Les autres sessions ouvertes sur ce compte seront fermées.":
|
||||||
|
"Other sessions open on this account will be closed.",
|
||||||
|
"Mot de passe actuel": "Current password",
|
||||||
|
"Se déconnecter": "Sign out",
|
||||||
|
|
||||||
|
// --- Explorateur -------------------------------------------------------
|
||||||
|
"Racine": "Root",
|
||||||
|
"Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier.":
|
||||||
|
"Your folders and files. Upload a file or create a folder.",
|
||||||
|
"Fil d'Ariane": "Breadcrumb",
|
||||||
|
"Discussion": "Discussion",
|
||||||
|
"Espace utilisé": "Space used",
|
||||||
|
"{used} sur {quota}": "{used} of {quota}",
|
||||||
|
"Envoyer": "Upload",
|
||||||
|
"Nouveau dossier": "New folder",
|
||||||
|
"Contrats 2026": "Contracts 2026",
|
||||||
|
"Emplacement vide": "Empty location",
|
||||||
|
"Créez un sous-dossier ou envoyez un fichier pour commencer.":
|
||||||
|
"Create a subfolder or upload a file to get started.",
|
||||||
|
"Dossiers": "Folders",
|
||||||
|
"Aperçu de {name}": "Preview of {name}",
|
||||||
|
"Retirer l'étoile de {name}": "Remove star from {name}",
|
||||||
|
"Étoiler {name}": "Star {name}",
|
||||||
|
"Télécharger": "Download",
|
||||||
|
"Renommer {name}": "Rename {name}",
|
||||||
|
"Déplacer {name}": "Move {name}",
|
||||||
|
"Supprimer {name}": "Delete {name}",
|
||||||
|
"Partager {name}": "Share {name}",
|
||||||
|
"Discussion {name}": "Discussion {name}",
|
||||||
|
"Mettre à la corbeille": "Move to trash",
|
||||||
|
"ce dossier": "this folder",
|
||||||
|
"ce fichier": "this file",
|
||||||
|
"Placer {name} ({kind}) dans la corbeille ?": "Move {name} ({kind}) to the trash?",
|
||||||
|
|
||||||
|
// --- Boites de dialogue ------------------------------------------------
|
||||||
|
"Lecture": "Read",
|
||||||
|
"Écriture": "Write",
|
||||||
|
"Nom": "Name",
|
||||||
|
"Renommer": "Rename",
|
||||||
|
"Déplacer": "Move",
|
||||||
|
"Destination de {name}.": "Destination for {name}.",
|
||||||
|
"Destination": "Destination",
|
||||||
|
"Partager « {name} »": "Share “{name}”",
|
||||||
|
"Membre": "Member",
|
||||||
|
"Choisir un membre": "Choose a member",
|
||||||
|
"Niveau": "Level",
|
||||||
|
"Expire le": "Expires on",
|
||||||
|
"Autoriser": "Grant",
|
||||||
|
"Accès accordés": "Granted access",
|
||||||
|
"Aucun partage pour ce dossier.": "No shares for this folder.",
|
||||||
|
"Révoquer {email}": "Revoke {email}",
|
||||||
|
"{level} · jusqu'au {date}": "{level} · until {date}",
|
||||||
|
"Aucun autre membre à ajouter.": "No other member to add.",
|
||||||
|
|
||||||
|
// --- Discussion de dossier --------------------------------------------
|
||||||
|
"Compte supprimé": "Deleted account",
|
||||||
|
"Supprimer le message": "Delete message",
|
||||||
|
"Ce message sera retiré du salon pour tout le monde.":
|
||||||
|
"This message will be removed from the room for everyone.",
|
||||||
|
"Membres du dossier": "Folder members",
|
||||||
|
"Membres": "Members",
|
||||||
|
"(vous)": "(you)",
|
||||||
|
"Dernière connexion le {date}": "Last sign-in on {date}",
|
||||||
|
"Jamais connecté": "Never signed in",
|
||||||
|
"Masquer les membres": "Hide members",
|
||||||
|
"Afficher les membres": "Show members",
|
||||||
|
"Discussion · {name}": "Discussion · {name}",
|
||||||
|
"Membres ayant accès à ce dossier": "Members with access to this folder",
|
||||||
|
"Fermer la discussion": "Close discussion",
|
||||||
|
"Aucun message": "No messages",
|
||||||
|
"Lancez la discussion : les membres du dossier verront votre message.":
|
||||||
|
"Start the conversation: folder members will see your message.",
|
||||||
|
"Écrire un message… (Entrée pour envoyer, Maj+Entrée pour retour à la ligne)":
|
||||||
|
"Write a message… (Enter to send, Shift+Enter for a new line)",
|
||||||
|
"Votre message": "Your message",
|
||||||
|
|
||||||
|
// --- Visionneuse -------------------------------------------------------
|
||||||
|
"Lecture impossible.": "Unable to read.",
|
||||||
|
"Ouvrir": "Open",
|
||||||
|
"Le PDF s'ouvre dans un nouvel onglet.": "The PDF opens in a new tab.",
|
||||||
|
"Aperçu indisponible pour ce format.": "Preview unavailable for this format.",
|
||||||
|
"Fichier précédent": "Previous file",
|
||||||
|
"Fichier suivant": "Next file",
|
||||||
|
|
||||||
|
// --- Favoris -----------------------------------------------------------
|
||||||
|
"Les fichiers que vous avez étoilés, tous dossiers confondus.":
|
||||||
|
"The files you starred, across all folders.",
|
||||||
|
"Aucun favori": "No favorites",
|
||||||
|
"Étoilez un fichier dans l'explorateur pour le retrouver ici.":
|
||||||
|
"Star a file in the browser to find it here.",
|
||||||
|
|
||||||
|
// --- Recherche ---------------------------------------------------------
|
||||||
|
"Saisissez au moins deux caractères.": "Enter at least two characters.",
|
||||||
|
"Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès.":
|
||||||
|
"Search by name in the folders and files you can access.",
|
||||||
|
"Terme recherché": "Search term",
|
||||||
|
"facture, rapport…": "invoice, report…",
|
||||||
|
"Rechercher": "Search",
|
||||||
|
"Télécharger {name}": "Download {name}",
|
||||||
|
"Aucun résultat": "No results",
|
||||||
|
"Rien ne correspond à « {q} ».": "Nothing matches “{q}”.",
|
||||||
|
|
||||||
|
// --- Galerie -----------------------------------------------------------
|
||||||
|
"Tout": "All",
|
||||||
|
"Images": "Images",
|
||||||
|
"Vidéos": "Videos",
|
||||||
|
"Audio": "Audio",
|
||||||
|
"Documents": "Documents",
|
||||||
|
"Archives": "Archives",
|
||||||
|
"Autres": "Other",
|
||||||
|
"Parcourez les médias auxquels vous avez accès.": "Browse the media you can access.",
|
||||||
|
"Filtrer par type": "Filter by type",
|
||||||
|
"Aucun média": "No media",
|
||||||
|
"Rien à afficher pour ce filtre.": "Nothing to show for this filter.",
|
||||||
|
|
||||||
|
// --- Corbeille ---------------------------------------------------------
|
||||||
|
"Vider la corbeille": "Empty trash",
|
||||||
|
"Tous les éléments seront définitivement supprimés. Cette action est irréversible.":
|
||||||
|
"All items will be permanently deleted. This action cannot be undone.",
|
||||||
|
"Vider": "Empty",
|
||||||
|
"Supprimer définitivement": "Delete permanently",
|
||||||
|
"Supprimer définitivement {name} ? Cette action est irréversible.":
|
||||||
|
"Permanently delete {name}? This action cannot be undone.",
|
||||||
|
"Les éléments sont définitivement supprimés après {days} jours.":
|
||||||
|
"Items are permanently deleted after {days} days.",
|
||||||
|
"Éléments supprimés récemment.": "Recently deleted items.",
|
||||||
|
"Corbeille vide": "Trash is empty",
|
||||||
|
"Aucun élément supprimé pour le moment.": "No items deleted yet.",
|
||||||
|
"Dossiers supprimés": "Deleted folders",
|
||||||
|
"Fichiers supprimés": "Deleted files",
|
||||||
|
"Supprimé le {date}": "Deleted on {date}",
|
||||||
|
"Restaurer {name}": "Restore {name}",
|
||||||
|
"Supprimer définitivement {name}": "Permanently delete {name}",
|
||||||
|
|
||||||
|
// --- Compte ------------------------------------------------------------
|
||||||
|
"Profil, photo, adresse e-mail et sessions ouvertes.":
|
||||||
|
"Profile, photo, email address and open sessions.",
|
||||||
|
"Identité": "Identity",
|
||||||
|
"Informations affichées dans l'interface.": "Information shown in the interface.",
|
||||||
|
"Prénom": "First name",
|
||||||
|
"Informations enregistrées.": "Information saved.",
|
||||||
|
"Photo de profil": "Profile photo",
|
||||||
|
"Image carrée, format PNG ou JPEG.": "Square image, PNG or JPEG.",
|
||||||
|
"Choisir une image": "Choose an image",
|
||||||
|
"Retirer": "Remove",
|
||||||
|
"Si aucune image n'est définie, vos initiales sont affichées.":
|
||||||
|
"If no image is set, your initials are shown.",
|
||||||
|
"Adresse actuelle : {email}": "Current address: {email}",
|
||||||
|
"Nouvelle adresse": "New address",
|
||||||
|
"Un e-mail de confirmation a été envoyé à la nouvelle adresse.":
|
||||||
|
"A confirmation email has been sent to the new address.",
|
||||||
|
"Demander le changement": "Request change",
|
||||||
|
"Sessions ouvertes": "Open sessions",
|
||||||
|
"Appareils actuellement connectés à votre compte.":
|
||||||
|
"Devices currently connected to your account.",
|
||||||
|
"Aucune session active.": "No active session.",
|
||||||
|
"Appareil inconnu": "Unknown device",
|
||||||
|
"Cette session": "This session",
|
||||||
|
"IP inconnue": "Unknown IP",
|
||||||
|
"vue le {date}": "seen on {date}",
|
||||||
|
"Fermer cette session": "Close this session",
|
||||||
|
"Fermer les autres sessions": "Close other sessions",
|
||||||
|
"Fermer la session": "Close session",
|
||||||
|
"Fermer la session en cours vous déconnectera immédiatement.":
|
||||||
|
"Closing the current session will sign you out immediately.",
|
||||||
|
|
||||||
|
// --- Préférences -------------------------------------------------------
|
||||||
|
"Préférences": "Preferences",
|
||||||
|
"Apparence et langue de l'interface.": "Interface appearance and language.",
|
||||||
|
"Thème": "Theme",
|
||||||
|
"Système": "System",
|
||||||
|
"Clair": "Light",
|
||||||
|
"Sombre": "Dark",
|
||||||
|
"Langue": "Language",
|
||||||
|
"Préférences enregistrées.": "Preferences saved.",
|
||||||
|
|
||||||
|
// --- Administration ----------------------------------------------------
|
||||||
|
"Créer des membres, ajustez leurs quotas et gérez les accès.":
|
||||||
|
"Create members, adjust their quotas and manage access.",
|
||||||
|
"Nouveau membre": "New member",
|
||||||
|
"nom ou e-mail": "name or email",
|
||||||
|
"Aucun membre": "No members",
|
||||||
|
"Inactif": "Inactive",
|
||||||
|
"À changer": "To change",
|
||||||
|
"vu le {date}": "seen on {date}",
|
||||||
|
"jamais connecté": "never signed in",
|
||||||
|
"Modifier": "Edit",
|
||||||
|
"Désactiver": "Deactivate",
|
||||||
|
"Réactiver": "Reactivate",
|
||||||
|
"Réinitialiser le mot de passe": "Reset password",
|
||||||
|
"Mot de passe réinitialisé. Les identifiants ont été envoyés à {email}.":
|
||||||
|
"Password reset. Credentials have been sent to {email}.",
|
||||||
|
"Supprimer le membre": "Delete member",
|
||||||
|
"Supprimer définitivement {email} ainsi que ses fichiers ? Cette action est irréversible.":
|
||||||
|
"Permanently delete {email} and their files? This action cannot be undone.",
|
||||||
|
"Compte créé. Les identifiants ont été envoyés à {email}.":
|
||||||
|
"Account created. Credentials have been sent to {email}.",
|
||||||
|
"Rôle": "Role",
|
||||||
|
"Utilisateur": "User",
|
||||||
|
"Administrateur": "Administrator",
|
||||||
|
"Quota (Go, optionnel)": "Quota (GB, optional)",
|
||||||
|
"Fichier max (Mo)": "Max file (MB)",
|
||||||
|
"Modifier le membre": "Edit member",
|
||||||
|
"Quota (Go)": "Quota (GB)",
|
||||||
|
"Emplacements de stockage": "Storage locations",
|
||||||
|
"Volumes montés utilisés pour stocker les fichiers.":
|
||||||
|
"Mounted volumes used to store files.",
|
||||||
|
"Nouvel emplacement": "New location",
|
||||||
|
"Aucun emplacement": "No locations",
|
||||||
|
"Go utilisés": "GB used",
|
||||||
|
"Identifiant technique": "Technical identifier",
|
||||||
|
"Chemin de montage": "Mount path",
|
||||||
|
"Journal d'activité": "Activity log",
|
||||||
|
"Dernières actions enregistrées.": "Latest recorded actions.",
|
||||||
|
"Filtrer par action": "Filter by action",
|
||||||
|
"Aucune entrée": "No entries",
|
||||||
|
"système": "system",
|
||||||
|
"{value} Go": "{value} GB",
|
||||||
|
"{used} / {quota} Go": "{used} / {quota} GB",
|
||||||
|
"{used} Go utilisés": "{used} GB used",
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Translate = (source: string, vars?: Record<string, string | number>) => string;
|
||||||
|
|
||||||
|
export const translate = (
|
||||||
|
language: Language,
|
||||||
|
source: string,
|
||||||
|
vars?: Record<string, string | number>,
|
||||||
|
): string => {
|
||||||
|
const template = language === "en" ? en[source] ?? source : source;
|
||||||
|
if (!vars) return template;
|
||||||
|
return template.replace(/\{(\w+)\}/g, (match, key: string) =>
|
||||||
|
vars[key] !== undefined ? String(vars[key]) : match,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface I18nValue {
|
||||||
|
lang: Language;
|
||||||
|
t: Translate;
|
||||||
|
}
|
||||||
|
|
||||||
|
const I18nContext = createContext<I18nValue | null>(null);
|
||||||
|
|
||||||
|
export const I18nProvider = ({
|
||||||
|
language,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
language: Language;
|
||||||
|
children: ReactNode;
|
||||||
|
}) => {
|
||||||
|
// La langue est poussee dans le module des que le provider rend : les
|
||||||
|
// formatages (`formatBytes`, `formatDate`) lisent cette valeur partagee, en
|
||||||
|
// dehors de React. L'appel est idempotent.
|
||||||
|
setLanguage(language);
|
||||||
|
|
||||||
|
const t = useCallback<Translate>(
|
||||||
|
(source, vars) => translate(language, source, vars),
|
||||||
|
[language],
|
||||||
|
);
|
||||||
|
|
||||||
|
const value = useMemo<I18nValue>(() => ({ lang: language, t }), [language, t]);
|
||||||
|
|
||||||
|
return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useI18n = (): I18nValue => {
|
||||||
|
const value = useContext(I18nContext);
|
||||||
|
if (!value) throw new Error("useI18n doit etre utilise dans un I18nProvider.");
|
||||||
|
return value;
|
||||||
|
};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import type { Language } from "./api";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Langue d'affichage courante, partagee par tout le module (hors composants
|
||||||
|
* React) : formatage des tailles et des dates. Le provider i18n la met a jour
|
||||||
|
* des qu'un utilisateur change de langue dans son compte.
|
||||||
|
*/
|
||||||
|
let language: Language = "fr";
|
||||||
|
|
||||||
|
export const getLanguage = (): Language => language;
|
||||||
|
|
||||||
|
export const setLanguage = (next: Language): void => {
|
||||||
|
language = next;
|
||||||
|
if (typeof document !== "undefined") document.documentElement.lang = next;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getLocale = (): string => (language === "en" ? "en-US" : "fr-FR");
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useEffect, type ReactNode } from "react";
|
||||||
|
import type { Theme } from "./api.js";
|
||||||
|
|
||||||
|
const STORAGE_KEY = "cohaise-theme";
|
||||||
|
|
||||||
|
const prefersDark = (): boolean =>
|
||||||
|
typeof window !== "undefined" &&
|
||||||
|
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||||
|
|
||||||
|
const isDark = (theme: Theme): boolean =>
|
||||||
|
theme === "dark" || (theme === "system" && prefersDark());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applique le theme choisi dans le compte sur la racine du document. Le meme
|
||||||
|
* choix est recopie dans `localStorage` pour que `public/theme.js` reproduise
|
||||||
|
* le rendu des le premier pixel, avant que React ne demarre.
|
||||||
|
*/
|
||||||
|
export const ThemeProvider = ({ theme, children }: { theme: Theme; children: ReactNode }) => {
|
||||||
|
useEffect(() => {
|
||||||
|
const apply = () => {
|
||||||
|
document.documentElement.classList.toggle("dark", isDark(theme));
|
||||||
|
};
|
||||||
|
apply();
|
||||||
|
try {
|
||||||
|
localStorage.setItem(STORAGE_KEY, theme);
|
||||||
|
} catch {
|
||||||
|
/* stockage indisponible : le rendu reste correct */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theme !== "system") return undefined;
|
||||||
|
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
|
const onChange = () => apply();
|
||||||
|
media.addEventListener("change", onChange);
|
||||||
|
return () => media.removeEventListener("change", onChange);
|
||||||
|
}, [theme]);
|
||||||
|
|
||||||
|
return <>{children}</>;
|
||||||
|
};
|
||||||
+21
-4
@@ -1,8 +1,10 @@
|
|||||||
import { StrictMode } from "react";
|
import { StrictMode, type ReactNode } from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { BrowserRouter } from "react-router-dom";
|
import { BrowserRouter } from "react-router-dom";
|
||||||
import { App } from "./App.js";
|
import { App } from "./App.js";
|
||||||
import { SessionProvider } from "./lib/session.js";
|
import { SessionProvider, useSession } from "./lib/session.js";
|
||||||
|
import { I18nProvider } from "./lib/i18n.js";
|
||||||
|
import { ThemeProvider } from "./lib/theme.js";
|
||||||
import { ConfirmProvider } from "./components/confirm.js";
|
import { ConfirmProvider } from "./components/confirm.js";
|
||||||
import "./styles/index.css";
|
import "./styles/index.css";
|
||||||
|
|
||||||
@@ -12,13 +14,28 @@ if (!container) {
|
|||||||
throw new Error("Element racine introuvable");
|
throw new Error("Element racine introuvable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enveloppe les preferences de la session (theme, langue) pour qu'elles
|
||||||
|
* s'appliquent a toute l'application, y compris aux ecrans hors coque.
|
||||||
|
*/
|
||||||
|
const Providers = ({ children }: { children: ReactNode }) => {
|
||||||
|
const { user } = useSession();
|
||||||
|
return (
|
||||||
|
<ThemeProvider theme={user?.theme ?? "system"}>
|
||||||
|
<I18nProvider language={user?.language ?? "fr"}>
|
||||||
|
<ConfirmProvider>{children}</ConfirmProvider>
|
||||||
|
</I18nProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
createRoot(container).render(
|
createRoot(container).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<SessionProvider>
|
<SessionProvider>
|
||||||
<ConfirmProvider>
|
<Providers>
|
||||||
<App />
|
<App />
|
||||||
</ConfirmProvider>
|
</Providers>
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
|
|||||||
+167
-104
@@ -9,6 +9,8 @@ import {
|
|||||||
type AuditEntry,
|
type AuditEntry,
|
||||||
type StorageLocation,
|
type StorageLocation,
|
||||||
} from "../lib/api.js";
|
} from "../lib/api.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
import { getLocale } from "../lib/locale.js";
|
||||||
import { Alert, Badge, EmptyState, Modal, PageHeader } from "../components/feedback.js";
|
import { Alert, Badge, EmptyState, Modal, PageHeader } from "../components/feedback.js";
|
||||||
import { useConfirm } from "../components/confirm.js";
|
import { useConfirm } from "../components/confirm.js";
|
||||||
import { IconAction } from "../components/IconAction.js";
|
import { IconAction } from "../components/IconAction.js";
|
||||||
@@ -27,7 +29,7 @@ const messageOf = (caught: unknown, fallback: string): string =>
|
|||||||
caught instanceof ApiError ? caught.message : fallback;
|
caught instanceof ApiError ? caught.message : fallback;
|
||||||
|
|
||||||
const toGb = (bytes: number): string =>
|
const toGb = (bytes: number): string =>
|
||||||
(bytes / GB).toLocaleString("fr-FR", { maximumFractionDigits: 1 });
|
(bytes / GB).toLocaleString(getLocale(), { maximumFractionDigits: 1 });
|
||||||
|
|
||||||
const StatCard = ({ label, value }: { label: string; value: string }) => (
|
const StatCard = ({ label, value }: { label: string; value: string }) => (
|
||||||
<div className="rounded-lg border border-border bg-surface p-3">
|
<div className="rounded-lg border border-border bg-surface p-3">
|
||||||
@@ -39,6 +41,7 @@ const StatCard = ({ label, value }: { label: string; value: string }) => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const AdminUsers = () => {
|
export const AdminUsers = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
const [users, setUsers] = useState<AdminUser[] | null>(null);
|
const [users, setUsers] = useState<AdminUser[] | null>(null);
|
||||||
const [stats, setStats] = useState<AdminStats | null>(null);
|
const [stats, setStats] = useState<AdminStats | null>(null);
|
||||||
@@ -57,7 +60,7 @@ export const AdminUsers = () => {
|
|||||||
const { users: list } = await api.adminUsers(term || undefined);
|
const { users: list } = await api.adminUsers(term || undefined);
|
||||||
setUsers(list);
|
setUsers(list);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Chargement impossible."));
|
setError(messageOf(caught, t("Chargement impossible.")));
|
||||||
setUsers([]);
|
setUsers([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -68,6 +71,7 @@ export const AdminUsers = () => {
|
|||||||
.adminStats()
|
.adminStats()
|
||||||
.then(setStats)
|
.then(setStats)
|
||||||
.catch(() => undefined);
|
.catch(() => undefined);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const toggleActive = async (user: AdminUser) => {
|
const toggleActive = async (user: AdminUser) => {
|
||||||
@@ -77,7 +81,7 @@ export const AdminUsers = () => {
|
|||||||
await api.adminUpdateUser(user.id, { is_active: !user.is_active });
|
await api.adminUpdateUser(user.id, { is_active: !user.is_active });
|
||||||
await load(termRef.current);
|
await load(termRef.current);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Mise à jour impossible."));
|
setError(messageOf(caught, t("Mise à jour impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(null);
|
setBusy(null);
|
||||||
}
|
}
|
||||||
@@ -89,9 +93,9 @@ export const AdminUsers = () => {
|
|||||||
setNotice(null);
|
setNotice(null);
|
||||||
try {
|
try {
|
||||||
await api.adminResetPassword(user.id);
|
await api.adminResetPassword(user.id);
|
||||||
setNotice(`Mot de passe réinitialisé. Les identifiants ont été envoyés à ${user.email}.`);
|
setNotice(t("Mot de passe réinitialisé. Les identifiants ont été envoyés à {email}.", { email: user.email }));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Réinitialisation impossible."));
|
setError(messageOf(caught, t("Réinitialisation impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(null);
|
setBusy(null);
|
||||||
}
|
}
|
||||||
@@ -99,14 +103,11 @@ export const AdminUsers = () => {
|
|||||||
|
|
||||||
const removeUser = async (user: AdminUser) => {
|
const removeUser = async (user: AdminUser) => {
|
||||||
const ok = await confirm({
|
const ok = await confirm({
|
||||||
title: "Supprimer le membre",
|
title: t("Supprimer le membre"),
|
||||||
message: (
|
message: t("Supprimer définitivement {email} ainsi que ses fichiers ? Cette action est irréversible.", {
|
||||||
<>
|
email: user.email,
|
||||||
Supprimer définitivement <span className="font-semibold text-foreground">{user.email}</span>{" "}
|
}),
|
||||||
ainsi que ses fichiers ? Cette action est irréversible.
|
confirmLabel: t("Supprimer"),
|
||||||
</>
|
|
||||||
),
|
|
||||||
confirmLabel: "Supprimer",
|
|
||||||
tone: "danger",
|
tone: "danger",
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
@@ -116,7 +117,7 @@ export const AdminUsers = () => {
|
|||||||
await api.adminDeleteUser(user.id);
|
await api.adminDeleteUser(user.id);
|
||||||
await load(termRef.current);
|
await load(termRef.current);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Suppression impossible."));
|
setError(messageOf(caught, t("Suppression impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(null);
|
setBusy(null);
|
||||||
}
|
}
|
||||||
@@ -125,24 +126,27 @@ export const AdminUsers = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Comptes"
|
title={t("Comptes")}
|
||||||
description="Créez des membres, ajustez leurs quotas et gérez les accès."
|
description={t("Créer des membres, ajustez leurs quotas et gérez les accès.")}
|
||||||
actions={
|
actions={
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||||
onClick={() => setCreateOpen(true)}
|
onClick={() => setCreateOpen(true)}
|
||||||
>
|
>
|
||||||
Nouveau membre
|
{t("Nouveau membre")}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
toolbar={
|
toolbar={
|
||||||
<>
|
<>
|
||||||
{stats ? (
|
{stats ? (
|
||||||
<div className="grid grid-cols-3 gap-3">
|
<div className="grid grid-cols-3 gap-3">
|
||||||
<StatCard label="Membres" value={String(stats.users)} />
|
<StatCard label={t("Membres")} value={String(stats.users)} />
|
||||||
<StatCard label="Fichiers" value={String(stats.files)} />
|
<StatCard label={t("Fichiers")} value={String(stats.files)} />
|
||||||
<StatCard label="Stockage" value={`${toGb(stats.usedBytes)} Go`} />
|
<StatCard
|
||||||
|
label={t("Stockage")}
|
||||||
|
value={t("{value} Go", { value: toGb(stats.usedBytes) })}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
@@ -155,15 +159,15 @@ export const AdminUsers = () => {
|
|||||||
>
|
>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input
|
<Input
|
||||||
label="Rechercher"
|
label={t("Rechercher")}
|
||||||
type="search"
|
type="search"
|
||||||
placeholder="nom ou e-mail"
|
placeholder={t("nom ou e-mail")}
|
||||||
value={q}
|
value={q}
|
||||||
onChange={(event) => setQ(event.target.value)}
|
onChange={(event) => setQ(event.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit" size="md" variant="secondary">
|
<Button type="submit" size="md" variant="secondary">
|
||||||
Filtrer
|
{t("Filtrer")}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
@@ -178,7 +182,7 @@ export const AdminUsers = () => {
|
|||||||
<Spinner size="md" />
|
<Spinner size="md" />
|
||||||
</div>
|
</div>
|
||||||
) : users.length === 0 ? (
|
) : users.length === 0 ? (
|
||||||
<EmptyState icon={<UsersIcon className="h-8 w-8" />} title="Aucun membre" />
|
<EmptyState icon={<UsersIcon className="h-8 w-8" />} title={t("Aucun membre")} />
|
||||||
) : (
|
) : (
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{users.map((user) => (
|
{users.map((user) => (
|
||||||
@@ -189,35 +193,40 @@ export const AdminUsers = () => {
|
|||||||
{user.first_name} {user.last_name}
|
{user.first_name} {user.last_name}
|
||||||
</span>
|
</span>
|
||||||
{user.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
{user.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
||||||
{!user.is_active ? <Badge tone="danger">Inactif</Badge> : null}
|
{!user.is_active ? <Badge tone="danger">{t("Inactif")}</Badge> : null}
|
||||||
{user.must_change_password ? <Badge tone="warning">À changer</Badge> : null}
|
{user.must_change_password ? <Badge tone="warning">{t("À changer")}</Badge> : null}
|
||||||
</span>
|
</span>
|
||||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||||
{user.email} · {toGb(user.used_bytes)} / {toGb(user.quota_bytes)} Go ·{" "}
|
{user.email} ·{" "}
|
||||||
|
{t("{used} / {quota} Go", {
|
||||||
|
used: toGb(user.used_bytes),
|
||||||
|
quota: toGb(user.quota_bytes),
|
||||||
|
})}{" "}
|
||||||
|
·{" "}
|
||||||
{user.last_login_at
|
{user.last_login_at
|
||||||
? `vu le ${formatDate(user.last_login_at)}`
|
? t("vu le {date}", { date: formatDate(user.last_login_at) })
|
||||||
: "jamais connecté"}
|
: t("jamais connecté")}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Button variant="ghost" size="sm" onClick={() => setEdit(user)}>
|
<Button variant="ghost" size="sm" onClick={() => setEdit(user)}>
|
||||||
Modifier
|
{t("Modifier")}
|
||||||
</Button>
|
</Button>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={user.is_active ? "Désactiver" : "Réactiver"}
|
label={user.is_active ? t("Désactiver") : t("Réactiver")}
|
||||||
icon={<HardDriveIcon className="h-4 w-4" />}
|
icon={<HardDriveIcon className="h-4 w-4" />}
|
||||||
isLoading={busy === user.id}
|
isLoading={busy === user.id}
|
||||||
onClick={() => void toggleActive(user)}
|
onClick={() => void toggleActive(user)}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label="Réinitialiser le mot de passe"
|
label={t("Réinitialiser le mot de passe")}
|
||||||
icon={<ActivityIcon className="h-4 w-4" />}
|
icon={<ActivityIcon className="h-4 w-4" />}
|
||||||
isLoading={busy === user.id}
|
isLoading={busy === user.id}
|
||||||
onClick={() => void resetPassword(user)}
|
onClick={() => void resetPassword(user)}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label="Supprimer"
|
label={t("Supprimer")}
|
||||||
icon={<TrashIcon className="h-4 w-4" />}
|
icon={<TrashIcon className="h-4 w-4" />}
|
||||||
tone="danger"
|
tone="danger"
|
||||||
isLoading={busy === user.id}
|
isLoading={busy === user.id}
|
||||||
@@ -234,7 +243,7 @@ export const AdminUsers = () => {
|
|||||||
onClose={() => setCreateOpen(false)}
|
onClose={() => setCreateOpen(false)}
|
||||||
onCreated={(email) => {
|
onCreated={(email) => {
|
||||||
setCreateOpen(false);
|
setCreateOpen(false);
|
||||||
setNotice(`Compte créé. Les identifiants ont été envoyés à ${email}.`);
|
setNotice(t("Compte créé. Les identifiants ont été envoyés à {email}.", { email }));
|
||||||
void load(termRef.current);
|
void load(termRef.current);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -261,6 +270,7 @@ const CreateUserDialog = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onCreated: (email: string) => void;
|
onCreated: (email: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [firstName, setFirstName] = useState("");
|
const [firstName, setFirstName] = useState("");
|
||||||
const [lastName, setLastName] = useState("");
|
const [lastName, setLastName] = useState("");
|
||||||
@@ -285,17 +295,17 @@ const CreateUserDialog = ({
|
|||||||
});
|
});
|
||||||
onCreated(user.email);
|
onCreated(user.email);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Création impossible."));
|
setError(messageOf(caught, t("Création impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title="Nouveau membre" onClose={onClose}>
|
<Modal open title={t("Nouveau membre")} onClose={onClose}>
|
||||||
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Adresse e-mail"
|
label={t("Adresse e-mail")}
|
||||||
type="email"
|
type="email"
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
@@ -304,13 +314,13 @@ const CreateUserDialog = ({
|
|||||||
/>
|
/>
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<Input
|
<Input
|
||||||
label="Prénom"
|
label={t("Prénom")}
|
||||||
required
|
required
|
||||||
value={firstName}
|
value={firstName}
|
||||||
onChange={(event) => setFirstName(event.target.value)}
|
onChange={(event) => setFirstName(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label={t("Nom")}
|
||||||
required
|
required
|
||||||
value={lastName}
|
value={lastName}
|
||||||
onChange={(event) => setLastName(event.target.value)}
|
onChange={(event) => setLastName(event.target.value)}
|
||||||
@@ -318,27 +328,27 @@ const CreateUserDialog = ({
|
|||||||
</div>
|
</div>
|
||||||
<label className="flex flex-col gap-1.5">
|
<label className="flex flex-col gap-1.5">
|
||||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
Rôle
|
{t("Rôle")}
|
||||||
</span>
|
</span>
|
||||||
<select
|
<select
|
||||||
value={role}
|
value={role}
|
||||||
onChange={(event) => setRole(event.target.value)}
|
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"
|
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="user">{t("Utilisateur")}</option>
|
||||||
<option value="admin">Administrateur</option>
|
<option value="admin">{t("Administrateur")}</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<Input
|
<Input
|
||||||
label="Quota (Go, optionnel)"
|
label={t("Quota (Go, optionnel)")}
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={quotaGb}
|
value={quotaGb}
|
||||||
onChange={(event) => setQuotaGb(event.target.value)}
|
onChange={(event) => setQuotaGb(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Fichier max (Mo)"
|
label={t("Fichier max (Mo)")}
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={maxFileMb}
|
value={maxFileMb}
|
||||||
@@ -348,10 +358,10 @@ const CreateUserDialog = ({
|
|||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={onClose}>
|
<Button variant="ghost" size="md" onClick={onClose}>
|
||||||
Annuler
|
{t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" size="md" isLoading={busy}>
|
<Button type="submit" size="md" isLoading={busy}>
|
||||||
Créer
|
{t("Créer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -368,6 +378,7 @@ const EditUserDialog = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onSaved: () => void;
|
onSaved: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [firstName, setFirstName] = useState(user.first_name);
|
const [firstName, setFirstName] = useState(user.first_name);
|
||||||
const [lastName, setLastName] = useState(user.last_name);
|
const [lastName, setLastName] = useState(user.last_name);
|
||||||
const [role, setRole] = useState(user.role_slug);
|
const [role, setRole] = useState(user.role_slug);
|
||||||
@@ -390,24 +401,24 @@ const EditUserDialog = ({
|
|||||||
});
|
});
|
||||||
onSaved();
|
onSaved();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Enregistrement impossible."));
|
setError(messageOf(caught, t("Enregistrement impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title="Modifier le membre" onClose={onClose}>
|
<Modal open title={t("Modifier le membre")} onClose={onClose}>
|
||||||
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<Input
|
<Input
|
||||||
label="Prénom"
|
label={t("Prénom")}
|
||||||
required
|
required
|
||||||
value={firstName}
|
value={firstName}
|
||||||
onChange={(event) => setFirstName(event.target.value)}
|
onChange={(event) => setFirstName(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label={t("Nom")}
|
||||||
required
|
required
|
||||||
value={lastName}
|
value={lastName}
|
||||||
onChange={(event) => setLastName(event.target.value)}
|
onChange={(event) => setLastName(event.target.value)}
|
||||||
@@ -415,27 +426,27 @@ const EditUserDialog = ({
|
|||||||
</div>
|
</div>
|
||||||
<label className="flex flex-col gap-1.5">
|
<label className="flex flex-col gap-1.5">
|
||||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
Rôle
|
{t("Rôle")}
|
||||||
</span>
|
</span>
|
||||||
<select
|
<select
|
||||||
value={role}
|
value={role}
|
||||||
onChange={(event) => setRole(event.target.value)}
|
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"
|
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="user">{t("Utilisateur")}</option>
|
||||||
<option value="admin">Administrateur</option>
|
<option value="admin">{t("Administrateur")}</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<Input
|
<Input
|
||||||
label="Quota (Go)"
|
label={t("Quota (Go)")}
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={quotaGb}
|
value={quotaGb}
|
||||||
onChange={(event) => setQuotaGb(event.target.value)}
|
onChange={(event) => setQuotaGb(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Fichier max (Mo)"
|
label={t("Fichier max (Mo)")}
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={maxFileMb}
|
value={maxFileMb}
|
||||||
@@ -445,10 +456,10 @@ const EditUserDialog = ({
|
|||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={onClose}>
|
<Button variant="ghost" size="md" onClick={onClose}>
|
||||||
Annuler
|
{t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" size="md" isLoading={busy}>
|
<Button type="submit" size="md" isLoading={busy}>
|
||||||
Enregistrer
|
{t("Enregistrer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -457,6 +468,7 @@ const EditUserDialog = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AdminStorage = () => {
|
export const AdminStorage = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [locations, setLocations] = useState<StorageLocation[] | null>(null);
|
const [locations, setLocations] = useState<StorageLocation[] | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
@@ -467,13 +479,14 @@ export const AdminStorage = () => {
|
|||||||
const { locations: list } = await api.adminStorageLocations();
|
const { locations: list } = await api.adminStorageLocations();
|
||||||
setLocations(list);
|
setLocations(list);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Chargement impossible."));
|
setError(messageOf(caught, t("Chargement impossible.")));
|
||||||
setLocations([]);
|
setLocations([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void load();
|
void load();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const toggle = async (location: StorageLocation) => {
|
const toggle = async (location: StorageLocation) => {
|
||||||
@@ -482,22 +495,22 @@ export const AdminStorage = () => {
|
|||||||
await api.adminUpdateStorageLocation(location.id, { is_active: !location.is_active });
|
await api.adminUpdateStorageLocation(location.id, { is_active: !location.is_active });
|
||||||
await load();
|
await load();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Mise à jour impossible."));
|
setError(messageOf(caught, t("Mise à jour impossible.")));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Emplacements de stockage"
|
title={t("Emplacements de stockage")}
|
||||||
description="Volumes montés utilisés pour stocker les fichiers."
|
description={t("Volumes montés utilisés pour stocker les fichiers.")}
|
||||||
actions={
|
actions={
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||||
onClick={() => setCreateOpen(true)}
|
onClick={() => setCreateOpen(true)}
|
||||||
>
|
>
|
||||||
Nouvel emplacement
|
{t("Nouvel emplacement")}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -509,7 +522,7 @@ export const AdminStorage = () => {
|
|||||||
<Spinner size="md" />
|
<Spinner size="md" />
|
||||||
</div>
|
</div>
|
||||||
) : locations.length === 0 ? (
|
) : locations.length === 0 ? (
|
||||||
<EmptyState icon={<HardDriveIcon className="h-8 w-8" />} title="Aucun emplacement" />
|
<EmptyState icon={<HardDriveIcon className="h-8 w-8" />} title={t("Aucun emplacement")} />
|
||||||
) : (
|
) : (
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{locations.map((location) => (
|
{locations.map((location) => (
|
||||||
@@ -519,17 +532,20 @@ export const AdminStorage = () => {
|
|||||||
<span className="truncate text-sm font-medium text-foreground">
|
<span className="truncate text-sm font-medium text-foreground">
|
||||||
{location.name}
|
{location.name}
|
||||||
</span>
|
</span>
|
||||||
{!location.is_active ? <Badge tone="danger">Inactif</Badge> : null}
|
{!location.is_active ? <Badge tone="danger">{t("Inactif")}</Badge> : null}
|
||||||
</span>
|
</span>
|
||||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||||
{location.slug} · {location.mount_path} ·{" "}
|
{location.slug} · {location.mount_path} ·{" "}
|
||||||
{location.quota_bytes
|
{location.quota_bytes
|
||||||
? `${toGb(location.used_bytes)} / ${toGb(location.quota_bytes)} Go`
|
? t("{used} / {quota} Go", {
|
||||||
: `${toGb(location.used_bytes)} Go utilisés`}
|
used: toGb(location.used_bytes),
|
||||||
|
quota: toGb(location.quota_bytes),
|
||||||
|
})
|
||||||
|
: t("{used} Go utilisés", { used: toGb(location.used_bytes) })}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<Button variant="ghost" size="sm" onClick={() => void toggle(location)}>
|
<Button variant="ghost" size="sm" onClick={() => void toggle(location)}>
|
||||||
{location.is_active ? "Désactiver" : "Réactiver"}
|
{location.is_active ? t("Désactiver") : t("Réactiver")}
|
||||||
</Button>
|
</Button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
@@ -556,6 +572,7 @@ const CreateLocationDialog = ({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onCreated: () => void;
|
onCreated: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [slug, setSlug] = useState("");
|
const [slug, setSlug] = useState("");
|
||||||
const [mountPath, setMountPath] = useState("");
|
const [mountPath, setMountPath] = useState("");
|
||||||
@@ -576,24 +593,24 @@ const CreateLocationDialog = ({
|
|||||||
});
|
});
|
||||||
onCreated();
|
onCreated();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Création impossible."));
|
setError(messageOf(caught, t("Création impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open title="Nouvel emplacement" onClose={onClose}>
|
<Modal open title={t("Nouvel emplacement")} onClose={onClose}>
|
||||||
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-3" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label={t("Nom")}
|
||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(event) => setName(event.target.value)}
|
onChange={(event) => setName(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Identifiant technique"
|
label={t("Identifiant technique")}
|
||||||
required
|
required
|
||||||
placeholder="principal"
|
placeholder="principal"
|
||||||
pattern="[a-z0-9][a-z0-9-]*"
|
pattern="[a-z0-9][a-z0-9-]*"
|
||||||
@@ -601,14 +618,14 @@ const CreateLocationDialog = ({
|
|||||||
onChange={(event) => setSlug(event.target.value)}
|
onChange={(event) => setSlug(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Chemin de montage"
|
label={t("Chemin de montage")}
|
||||||
required
|
required
|
||||||
placeholder="/data/cloud"
|
placeholder="/data/cloud"
|
||||||
value={mountPath}
|
value={mountPath}
|
||||||
onChange={(event) => setMountPath(event.target.value)}
|
onChange={(event) => setMountPath(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Quota (Go, optionnel)"
|
label={t("Quota (Go, optionnel)")}
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={quotaGb}
|
value={quotaGb}
|
||||||
@@ -617,10 +634,10 @@ const CreateLocationDialog = ({
|
|||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button variant="ghost" size="md" onClick={onClose}>
|
<Button variant="ghost" size="md" onClick={onClose}>
|
||||||
Annuler
|
{t("Annuler")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" size="md" isLoading={busy}>
|
<Button type="submit" size="md" isLoading={busy}>
|
||||||
Créer
|
{t("Créer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -629,65 +646,111 @@ const CreateLocationDialog = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AdminAudit = () => {
|
export const AdminAudit = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [entries, setEntries] = useState<AuditEntry[] | null>(null);
|
const [entries, setEntries] = useState<AuditEntry[] | null>(null);
|
||||||
const [action, setAction] = useState("");
|
const [action, setAction] = useState("");
|
||||||
|
const [userId, setUserId] = useState("");
|
||||||
|
const [filters, setFilters] = useState<{
|
||||||
|
actions: string[];
|
||||||
|
users: { id: string; email: string | null }[];
|
||||||
|
}>({ actions: [], users: [] });
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [loadingMore, setLoadingMore] = useState(false);
|
const [loadingMore, setLoadingMore] = useState(false);
|
||||||
|
|
||||||
const load = async (term: string) => {
|
const load = async (nextAction: string, nextUser: string) => {
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const { entries: list } = await api.adminAudit(100, 0, term || undefined);
|
const { entries: list } = await api.adminAudit(
|
||||||
|
100,
|
||||||
|
0,
|
||||||
|
nextAction || undefined,
|
||||||
|
nextUser || undefined,
|
||||||
|
);
|
||||||
setEntries(list);
|
setEntries(list);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Chargement impossible."));
|
setError(messageOf(caught, t("Chargement impossible.")));
|
||||||
setEntries([]);
|
setEntries([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void load("");
|
void load("", "");
|
||||||
|
void api
|
||||||
|
.adminAuditFilters()
|
||||||
|
.then(setFilters)
|
||||||
|
.catch(() => undefined);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const apply = (nextAction: string, nextUser: string) => {
|
||||||
|
setAction(nextAction);
|
||||||
|
setUserId(nextUser);
|
||||||
|
setEntries(null);
|
||||||
|
void load(nextAction, nextUser);
|
||||||
|
};
|
||||||
|
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
if (!entries) return;
|
if (!entries) return;
|
||||||
setLoadingMore(true);
|
setLoadingMore(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const { entries: more } = await api.adminAudit(100, entries.length, action || undefined);
|
const { entries: more } = await api.adminAudit(
|
||||||
|
100,
|
||||||
|
entries.length,
|
||||||
|
action || undefined,
|
||||||
|
userId || undefined,
|
||||||
|
);
|
||||||
setEntries((previous) => [...(previous ?? []), ...more]);
|
setEntries((previous) => [...(previous ?? []), ...more]);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(messageOf(caught, "Chargement impossible."));
|
setError(messageOf(caught, t("Chargement impossible.")));
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingMore(false);
|
setLoadingMore(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fieldClass =
|
||||||
|
"font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground";
|
||||||
|
const selectClass =
|
||||||
|
"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";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Journal d'activité"
|
title={t("Journal d'activité")}
|
||||||
description="Dernières actions enregistrées."
|
description={t("Dernières actions enregistrées.")}
|
||||||
toolbar={
|
toolbar={
|
||||||
<form
|
<div className="flex flex-wrap items-end gap-3">
|
||||||
className="flex items-end gap-2"
|
<label className="flex min-w-48 flex-col gap-1.5">
|
||||||
onSubmit={(event) => {
|
<span className={fieldClass}>{t("Utilisateur")}</span>
|
||||||
event.preventDefault();
|
<select
|
||||||
void load(action);
|
value={userId}
|
||||||
}}
|
onChange={(event) => apply(action, event.target.value)}
|
||||||
>
|
className={selectClass}
|
||||||
<div className="flex-1">
|
>
|
||||||
<Input
|
<option value="">{t("Tous les utilisateurs")}</option>
|
||||||
label="Filtrer par action"
|
{filters.users.map((user) => (
|
||||||
placeholder="auth.login, file.upload…"
|
<option key={user.id} value={user.id}>
|
||||||
|
{user.email ?? user.id}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label className="flex min-w-48 flex-col gap-1.5">
|
||||||
|
<span className={fieldClass}>{t("Type d'action")}</span>
|
||||||
|
<select
|
||||||
value={action}
|
value={action}
|
||||||
onChange={(event) => setAction(event.target.value)}
|
onChange={(event) => apply(event.target.value, userId)}
|
||||||
/>
|
className={selectClass}
|
||||||
</div>
|
>
|
||||||
<Button type="submit" variant="secondary" size="md">
|
<option value="">{t("Toutes les actions")}</option>
|
||||||
Filtrer
|
{filters.actions.map((value) => (
|
||||||
</Button>
|
<option key={value} value={value}>
|
||||||
</form>
|
{value}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -698,7 +761,7 @@ export const AdminAudit = () => {
|
|||||||
<Spinner size="md" />
|
<Spinner size="md" />
|
||||||
</div>
|
</div>
|
||||||
) : entries.length === 0 ? (
|
) : entries.length === 0 ? (
|
||||||
<EmptyState icon={<ActivityIcon className="h-8 w-8" />} title="Aucune entrée" />
|
<EmptyState icon={<ActivityIcon className="h-8 w-8" />} title={t("Aucune entrée")} />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
@@ -713,7 +776,7 @@ export const AdminAudit = () => {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||||
{entry.user_email ?? "système"} · {formatDate(entry.created_at)}
|
{entry.user_email ?? t("système")} · {formatDate(entry.created_at)}
|
||||||
{entry.ip_address ? ` · ${entry.ip_address}` : ""}
|
{entry.ip_address ? ` · ${entry.ip_address}` : ""}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -728,7 +791,7 @@ export const AdminAudit = () => {
|
|||||||
isLoading={loadingMore}
|
isLoading={loadingMore}
|
||||||
onClick={() => void loadMore()}
|
onClick={() => void loadMore()}
|
||||||
>
|
>
|
||||||
Charger plus
|
{t("Charger plus")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
+121
-47
@@ -1,5 +1,5 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { Button, Card, Spinner } from "../ui/index.js";
|
import { Button, Card, Spinner, cn } from "../ui/index.js";
|
||||||
import {
|
import {
|
||||||
ApiError,
|
ApiError,
|
||||||
api,
|
api,
|
||||||
@@ -8,7 +8,10 @@ import {
|
|||||||
type UploadedFile,
|
type UploadedFile,
|
||||||
} from "../lib/api.js";
|
} from "../lib/api.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
import { getLocale } from "../lib/locale.js";
|
||||||
|
import { mediaKind } from "../lib/media.js";
|
||||||
|
import { Alert, Badge, EmptyState, PageHeader } from "../components/feedback.js";
|
||||||
import { useConfirm } from "../components/confirm.js";
|
import { useConfirm } from "../components/confirm.js";
|
||||||
import { MediaViewer } from "../components/MediaViewer.js";
|
import { MediaViewer } from "../components/MediaViewer.js";
|
||||||
import { MediaThumb } from "../components/MediaThumb.js";
|
import { MediaThumb } from "../components/MediaThumb.js";
|
||||||
@@ -48,8 +51,19 @@ type Dialog =
|
|||||||
| { kind: "share"; folder: Folder }
|
| { kind: "share"; folder: Folder }
|
||||||
| null;
|
| null;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
export const Browser = () => {
|
export const Browser = () => {
|
||||||
const { user, refresh } = useSession();
|
const { user, refresh } = useSession();
|
||||||
|
const { t } = useI18n();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
const [path, setPath] = useState<Crumb[]>([{ id: null, name: "Racine" }]);
|
const [path, setPath] = useState<Crumb[]>([{ id: null, name: "Racine" }]);
|
||||||
const [folders, setFolders] = useState<Folder[]>([]);
|
const [folders, setFolders] = useState<Folder[]>([]);
|
||||||
@@ -61,6 +75,8 @@ export const Browser = () => {
|
|||||||
const [dialog, setDialog] = useState<Dialog>(null);
|
const [dialog, setDialog] = useState<Dialog>(null);
|
||||||
const [viewer, setViewer] = useState<number | null>(null);
|
const [viewer, setViewer] = useState<number | null>(null);
|
||||||
const [chat, setChat] = useState<ChatFolder | null>(null);
|
const [chat, setChat] = useState<ChatFolder | null>(null);
|
||||||
|
const [unread, setUnread] = useState<Record<string, number>>({});
|
||||||
|
const [kind, setKind] = useState<string>("");
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const current = path[path.length - 1] ?? { id: null, name: "Racine" };
|
const current = path[path.length - 1] ?? { id: null, name: "Racine" };
|
||||||
@@ -76,18 +92,37 @@ export const Browser = () => {
|
|||||||
setFolders(folderResult.folders);
|
setFolders(folderResult.folders);
|
||||||
setFiles(fileResult.files);
|
setFiles(fileResult.files);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
setFolders([]);
|
setFolders([]);
|
||||||
setFiles([]);
|
setFiles([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
}, [t]);
|
||||||
|
|
||||||
|
const refreshUnread = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const { unread: counts } = await api.chatUnread();
|
||||||
|
setUnread(counts);
|
||||||
|
} catch {
|
||||||
|
/* les pastilles sont un confort : un echec ne bloque pas l'explorateur */
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void load(current.id);
|
void load(current.id);
|
||||||
}, [current.id, load]);
|
}, [current.id, load]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void refreshUnread();
|
||||||
|
}, [current.id, refreshUnread]);
|
||||||
|
|
||||||
|
// Le filtre de type n'est propre qu'au dossier affiche : on repart sur
|
||||||
|
// « Tout » a chaque navigation, faute de voir un dossier vide pour rien.
|
||||||
|
useEffect(() => {
|
||||||
|
setKind("");
|
||||||
|
}, [current.id]);
|
||||||
|
|
||||||
const reload = useCallback(() => load(current.id), [current.id, load]);
|
const reload = useCallback(() => load(current.id), [current.id, load]);
|
||||||
|
|
||||||
const open = (folder: Folder) => {
|
const open = (folder: Folder) => {
|
||||||
@@ -107,7 +142,7 @@ export const Browser = () => {
|
|||||||
void refresh();
|
void refresh();
|
||||||
await reload();
|
await reload();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Envoi impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false);
|
setUploading(false);
|
||||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||||
@@ -115,16 +150,11 @@ export const Browser = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const removeTarget = async (target: Target) => {
|
const removeTarget = async (target: Target) => {
|
||||||
const label = target.type === "folder" ? "ce dossier" : "ce fichier";
|
const kind = target.type === "folder" ? t("ce dossier") : t("ce fichier");
|
||||||
const ok = await confirm({
|
const ok = await confirm({
|
||||||
title: "Mettre à la corbeille",
|
title: t("Mettre à la corbeille"),
|
||||||
message: (
|
message: t("Placer {name} ({kind}) dans la corbeille ?", { name: target.name, kind }),
|
||||||
<>
|
confirmLabel: t("Corbeille"),
|
||||||
Placer <span className="font-semibold text-foreground">{target.name}</span> ({label}) dans la
|
|
||||||
corbeille ?
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
confirmLabel: "Corbeille",
|
|
||||||
tone: "danger",
|
tone: "danger",
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
@@ -139,7 +169,7 @@ export const Browser = () => {
|
|||||||
}
|
}
|
||||||
await reload();
|
await reload();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Suppression impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setRemoving(null);
|
setRemoving(null);
|
||||||
}
|
}
|
||||||
@@ -151,12 +181,19 @@ export const Browser = () => {
|
|||||||
const { file: updated } = await api.starFile(file.id);
|
const { file: updated } = await api.starFile(file.id);
|
||||||
setFiles((previous) => previous.map((item) => (item.id === updated.id ? updated : item)));
|
setFiles((previous) => previous.map((item) => (item.id === updated.id ? updated : item)));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Action impossible."));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const closeChat = () => {
|
||||||
|
setChat(null);
|
||||||
|
void refreshUnread();
|
||||||
|
};
|
||||||
|
|
||||||
const canWrite = user?.role_slug === "admin" || user?.role_slug === "user";
|
const canWrite = user?.role_slug === "admin" || user?.role_slug === "user";
|
||||||
const empty = folders.length === 0 && files.length === 0;
|
const empty = folders.length === 0 && files.length === 0;
|
||||||
|
const visibleFiles = kind ? files.filter((file) => mediaKind(file.mime_type) === kind) : files;
|
||||||
|
const currentUnread = current.id ? unread[current.id] ?? 0 : 0;
|
||||||
const quotaPercent =
|
const quotaPercent =
|
||||||
user && user.quota_bytes > 0
|
user && user.quota_bytes > 0
|
||||||
? Math.min(100, Math.round((user.used_bytes / user.quota_bytes) * 100))
|
? Math.min(100, Math.round((user.used_bytes / user.quota_bytes) * 100))
|
||||||
@@ -166,7 +203,7 @@ export const Browser = () => {
|
|||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={current.name}
|
title={current.name}
|
||||||
description="Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier."
|
description={t("Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier.")}
|
||||||
toolbar={
|
toolbar={
|
||||||
<div className="flex flex-wrap items-center gap-3">
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
{path.length > 1 ? (
|
{path.length > 1 ? (
|
||||||
@@ -176,11 +213,11 @@ export const Browser = () => {
|
|||||||
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"
|
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" />
|
<ArrowLeftIcon className="h-3.5 w-3.5" />
|
||||||
Retour
|
{t("Retour")}
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<nav aria-label="Fil d'Ariane" className="min-w-0">
|
<nav aria-label={t("Fil d'Ariane")} className="min-w-0">
|
||||||
<ol className="flex flex-wrap items-center gap-1.5 text-xs">
|
<ol className="flex flex-wrap items-center gap-1.5 text-xs">
|
||||||
{path.map((crumb, index) => (
|
{path.map((crumb, index) => (
|
||||||
<li key={`${crumb.id ?? "root"}-${index}`} className="flex items-center gap-1.5">
|
<li key={`${crumb.id ?? "root"}-${index}`} className="flex items-center gap-1.5">
|
||||||
@@ -191,7 +228,7 @@ export const Browser = () => {
|
|||||||
) : null}
|
) : null}
|
||||||
{index === path.length - 1 ? (
|
{index === path.length - 1 ? (
|
||||||
<span className="font-medium text-foreground" aria-current="page">
|
<span className="font-medium text-foreground" aria-current="page">
|
||||||
{crumb.name}
|
{t(crumb.name)}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
@@ -199,7 +236,7 @@ export const Browser = () => {
|
|||||||
onClick={() => goTo(index)}
|
onClick={() => goTo(index)}
|
||||||
className="text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
|
className="text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
{crumb.name}
|
{t(crumb.name)}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</li>
|
</li>
|
||||||
@@ -214,7 +251,10 @@ export const Browser = () => {
|
|||||||
iconLeading={<ChatIcon className="h-3.5 w-3.5" />}
|
iconLeading={<ChatIcon className="h-3.5 w-3.5" />}
|
||||||
onClick={() => setChat({ id: current.id as string, name: current.name })}
|
onClick={() => setChat({ id: current.id as string, name: current.name })}
|
||||||
>
|
>
|
||||||
Discussion
|
<span className="inline-flex items-center gap-2">
|
||||||
|
{t("Discussion")}
|
||||||
|
{currentUnread > 0 ? <Badge tone="accent">{currentUnread}</Badge> : null}
|
||||||
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -225,9 +265,12 @@ export const Browser = () => {
|
|||||||
<div className="flex flex-col gap-3 p-4 sm:flex-row sm:items-center sm:justify-between">
|
<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="min-w-0 flex-1">
|
||||||
<div className="flex items-baseline justify-between gap-3">
|
<div className="flex items-baseline justify-between gap-3">
|
||||||
<span className="text-xs font-medium text-foreground">Espace utilisé</span>
|
<span className="text-xs font-medium text-foreground">{t("Espace utilisé")}</span>
|
||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
{formatBytes(user?.used_bytes ?? 0)} sur {formatBytes(user?.quota_bytes ?? 0)}
|
{t("{used} sur {quota}", {
|
||||||
|
used: formatBytes(user?.used_bytes ?? 0),
|
||||||
|
quota: formatBytes(user?.quota_bytes ?? 0),
|
||||||
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-surface-muted">
|
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-surface-muted">
|
||||||
@@ -254,7 +297,7 @@ export const Browser = () => {
|
|||||||
isLoading={uploading}
|
isLoading={uploading}
|
||||||
onClick={() => fileInputRef.current?.click()}
|
onClick={() => fileInputRef.current?.click()}
|
||||||
>
|
>
|
||||||
Envoyer
|
{t("Envoyer")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -262,13 +305,35 @@ export const Browser = () => {
|
|||||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||||
onClick={() => setDialog({ kind: "create" })}
|
onClick={() => setDialog({ kind: "create" })}
|
||||||
>
|
>
|
||||||
Nouveau dossier
|
{t("Nouveau dossier")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{files.length > 0 ? (
|
||||||
|
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label={t("Filtrer par type")}>
|
||||||
|
{KINDS.map((option) => (
|
||||||
|
<button
|
||||||
|
key={option.value}
|
||||||
|
type="button"
|
||||||
|
role="tab"
|
||||||
|
aria-selected={kind === option.value}
|
||||||
|
onClick={() => setKind(option.value)}
|
||||||
|
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",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{t(option.label)}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -278,15 +343,15 @@ export const Browser = () => {
|
|||||||
) : empty ? (
|
) : empty ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={<FolderIcon className="h-8 w-8" />}
|
icon={<FolderIcon className="h-8 w-8" />}
|
||||||
title="Emplacement vide"
|
title={t("Emplacement vide")}
|
||||||
description="Créez un sous-dossier ou envoyez un fichier pour commencer."
|
description={t("Créez un sous-dossier ou envoyez un fichier pour commencer.")}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
{folders.length > 0 ? (
|
{folders.length > 0 ? (
|
||||||
<section aria-label="Dossiers">
|
<section aria-label={t("Dossiers")}>
|
||||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Dossiers
|
{t("Dossiers")}
|
||||||
</h2>
|
</h2>
|
||||||
<ul className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
<ul className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
{folders.map((folder) => (
|
{folders.map((folder) => (
|
||||||
@@ -307,24 +372,25 @@ export const Browser = () => {
|
|||||||
{folder.name}
|
{folder.name}
|
||||||
</span>
|
</span>
|
||||||
<span className="mt-0.5 block text-[0.6875rem] text-subtle-foreground">
|
<span className="mt-0.5 block text-[0.6875rem] text-subtle-foreground">
|
||||||
{new Date(folder.created_at).toLocaleDateString("fr-FR")}
|
{new Date(folder.created_at).toLocaleDateString(getLocale())}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Discussion ${folder.name}`}
|
label={t("Discussion {name}", { name: folder.name })}
|
||||||
icon={<ChatIcon className="h-4 w-4" />}
|
icon={<ChatIcon className="h-4 w-4" />}
|
||||||
|
badge={unread[folder.id] ?? 0}
|
||||||
onClick={() => setChat({ id: folder.id, name: folder.name })}
|
onClick={() => setChat({ id: folder.id, name: folder.name })}
|
||||||
/>
|
/>
|
||||||
{canWrite ? (
|
{canWrite ? (
|
||||||
<div className="flex shrink-0 items-center gap-0.5">
|
<div className="flex shrink-0 items-center gap-0.5">
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Partager ${folder.name}`}
|
label={t("Partager {name}", { name: folder.name })}
|
||||||
icon={<ShareIcon className="h-4 w-4" />}
|
icon={<ShareIcon className="h-4 w-4" />}
|
||||||
onClick={() => setDialog({ kind: "share", folder })}
|
onClick={() => setDialog({ kind: "share", folder })}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Renommer ${folder.name}`}
|
label={t("Renommer {name}", { name: folder.name })}
|
||||||
icon={<PenIcon className="h-4 w-4" />}
|
icon={<PenIcon className="h-4 w-4" />}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setDialog({
|
setDialog({
|
||||||
@@ -334,7 +400,7 @@ export const Browser = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Déplacer ${folder.name}`}
|
label={t("Déplacer {name}", { name: folder.name })}
|
||||||
icon={<MoveIcon className="h-4 w-4" />}
|
icon={<MoveIcon className="h-4 w-4" />}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setDialog({
|
setDialog({
|
||||||
@@ -344,7 +410,7 @@ export const Browser = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Supprimer ${folder.name}`}
|
label={t("Supprimer {name}", { name: folder.name })}
|
||||||
icon={<TrashIcon className="h-4 w-4" />}
|
icon={<TrashIcon className="h-4 w-4" />}
|
||||||
isLoading={removing === folder.id}
|
isLoading={removing === folder.id}
|
||||||
tone="danger"
|
tone="danger"
|
||||||
@@ -361,18 +427,21 @@ export const Browser = () => {
|
|||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{files.length > 0 ? (
|
{files.length > 0 ? (
|
||||||
<section aria-label="Fichiers">
|
<section aria-label={t("Fichiers")}>
|
||||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Fichiers
|
{t("Fichiers")}
|
||||||
</h2>
|
</h2>
|
||||||
|
{visibleFiles.length === 0 ? (
|
||||||
|
<p className="text-xs text-muted-foreground">{t("Rien à afficher pour ce filtre.")}</p>
|
||||||
|
) : (
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{files.map((file, index) => (
|
{visibleFiles.map((file, index) => (
|
||||||
<li key={file.id} className="flex items-center gap-2 px-3 py-2.5">
|
<li key={file.id} className="flex items-center gap-2 px-3 py-2.5">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setViewer(index)}
|
onClick={() => setViewer(index)}
|
||||||
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 transition-colors hover:border-border-strong focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
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 transition-colors hover:border-border-strong focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||||
aria-label={`Aperçu de ${file.name}`}
|
aria-label={t("Aperçu de {name}", { name: file.name })}
|
||||||
>
|
>
|
||||||
<MediaThumb id={file.id} mime={file.mime_type} name={file.name} />
|
<MediaThumb id={file.id} mime={file.mime_type} name={file.name} />
|
||||||
</button>
|
</button>
|
||||||
@@ -382,12 +451,16 @@ export const Browser = () => {
|
|||||||
</span>
|
</span>
|
||||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||||
{formatBytes(file.size_bytes)} ·{" "}
|
{formatBytes(file.size_bytes)} ·{" "}
|
||||||
{new Date(file.created_at).toLocaleDateString("fr-FR")}
|
{new Date(file.created_at).toLocaleDateString(getLocale())}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<IconAction
|
<IconAction
|
||||||
label={file.is_starred ? `Retirer l'étoile de ${file.name}` : `Étoiler ${file.name}`}
|
label={
|
||||||
|
file.is_starred
|
||||||
|
? t("Retirer l'étoile de {name}", { name: file.name })
|
||||||
|
: t("Étoiler {name}", { name: file.name })
|
||||||
|
}
|
||||||
icon={
|
icon={
|
||||||
<StarIcon className="h-4 w-4" {...(file.is_starred ? { filled: true } : {})} />
|
<StarIcon className="h-4 w-4" {...(file.is_starred ? { filled: true } : {})} />
|
||||||
}
|
}
|
||||||
@@ -400,13 +473,13 @@ export const Browser = () => {
|
|||||||
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"
|
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" />
|
<DownloadIcon className="h-3.5 w-3.5" />
|
||||||
<span className="hidden sm:inline">Télécharger</span>
|
<span className="hidden sm:inline">{t("Télécharger")}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{canWrite ? (
|
{canWrite ? (
|
||||||
<>
|
<>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Renommer ${file.name}`}
|
label={t("Renommer {name}", { name: file.name })}
|
||||||
icon={<PenIcon className="h-4 w-4" />}
|
icon={<PenIcon className="h-4 w-4" />}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setDialog({
|
setDialog({
|
||||||
@@ -416,7 +489,7 @@ export const Browser = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Déplacer ${file.name}`}
|
label={t("Déplacer {name}", { name: file.name })}
|
||||||
icon={<MoveIcon className="h-4 w-4" />}
|
icon={<MoveIcon className="h-4 w-4" />}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setDialog({
|
setDialog({
|
||||||
@@ -426,7 +499,7 @@ export const Browser = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Supprimer ${file.name}`}
|
label={t("Supprimer {name}", { name: file.name })}
|
||||||
icon={<TrashIcon className="h-4 w-4" />}
|
icon={<TrashIcon className="h-4 w-4" />}
|
||||||
isLoading={removing === file.id}
|
isLoading={removing === file.id}
|
||||||
tone="danger"
|
tone="danger"
|
||||||
@@ -439,6 +512,7 @@ export const Browser = () => {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -483,14 +557,14 @@ export const Browser = () => {
|
|||||||
|
|
||||||
{viewer !== null ? (
|
{viewer !== null ? (
|
||||||
<MediaViewer
|
<MediaViewer
|
||||||
items={files.map((item) => ({ id: item.id, name: item.name, mime_type: item.mime_type }))}
|
items={visibleFiles.map((item) => ({ id: item.id, name: item.name, mime_type: item.mime_type }))}
|
||||||
startIndex={viewer}
|
startIndex={viewer}
|
||||||
onClose={() => setViewer(null)}
|
onClose={() => setViewer(null)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{chat ? (
|
{chat ? (
|
||||||
<FolderChat key={chat.id} folder={chat} onClose={() => setChat(null)} />
|
<FolderChat key={chat.id} folder={chat} onClose={closeChat} />
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Inpu
|
|||||||
import { Alert } from "../components/feedback.js";
|
import { Alert } from "../components/feedback.js";
|
||||||
import { ApiError, api } from "../lib/api.js";
|
import { ApiError, api } from "../lib/api.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
export const ChangePassword = () => {
|
export const ChangePassword = () => {
|
||||||
const { user, refresh, logout } = useSession();
|
const { user, refresh, logout } = useSession();
|
||||||
|
const { t } = useI18n();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [current, setCurrent] = useState("");
|
const [current, setCurrent] = useState("");
|
||||||
const [next, setNext] = useState("");
|
const [next, setNext] = useState("");
|
||||||
@@ -17,7 +19,7 @@ export const ChangePassword = () => {
|
|||||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (next !== confirm) {
|
if (next !== confirm) {
|
||||||
setError("Les deux mots de passe ne correspondent pas.");
|
setError(t("Les deux mots de passe ne correspondent pas."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
@@ -27,7 +29,7 @@ export const ChangePassword = () => {
|
|||||||
await refresh();
|
await refresh();
|
||||||
navigate("/files", { replace: true });
|
navigate("/files", { replace: true });
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Changement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Changement impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
@@ -48,27 +50,26 @@ export const ChangePassword = () => {
|
|||||||
CoHaiSe
|
CoHaiSe
|
||||||
</p>
|
</p>
|
||||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||||
Nouveau mot de passe
|
{t("Nouveau mot de passe")}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
<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
|
{t("Bienvenue {name}. Ce mot de passe a été défini par un administrateur : choisissez le vôtre.", { name: user?.first_name ?? "" })}
|
||||||
administrateur : choisissez le vôtre.
|
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Changement requis</CardTitle>
|
<CardTitle>{t("Changement requis")}</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Les autres sessions ouvertes sur ce compte seront fermées.
|
{t("Les autres sessions ouvertes sur ce compte seront fermées.")}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Mot de passe actuel"
|
label={t("Mot de passe actuel")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
required
|
required
|
||||||
@@ -77,17 +78,17 @@ export const ChangePassword = () => {
|
|||||||
onChange={(event) => setCurrent(event.target.value)}
|
onChange={(event) => setCurrent(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Nouveau mot de passe"
|
label={t("Nouveau mot de passe")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
required
|
required
|
||||||
minLength={8}
|
minLength={8}
|
||||||
hint="8 caractères minimum."
|
hint={t("8 caractères minimum.")}
|
||||||
value={next}
|
value={next}
|
||||||
onChange={(event) => setNext(event.target.value)}
|
onChange={(event) => setNext(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Confirmation"
|
label={t("Confirmation")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
required
|
required
|
||||||
@@ -97,7 +98,7 @@ export const ChangePassword = () => {
|
|||||||
/>
|
/>
|
||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||||
Enregistrer
|
{t("Enregistrer")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -106,7 +107,7 @@ export const ChangePassword = () => {
|
|||||||
fullWidth
|
fullWidth
|
||||||
onClick={() => void logout()}
|
onClick={() => void logout()}
|
||||||
>
|
>
|
||||||
Se déconnecter
|
{t("Se déconnecter")}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import { Button, Card, CardContent, CardHeader, CardTitle, Spinner } from "../ui
|
|||||||
import { Alert } from "../components/feedback.js";
|
import { Alert } from "../components/feedback.js";
|
||||||
import { ApiError, api } from "../lib/api.js";
|
import { ApiError, api } from "../lib/api.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
export const ConfirmEmail = () => {
|
export const ConfirmEmail = () => {
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const token = params.get("token") ?? "";
|
const token = params.get("token") ?? "";
|
||||||
const { refresh } = useSession();
|
const { refresh } = useSession();
|
||||||
|
const { t } = useI18n();
|
||||||
const [state, setState] = useState<"loading" | "success" | "error">("loading");
|
const [state, setState] = useState<"loading" | "success" | "error">("loading");
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const started = useRef(false);
|
const started = useRef(false);
|
||||||
@@ -18,7 +20,7 @@ export const ConfirmEmail = () => {
|
|||||||
started.current = true;
|
started.current = true;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
setState("error");
|
setState("error");
|
||||||
setError("Ce lien est incomplet ou invalide.");
|
setError(t("Ce lien est incomplet ou invalide."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
api
|
api
|
||||||
@@ -29,7 +31,7 @@ export const ConfirmEmail = () => {
|
|||||||
})
|
})
|
||||||
.catch((caught: unknown) => {
|
.catch((caught: unknown) => {
|
||||||
setState("error");
|
setState("error");
|
||||||
setError(caught instanceof ApiError ? caught.message : "Confirmation impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Confirmation impossible."));
|
||||||
});
|
});
|
||||||
}, [token, refresh]);
|
}, [token, refresh]);
|
||||||
|
|
||||||
@@ -48,7 +50,7 @@ export const ConfirmEmail = () => {
|
|||||||
CoHaiSe
|
CoHaiSe
|
||||||
</p>
|
</p>
|
||||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||||
Changement d'adresse
|
{t("Changement d'adresse")}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -56,7 +58,7 @@ export const ConfirmEmail = () => {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Confirmation</CardTitle>
|
<CardTitle>{t("Confirmation")}</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-4">
|
<CardContent className="flex flex-col gap-4">
|
||||||
{state === "loading" ? (
|
{state === "loading" ? (
|
||||||
@@ -65,10 +67,10 @@ export const ConfirmEmail = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : state === "success" ? (
|
) : state === "success" ? (
|
||||||
<>
|
<>
|
||||||
<Alert tone="success">Votre adresse e-mail a été mise à jour.</Alert>
|
<Alert tone="success">{t("Votre adresse e-mail a été mise à jour.")}</Alert>
|
||||||
<Link to="/files">
|
<Link to="/files">
|
||||||
<Button size="lg" fullWidth>
|
<Button size="lg" fullWidth>
|
||||||
Accéder à mes fichiers
|
{t("Accéder à mes fichiers")}
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</>
|
</>
|
||||||
@@ -77,7 +79,7 @@ export const ConfirmEmail = () => {
|
|||||||
<Alert>{error}</Alert>
|
<Alert>{error}</Alert>
|
||||||
<Link to="/profile">
|
<Link to="/profile">
|
||||||
<Button size="lg" fullWidth>
|
<Button size="lg" fullWidth>
|
||||||
Mon compte
|
{t("Mon compte")}
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import { MediaViewer } from "../components/MediaViewer.js";
|
|||||||
import { MediaThumb } from "../components/MediaThumb.js";
|
import { MediaThumb } from "../components/MediaThumb.js";
|
||||||
import { IconAction } from "../components/IconAction.js";
|
import { IconAction } from "../components/IconAction.js";
|
||||||
import { DownloadIcon, FolderIcon, StarIcon } from "../components/icons.js";
|
import { DownloadIcon, FolderIcon, StarIcon } from "../components/icons.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
export const Favorites = () => {
|
export const Favorites = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [files, setFiles] = useState<FavoriteFile[]>([]);
|
const [files, setFiles] = useState<FavoriteFile[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -22,7 +24,7 @@ export const Favorites = () => {
|
|||||||
setError(null);
|
setError(null);
|
||||||
})
|
})
|
||||||
.catch((caught: unknown) => {
|
.catch((caught: unknown) => {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
setFiles([]);
|
setFiles([]);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
@@ -34,15 +36,15 @@ export const Favorites = () => {
|
|||||||
await api.starFile(file.id);
|
await api.starFile(file.id);
|
||||||
setFiles((previous) => previous.filter((item) => item.id !== file.id));
|
setFiles((previous) => previous.filter((item) => item.id !== file.id));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Action impossible."));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Favoris"
|
title={t("Favoris")}
|
||||||
description="Les fichiers que vous avez étoilés, tous dossiers confondus."
|
description={t("Les fichiers que vous avez étoilés, tous dossiers confondus.")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
@@ -54,8 +56,8 @@ export const Favorites = () => {
|
|||||||
) : files.length === 0 ? (
|
) : files.length === 0 ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={<StarIcon className="h-8 w-8" />}
|
icon={<StarIcon className="h-8 w-8" />}
|
||||||
title="Aucun favori"
|
title={t("Aucun favori")}
|
||||||
description="Étoilez un fichier dans l'explorateur pour le retrouver ici."
|
description={t("Étoilez un fichier dans l'explorateur pour le retrouver ici.")}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
@@ -65,7 +67,7 @@ export const Favorites = () => {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={() => setViewer(index)}
|
onClick={() => setViewer(index)}
|
||||||
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 transition-colors hover:border-border-strong focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
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 transition-colors hover:border-border-strong focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||||
aria-label={`Aperçu de ${file.name}`}
|
aria-label={t("Aperçu de {name}", { name: file.name })}
|
||||||
>
|
>
|
||||||
<MediaThumb id={file.id} mime={file.mime_type} name={file.name} />
|
<MediaThumb id={file.id} mime={file.mime_type} name={file.name} />
|
||||||
</button>
|
</button>
|
||||||
@@ -75,14 +77,14 @@ export const Favorites = () => {
|
|||||||
</span>
|
</span>
|
||||||
<span className="flex items-center gap-1.5 text-[0.6875rem] text-subtle-foreground">
|
<span className="flex items-center gap-1.5 text-[0.6875rem] text-subtle-foreground">
|
||||||
<FolderIcon className="h-3 w-3 shrink-0" />
|
<FolderIcon className="h-3 w-3 shrink-0" />
|
||||||
<span className="truncate">{file.folder_name ?? "Racine"}</span>
|
<span className="truncate">{file.folder_name ?? t("Racine")}</span>
|
||||||
<span aria-hidden="true">·</span>
|
<span aria-hidden="true">·</span>
|
||||||
<span className="shrink-0">{formatBytes(file.size_bytes)}</span>
|
<span className="shrink-0">{formatBytes(file.size_bytes)}</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Retirer l'étoile de ${file.name}`}
|
label={t("Retirer l'étoile de {name}", { name: file.name })}
|
||||||
icon={<StarIcon className="h-4 w-4" filled />}
|
icon={<StarIcon className="h-4 w-4" filled />}
|
||||||
onClick={() => void unstar(file)}
|
onClick={() => void unstar(file)}
|
||||||
/>
|
/>
|
||||||
@@ -93,7 +95,7 @@ export const Favorites = () => {
|
|||||||
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"
|
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" />
|
<DownloadIcon className="h-3.5 w-3.5" />
|
||||||
<span className="hidden sm:inline">Télécharger</span>
|
<span className="hidden sm:inline">{t("Télécharger")}</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ import { Link } from "react-router-dom";
|
|||||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||||
import { Alert } from "../components/feedback.js";
|
import { Alert } from "../components/feedback.js";
|
||||||
import { ApiError, api } from "../lib/api.js";
|
import { ApiError, api } from "../lib/api.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
export const ForgotPassword = () => {
|
export const ForgotPassword = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [sent, setSent] = useState(false);
|
const [sent, setSent] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -18,7 +20,7 @@ export const ForgotPassword = () => {
|
|||||||
await api.forgotPassword(email);
|
await api.forgotPassword(email);
|
||||||
setSent(true);
|
setSent(true);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Demande impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Demande impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
@@ -39,7 +41,7 @@ export const ForgotPassword = () => {
|
|||||||
CoHaiSe
|
CoHaiSe
|
||||||
</p>
|
</p>
|
||||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||||
Mot de passe oublié
|
{t("Mot de passe oublié")}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -47,23 +49,22 @@ export const ForgotPassword = () => {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Réinitialisation</CardTitle>
|
<CardTitle>{t("Réinitialisation")}</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Nous vous enverrons un lien valable une heure.
|
{t("Nous vous enverrons un lien valable une heure.")}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{sent ? (
|
{sent ? (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Alert tone="success">
|
<Alert tone="success">
|
||||||
Si cette adresse correspond à un compte, un message contenant le lien de
|
{t("Si cette adresse correspond à un compte, un message contenant le lien de réinitialisation vient d'être envoyé.")}
|
||||||
réinitialisation vient d'être envoyé.
|
|
||||||
</Alert>
|
</Alert>
|
||||||
<Link
|
<Link
|
||||||
to="/login"
|
to="/login"
|
||||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
Retour à la connexion
|
{t("Retour à la connexion")}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -72,7 +73,7 @@ export const ForgotPassword = () => {
|
|||||||
onSubmit={(event) => void submit(event)}
|
onSubmit={(event) => void submit(event)}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
label="Adresse e-mail"
|
label={t("Adresse e-mail")}
|
||||||
type="email"
|
type="email"
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
required
|
required
|
||||||
@@ -82,13 +83,13 @@ export const ForgotPassword = () => {
|
|||||||
/>
|
/>
|
||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||||
Envoyer le lien
|
{t("Envoyer le lien")}
|
||||||
</Button>
|
</Button>
|
||||||
<Link
|
<Link
|
||||||
to="/login"
|
to="/login"
|
||||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
Retour à la connexion
|
{t("Retour à la connexion")}
|
||||||
</Link>
|
</Link>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
|||||||
import { MediaViewer } from "../components/MediaViewer.js";
|
import { MediaViewer } from "../components/MediaViewer.js";
|
||||||
import { MediaThumb } from "../components/MediaThumb.js";
|
import { MediaThumb } from "../components/MediaThumb.js";
|
||||||
import { ImageIcon } from "../components/icons.js";
|
import { ImageIcon } from "../components/icons.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
const KINDS = [
|
const KINDS = [
|
||||||
{ value: "", label: "Tout" },
|
{ value: "", label: "Tout" },
|
||||||
@@ -19,6 +20,7 @@ const KINDS = [
|
|||||||
const PAGE = 60;
|
const PAGE = 60;
|
||||||
|
|
||||||
export const Gallery = () => {
|
export const Gallery = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [kind, setKind] = useState<string>("image");
|
const [kind, setKind] = useState<string>("image");
|
||||||
const [items, setItems] = useState<MediaItem[]>([]);
|
const [items, setItems] = useState<MediaItem[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -35,7 +37,7 @@ export const Gallery = () => {
|
|||||||
setError(null);
|
setError(null);
|
||||||
})
|
})
|
||||||
.catch((caught: unknown) => {
|
.catch((caught: unknown) => {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
setItems([]);
|
setItems([]);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
@@ -48,7 +50,7 @@ export const Gallery = () => {
|
|||||||
const { items: more } = await api.gallery(kind, PAGE, items.length);
|
const { items: more } = await api.gallery(kind, PAGE, items.length);
|
||||||
setItems((previous) => [...previous, ...more]);
|
setItems((previous) => [...previous, ...more]);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingMore(false);
|
setLoadingMore(false);
|
||||||
}
|
}
|
||||||
@@ -57,10 +59,10 @@ export const Gallery = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Galerie"
|
title={t("Galerie")}
|
||||||
description="Parcourez les médias auxquels vous avez accès."
|
description={t("Parcourez les médias auxquels vous avez accès.")}
|
||||||
toolbar={
|
toolbar={
|
||||||
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label="Filtrer par type">
|
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label={t("Filtrer par type")}>
|
||||||
{KINDS.map((option) => (
|
{KINDS.map((option) => (
|
||||||
<button
|
<button
|
||||||
key={option.value}
|
key={option.value}
|
||||||
@@ -78,7 +80,7 @@ export const Gallery = () => {
|
|||||||
: "border-border-control text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
: "border-border-control text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{option.label}
|
{t(option.label)}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -94,8 +96,8 @@ export const Gallery = () => {
|
|||||||
) : items.length === 0 ? (
|
) : items.length === 0 ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={<ImageIcon className="h-8 w-8" />}
|
icon={<ImageIcon className="h-8 w-8" />}
|
||||||
title="Aucun média"
|
title={t("Aucun média")}
|
||||||
description="Rien à afficher pour ce filtre."
|
description={t("Rien à afficher pour ce filtre.")}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@@ -131,7 +133,7 @@ export const Gallery = () => {
|
|||||||
{items.length >= PAGE ? (
|
{items.length >= PAGE ? (
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<Button variant="secondary" size="md" isLoading={loadingMore} onClick={() => void loadMore()}>
|
<Button variant="secondary" size="md" isLoading={loadingMore} onClick={() => void loadMore()}>
|
||||||
Charger plus
|
{t("Charger plus")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ import { Link, Navigate, useNavigate } from "react-router-dom";
|
|||||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||||
import { ApiError, api } from "../lib/api.js";
|
import { ApiError, api } from "../lib/api.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
export const Login = () => {
|
export const Login = () => {
|
||||||
const { user, setUser } = useSession();
|
const { user, setUser } = useSession();
|
||||||
|
const { t } = useI18n();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
@@ -23,7 +25,7 @@ export const Login = () => {
|
|||||||
setUser(current);
|
setUser(current);
|
||||||
navigate(current.must_change_password ? "/change-password" : "/files", { replace: true });
|
navigate(current.must_change_password ? "/change-password" : "/files", { replace: true });
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Connexion impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Connexion impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
@@ -49,19 +51,19 @@ export const Login = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||||
Connectez-vous pour accéder à vos fichiers.
|
{t("Connectez-vous pour accéder à vos fichiers.")}
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Connexion</CardTitle>
|
<CardTitle>{t("Connexion")}</CardTitle>
|
||||||
<CardDescription>Votre session reste ouverte 14 jours.</CardDescription>
|
<CardDescription>{t("Votre session reste ouverte 14 jours.")}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Adresse e-mail"
|
label={t("Adresse e-mail")}
|
||||||
type="email"
|
type="email"
|
||||||
autoComplete="username"
|
autoComplete="username"
|
||||||
required
|
required
|
||||||
@@ -70,7 +72,7 @@ export const Login = () => {
|
|||||||
onChange={(event) => setEmail(event.target.value)}
|
onChange={(event) => setEmail(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Mot de passe"
|
label={t("Mot de passe")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
required
|
required
|
||||||
@@ -80,7 +82,7 @@ export const Login = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||||
Se connecter
|
{t("Se connecter")}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -91,7 +93,7 @@ export const Login = () => {
|
|||||||
to="/forgot-password"
|
to="/forgot-password"
|
||||||
className="underline-offset-2 hover:text-foreground hover:underline"
|
className="underline-offset-2 hover:text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
Mot de passe oublié ?
|
{t("Mot de passe oublié ?")}
|
||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+132
-42
@@ -1,13 +1,26 @@
|
|||||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Spinner } from "../ui/index.js";
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Spinner } from "../ui/index.js";
|
||||||
import { ApiError, api, formatDate, type SessionInfo } from "../lib/api.js";
|
import { ApiError, api, formatDate, type Language, type SessionInfo, type Theme } from "../lib/api.js";
|
||||||
import { useSession } from "../lib/session.js";
|
import { useSession } from "../lib/session.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
import { Alert, Badge, PageHeader } from "../components/feedback.js";
|
import { Alert, Badge, PageHeader } from "../components/feedback.js";
|
||||||
import { useConfirm } from "../components/confirm.js";
|
import { useConfirm } from "../components/confirm.js";
|
||||||
import { TrashIcon } from "../components/icons.js";
|
import { TrashIcon } from "../components/icons.js";
|
||||||
|
|
||||||
|
const THEMES: { value: Theme; label: string }[] = [
|
||||||
|
{ value: "system", label: "Système" },
|
||||||
|
{ value: "light", label: "Clair" },
|
||||||
|
{ value: "dark", label: "Sombre" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const LANGUAGES: { value: Language; label: string }[] = [
|
||||||
|
{ value: "fr", label: "Français" },
|
||||||
|
{ value: "en", label: "English" },
|
||||||
|
];
|
||||||
|
|
||||||
export const Profile = () => {
|
export const Profile = () => {
|
||||||
const { user, refresh } = useSession();
|
const { user, refresh } = useSession();
|
||||||
|
const { t } = useI18n();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
|
|
||||||
const [firstName, setFirstName] = useState(user?.first_name ?? "");
|
const [firstName, setFirstName] = useState(user?.first_name ?? "");
|
||||||
@@ -16,7 +29,12 @@ export const Profile = () => {
|
|||||||
const [profileError, setProfileError] = useState<string | null>(null);
|
const [profileError, setProfileError] = useState<string | null>(null);
|
||||||
const [savingProfile, setSavingProfile] = useState(false);
|
const [savingProfile, setSavingProfile] = useState(false);
|
||||||
|
|
||||||
const [avatarNonce, setAvatarNonce] = useState(0);
|
const [theme, setTheme] = useState<Theme>(user?.theme ?? "system");
|
||||||
|
const [language, setLanguage] = useState<Language>(user?.language ?? "fr");
|
||||||
|
const [prefMessage, setPrefMessage] = useState<string | null>(null);
|
||||||
|
const [prefError, setPrefError] = useState<string | null>(null);
|
||||||
|
const [savingPrefs, setSavingPrefs] = useState(false);
|
||||||
|
|
||||||
const [avatarError, setAvatarError] = useState<string | null>(null);
|
const [avatarError, setAvatarError] = useState<string | null>(null);
|
||||||
const avatarInput = useRef<HTMLInputElement>(null);
|
const avatarInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
@@ -34,6 +52,8 @@ export const Profile = () => {
|
|||||||
if (user) {
|
if (user) {
|
||||||
setFirstName((current) => (current === "" ? user.first_name : current));
|
setFirstName((current) => (current === "" ? user.first_name : current));
|
||||||
setLastName((current) => (current === "" ? user.last_name : current));
|
setLastName((current) => (current === "" ? user.last_name : current));
|
||||||
|
setTheme(user.theme);
|
||||||
|
setLanguage(user.language);
|
||||||
}
|
}
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
@@ -43,13 +63,14 @@ export const Profile = () => {
|
|||||||
const { sessions: list } = await api.sessions();
|
const { sessions: list } = await api.sessions();
|
||||||
setSessions(list);
|
setSessions(list);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setSessionsError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setSessionsError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
setSessions([]);
|
setSessions([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadSessions();
|
void loadSessions();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const saveProfile = async (event: FormEvent<HTMLFormElement>) => {
|
const saveProfile = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
@@ -60,14 +81,30 @@ export const Profile = () => {
|
|||||||
try {
|
try {
|
||||||
await api.updateProfile(firstName.trim(), lastName.trim());
|
await api.updateProfile(firstName.trim(), lastName.trim());
|
||||||
await refresh();
|
await refresh();
|
||||||
setProfileMessage("Informations enregistrées.");
|
setProfileMessage(t("Informations enregistrées."));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setProfileError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
setProfileError(caught instanceof ApiError ? caught.message : t("Enregistrement impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setSavingProfile(false);
|
setSavingProfile(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const savePreferences = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
setSavingPrefs(true);
|
||||||
|
setPrefError(null);
|
||||||
|
setPrefMessage(null);
|
||||||
|
try {
|
||||||
|
await api.updatePreferences(theme, language);
|
||||||
|
await refresh();
|
||||||
|
setPrefMessage(t("Préférences enregistrées."));
|
||||||
|
} catch (caught) {
|
||||||
|
setPrefError(caught instanceof ApiError ? caught.message : t("Enregistrement impossible."));
|
||||||
|
} finally {
|
||||||
|
setSavingPrefs(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const requestEmail = async (event: FormEvent<HTMLFormElement>) => {
|
const requestEmail = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setSendingEmail(true);
|
setSendingEmail(true);
|
||||||
@@ -77,9 +114,9 @@ export const Profile = () => {
|
|||||||
await api.requestEmailChange(password, newEmail.trim());
|
await api.requestEmailChange(password, newEmail.trim());
|
||||||
setPassword("");
|
setPassword("");
|
||||||
setNewEmail("");
|
setNewEmail("");
|
||||||
setEmailMessage("Un e-mail de confirmation a été envoyé à la nouvelle adresse.");
|
setEmailMessage(t("Un e-mail de confirmation a été envoyé à la nouvelle adresse."));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setEmailError(caught instanceof ApiError ? caught.message : "Demande impossible.");
|
setEmailError(caught instanceof ApiError ? caught.message : t("Demande impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setSendingEmail(false);
|
setSendingEmail(false);
|
||||||
}
|
}
|
||||||
@@ -90,10 +127,9 @@ export const Profile = () => {
|
|||||||
setAvatarError(null);
|
setAvatarError(null);
|
||||||
try {
|
try {
|
||||||
await api.uploadAvatar(file);
|
await api.uploadAvatar(file);
|
||||||
setAvatarNonce((value) => value + 1);
|
|
||||||
await refresh();
|
await refresh();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
setAvatarError(caught instanceof ApiError ? caught.message : t("Envoi impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
if (avatarInput.current) avatarInput.current.value = "";
|
if (avatarInput.current) avatarInput.current.value = "";
|
||||||
}
|
}
|
||||||
@@ -103,19 +139,18 @@ export const Profile = () => {
|
|||||||
setAvatarError(null);
|
setAvatarError(null);
|
||||||
try {
|
try {
|
||||||
await api.deleteAvatar();
|
await api.deleteAvatar();
|
||||||
setAvatarNonce((value) => value + 1);
|
|
||||||
await refresh();
|
await refresh();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
setAvatarError(caught instanceof ApiError ? caught.message : t("Suppression impossible."));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const revokeSession = async (session: SessionInfo) => {
|
const revokeSession = async (session: SessionInfo) => {
|
||||||
if (session.current) {
|
if (session.current) {
|
||||||
const ok = await confirm({
|
const ok = await confirm({
|
||||||
title: "Fermer la session",
|
title: t("Fermer la session"),
|
||||||
message: "Fermer la session en cours vous déconnectera immédiatement.",
|
message: t("Fermer la session en cours vous déconnectera immédiatement."),
|
||||||
confirmLabel: "Fermer",
|
confirmLabel: t("Fermer"),
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
}
|
}
|
||||||
@@ -129,7 +164,7 @@ export const Profile = () => {
|
|||||||
}
|
}
|
||||||
setSessions((previous) => (previous ?? []).filter((item) => item.id !== session.id));
|
setSessions((previous) => (previous ?? []).filter((item) => item.id !== session.id));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setSessionsError(caught instanceof ApiError ? caught.message : "Révocation impossible.");
|
setSessionsError(caught instanceof ApiError ? caught.message : t("Révocation impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setRevoking(null);
|
setRevoking(null);
|
||||||
}
|
}
|
||||||
@@ -141,7 +176,7 @@ export const Profile = () => {
|
|||||||
await api.revokeOtherSessions();
|
await api.revokeOtherSessions();
|
||||||
setSessions((previous) => (previous ?? []).filter((item) => item.current));
|
setSessions((previous) => (previous ?? []).filter((item) => item.current));
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setSessionsError(caught instanceof ApiError ? caught.message : "Révocation impossible.");
|
setSessionsError(caught instanceof ApiError ? caught.message : t("Révocation impossible."));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -155,25 +190,78 @@ export const Profile = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
<PageHeader title="Mon compte" description="Profil, photo, adresse e-mail et sessions ouvertes." />
|
<PageHeader title={t("Mon compte")} description={t("Profil, photo, adresse e-mail et sessions ouvertes.")} />
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>{t("Préférences")}</CardTitle>
|
||||||
|
<CardDescription>{t("Apparence et langue de l'interface.")}</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<form className="flex flex-col gap-4" onSubmit={(event) => void savePreferences(event)}>
|
||||||
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
|
<label className="flex flex-col gap-1.5">
|
||||||
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
|
{t("Thème")}
|
||||||
|
</span>
|
||||||
|
<select
|
||||||
|
value={theme}
|
||||||
|
onChange={(event) => setTheme(event.target.value as Theme)}
|
||||||
|
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"
|
||||||
|
>
|
||||||
|
{THEMES.map((option) => (
|
||||||
|
<option key={option.value} value={option.value}>
|
||||||
|
{t(option.label)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label className="flex flex-col gap-1.5">
|
||||||
|
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||||
|
{t("Langue")}
|
||||||
|
</span>
|
||||||
|
<select
|
||||||
|
value={language}
|
||||||
|
onChange={(event) => setLanguage(event.target.value as Language)}
|
||||||
|
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"
|
||||||
|
>
|
||||||
|
{LANGUAGES.map((option) => (
|
||||||
|
<option key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{prefError ? <Alert>{prefError}</Alert> : null}
|
||||||
|
{prefMessage ? <Alert tone="success">{prefMessage}</Alert> : null}
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<Button type="submit" size="md" isLoading={savingPrefs}>
|
||||||
|
{t("Enregistrer")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Identité</CardTitle>
|
<CardTitle>{t("Identité")}</CardTitle>
|
||||||
<CardDescription>Informations affichées dans l'interface.</CardDescription>
|
<CardDescription>{t("Informations affichées dans l'interface.")}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void saveProfile(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void saveProfile(event)}>
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
<Input
|
<Input
|
||||||
label="Prénom"
|
label={t("Prénom")}
|
||||||
required
|
required
|
||||||
maxLength={255}
|
maxLength={255}
|
||||||
value={firstName}
|
value={firstName}
|
||||||
onChange={(event) => setFirstName(event.target.value)}
|
onChange={(event) => setFirstName(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Nom"
|
label={t("Nom")}
|
||||||
required
|
required
|
||||||
maxLength={255}
|
maxLength={255}
|
||||||
value={lastName}
|
value={lastName}
|
||||||
@@ -184,7 +272,7 @@ export const Profile = () => {
|
|||||||
{profileMessage ? <Alert tone="success">{profileMessage}</Alert> : null}
|
{profileMessage ? <Alert tone="success">{profileMessage}</Alert> : null}
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button type="submit" size="md" isLoading={savingProfile}>
|
<Button type="submit" size="md" isLoading={savingProfile}>
|
||||||
Enregistrer
|
{t("Enregistrer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -193,14 +281,14 @@ export const Profile = () => {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Photo de profil</CardTitle>
|
<CardTitle>{t("Photo de profil")}</CardTitle>
|
||||||
<CardDescription>Image carrée, format PNG ou JPEG.</CardDescription>
|
<CardDescription>{t("Image carrée, format PNG ou JPEG.")}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-4">
|
<CardContent className="flex flex-col gap-4">
|
||||||
<div className="flex items-center 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">
|
<span className="flex h-16 w-16 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface-muted">
|
||||||
<img
|
<img
|
||||||
src={`${api.avatarUrl(user.id)}?v=${avatarNonce}`}
|
src={`${api.avatarUrl(user.id)}?v=${user.avatar_updated_at ?? ""}`}
|
||||||
alt=""
|
alt=""
|
||||||
className="h-full w-full object-cover"
|
className="h-full w-full object-cover"
|
||||||
onError={(event) => {
|
onError={(event) => {
|
||||||
@@ -218,14 +306,14 @@ export const Profile = () => {
|
|||||||
/>
|
/>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button variant="secondary" size="sm" onClick={() => avatarInput.current?.click()}>
|
<Button variant="secondary" size="sm" onClick={() => avatarInput.current?.click()}>
|
||||||
Choisir une image
|
{t("Choisir une image")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" onClick={() => void removeAvatar()}>
|
<Button variant="ghost" size="sm" onClick={() => void removeAvatar()}>
|
||||||
Retirer
|
{t("Retirer")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-[0.6875rem] text-subtle-foreground">
|
<p className="text-[0.6875rem] text-subtle-foreground">
|
||||||
Si aucune image n'est définie, vos initiales sont affichées.
|
{t("Si aucune image n'est définie, vos initiales sont affichées.")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -235,21 +323,21 @@ export const Profile = () => {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Adresse e-mail</CardTitle>
|
<CardTitle>{t("Adresse e-mail")}</CardTitle>
|
||||||
<CardDescription>Adresse actuelle : {user.email}</CardDescription>
|
<CardDescription>{t("Adresse actuelle : {email}", { email: user.email })}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void requestEmail(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void requestEmail(event)}>
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
<Input
|
<Input
|
||||||
label="Nouvelle adresse"
|
label={t("Nouvelle adresse")}
|
||||||
type="email"
|
type="email"
|
||||||
required
|
required
|
||||||
value={newEmail}
|
value={newEmail}
|
||||||
onChange={(event) => setNewEmail(event.target.value)}
|
onChange={(event) => setNewEmail(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Mot de passe actuel"
|
label={t("Mot de passe actuel")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
required
|
required
|
||||||
@@ -261,17 +349,17 @@ export const Profile = () => {
|
|||||||
{emailMessage ? <Alert tone="success">{emailMessage}</Alert> : null}
|
{emailMessage ? <Alert tone="success">{emailMessage}</Alert> : null}
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button type="submit" size="md" isLoading={sendingEmail}>
|
<Button type="submit" size="md" isLoading={sendingEmail}>
|
||||||
Demander le changement
|
{t("Demander le changement")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card className="lg:col-span-2">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Sessions ouvertes</CardTitle>
|
<CardTitle>{t("Sessions ouvertes")}</CardTitle>
|
||||||
<CardDescription>Appareils actuellement connectés à votre compte.</CardDescription>
|
<CardDescription>{t("Appareils actuellement connectés à votre compte.")}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-4">
|
<CardContent className="flex flex-col gap-4">
|
||||||
{sessionsError ? <Alert>{sessionsError}</Alert> : null}
|
{sessionsError ? <Alert>{sessionsError}</Alert> : null}
|
||||||
@@ -280,7 +368,7 @@ export const Profile = () => {
|
|||||||
<Spinner size="sm" />
|
<Spinner size="sm" />
|
||||||
</div>
|
</div>
|
||||||
) : sessions.length === 0 ? (
|
) : sessions.length === 0 ? (
|
||||||
<p className="text-xs text-muted-foreground">Aucune session active.</p>
|
<p className="text-xs text-muted-foreground">{t("Aucune session active.")}</p>
|
||||||
) : (
|
) : (
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-md border border-border">
|
<ul className="flex flex-col divide-y divide-border rounded-md border border-border">
|
||||||
{sessions.map((session) => (
|
{sessions.map((session) => (
|
||||||
@@ -288,17 +376,18 @@ export const Profile = () => {
|
|||||||
<span className="min-w-0 flex-1">
|
<span className="min-w-0 flex-1">
|
||||||
<span className="flex items-center gap-2">
|
<span className="flex items-center gap-2">
|
||||||
<span className="truncate text-xs font-medium text-foreground">
|
<span className="truncate text-xs font-medium text-foreground">
|
||||||
{session.user_agent ? session.user_agent.slice(0, 60) : "Appareil inconnu"}
|
{session.user_agent ? session.user_agent.slice(0, 60) : t("Appareil inconnu")}
|
||||||
</span>
|
</span>
|
||||||
{session.current ? <Badge tone="accent">Cette session</Badge> : null}
|
{session.current ? <Badge tone="accent">{t("Cette session")}</Badge> : null}
|
||||||
</span>
|
</span>
|
||||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||||
{session.ip_address ?? "IP inconnue"} · vue le {formatDate(session.last_seen_at)}
|
{session.ip_address ?? t("IP inconnue")} ·{" "}
|
||||||
|
{t("vue le {date}", { date: formatDate(session.last_seen_at) })}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Fermer cette session"
|
aria-label={t("Fermer cette session")}
|
||||||
disabled={revoking === session.id}
|
disabled={revoking === session.id}
|
||||||
onClick={() => void revokeSession(session)}
|
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"
|
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-destructive disabled:opacity-50"
|
||||||
@@ -317,11 +406,12 @@ export const Profile = () => {
|
|||||||
disabled={sessions === null || sessions.length <= 1}
|
disabled={sessions === null || sessions.length <= 1}
|
||||||
onClick={() => void revokeOthers()}
|
onClick={() => void revokeOthers()}
|
||||||
>
|
>
|
||||||
Fermer les autres sessions
|
{t("Fermer les autres sessions")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ import { Link, useSearchParams } from "react-router-dom";
|
|||||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||||
import { Alert } from "../components/feedback.js";
|
import { Alert } from "../components/feedback.js";
|
||||||
import { ApiError, api } from "../lib/api.js";
|
import { ApiError, api } from "../lib/api.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
export const ResetPassword = () => {
|
export const ResetPassword = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const token = params.get("token") ?? "";
|
const token = params.get("token") ?? "";
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
@@ -16,7 +18,7 @@ export const ResetPassword = () => {
|
|||||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (password !== confirm) {
|
if (password !== confirm) {
|
||||||
setError("Les deux mots de passe ne correspondent pas.");
|
setError(t("Les deux mots de passe ne correspondent pas."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
@@ -25,7 +27,7 @@ export const ResetPassword = () => {
|
|||||||
await api.resetPassword(token, password);
|
await api.resetPassword(token, password);
|
||||||
setDone(true);
|
setDone(true);
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Réinitialisation impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Réinitialisation impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,7 @@ export const ResetPassword = () => {
|
|||||||
CoHaiSe
|
CoHaiSe
|
||||||
</p>
|
</p>
|
||||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||||
Nouveau mot de passe
|
{t("Nouveau mot de passe")}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,46 +56,46 @@ export const ResetPassword = () => {
|
|||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Réinitialisation</CardTitle>
|
<CardTitle>{t("Réinitialisation")}</CardTitle>
|
||||||
<CardDescription>Choisissez un mot de passe robuste.</CardDescription>
|
<CardDescription>{t("Choisissez un mot de passe robuste.")}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{!token ? (
|
{!token ? (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Alert>Ce lien est incomplet ou invalide.</Alert>
|
<Alert>{t("Ce lien est incomplet ou invalide.")}</Alert>
|
||||||
<Link
|
<Link
|
||||||
to="/forgot-password"
|
to="/forgot-password"
|
||||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
Demander un nouveau lien
|
{t("Demander un nouveau lien")}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
) : done ? (
|
) : done ? (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Alert tone="success">
|
<Alert tone="success">
|
||||||
Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.
|
{t("Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.")}
|
||||||
</Alert>
|
</Alert>
|
||||||
<Link to="/login">
|
<Link to="/login">
|
||||||
<Button size="lg" fullWidth>
|
<Button size="lg" fullWidth>
|
||||||
Se connecter
|
{t("Se connecter")}
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||||
<Input
|
<Input
|
||||||
label="Nouveau mot de passe"
|
label={t("Nouveau mot de passe")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
required
|
required
|
||||||
minLength={8}
|
minLength={8}
|
||||||
autoFocus
|
autoFocus
|
||||||
hint="8 caractères minimum."
|
hint={t("8 caractères minimum.")}
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(event) => setPassword(event.target.value)}
|
onChange={(event) => setPassword(event.target.value)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Confirmation"
|
label={t("Confirmation")}
|
||||||
type="password"
|
type="password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
required
|
required
|
||||||
@@ -103,7 +105,7 @@ export const ResetPassword = () => {
|
|||||||
/>
|
/>
|
||||||
{error ? <Alert>{error}</Alert> : null}
|
{error ? <Alert>{error}</Alert> : null}
|
||||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||||
Réinitialiser
|
{t("Réinitialiser")}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Button, Input, Spinner } from "../ui/index.js";
|
|||||||
import { ApiError, api, formatBytes, type Folder, type UploadedFile } from "../lib/api.js";
|
import { ApiError, api, formatBytes, type Folder, type UploadedFile } from "../lib/api.js";
|
||||||
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||||
import { DownloadIcon, FileIcon, FolderIcon, SearchIcon } from "../components/icons.js";
|
import { DownloadIcon, FileIcon, FolderIcon, SearchIcon } from "../components/icons.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
interface Results {
|
interface Results {
|
||||||
folders: Folder[];
|
folders: Folder[];
|
||||||
@@ -10,6 +11,7 @@ interface Results {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Search = () => {
|
export const Search = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const [q, setQ] = useState("");
|
const [q, setQ] = useState("");
|
||||||
const [results, setResults] = useState<Results | null>(null);
|
const [results, setResults] = useState<Results | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -19,7 +21,7 @@ export const Search = () => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const query = q.trim();
|
const query = q.trim();
|
||||||
if (query.length < 2) {
|
if (query.length < 2) {
|
||||||
setError("Saisissez au moins deux caractères.");
|
setError(t("Saisissez au moins deux caractères."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -28,7 +30,7 @@ export const Search = () => {
|
|||||||
const { folders, files } = await api.search(query);
|
const { folders, files } = await api.search(query);
|
||||||
setResults({ folders, files });
|
setResults({ folders, files });
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Recherche impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Recherche impossible."));
|
||||||
setResults(null);
|
setResults(null);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -40,16 +42,16 @@ export const Search = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Recherche"
|
title={t("Recherche")}
|
||||||
description="Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès."
|
description={t("Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès.")}
|
||||||
toolbar={
|
toolbar={
|
||||||
<form className="flex items-end gap-2" onSubmit={(event) => void submit(event)}>
|
<form className="flex items-end gap-2" onSubmit={(event) => void submit(event)}>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Input
|
<Input
|
||||||
label="Terme recherché"
|
label={t("Terme recherché")}
|
||||||
type="search"
|
type="search"
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder="facture, rapport…"
|
placeholder={t("facture, rapport…")}
|
||||||
value={q}
|
value={q}
|
||||||
onChange={(event) => setQ(event.target.value)}
|
onChange={(event) => setQ(event.target.value)}
|
||||||
/>
|
/>
|
||||||
@@ -60,7 +62,7 @@ export const Search = () => {
|
|||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
iconLeading={<SearchIcon className="h-3.5 w-3.5" />}
|
iconLeading={<SearchIcon className="h-3.5 w-3.5" />}
|
||||||
>
|
>
|
||||||
Rechercher
|
{t("Rechercher")}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@@ -75,15 +77,15 @@ export const Search = () => {
|
|||||||
) : results === null ? null : total === 0 ? (
|
) : results === null ? null : total === 0 ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={<SearchIcon className="h-8 w-8" />}
|
icon={<SearchIcon className="h-8 w-8" />}
|
||||||
title="Aucun résultat"
|
title={t("Aucun résultat")}
|
||||||
description={`Rien ne correspond à « ${q.trim()} ».`}
|
description={t("Rien ne correspond à « {q} ».", { q: q.trim() })}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
{results.folders.length > 0 ? (
|
{results.folders.length > 0 ? (
|
||||||
<section aria-label="Dossiers">
|
<section aria-label={t("Dossiers")}>
|
||||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Dossiers
|
{t("Dossiers")}
|
||||||
</h2>
|
</h2>
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{results.folders.map((folder) => (
|
{results.folders.map((folder) => (
|
||||||
@@ -101,9 +103,9 @@ export const Search = () => {
|
|||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{results.files.length > 0 ? (
|
{results.files.length > 0 ? (
|
||||||
<section aria-label="Fichiers">
|
<section aria-label={t("Fichiers")}>
|
||||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Fichiers
|
{t("Fichiers")}
|
||||||
</h2>
|
</h2>
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{results.files.map((file) => (
|
{results.files.map((file) => (
|
||||||
@@ -122,7 +124,7 @@ export const Search = () => {
|
|||||||
<a
|
<a
|
||||||
href={api.downloadUrl(file.id)}
|
href={api.downloadUrl(file.id)}
|
||||||
download={file.name}
|
download={file.name}
|
||||||
aria-label={`Télécharger ${file.name}`}
|
aria-label={t("Télécharger {name}", { name: 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"
|
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" />
|
<DownloadIcon className="h-4 w-4" />
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
|||||||
import { useConfirm } from "../components/confirm.js";
|
import { useConfirm } from "../components/confirm.js";
|
||||||
import { IconAction } from "../components/IconAction.js";
|
import { IconAction } from "../components/IconAction.js";
|
||||||
import { FileIcon, FolderIcon, RestoreIcon, TrashIcon } from "../components/icons.js";
|
import { FileIcon, FolderIcon, RestoreIcon, TrashIcon } from "../components/icons.js";
|
||||||
|
import { useI18n } from "../lib/i18n.js";
|
||||||
|
|
||||||
interface TrashData {
|
interface TrashData {
|
||||||
retentionDays: number;
|
retentionDays: number;
|
||||||
@@ -20,6 +21,7 @@ interface TrashData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Trash = () => {
|
export const Trash = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
const [data, setData] = useState<TrashData | null>(null);
|
const [data, setData] = useState<TrashData | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -32,7 +34,7 @@ export const Trash = () => {
|
|||||||
try {
|
try {
|
||||||
setData(await api.trash());
|
setData(await api.trash());
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||||
setData(null);
|
setData(null);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -50,7 +52,7 @@ export const Trash = () => {
|
|||||||
await action();
|
await action();
|
||||||
await load();
|
await load();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
setError(caught instanceof ApiError ? caught.message : t("Action impossible."));
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(null);
|
setBusy(null);
|
||||||
}
|
}
|
||||||
@@ -58,9 +60,9 @@ export const Trash = () => {
|
|||||||
|
|
||||||
const emptyTrash = async () => {
|
const emptyTrash = async () => {
|
||||||
const ok = await confirm({
|
const ok = await confirm({
|
||||||
title: "Vider la corbeille",
|
title: t("Vider la corbeille"),
|
||||||
message: "Tous les éléments seront définitivement supprimés. Cette action est irréversible.",
|
message: t("Tous les éléments seront définitivement supprimés. Cette action est irréversible."),
|
||||||
confirmLabel: "Vider",
|
confirmLabel: t("Vider"),
|
||||||
tone: "danger",
|
tone: "danger",
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
@@ -69,14 +71,9 @@ export const Trash = () => {
|
|||||||
|
|
||||||
const purge = async (key: string, name: string, action: () => Promise<unknown>) => {
|
const purge = async (key: string, name: string, action: () => Promise<unknown>) => {
|
||||||
const ok = await confirm({
|
const ok = await confirm({
|
||||||
title: "Supprimer définitivement",
|
title: t("Supprimer définitivement"),
|
||||||
message: (
|
message: t("Supprimer définitivement {name} ? Cette action est irréversible.", { name }),
|
||||||
<>
|
confirmLabel: t("Supprimer"),
|
||||||
Supprimer définitivement <span className="font-semibold text-foreground">{name}</span> ?
|
|
||||||
Cette action est irréversible.
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
confirmLabel: "Supprimer",
|
|
||||||
tone: "danger",
|
tone: "danger",
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
@@ -88,16 +85,18 @@ export const Trash = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="Corbeille"
|
title={t("Corbeille")}
|
||||||
description={
|
description={
|
||||||
data
|
data
|
||||||
? `Les éléments sont définitivement supprimés après ${data.retentionDays} jours.`
|
? t("Les éléments sont définitivement supprimés après {days} jours.", {
|
||||||
: "Éléments supprimés récemment."
|
days: data.retentionDays,
|
||||||
|
})
|
||||||
|
: t("Éléments supprimés récemment.")
|
||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
data && !empty ? (
|
data && !empty ? (
|
||||||
<Button variant="destructive" size="sm" isLoading={busy === "empty"} onClick={emptyTrash}>
|
<Button variant="destructive" size="sm" isLoading={busy === "empty"} onClick={emptyTrash}>
|
||||||
Vider la corbeille
|
{t("Vider la corbeille")}
|
||||||
</Button>
|
</Button>
|
||||||
) : undefined
|
) : undefined
|
||||||
}
|
}
|
||||||
@@ -112,15 +111,15 @@ export const Trash = () => {
|
|||||||
) : empty ? (
|
) : empty ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
icon={<TrashIcon className="h-8 w-8" />}
|
icon={<TrashIcon className="h-8 w-8" />}
|
||||||
title="Corbeille vide"
|
title={t("Corbeille vide")}
|
||||||
description="Aucun élément supprimé pour le moment."
|
description={t("Aucun élément supprimé pour le moment.")}
|
||||||
/>
|
/>
|
||||||
) : data ? (
|
) : data ? (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
{data.folders.length > 0 ? (
|
{data.folders.length > 0 ? (
|
||||||
<section aria-label="Dossiers supprimés">
|
<section aria-label={t("Dossiers supprimés")}>
|
||||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Dossiers
|
{t("Dossiers")}
|
||||||
</h2>
|
</h2>
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{data.folders.map((folder) => (
|
{data.folders.map((folder) => (
|
||||||
@@ -133,11 +132,11 @@ export const Trash = () => {
|
|||||||
{folder.name}
|
{folder.name}
|
||||||
</span>
|
</span>
|
||||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||||
Supprimé le {formatDate(folder.deleted_at)}
|
{t("Supprimé le {date}", { date: formatDate(folder.deleted_at) })}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Restaurer ${folder.name}`}
|
label={t("Restaurer {name}", { name: folder.name })}
|
||||||
icon={<RestoreIcon className="h-4 w-4" />}
|
icon={<RestoreIcon className="h-4 w-4" />}
|
||||||
isLoading={busy === `restore-${folder.id}`}
|
isLoading={busy === `restore-${folder.id}`}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@@ -145,7 +144,7 @@ export const Trash = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Supprimer définitivement ${folder.name}`}
|
label={t("Supprimer définitivement {name}", { name: folder.name })}
|
||||||
icon={<TrashIcon className="h-4 w-4" />}
|
icon={<TrashIcon className="h-4 w-4" />}
|
||||||
tone="danger"
|
tone="danger"
|
||||||
isLoading={busy === `purge-${folder.id}`}
|
isLoading={busy === `purge-${folder.id}`}
|
||||||
@@ -162,9 +161,9 @@ export const Trash = () => {
|
|||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{data.files.length > 0 ? (
|
{data.files.length > 0 ? (
|
||||||
<section aria-label="Fichiers supprimés">
|
<section aria-label={t("Fichiers supprimés")}>
|
||||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||||
Fichiers
|
{t("Fichiers")}
|
||||||
</h2>
|
</h2>
|
||||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||||
{data.files.map((file) => (
|
{data.files.map((file) => (
|
||||||
@@ -177,11 +176,12 @@ export const Trash = () => {
|
|||||||
{file.name}
|
{file.name}
|
||||||
</span>
|
</span>
|
||||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||||
{formatBytes(file.size_bytes)} · supprimé le {formatDate(file.deleted_at)}
|
{formatBytes(file.size_bytes)} ·{" "}
|
||||||
|
{t("Supprimé le {date}", { date: formatDate(file.deleted_at) })}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Restaurer ${file.name}`}
|
label={t("Restaurer {name}", { name: file.name })}
|
||||||
icon={<RestoreIcon className="h-4 w-4" />}
|
icon={<RestoreIcon className="h-4 w-4" />}
|
||||||
isLoading={busy === `restore-${file.id}`}
|
isLoading={busy === `restore-${file.id}`}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@@ -189,7 +189,7 @@ export const Trash = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
label={`Supprimer définitivement ${file.name}`}
|
label={t("Supprimer définitivement {name}", { name: file.name })}
|
||||||
icon={<TrashIcon className="h-4 w-4" />}
|
icon={<TrashIcon className="h-4 w-4" />}
|
||||||
isLoading={busy === `purge-${file.id}`}
|
isLoading={busy === `purge-${file.id}`}
|
||||||
tone="danger"
|
tone="danger"
|
||||||
|
|||||||
Reference in New Issue
Block a user