ci(deploy): back up before migrating and run migrations explicitly (#9)
CD — Deployment / deploy (push) Successful in 23s
CD — Deployment / deploy (push) Successful in 23s
- dump the database to ./backups before applying migrations - run the one-shot migrate service on every deploy instead of relying only on the api depends_on, so a migration is never skipped - translate the workflow comments to English --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #9 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #9.
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState } from "react";
|
||||
import { NavLink, Outlet } from "react-router-dom";
|
||||
import { Button, cn } from "../ui/index.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { Avatar } from "./Avatar.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
@@ -50,6 +51,7 @@ const navClass = ({ isActive }: { isActive: boolean }) =>
|
||||
|
||||
export const AppShell = () => {
|
||||
const { user, logout } = useSession();
|
||||
const { t } = useI18n();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
if (!user) return null;
|
||||
|
||||
@@ -80,7 +82,7 @@ export const AppShell = () => {
|
||||
return (
|
||||
<NavLink key={item.to} to={item.to} className={navClass} onClick={() => setMenuOpen(false)}>
|
||||
<Icon className="h-4 w-4" />
|
||||
{item.label}
|
||||
{t(item.label)}
|
||||
</NavLink>
|
||||
);
|
||||
};
|
||||
@@ -93,7 +95,7 @@ export const AppShell = () => {
|
||||
{isAdmin ? (
|
||||
<>
|
||||
<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>
|
||||
{ADMIN_NAV.map(renderLink)}
|
||||
</>
|
||||
@@ -108,7 +110,7 @@ export const AppShell = () => {
|
||||
<button
|
||||
type="button"
|
||||
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}
|
||||
onClick={() => setMenuOpen((value) => !value)}
|
||||
>
|
||||
@@ -139,7 +141,7 @@ export const AppShell = () => {
|
||||
iconLeading={<LogoutIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => void logout()}
|
||||
>
|
||||
<span className="hidden sm:inline">Déconnexion</span>
|
||||
<span className="hidden sm:inline">{t("Déconnexion")}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
} from "react";
|
||||
import { Button, Spinner, cn } from "../ui/index.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 { useConfirm } from "./confirm.js";
|
||||
import { Avatar } from "./Avatar.js";
|
||||
@@ -22,10 +24,10 @@ const POLL_MEMBERS_MS = 30_000;
|
||||
const GROUP_WINDOW_MS = 5 * 60 * 1000;
|
||||
|
||||
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 =>
|
||||
new Date(value).toLocaleDateString("fr-FR", {
|
||||
new Date(value).toLocaleDateString(getLocale(), {
|
||||
weekday: "long",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
@@ -34,8 +36,10 @@ const dayOf = (value: string): string =>
|
||||
const isSameDay = (a: string, b: string): boolean =>
|
||||
new Date(a).toDateString() === new Date(b).toDateString();
|
||||
|
||||
const fullName = (member: { first_name: string | null; last_name: string | null }): string =>
|
||||
`${member.first_name ?? ""} ${member.last_name ?? ""}`.trim() || "Compte supprimé";
|
||||
const fullName = (
|
||||
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 =>
|
||||
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.
|
||||
*/
|
||||
export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: () => void }) => {
|
||||
const { t } = useI18n();
|
||||
const { user } = useSession();
|
||||
const confirm = useConfirm();
|
||||
const folderId = folder.id;
|
||||
@@ -114,7 +119,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
setError(null);
|
||||
} catch (caught) {
|
||||
if (!active) return;
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
} finally {
|
||||
if (active) {
|
||||
setLoading(false);
|
||||
@@ -189,7 +194,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
mergeMessages([message]);
|
||||
setDraft("");
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Envoi impossible."));
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
@@ -198,9 +203,9 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
const remove = async (message: ChatMessage) => {
|
||||
if (
|
||||
!(await confirm({
|
||||
title: "Supprimer le message",
|
||||
message: "Ce message sera retiré du salon pour tout le monde.",
|
||||
confirmLabel: "Supprimer",
|
||||
title: t("Supprimer le message"),
|
||||
message: t("Ce message sera retiré du salon pour tout le monde."),
|
||||
confirmLabel: t("Supprimer"),
|
||||
tone: "danger",
|
||||
}))
|
||||
)
|
||||
@@ -210,7 +215,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
await api.chatDeleteMessage(folderId, message.id);
|
||||
setMessages((previous) => previous.filter((item) => item.id !== message.id));
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Suppression impossible."));
|
||||
} finally {
|
||||
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",
|
||||
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">
|
||||
<span className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
Membres
|
||||
{t("Membres")}
|
||||
</span>
|
||||
<span className="text-xs text-subtle-foreground">{members.length}</span>
|
||||
</div>
|
||||
@@ -270,15 +275,17 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<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 ? (
|
||||
<span className="text-subtle-foreground">(vous)</span>
|
||||
<span className="text-subtle-foreground">{t("(vous)")}</span>
|
||||
) : null}
|
||||
</p>
|
||||
<p className="truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{member.last_login_at
|
||||
? `Dernière connexion le ${formatDate(member.last_login_at)}`
|
||||
: "Jamais connecté"}
|
||||
? t("Dernière connexion le {date}", {
|
||||
date: formatDate(member.last_login_at),
|
||||
})
|
||||
: t("Jamais connecté")}
|
||||
</p>
|
||||
</div>
|
||||
{member.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
||||
@@ -300,7 +307,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
<button
|
||||
type="button"
|
||||
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}
|
||||
onClick={() => setMembersOpen((value) => !value)}
|
||||
>
|
||||
@@ -308,16 +315,16 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
</button>
|
||||
<div className="min-w-0 flex-1">
|
||||
<h1 className="truncate font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
||||
Discussion · {folder.name}
|
||||
{t("Discussion · {name}", { name: folder.name })}
|
||||
</h1>
|
||||
<p className="text-[0.6875rem] text-subtle-foreground">
|
||||
Membres ayant accès à ce dossier
|
||||
{t("Membres ayant accès à ce dossier")}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
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"
|
||||
>
|
||||
<CloseIcon className="h-5 w-5" />
|
||||
@@ -342,8 +349,10 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
) : messages.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<ChatIcon className="h-8 w-8" />}
|
||||
title="Aucun message"
|
||||
description="Lancez la discussion : les membres du dossier verront votre message."
|
||||
title={t("Aucun message")}
|
||||
description={t(
|
||||
"Lancez la discussion : les membres du dossier verront votre message.",
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<ol className="flex flex-col gap-1">
|
||||
@@ -382,7 +391,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
<span
|
||||
className={cn("font-medium", own ? "text-accent" : "text-foreground")}
|
||||
>
|
||||
{fullName(message)}
|
||||
{fullName(message, t("Compte supprimé"))}
|
||||
</span>
|
||||
<span className="text-[0.6875rem] text-subtle-foreground">
|
||||
{timeOf(message.created_at)}
|
||||
@@ -396,7 +405,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
{canDelete ? (
|
||||
<span className="opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||
<IconAction
|
||||
label="Supprimer le message"
|
||||
label={t("Supprimer le message")}
|
||||
tone="danger"
|
||||
isLoading={deletingId === message.id}
|
||||
icon={<TrashIcon className="h-3.5 w-3.5" />}
|
||||
@@ -421,8 +430,10 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
onKeyDown={onComposerKeyDown}
|
||||
rows={1}
|
||||
maxLength={MAX_LENGTH}
|
||||
placeholder="Écrire un message… (Entrée pour envoyer, Maj+Entrée pour retour à la ligne)"
|
||||
aria-label="Votre message"
|
||||
placeholder={t(
|
||||
"É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"
|
||||
/>
|
||||
<Button
|
||||
@@ -432,7 +443,7 @@ export const FolderChat = ({ folder, onClose }: { folder: ChatFolder; onClose: (
|
||||
disabled={draft.trim().length === 0}
|
||||
iconLeading={<SendIcon className="h-4 w-4" />}
|
||||
>
|
||||
<span className="hidden sm:inline">Envoyer</span>
|
||||
<span className="hidden sm:inline">{t("Envoyer")}</span>
|
||||
</Button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
@@ -7,12 +7,14 @@ export const IconAction = ({
|
||||
onClick,
|
||||
isLoading = false,
|
||||
tone = "neutral",
|
||||
badge = 0,
|
||||
}: {
|
||||
label: string;
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
isLoading?: boolean;
|
||||
tone?: "neutral" | "danger";
|
||||
badge?: number;
|
||||
}) => (
|
||||
<button
|
||||
type="button"
|
||||
@@ -21,11 +23,19 @@ export const IconAction = ({
|
||||
disabled={isLoading}
|
||||
onClick={onClick}
|
||||
className={cn(
|
||||
"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors",
|
||||
"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",
|
||||
tone === "danger" && "hover:text-destructive",
|
||||
)}
|
||||
>
|
||||
{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>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { cn } from "../ui/index.js";
|
||||
import { api } from "../lib/api.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, DownloadIcon, FileIcon } from "./icons.js";
|
||||
|
||||
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";
|
||||
|
||||
const TextViewer = ({ id }: { id: string }) => {
|
||||
const { t } = useI18n();
|
||||
const [text, setText] = useState<string | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
@@ -49,8 +51,8 @@ const TextViewer = ({ id }: { id: string }) => {
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
if (failed) return <p className="text-sm text-white/70">Lecture impossible.</p>;
|
||||
if (text === null) return <p className="text-sm text-white/70">Chargement…</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">{t("Chargement…")}</p>;
|
||||
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">
|
||||
{text}
|
||||
@@ -66,33 +68,37 @@ const Panel = ({
|
||||
item: MediaViewerItem;
|
||||
message: string;
|
||||
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">
|
||||
<FileIcon className="h-12 w-12 text-white/60" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium text-white">{item.name}</p>
|
||||
<p className="mt-1 text-xs text-white/60">{message}</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
{openable ? (
|
||||
<a
|
||||
href={api.previewUrl(item.id)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={actionClass}
|
||||
>
|
||||
Ouvrir
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
return (
|
||||
<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">
|
||||
<FileIcon className="h-12 w-12 text-white/60" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium text-white">{item.name}</p>
|
||||
<p className="mt-1 text-xs text-white/60">{message}</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
{openable ? (
|
||||
<a
|
||||
href={api.previewUrl(item.id)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
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>
|
||||
) : null}
|
||||
<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 { t } = useI18n();
|
||||
const kind = kindOf(item.mime_type);
|
||||
if (kind === "image") {
|
||||
return (
|
||||
@@ -124,11 +130,11 @@ const Body = ({ item }: { item: MediaViewerItem }) => {
|
||||
}
|
||||
if (kind === "text") return <TextViewer id={item.id} />;
|
||||
if (kind === "pdf") {
|
||||
return (
|
||||
<Panel item={item} message="Le PDF s'ouvre dans un nouvel onglet." openable />
|
||||
);
|
||||
return <Panel item={item} message={t("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 = ({
|
||||
@@ -140,6 +146,7 @@ export const MediaViewer = ({
|
||||
startIndex: number;
|
||||
onClose: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [index, setIndex] = useState(startIndex);
|
||||
const current = items[index];
|
||||
|
||||
@@ -169,11 +176,11 @@ export const MediaViewer = ({
|
||||
href={api.downloadUrl(current.id)}
|
||||
download={current.name}
|
||||
className={controlClass}
|
||||
aria-label="Télécharger"
|
||||
aria-label={t("Télécharger")}
|
||||
>
|
||||
<DownloadIcon className="h-4 w-4" />
|
||||
</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" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -190,7 +197,7 @@ export const MediaViewer = ({
|
||||
type="button"
|
||||
onClick={() => setIndex((value) => value - 1)}
|
||||
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" />
|
||||
</button>
|
||||
@@ -203,7 +210,7 @@ export const MediaViewer = ({
|
||||
type="button"
|
||||
onClick={() => setIndex((value) => value + 1)}
|
||||
className={cn(controlClass, "absolute right-4 z-10")}
|
||||
aria-label="Fichier suivant"
|
||||
aria-label={t("Fichier suivant")}
|
||||
>
|
||||
<ArrowRightIcon className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { Button } from "../ui/index.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { Modal } from "./feedback.js";
|
||||
|
||||
export interface ConfirmOptions {
|
||||
@@ -33,6 +34,7 @@ const ConfirmContext = createContext<ConfirmFn | null>(null);
|
||||
* `useConfirm()` renvoie une promesse resolue a `true` (confirme) ou `false`.
|
||||
*/
|
||||
export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
||||
const { t } = useI18n();
|
||||
const [pending, setPending] = useState<PendingConfirm | null>(null);
|
||||
|
||||
const confirm = useCallback<ConfirmFn>(
|
||||
@@ -52,7 +54,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
||||
{children}
|
||||
<Modal
|
||||
open={pending !== null}
|
||||
title={pending?.options.title ?? "Confirmation"}
|
||||
title={pending?.options.title ?? t("Confirmation")}
|
||||
onClose={() => answer(false)}
|
||||
>
|
||||
<div className="flex flex-col gap-5">
|
||||
@@ -61,7 +63,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
||||
</p>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={() => answer(false)}>
|
||||
{pending?.options.cancelLabel ?? "Annuler"}
|
||||
{pending?.options.cancelLabel ?? t("Annuler")}
|
||||
</Button>
|
||||
<Button
|
||||
variant={tone === "danger" ? "destructive" : "primary"}
|
||||
@@ -69,7 +71,7 @@ export const ConfirmProvider = ({ children }: { children: ReactNode }) => {
|
||||
autoFocus
|
||||
onClick={() => answer(true)}
|
||||
>
|
||||
{pending?.options.confirmLabel ?? "Confirmer"}
|
||||
{pending?.options.confirmLabel ?? t("Confirmer")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,9 +4,11 @@ import {
|
||||
ApiError,
|
||||
api,
|
||||
formatDate,
|
||||
type DirectoryUser,
|
||||
type Folder,
|
||||
type FolderPermission,
|
||||
} from "../lib/api.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { Alert, Modal } from "./feedback.js";
|
||||
import { TrashIcon } from "./icons.js";
|
||||
|
||||
@@ -35,8 +37,8 @@ export const CreateFolderDialog = ({
|
||||
onClose: () => void;
|
||||
onCreated: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
@@ -45,40 +47,34 @@ export const CreateFolderDialog = ({
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.createFolder(name, parentId, description.trim() || undefined);
|
||||
await api.createFolder(name, parentId);
|
||||
onCreated();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Création impossible."));
|
||||
setError(messageOf(caught, t("Création impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
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)}>
|
||||
<Input
|
||||
label="Nom"
|
||||
label={t("Nom")}
|
||||
required
|
||||
maxLength={255}
|
||||
autoFocus
|
||||
placeholder="Contrats 2026"
|
||||
placeholder={t("Contrats 2026")}
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Description (optionnelle)"
|
||||
maxLength={2000}
|
||||
value={description}
|
||||
onChange={(event) => setDescription(event.target.value)}
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={onClose}>
|
||||
Annuler
|
||||
{t("Annuler")}
|
||||
</Button>
|
||||
<Button type="submit" size="md" isLoading={busy}>
|
||||
Créer
|
||||
{t("Créer")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -95,6 +91,7 @@ export const RenameDialog = ({
|
||||
onClose: () => void;
|
||||
onDone: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [name, setName] = useState(target.name);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
@@ -104,21 +101,21 @@ export const RenameDialog = ({
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
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);
|
||||
onDone();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Renommage impossible."));
|
||||
setError(messageOf(caught, t("Renommage impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
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)}>
|
||||
<Input
|
||||
label="Nom"
|
||||
label={t("Nom")}
|
||||
required
|
||||
maxLength={255}
|
||||
autoFocus
|
||||
@@ -128,10 +125,10 @@ export const RenameDialog = ({
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={onClose}>
|
||||
Annuler
|
||||
{t("Annuler")}
|
||||
</Button>
|
||||
<Button type="submit" size="md" isLoading={busy}>
|
||||
Enregistrer
|
||||
{t("Enregistrer")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -167,6 +164,7 @@ export const MoveDialog = ({
|
||||
onClose: () => void;
|
||||
onDone: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [entries, setEntries] = useState<TreeEntry[] | null>(null);
|
||||
const [destination, setDestination] = useState<string>("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -175,7 +173,7 @@ export const MoveDialog = ({
|
||||
useEffect(() => {
|
||||
loadTree()
|
||||
.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>) => {
|
||||
@@ -188,24 +186,24 @@ export const MoveDialog = ({
|
||||
else await api.moveFile(target.id, parentId);
|
||||
onDone();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Déplacement impossible."));
|
||||
setError(messageOf(caught, t("Déplacement impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
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)}>
|
||||
<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>
|
||||
{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">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Destination
|
||||
{t("Destination")}
|
||||
</span>
|
||||
<select
|
||||
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",
|
||||
)}
|
||||
>
|
||||
<option value="">Racine</option>
|
||||
<option value="">{t("Racine")}</option>
|
||||
{(entries ?? [])
|
||||
.filter((entry) => entry.id !== target.id)
|
||||
.map((entry) => (
|
||||
@@ -229,10 +227,10 @@ export const MoveDialog = ({
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="md" onClick={onClose}>
|
||||
Annuler
|
||||
{t("Annuler")}
|
||||
</Button>
|
||||
<Button type="submit" size="md" isLoading={busy} disabled={entries === null}>
|
||||
Déplacer
|
||||
{t("Déplacer")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -247,7 +245,9 @@ export const ShareDialog = ({
|
||||
folder: Folder;
|
||||
onClose: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [permissions, setPermissions] = useState<FolderPermission[] | null>(null);
|
||||
const [members, setMembers] = useState<DirectoryUser[] | null>(null);
|
||||
const [email, setEmail] = useState("");
|
||||
const [level, setLevel] = useState<string>("read");
|
||||
const [expiresAt, setExpiresAt] = useState("");
|
||||
@@ -256,12 +256,17 @@ export const ShareDialog = ({
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
const { permissions: list } = await api.folderPermissions(folder.id);
|
||||
const [{ permissions: list }, { users }] = await Promise.all([
|
||||
api.folderPermissions(folder.id),
|
||||
api.directory(),
|
||||
]);
|
||||
setPermissions(list);
|
||||
setMembers(users);
|
||||
setError(null);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement des partages impossible."));
|
||||
setError(messageOf(caught, t("Chargement des partages impossible.")));
|
||||
setPermissions([]);
|
||||
setMembers([]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -270,6 +275,10 @@ export const ShareDialog = ({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [folder.id]);
|
||||
|
||||
const candidates = (members ?? []).filter(
|
||||
(member) => !(permissions ?? []).some((permission) => permission.user_id === member.id),
|
||||
);
|
||||
|
||||
const grant = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
@@ -281,7 +290,7 @@ export const ShareDialog = ({
|
||||
setExpiresAt("");
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Partage impossible."));
|
||||
setError(messageOf(caught, t("Partage impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -293,26 +302,43 @@ export const ShareDialog = ({
|
||||
await api.revokePermission(folder.id, userId);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Révocation impossible."));
|
||||
setError(messageOf(caught, t("Révocation impossible.")));
|
||||
}
|
||||
};
|
||||
|
||||
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">
|
||||
<form className="flex flex-col gap-3" onSubmit={(event) => void grant(event)}>
|
||||
<Input
|
||||
label="Adresse e-mail du membre"
|
||||
type="email"
|
||||
required
|
||||
autoFocus
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
{t("Membre")}
|
||||
</span>
|
||||
<select
|
||||
value={email}
|
||||
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">
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Niveau
|
||||
{t("Niveau")}
|
||||
</span>
|
||||
<select
|
||||
value={level}
|
||||
@@ -321,13 +347,13 @@ export const ShareDialog = ({
|
||||
>
|
||||
{LEVELS.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{LEVEL_LABEL[value]}
|
||||
{t(LEVEL_LABEL[value] ?? value)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<Input
|
||||
label="Expire le"
|
||||
label={t("Expire le")}
|
||||
type="date"
|
||||
value={expiresAt}
|
||||
onChange={(event) => setExpiresAt(event.target.value)}
|
||||
@@ -335,20 +361,20 @@ export const ShareDialog = ({
|
||||
</div>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="md" isLoading={busy}>
|
||||
Autoriser
|
||||
<Button type="submit" size="md" isLoading={busy} disabled={candidates.length === 0}>
|
||||
{t("Autoriser")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<h3 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Accès accordés
|
||||
{t("Accès accordés")}
|
||||
</h3>
|
||||
{permissions === null ? (
|
||||
<Alert tone="info">Chargement…</Alert>
|
||||
<Alert tone="info">{t("Chargement…")}</Alert>
|
||||
) : 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">
|
||||
{permissions.map((permission) => (
|
||||
@@ -358,13 +384,18 @@ export const ShareDialog = ({
|
||||
{permission.first_name} {permission.last_name}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{permission.email} · {LEVEL_LABEL[permission.level] ?? permission.level}
|
||||
{permission.expires_at ? ` · jusqu'au ${formatDate(permission.expires_at)}` : ""}
|
||||
{permission.email} ·{" "}
|
||||
{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>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Révoquer ${permission.email}`}
|
||||
aria-label={t("Révoquer {email}", { email: permission.email })}
|
||||
onClick={() => void revoke(permission.user_id)}
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-destructive"
|
||||
>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
import { cn } from "../ui/index.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { CloseIcon } from "./icons.js";
|
||||
|
||||
export const Modal = ({
|
||||
@@ -13,6 +14,8 @@ export const Modal = ({
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
@@ -48,7 +51,7 @@ export const Modal = ({
|
||||
<button
|
||||
type="button"
|
||||
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"
|
||||
>
|
||||
<CloseIcon className="h-5 w-5" />
|
||||
|
||||
Reference in New Issue
Block a user