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:
@@ -1,4 +1,4 @@
|
||||
name: CD — Déploiement
|
||||
name: CD — Deployment
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -20,19 +20,25 @@ jobs:
|
||||
deploy:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Récupérer puis reconstruire
|
||||
- name: Fetch latest code and rebuild
|
||||
env:
|
||||
# Chemin du dépôt sur le serveur. Défini via le secret DEPLOY_DIR si
|
||||
# besoin ; sinon la valeur par défaut ci-dessous est utilisée.
|
||||
# Repository path on the server. Set it through the DEPLOY_DIR
|
||||
# secret when needed; otherwise the default below is used.
|
||||
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }}
|
||||
run: |
|
||||
set -eu
|
||||
dir="${DEPLOY_DIR:-/srv/apps/cohaise-cloud/CoHaiSe-CLOUD}"
|
||||
cd "$dir"
|
||||
git pull --ff-only origin main
|
||||
# Le build des images compile et typecheck chaque workspace (tsc) :
|
||||
# aucune toolchain Node n'est requise sur l'hote.
|
||||
# Image builds compile and typecheck every workspace (tsc): no Node
|
||||
# toolchain is required on the host.
|
||||
docker compose build api migrate nginx
|
||||
# Back up the database before a potentially destructive migration.
|
||||
# Dumps land in ./backups on the host, never in the repository.
|
||||
make backup
|
||||
# Run migrations explicitly: the one-shot service must execute on
|
||||
# every deploy, not only when its image happens to change.
|
||||
docker compose run --rm migrate
|
||||
make front
|
||||
docker compose up -d api nginx
|
||||
docker image prune -f
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
-- 008_user_preferences.sql
|
||||
--
|
||||
-- 1. Preferences d'affichage par utilisateur (theme et langue), choisies dans
|
||||
-- le compte. Le rendu serveur reste en francais ; ces colonnes ne servent
|
||||
-- qu'a l'interface cliente.
|
||||
-- 2. Favoris par utilisateur : `files.is_starred` etait un marqueur global,
|
||||
-- partage entre tous les comptes ayant acces au fichier. Une table de
|
||||
-- jointure remplace ce marqueur. Les etoiles deja posees sont reprises par
|
||||
-- le proprietaire du fichier.
|
||||
-- 3. Suivi de lecture du chat par utilisateur, pour les pastilles de messages
|
||||
-- non lus dans la vue des dossiers.
|
||||
-- 4. Suppression de `folders.description`, champ jamais affiche.
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN theme VARCHAR(10) NOT NULL DEFAULT 'system' AFTER max_file_bytes,
|
||||
ADD COLUMN language VARCHAR(5) NOT NULL DEFAULT 'fr' AFTER theme,
|
||||
ADD CONSTRAINT chk_users_theme CHECK (theme IN ('system', 'light', 'dark')),
|
||||
ADD CONSTRAINT chk_users_language CHECK (language IN ('fr', 'en'));
|
||||
|
||||
CREATE TABLE user_file_stars (
|
||||
user_id CHAR(36) NOT NULL,
|
||||
file_id CHAR(36) NOT NULL,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (user_id, file_id),
|
||||
KEY idx_user_file_stars_file (file_id),
|
||||
CONSTRAINT fk_user_file_stars_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_user_file_stars_file FOREIGN KEY (file_id) REFERENCES files (id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO user_file_stars (user_id, file_id)
|
||||
SELECT owner_id, id FROM files WHERE is_starred = 1 AND owner_id IS NOT NULL;
|
||||
|
||||
DROP INDEX idx_files_starred ON files;
|
||||
ALTER TABLE files DROP COLUMN is_starred;
|
||||
|
||||
CREATE TABLE chat_reads (
|
||||
folder_id CHAR(36) NOT NULL,
|
||||
user_id CHAR(36) NOT NULL,
|
||||
last_read_message_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (folder_id, user_id),
|
||||
KEY idx_chat_reads_user (user_id),
|
||||
CONSTRAINT fk_chat_reads_folder FOREIGN KEY (folder_id) REFERENCES folders (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_chat_reads_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
ALTER TABLE folders DROP COLUMN description;
|
||||
@@ -5,6 +5,7 @@ import { registerAccountRoutes } from "./routes/account.js";
|
||||
import { registerAdminRoutes } from "./routes/admin.js";
|
||||
import { registerAuthRoutes } from "./routes/auth.js";
|
||||
import { registerChatRoutes } from "./routes/chat.js";
|
||||
import { registerDirectoryRoutes } from "./routes/directory.js";
|
||||
import { registerFileRoutes } from "./routes/files.js";
|
||||
import { registerFolderRoutes } from "./routes/folders.js";
|
||||
import { registerMediaRoutes } from "./routes/media.js";
|
||||
@@ -23,6 +24,7 @@ void startService({
|
||||
registerAuthRoutes(app, db, config);
|
||||
registerAccountRoutes(app, db, config);
|
||||
registerChatRoutes(app, db, config);
|
||||
registerDirectoryRoutes(app, db);
|
||||
registerFolderRoutes(app, db, config);
|
||||
registerFileRoutes(app, db, config);
|
||||
registerMediaRoutes(app, db);
|
||||
|
||||
@@ -51,6 +51,11 @@ const profileInput = z.object({
|
||||
last_name: z.string().trim().min(1).max(50),
|
||||
});
|
||||
|
||||
const preferencesInput = z.object({
|
||||
theme: z.enum(["system", "light", "dark"]),
|
||||
language: z.enum(["fr", "en"]),
|
||||
});
|
||||
|
||||
const forgotInput = z.object({ email: z.string().trim().email().max(255) });
|
||||
|
||||
const resetInput = z.object({
|
||||
@@ -90,6 +95,27 @@ export const registerAccountRoutes = (app: App, db: Db, config: Config): void =>
|
||||
return context.json({ ok: true, first_name: data.first_name, last_name: data.last_name });
|
||||
});
|
||||
|
||||
app.get("/api/cloud/account/preferences", requireAuth, async (context) => {
|
||||
const user = currentUser(context);
|
||||
const row = await db.one<{ theme: string; language: string }>(
|
||||
"SELECT theme, language FROM users WHERE id = ? AND deleted_at IS NULL",
|
||||
[user.id],
|
||||
);
|
||||
if (!row) throw AppError.notFound("Compte introuvable.");
|
||||
return context.json({ theme: row.theme, language: row.language });
|
||||
});
|
||||
|
||||
app.patch("/api/cloud/account/preferences", requireAuth, async (context) => {
|
||||
const user = currentUser(context);
|
||||
const data = parse(preferencesInput, await context.req.json().catch(() => null));
|
||||
await db.exec("UPDATE users SET theme = ?, language = ? WHERE id = ?", [
|
||||
data.theme,
|
||||
data.language,
|
||||
user.id,
|
||||
]);
|
||||
return context.json({ theme: data.theme, language: data.language });
|
||||
});
|
||||
|
||||
app.get("/api/cloud/account/sessions", requireAuth, async (context) => {
|
||||
const user = currentUser(context);
|
||||
const current = sha256(context.get("token") ?? "");
|
||||
|
||||
+43
-11
@@ -433,21 +433,53 @@ export const registerAdminRoutes = (app: App, db: Db, config: Config): void => {
|
||||
return context.json({ ok: true });
|
||||
});
|
||||
|
||||
/**
|
||||
* Facettes du journal : valeurs distinctes utilisees pour alimenter les
|
||||
* listes deroulantes de filtre (actions et comptes ayant agi). Un compte
|
||||
* supprime reste identifiable par son e-mail conserve dans le journal.
|
||||
*/
|
||||
app.get("/api/cloud/admin/audit/filters", requireAuth, async (context) => {
|
||||
requireAdmin(context);
|
||||
const actions = await db.query<{ action: string }>(
|
||||
"SELECT DISTINCT action FROM audit_logs ORDER BY action ASC",
|
||||
);
|
||||
const users = await db.query<{ user_id: string; user_email: string | null }>(
|
||||
`SELECT user_id, MAX(user_email) AS user_email
|
||||
FROM audit_logs
|
||||
WHERE user_id IS NOT NULL
|
||||
GROUP BY user_id
|
||||
ORDER BY user_email ASC`,
|
||||
);
|
||||
return context.json({
|
||||
actions: actions.map((row) => row.action),
|
||||
users: users.map((row) => ({ id: row.user_id, email: row.user_email })),
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/api/cloud/admin/audit", requireAuth, async (context) => {
|
||||
requireAdmin(context);
|
||||
const limit = Math.min(500, Math.max(1, Number(context.req.query("limit")) || 100));
|
||||
const offset = Math.max(0, Number(context.req.query("offset")) || 0);
|
||||
const action = context.req.query("action");
|
||||
const rows = action
|
||||
? await db.query(
|
||||
`SELECT id, user_id, user_email, action, resource, resource_id, details, ip_address, created_at
|
||||
FROM audit_logs WHERE action = ? ORDER BY created_at DESC LIMIT ${limit} OFFSET ${offset}`,
|
||||
[action],
|
||||
)
|
||||
: await db.query(
|
||||
`SELECT id, user_id, user_email, action, resource, resource_id, details, ip_address, created_at
|
||||
FROM audit_logs ORDER BY created_at DESC LIMIT ${limit} OFFSET ${offset}`,
|
||||
);
|
||||
const action = context.req.query("action") || null;
|
||||
const userId = context.req.query("userId") || null;
|
||||
|
||||
const conditions: string[] = [];
|
||||
const params: unknown[] = [];
|
||||
if (action) {
|
||||
conditions.push("action = ?");
|
||||
params.push(action);
|
||||
}
|
||||
if (userId) {
|
||||
conditions.push("user_id = ?");
|
||||
params.push(userId);
|
||||
}
|
||||
const where = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
|
||||
|
||||
const rows = await db.query(
|
||||
`SELECT id, user_id, user_email, action, resource, resource_id, details, ip_address, created_at
|
||||
FROM audit_logs${where} ORDER BY created_at DESC LIMIT ${limit} OFFSET ${offset}`,
|
||||
params,
|
||||
);
|
||||
return context.json({ entries: rows });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -46,6 +46,8 @@ interface UserRow {
|
||||
max_file_bytes: number;
|
||||
must_change_password: number;
|
||||
is_active: number;
|
||||
theme: string;
|
||||
language: string;
|
||||
avatar_updated_at: Date | null;
|
||||
}
|
||||
|
||||
@@ -60,6 +62,8 @@ const publicUser = (row: UserRow) => ({
|
||||
used_bytes: row.used_bytes,
|
||||
max_file_bytes: row.max_file_bytes,
|
||||
must_change_password: row.must_change_password,
|
||||
theme: row.theme,
|
||||
language: row.language,
|
||||
has_avatar: row.avatar_updated_at !== null,
|
||||
avatar_updated_at: row.avatar_updated_at,
|
||||
});
|
||||
@@ -68,6 +72,7 @@ const SELECT_USER = `
|
||||
SELECT u.id, u.email, u.first_name, u.last_name, u.password_hash,
|
||||
r.slug AS role_slug, r.name AS role_name,
|
||||
u.quota_bytes, u.used_bytes, u.max_file_bytes, u.must_change_password, u.is_active,
|
||||
u.theme, u.language,
|
||||
ua.updated_at AS avatar_updated_at
|
||||
FROM users u
|
||||
JOIN roles r ON r.id = u.role_id
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
type Config,
|
||||
type Db,
|
||||
} from "../lib/index.js";
|
||||
import { audit, canManageFolder, canRead } from "../access.js";
|
||||
import { audit, canManageFolder, canRead, READ_SQL } from "../access.js";
|
||||
|
||||
/**
|
||||
* Chat attache a un dossier. Le salon ne se lit et ne s'ecrit qu'avec l'acces
|
||||
@@ -80,6 +80,51 @@ export const registerChatRoutes = (app: App, db: Db, config: Config): void => {
|
||||
return folder;
|
||||
};
|
||||
|
||||
/** Reprise du curseur de lecture du salon pour la session courante. */
|
||||
const markRead = async (folderId: string, userId: string, messageId: number): Promise<void> => {
|
||||
if (messageId <= 0) return;
|
||||
await db
|
||||
.exec(
|
||||
`INSERT INTO chat_reads (folder_id, user_id, last_read_message_id)
|
||||
VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
last_read_message_id = GREATEST(last_read_message_id, ?),
|
||||
updated_at = UTC_TIMESTAMP(3)`,
|
||||
[folderId, userId, messageId, messageId],
|
||||
)
|
||||
.catch(() => undefined);
|
||||
};
|
||||
|
||||
/**
|
||||
* Pastilles de messages non lus : tous les salons accessibles a la session
|
||||
* qui contiennent au moins un message qu'elle n'a pas encore lu. Les
|
||||
* messages de la session ignores : il n'a rien de neuf a lire.
|
||||
*/
|
||||
app.get("/api/cloud/chat/unread", requireAuth, async (context) => {
|
||||
const user = currentUser(context);
|
||||
const rows = await db.query<{ folder_id: string; unread: number }>(
|
||||
`SELECT f.id AS folder_id, COUNT(m.id) AS unread
|
||||
FROM folders f
|
||||
JOIN chat_messages m
|
||||
ON m.folder_id = f.id
|
||||
AND m.deleted_at IS NULL
|
||||
AND m.user_id <> ?
|
||||
WHERE f.deleted_at IS NULL
|
||||
AND m.id > COALESCE (
|
||||
SELECT cr.last_read_message_id
|
||||
FROM chat_reads cr
|
||||
WHERE cr.folder_id = f.id AND cr.user_id = ? )
|
||||
AND ${READ_SQL}
|
||||
GROUP BY f.id
|
||||
HAVING unread > 0`,
|
||||
[user.id, user.id, user.id, user.id],
|
||||
);
|
||||
|
||||
const unread: Record<string, number> = {};
|
||||
for (const row of rows) unread[row.folder_id] = Number(row.unread);
|
||||
return context.json({ unread });
|
||||
});
|
||||
|
||||
app.get("/api/cloud/folders/:folderId/chat/members", requireAuth, async (context) => {
|
||||
const user = currentUser(context);
|
||||
const folderId = context.req.param("folderId") ?? "";
|
||||
@@ -158,6 +203,9 @@ export const registerChatRoutes = (app: App, db: Db, config: Config): void => {
|
||||
)
|
||||
).reverse();
|
||||
|
||||
const newest = rows.reduce((max, row) => Math.max(max, row.id), 0);
|
||||
await markRead(folderId, user.id, newest);
|
||||
|
||||
return context.json({ messages: rows.map(publicMessage) });
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
attachUser,
|
||||
currentUser,
|
||||
requireAuth,
|
||||
type App,
|
||||
type Db,
|
||||
} from "../lib/index.js";
|
||||
|
||||
/**
|
||||
* Repertoire des comptes actifs, reduit au strict necessaire pour choisir un
|
||||
* destinataire lors d'un partage. La session courante est exclue : on ne se
|
||||
* partage pas un dossier a soi-meme. Aucune donnee sensible n'est exposee.
|
||||
*/
|
||||
export const registerDirectoryRoutes = (app: App, db: Db): void => {
|
||||
app.use("/api/cloud/directory", attachUser(db));
|
||||
|
||||
app.get("/api/cloud/directory", requireAuth, async (context) => {
|
||||
const user = currentUser(context);
|
||||
const rows = await db.query<{
|
||||
id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
avatar_updated_at: Date | null;
|
||||
}>(
|
||||
`SELECT u.id, u.first_name, u.last_name, u.email,
|
||||
ua.updated_at AS avatar_updated_at
|
||||
FROM users u
|
||||
LEFT JOIN user_avatars ua ON ua.user_id = u.id
|
||||
WHERE u.deleted_at IS NULL AND u.is_active = 1 AND u.id <> ?
|
||||
ORDER BY u.first_name ASC, u.last_name ASC
|
||||
LIMIT 1000`,
|
||||
[user.id],
|
||||
);
|
||||
|
||||
return context.json({
|
||||
users: rows.map((row) => ({
|
||||
id: row.id,
|
||||
first_name: row.first_name,
|
||||
last_name: row.last_name,
|
||||
email: row.email,
|
||||
has_avatar: row.avatar_updated_at !== null,
|
||||
avatar_updated_at: row.avatar_updated_at,
|
||||
})),
|
||||
});
|
||||
});
|
||||
};
|
||||
+45
-29
@@ -71,9 +71,11 @@ interface FileRow {
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
const SELECT_FILE = `SELECT id, folder_id, name, mime_type, size_bytes, checksum_sha256,
|
||||
relative_path, owner_id, is_starred, download_count, created_at, updated_at
|
||||
FROM files`;
|
||||
const SELECT_FILE = `SELECT f.id, f.folder_id, f.name, f.mime_type, f.size_bytes, f.checksum_sha256,
|
||||
f.relative_path, f.owner_id,
|
||||
EXISTS (SELECT 1 FROM user_file_stars s WHERE s.file_id = f.id AND s.user_id = ?) AS is_starred,
|
||||
f.download_count, f.created_at, f.updated_at
|
||||
FROM files f`;
|
||||
|
||||
const publicFile = (row: FileRow) => ({
|
||||
id: row.id,
|
||||
@@ -371,7 +373,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
config.TRUST_PROXY,
|
||||
);
|
||||
|
||||
const created = await db.required<FileRow>(`${SELECT_FILE} WHERE id = ?`, [id]);
|
||||
const created = await db.required<FileRow>(`${SELECT_FILE} WHERE f.id = ?`, [user.id, id]);
|
||||
return context.json({ file: publicFile(created) }, 201);
|
||||
},
|
||||
);
|
||||
@@ -398,22 +400,22 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
|
||||
const rows = await db.query<FileRow>(
|
||||
`${SELECT_FILE}
|
||||
WHERE deleted_at IS NULL
|
||||
AND (folder_id <=> ?)
|
||||
WHERE f.deleted_at IS NULL
|
||||
AND (f.folder_id <=> ?)
|
||||
AND ( ? = 1
|
||||
OR owner_id = ?
|
||||
OR ( folder_id IS NOT NULL
|
||||
AND EXISTS ( SELECT 1 FROM folders f
|
||||
WHERE f.id = files.folder_id AND f.access_type = 'public' ) )
|
||||
OR ( folder_id IS NOT NULL
|
||||
OR f.owner_id = ?
|
||||
OR ( f.folder_id IS NOT NULL
|
||||
AND EXISTS ( SELECT 1 FROM folders f2
|
||||
WHERE f2.id = f.folder_id AND f2.access_type = 'public' ) )
|
||||
OR ( f.folder_id IS NOT NULL
|
||||
AND EXISTS ( SELECT 1 FROM folder_permissions fp
|
||||
WHERE fp.folder_id = files.folder_id
|
||||
WHERE fp.folder_id = f.folder_id
|
||||
AND fp.user_id = ?
|
||||
AND fp.level IN ('read', 'write', 'admin')
|
||||
AND ( fp.expires_at IS NULL
|
||||
OR fp.expires_at > UTC_TIMESTAMP() ) ) ) )
|
||||
ORDER BY is_starred DESC, name`,
|
||||
[folderId, 0, user.id, user.id],
|
||||
ORDER BY is_starred DESC, f.name`,
|
||||
[user.id, folderId, 0, user.id, user.id],
|
||||
);
|
||||
|
||||
return context.json({ folderId, files: rows.map(publicFile) });
|
||||
@@ -429,12 +431,12 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const user = currentUser(context);
|
||||
const rows = await db.query<FileRow & { folder_name: string | null }>(
|
||||
`SELECT fi.id, fi.folder_id, fi.name, fi.mime_type, fi.size_bytes, fi.checksum_sha256,
|
||||
fi.relative_path, fi.owner_id, fi.is_starred, fi.download_count,
|
||||
fi.relative_path, fi.owner_id, 1 AS is_starred, fi.download_count,
|
||||
fi.created_at, fi.updated_at, fo.name AS folder_name
|
||||
FROM files fi
|
||||
JOIN user_file_stars ufs ON ufs.file_id = fi.id AND ufs.user_id = ?
|
||||
LEFT JOIN folders fo ON fo.id = fi.folder_id
|
||||
WHERE fi.deleted_at IS NULL
|
||||
AND fi.is_starred = 1
|
||||
AND ( fi.owner_id = ?
|
||||
OR ( fi.folder_id IS NOT NULL
|
||||
AND EXISTS ( SELECT 1 FROM folders f
|
||||
@@ -446,8 +448,8 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
AND fp.level IN ('read', 'write', 'admin')
|
||||
AND ( fp.expires_at IS NULL
|
||||
OR fp.expires_at > UTC_TIMESTAMP() ) ) ) )
|
||||
ORDER BY fi.created_at DESC`,
|
||||
[user.id, user.id],
|
||||
ORDER BY ufs.created_at DESC`,
|
||||
[user.id, user.id, user.id],
|
||||
);
|
||||
|
||||
return context.json({
|
||||
@@ -460,7 +462,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const allowed =
|
||||
@@ -499,7 +501,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const allowed =
|
||||
@@ -528,7 +530,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Image introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Image introuvable.");
|
||||
|
||||
const allowed =
|
||||
@@ -563,7 +565,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const owner = row.owner_id !== null && row.owner_id === user.id;
|
||||
@@ -587,7 +589,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const updated = await db.required<FileRow>(`${SELECT_FILE} WHERE id = ?`, [row.id]);
|
||||
const updated = await db.required<FileRow>(`${SELECT_FILE} WHERE f.id = ?`, [user.id, row.id]);
|
||||
await audit(db, context, user, "file.rename", "file", row.id, { name }, config.TRUST_PROXY);
|
||||
return context.json({ file: publicFile(updated) });
|
||||
});
|
||||
@@ -598,7 +600,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const owner = row.owner_id !== null && row.owner_id === user.id;
|
||||
@@ -623,7 +625,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const updated = await db.required<FileRow>(`${SELECT_FILE} WHERE id = ?`, [row.id]);
|
||||
const updated = await db.required<FileRow>(`${SELECT_FILE} WHERE f.id = ?`, [user.id, row.id]);
|
||||
await audit(db, context, user, "file.move", "file", row.id, { folderId: destination }, config.TRUST_PROXY);
|
||||
return context.json({ file: publicFile(updated) });
|
||||
});
|
||||
@@ -634,7 +636,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const allowed =
|
||||
@@ -642,8 +644,22 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
(row.folder_id !== null && (await canRead(db, user, row.folder_id)));
|
||||
if (!allowed) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
await db.exec("UPDATE files SET is_starred = 1 - is_starred WHERE id = ?", [row.id]);
|
||||
const updated = await db.required<FileRow>(`${SELECT_FILE} WHERE id = ?`, [row.id]);
|
||||
const starred = await db.one(
|
||||
"SELECT 1 AS mark FROM user_file_stars WHERE user_id = ? AND file_id = ?",
|
||||
[user.id, row.id],
|
||||
);
|
||||
if (starred) {
|
||||
await db.exec(
|
||||
"DELETE FROM user_file_stars WHERE user_id = ? AND file_id = ?",
|
||||
[user.id, row.id],
|
||||
);
|
||||
} else {
|
||||
await db.exec(
|
||||
"INSERT INTO user_file_stars (user_id, file_id) VALUES (?, ?)",
|
||||
[user.id, row.id],
|
||||
);
|
||||
}
|
||||
const updated = await db.required<FileRow>(`${SELECT_FILE} WHERE f.id = ?`, [user.id, row.id]);
|
||||
return context.json({ file: publicFile(updated) });
|
||||
});
|
||||
|
||||
@@ -652,7 +668,7 @@ export const registerFileRoutes = (app: App, db: Db, config: Config): void => {
|
||||
const rawId = context.req.param("id");
|
||||
if (!uuid.safeParse(rawId).success) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE id = ? AND deleted_at IS NULL`, [rawId]);
|
||||
const row = await db.one<FileRow>(`${SELECT_FILE} WHERE f.id = ? AND f.deleted_at IS NULL`, [user.id, rawId]);
|
||||
if (!row) throw AppError.notFound("Fichier introuvable.");
|
||||
|
||||
const owner = row.owner_id !== null && row.owner_id === user.id;
|
||||
|
||||
@@ -22,12 +22,10 @@ const uuid = z
|
||||
const createFolder = z.object({
|
||||
name: z.string().trim().min(1).max(255),
|
||||
parentId: uuid.nullish(),
|
||||
description: z.string().trim().max(2000).nullish(),
|
||||
});
|
||||
|
||||
const updateFolder = z.object({
|
||||
name: z.string().trim().min(1).max(255).optional(),
|
||||
description: z.string().trim().max(2000).nullish(),
|
||||
name: z.string().trim().min(1).max(255),
|
||||
});
|
||||
|
||||
const moveFolder = z.object({
|
||||
@@ -44,7 +42,6 @@ interface FolderRow {
|
||||
id: string;
|
||||
parent_id: string | null;
|
||||
name: string;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
access_type: string;
|
||||
is_system: number;
|
||||
@@ -53,7 +50,7 @@ interface FolderRow {
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
const SELECT_FOLDER = `SELECT f.id, f.parent_id, f.name, f.description, f.owner_id,
|
||||
const SELECT_FOLDER = `SELECT f.id, f.parent_id, f.name, f.owner_id,
|
||||
f.access_type, f.is_system, f.storage_location_id, f.created_at, f.updated_at
|
||||
FROM folders f`;
|
||||
|
||||
@@ -61,7 +58,6 @@ const publicFolder = (row: FolderRow) => ({
|
||||
id: row.id,
|
||||
parent_id: row.parent_id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
owner_id: row.owner_id,
|
||||
access_type: row.access_type,
|
||||
is_system: row.is_system === 1,
|
||||
@@ -148,7 +144,7 @@ export const registerFolderRoutes = (app: App, db: Db, config: Config): void =>
|
||||
requireRole("admin", "user"),
|
||||
async (context) => {
|
||||
const user = currentUser(context);
|
||||
const { name: rawName, parentId, description } = parse(
|
||||
const { name: rawName, parentId } = parse(
|
||||
createFolder,
|
||||
await context.req.json().catch(() => null),
|
||||
);
|
||||
@@ -190,9 +186,9 @@ export const registerFolderRoutes = (app: App, db: Db, config: Config): void =>
|
||||
const id = randomUUID();
|
||||
try {
|
||||
await db.exec(
|
||||
`INSERT INTO folders (id, storage_location_id, parent_id, name, description, owner_id, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[id, locationId, parentId ?? null, name, description ?? null, user.id, user.id],
|
||||
`INSERT INTO folders (id, storage_location_id, parent_id, name, owner_id, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
[id, locationId, parentId ?? null, name, user.id, user.id],
|
||||
);
|
||||
} catch (error) {
|
||||
if ((error as { errno?: number }).errno === 1062) {
|
||||
@@ -219,16 +215,10 @@ export const registerFolderRoutes = (app: App, db: Db, config: Config): void =>
|
||||
if (!(await canManageFolder(db, user, id))) throw AppError.notFound("Dossier introuvable.");
|
||||
|
||||
const data = parse(updateFolder, await context.req.json().catch(() => null));
|
||||
if (data.name === undefined && data.description === undefined) {
|
||||
throw AppError.badRequest("Rien a modifier.");
|
||||
}
|
||||
const name = data.name === undefined ? existing.name : assertName(data.name);
|
||||
const name = assertName(data.name);
|
||||
|
||||
try {
|
||||
await db.exec(
|
||||
"UPDATE folders SET name = ?, description = ? WHERE id = ?",
|
||||
[name, data.description === undefined ? existing.description : data.description, id],
|
||||
);
|
||||
await db.exec("UPDATE folders SET name = ? WHERE id = ?", [name, id]);
|
||||
} catch (error) {
|
||||
if ((error as { errno?: number }).errno === 1062) {
|
||||
throw AppError.conflict("Ce nom existe deja ici.");
|
||||
|
||||
@@ -42,10 +42,11 @@ export const registerMediaRoutes = (app: App, db: Db): void => {
|
||||
has_thumbnail: number;
|
||||
}>(
|
||||
`SELECT fi.id, fi.folder_id, fi.name, fi.mime_type, fi.size_bytes, fi.owner_id,
|
||||
fi.is_starred, mm.kind, mm.width, mm.height, fi.created_at,
|
||||
(ufs.file_id IS NOT NULL) AS is_starred, mm.kind, mm.width, mm.height, fi.created_at,
|
||||
EXISTS ( SELECT 1 FROM file_variants fv
|
||||
WHERE fv.file_id = fi.id AND fv.purpose = 'thumbnail' ) AS has_thumbnail
|
||||
FROM files fi
|
||||
LEFT JOIN user_file_stars ufs ON ufs.file_id = fi.id AND ufs.user_id = ?
|
||||
LEFT JOIN media_metadata mm ON mm.file_id = fi.id
|
||||
WHERE fi.deleted_at IS NULL
|
||||
AND ( ? = '' OR mm.kind = ? )
|
||||
@@ -61,7 +62,7 @@ export const registerMediaRoutes = (app: App, db: Db): void => {
|
||||
AND ( fp.expires_at IS NULL OR fp.expires_at > UTC_TIMESTAMP() ) ) ) )
|
||||
ORDER BY fi.created_at DESC
|
||||
LIMIT ${limit} OFFSET ${offset}`,
|
||||
[kind, kind, 0, user.id, user.id],
|
||||
[user.id, kind, kind, 0, user.id, user.id],
|
||||
);
|
||||
|
||||
return context.json({
|
||||
|
||||
@@ -32,13 +32,12 @@ export const registerSearchRoutes = (app: App, db: Db): void => {
|
||||
id: string;
|
||||
parent_id: string | null;
|
||||
name: string;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
access_type: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}>(
|
||||
`SELECT f.id, f.parent_id, f.name, f.description, f.owner_id,
|
||||
`SELECT f.id, f.parent_id, f.name, f.owner_id,
|
||||
f.access_type, f.created_at, f.updated_at
|
||||
FROM folders f
|
||||
WHERE f.deleted_at IS NULL
|
||||
@@ -66,8 +65,9 @@ export const registerSearchRoutes = (app: App, db: Db): void => {
|
||||
updated_at: string;
|
||||
}>(
|
||||
`SELECT fi.id, fi.folder_id, fi.name, fi.mime_type, fi.size_bytes, fi.owner_id,
|
||||
fi.is_starred, fi.created_at, fi.updated_at
|
||||
(ufs.file_id IS NOT NULL) AS is_starred, fi.created_at, fi.updated_at
|
||||
FROM files fi
|
||||
LEFT JOIN user_file_stars ufs ON ufs.file_id = fi.id AND ufs.user_id = ?
|
||||
WHERE fi.deleted_at IS NULL
|
||||
AND fi.name LIKE ?
|
||||
AND ( ? = 1
|
||||
@@ -81,7 +81,7 @@ export const registerSearchRoutes = (app: App, db: Db): void => {
|
||||
AND ( fp.expires_at IS NULL OR fp.expires_at > UTC_TIMESTAMP() ) ) ) )
|
||||
ORDER BY fi.name
|
||||
LIMIT ${LIMIT}`,
|
||||
[pattern, 0, user.id, user.id],
|
||||
[user.id, pattern, 0, user.id, user.id],
|
||||
);
|
||||
|
||||
return context.json({
|
||||
@@ -90,7 +90,6 @@ export const registerSearchRoutes = (app: App, db: Db): void => {
|
||||
id: row.id,
|
||||
parent_id: row.parent_id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
owner_id: row.owner_id,
|
||||
access_type: row.access_type,
|
||||
created_at: row.created_at,
|
||||
|
||||
@@ -119,7 +119,6 @@ interface TrashFolderRow {
|
||||
id: string;
|
||||
parent_id: string | null;
|
||||
name: string;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
access_type: string;
|
||||
created_at: string;
|
||||
@@ -143,7 +142,6 @@ const publicFolder = (row: TrashFolderRow) => ({
|
||||
id: row.id,
|
||||
parent_id: row.parent_id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
owner_id: row.owner_id,
|
||||
access_type: row.access_type,
|
||||
created_at: row.created_at,
|
||||
@@ -161,7 +159,7 @@ export const registerTrashRoutes = (app: App, db: Db, config: Config): void => {
|
||||
// Seuls les elements dont le parent n'est pas lui-meme supprime figurent en
|
||||
// tete de corbeille : le reste suit la suppression du parent.
|
||||
const folders = await db.query<TrashFolderRow>(
|
||||
`SELECT f.id, f.parent_id, f.name, f.description, f.owner_id, f.access_type,
|
||||
`SELECT f.id, f.parent_id, f.name, f.owner_id, f.access_type,
|
||||
f.created_at, f.updated_at, f.deleted_at
|
||||
FROM folders f
|
||||
LEFT JOIN folders p ON p.id = f.parent_id
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
(function () {
|
||||
try {
|
||||
var stored = localStorage.getItem("cohaise-theme");
|
||||
var theme = stored === "light" || stored === "dark" ? stored : "system";
|
||||
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
var theme = stored || (prefersDark ? "dark" : "light");
|
||||
if (theme === "dark") document.documentElement.classList.add("dark");
|
||||
var dark = theme === "dark" || (theme === "system" && prefersDark);
|
||||
document.documentElement.classList.toggle("dark", dark);
|
||||
} catch (error) {
|
||||
void error;
|
||||
}
|
||||
|
||||
@@ -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" />
|
||||
|
||||
+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 {
|
||||
id: string;
|
||||
email: string;
|
||||
@@ -9,6 +14,8 @@ export interface User {
|
||||
used_bytes: number;
|
||||
max_file_bytes: number;
|
||||
must_change_password: boolean;
|
||||
theme: Theme;
|
||||
language: Language;
|
||||
has_avatar: boolean;
|
||||
avatar_updated_at: string | null;
|
||||
}
|
||||
@@ -17,7 +24,6 @@ export interface Folder {
|
||||
id: string;
|
||||
parent_id: string | null;
|
||||
name: string;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
access_type: string;
|
||||
is_system: boolean;
|
||||
@@ -67,7 +73,6 @@ export interface TrashFolder {
|
||||
id: string;
|
||||
parent_id: string | null;
|
||||
name: string;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
access_type: string;
|
||||
created_at: string;
|
||||
@@ -171,6 +176,15 @@ export interface ChatMessage {
|
||||
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 {
|
||||
readonly status: number;
|
||||
|
||||
@@ -268,6 +282,9 @@ export const api = {
|
||||
// --- Compte ------------------------------------------------------------
|
||||
updateProfile: (first_name: string, last_name: string) =>
|
||||
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"),
|
||||
revokeSession: (id: string) => del<{ ok: boolean }>(`/account/sessions/${encodeURIComponent(id)}`),
|
||||
revokeOtherSessions: () => del<{ ok: boolean }>("/account/sessions"),
|
||||
@@ -275,15 +292,16 @@ export const api = {
|
||||
uploadAvatar: (file: File) => putBinary<{ ok: boolean }>("/account/avatar", file, file.type),
|
||||
deleteAvatar: () => del<{ ok: boolean }>("/account/avatar"),
|
||||
|
||||
directory: () => request<{ users: DirectoryUser[] }>("/directory"),
|
||||
// --- Dossiers ----------------------------------------------------------
|
||||
folders: (parentId?: string | null) =>
|
||||
request<{ parentId: string | null; folders: Folder[] }>(
|
||||
`/folders${query({ parentId })}`,
|
||||
),
|
||||
createFolder: (name: string, parentId?: string | null, description?: string) =>
|
||||
post<{ folder: Folder }>("/folders", { name, parentId: parentId ?? null, description }),
|
||||
updateFolder: (id: string, payload: { name?: string; description?: string | null }) =>
|
||||
patch<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}`, payload),
|
||||
createFolder: (name: string, parentId?: string | null) =>
|
||||
post<{ folder: Folder }>("/folders", { name, parentId: parentId ?? null }),
|
||||
updateFolder: (id: string, name: string) =>
|
||||
patch<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}`, { name }),
|
||||
moveFolder: (id: string, parentId: string | null) =>
|
||||
post<{ folder: Folder }>(`/folders/${encodeURIComponent(id)}/move`, { parentId }),
|
||||
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 }),
|
||||
chatDeleteMessage: (folderId: string, id: number) =>
|
||||
del<{ ok: boolean }>(`/folders/${encodeURIComponent(folderId)}/chat/messages/${id}`),
|
||||
chatUnread: () => request<{ unread: Record<string, number> }>("/chat/unread"),
|
||||
|
||||
// --- Administration ----------------------------------------------------
|
||||
adminStats: () => request<AdminStats>("/admin/stats"),
|
||||
@@ -391,22 +410,27 @@ export const api = {
|
||||
id: number,
|
||||
payload: { name?: string; quota_bytes?: number | null; is_active?: boolean },
|
||||
) => patch<{ ok: boolean }>(`/admin/storage-locations/${id}`, payload),
|
||||
adminAudit: (limit = 100, offset = 0, action?: string) =>
|
||||
request<{ entries: AuditEntry[] }>(`/admin/audit${query({ limit, offset, action })}`),
|
||||
adminAudit: (limit = 100, offset = 0, action?: string, userId?: string) =>
|
||||
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. */
|
||||
export const formatBytes = (bytes: number): string => {
|
||||
if (bytes < 1024) return `${bytes} o`;
|
||||
const units = ["Ko", "Mo", "Go", "To"];
|
||||
const english = getLanguage() === "en";
|
||||
if (bytes < 1024) return `${bytes} ${english ? "B" : "o"}`;
|
||||
const units = english ? ["KB", "MB", "GB", "TB"] : ["Ko", "Mo", "Go", "To"];
|
||||
let value = bytes;
|
||||
let index = -1;
|
||||
do {
|
||||
value /= 1024;
|
||||
index += 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 =>
|
||||
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 { BrowserRouter } from "react-router-dom";
|
||||
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 "./styles/index.css";
|
||||
|
||||
@@ -12,13 +14,28 @@ if (!container) {
|
||||
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(
|
||||
<StrictMode>
|
||||
<BrowserRouter>
|
||||
<SessionProvider>
|
||||
<ConfirmProvider>
|
||||
<Providers>
|
||||
<App />
|
||||
</ConfirmProvider>
|
||||
</Providers>
|
||||
</SessionProvider>
|
||||
</BrowserRouter>
|
||||
</StrictMode>,
|
||||
|
||||
+167
-104
@@ -9,6 +9,8 @@ import {
|
||||
type AuditEntry,
|
||||
type StorageLocation,
|
||||
} 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 { useConfirm } from "../components/confirm.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
@@ -27,7 +29,7 @@ const messageOf = (caught: unknown, fallback: string): string =>
|
||||
caught instanceof ApiError ? caught.message : fallback;
|
||||
|
||||
const toGb = (bytes: number): string =>
|
||||
(bytes / GB).toLocaleString("fr-FR", { maximumFractionDigits: 1 });
|
||||
(bytes / GB).toLocaleString(getLocale(), { maximumFractionDigits: 1 });
|
||||
|
||||
const StatCard = ({ label, value }: { label: string; value: string }) => (
|
||||
<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 = () => {
|
||||
const { t } = useI18n();
|
||||
const confirm = useConfirm();
|
||||
const [users, setUsers] = useState<AdminUser[] | null>(null);
|
||||
const [stats, setStats] = useState<AdminStats | null>(null);
|
||||
@@ -57,7 +60,7 @@ export const AdminUsers = () => {
|
||||
const { users: list } = await api.adminUsers(term || undefined);
|
||||
setUsers(list);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setError(messageOf(caught, t("Chargement impossible.")));
|
||||
setUsers([]);
|
||||
}
|
||||
};
|
||||
@@ -68,6 +71,7 @@ export const AdminUsers = () => {
|
||||
.adminStats()
|
||||
.then(setStats)
|
||||
.catch(() => undefined);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const toggleActive = async (user: AdminUser) => {
|
||||
@@ -77,7 +81,7 @@ export const AdminUsers = () => {
|
||||
await api.adminUpdateUser(user.id, { is_active: !user.is_active });
|
||||
await load(termRef.current);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Mise à jour impossible."));
|
||||
setError(messageOf(caught, t("Mise à jour impossible.")));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
@@ -89,9 +93,9 @@ export const AdminUsers = () => {
|
||||
setNotice(null);
|
||||
try {
|
||||
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) {
|
||||
setError(messageOf(caught, "Réinitialisation impossible."));
|
||||
setError(messageOf(caught, t("Réinitialisation impossible.")));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
@@ -99,14 +103,11 @@ export const AdminUsers = () => {
|
||||
|
||||
const removeUser = async (user: AdminUser) => {
|
||||
const ok = await confirm({
|
||||
title: "Supprimer le membre",
|
||||
message: (
|
||||
<>
|
||||
Supprimer définitivement <span className="font-semibold text-foreground">{user.email}</span>{" "}
|
||||
ainsi que ses fichiers ? Cette action est irréversible.
|
||||
</>
|
||||
),
|
||||
confirmLabel: "Supprimer",
|
||||
title: t("Supprimer le membre"),
|
||||
message: t("Supprimer définitivement {email} ainsi que ses fichiers ? Cette action est irréversible.", {
|
||||
email: user.email,
|
||||
}),
|
||||
confirmLabel: t("Supprimer"),
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
@@ -116,7 +117,7 @@ export const AdminUsers = () => {
|
||||
await api.adminDeleteUser(user.id);
|
||||
await load(termRef.current);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Suppression impossible."));
|
||||
setError(messageOf(caught, t("Suppression impossible.")));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
@@ -125,24 +126,27 @@ export const AdminUsers = () => {
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Comptes"
|
||||
description="Créez des membres, ajustez leurs quotas et gérez les accès."
|
||||
title={t("Comptes")}
|
||||
description={t("Créer des membres, ajustez leurs quotas et gérez les accès.")}
|
||||
actions={
|
||||
<Button
|
||||
size="sm"
|
||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
Nouveau membre
|
||||
{t("Nouveau membre")}
|
||||
</Button>
|
||||
}
|
||||
toolbar={
|
||||
<>
|
||||
{stats ? (
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<StatCard label="Membres" value={String(stats.users)} />
|
||||
<StatCard label="Fichiers" value={String(stats.files)} />
|
||||
<StatCard label="Stockage" value={`${toGb(stats.usedBytes)} Go`} />
|
||||
<StatCard label={t("Membres")} value={String(stats.users)} />
|
||||
<StatCard label={t("Fichiers")} value={String(stats.files)} />
|
||||
<StatCard
|
||||
label={t("Stockage")}
|
||||
value={t("{value} Go", { value: toGb(stats.usedBytes) })}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -155,15 +159,15 @@ export const AdminUsers = () => {
|
||||
>
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
label="Rechercher"
|
||||
label={t("Rechercher")}
|
||||
type="search"
|
||||
placeholder="nom ou e-mail"
|
||||
placeholder={t("nom ou e-mail")}
|
||||
value={q}
|
||||
onChange={(event) => setQ(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" size="md" variant="secondary">
|
||||
Filtrer
|
||||
{t("Filtrer")}
|
||||
</Button>
|
||||
</form>
|
||||
</>
|
||||
@@ -178,7 +182,7 @@ export const AdminUsers = () => {
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : 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">
|
||||
{users.map((user) => (
|
||||
@@ -189,35 +193,40 @@ export const AdminUsers = () => {
|
||||
{user.first_name} {user.last_name}
|
||||
</span>
|
||||
{user.role_slug === "admin" ? <Badge tone="accent">Admin</Badge> : null}
|
||||
{!user.is_active ? <Badge tone="danger">Inactif</Badge> : null}
|
||||
{user.must_change_password ? <Badge tone="warning">À changer</Badge> : null}
|
||||
{!user.is_active ? <Badge tone="danger">{t("Inactif")}</Badge> : null}
|
||||
{user.must_change_password ? <Badge tone="warning">{t("À changer")}</Badge> : null}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{user.email} · {toGb(user.used_bytes)} / {toGb(user.quota_bytes)} Go ·{" "}
|
||||
{user.email} ·{" "}
|
||||
{t("{used} / {quota} Go", {
|
||||
used: toGb(user.used_bytes),
|
||||
quota: toGb(user.quota_bytes),
|
||||
})}{" "}
|
||||
·{" "}
|
||||
{user.last_login_at
|
||||
? `vu le ${formatDate(user.last_login_at)}`
|
||||
: "jamais connecté"}
|
||||
? t("vu le {date}", { date: formatDate(user.last_login_at) })
|
||||
: t("jamais connecté")}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<Button variant="ghost" size="sm" onClick={() => setEdit(user)}>
|
||||
Modifier
|
||||
{t("Modifier")}
|
||||
</Button>
|
||||
<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" />}
|
||||
isLoading={busy === user.id}
|
||||
onClick={() => void toggleActive(user)}
|
||||
/>
|
||||
<IconAction
|
||||
label="Réinitialiser le mot de passe"
|
||||
label={t("Réinitialiser le mot de passe")}
|
||||
icon={<ActivityIcon className="h-4 w-4" />}
|
||||
isLoading={busy === user.id}
|
||||
onClick={() => void resetPassword(user)}
|
||||
/>
|
||||
<IconAction
|
||||
label="Supprimer"
|
||||
label={t("Supprimer")}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
tone="danger"
|
||||
isLoading={busy === user.id}
|
||||
@@ -234,7 +243,7 @@ export const AdminUsers = () => {
|
||||
onClose={() => setCreateOpen(false)}
|
||||
onCreated={(email) => {
|
||||
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);
|
||||
}}
|
||||
/>
|
||||
@@ -261,6 +270,7 @@ const CreateUserDialog = ({
|
||||
onClose: () => void;
|
||||
onCreated: (email: string) => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [email, setEmail] = useState("");
|
||||
const [firstName, setFirstName] = useState("");
|
||||
const [lastName, setLastName] = useState("");
|
||||
@@ -285,17 +295,17 @@ const CreateUserDialog = ({
|
||||
});
|
||||
onCreated(user.email);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Création impossible."));
|
||||
setError(messageOf(caught, t("Création impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
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)}>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
label={t("Adresse e-mail")}
|
||||
type="email"
|
||||
required
|
||||
autoFocus
|
||||
@@ -304,13 +314,13 @@ const CreateUserDialog = ({
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Prénom"
|
||||
label={t("Prénom")}
|
||||
required
|
||||
value={firstName}
|
||||
onChange={(event) => setFirstName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom"
|
||||
label={t("Nom")}
|
||||
required
|
||||
value={lastName}
|
||||
onChange={(event) => setLastName(event.target.value)}
|
||||
@@ -318,27 +328,27 @@ const CreateUserDialog = ({
|
||||
</div>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Rôle
|
||||
{t("Rôle")}
|
||||
</span>
|
||||
<select
|
||||
value={role}
|
||||
onChange={(event) => setRole(event.target.value)}
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground"
|
||||
>
|
||||
<option value="user">Utilisateur</option>
|
||||
<option value="admin">Administrateur</option>
|
||||
<option value="user">{t("Utilisateur")}</option>
|
||||
<option value="admin">{t("Administrateur")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Quota (Go, optionnel)"
|
||||
label={t("Quota (Go, optionnel)")}
|
||||
type="number"
|
||||
min={1}
|
||||
value={quotaGb}
|
||||
onChange={(event) => setQuotaGb(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fichier max (Mo)"
|
||||
label={t("Fichier max (Mo)")}
|
||||
type="number"
|
||||
min={1}
|
||||
value={maxFileMb}
|
||||
@@ -348,10 +358,10 @@ const CreateUserDialog = ({
|
||||
{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>
|
||||
@@ -368,6 +378,7 @@ const EditUserDialog = ({
|
||||
onClose: () => void;
|
||||
onSaved: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [firstName, setFirstName] = useState(user.first_name);
|
||||
const [lastName, setLastName] = useState(user.last_name);
|
||||
const [role, setRole] = useState(user.role_slug);
|
||||
@@ -390,24 +401,24 @@ const EditUserDialog = ({
|
||||
});
|
||||
onSaved();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Enregistrement impossible."));
|
||||
setError(messageOf(caught, t("Enregistrement impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
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)}>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Prénom"
|
||||
label={t("Prénom")}
|
||||
required
|
||||
value={firstName}
|
||||
onChange={(event) => setFirstName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom"
|
||||
label={t("Nom")}
|
||||
required
|
||||
value={lastName}
|
||||
onChange={(event) => setLastName(event.target.value)}
|
||||
@@ -415,27 +426,27 @@ const EditUserDialog = ({
|
||||
</div>
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground">
|
||||
Rôle
|
||||
{t("Rôle")}
|
||||
</span>
|
||||
<select
|
||||
value={role}
|
||||
onChange={(event) => setRole(event.target.value)}
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground"
|
||||
>
|
||||
<option value="user">Utilisateur</option>
|
||||
<option value="admin">Administrateur</option>
|
||||
<option value="user">{t("Utilisateur")}</option>
|
||||
<option value="admin">{t("Administrateur")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Input
|
||||
label="Quota (Go)"
|
||||
label={t("Quota (Go)")}
|
||||
type="number"
|
||||
min={1}
|
||||
value={quotaGb}
|
||||
onChange={(event) => setQuotaGb(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fichier max (Mo)"
|
||||
label={t("Fichier max (Mo)")}
|
||||
type="number"
|
||||
min={1}
|
||||
value={maxFileMb}
|
||||
@@ -445,10 +456,10 @@ const EditUserDialog = ({
|
||||
{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>
|
||||
@@ -457,6 +468,7 @@ const EditUserDialog = ({
|
||||
};
|
||||
|
||||
export const AdminStorage = () => {
|
||||
const { t } = useI18n();
|
||||
const [locations, setLocations] = useState<StorageLocation[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
@@ -467,13 +479,14 @@ export const AdminStorage = () => {
|
||||
const { locations: list } = await api.adminStorageLocations();
|
||||
setLocations(list);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setError(messageOf(caught, t("Chargement impossible.")));
|
||||
setLocations([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const toggle = async (location: StorageLocation) => {
|
||||
@@ -482,22 +495,22 @@ export const AdminStorage = () => {
|
||||
await api.adminUpdateStorageLocation(location.id, { is_active: !location.is_active });
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Mise à jour impossible."));
|
||||
setError(messageOf(caught, t("Mise à jour impossible.")));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Emplacements de stockage"
|
||||
description="Volumes montés utilisés pour stocker les fichiers."
|
||||
title={t("Emplacements de stockage")}
|
||||
description={t("Volumes montés utilisés pour stocker les fichiers.")}
|
||||
actions={
|
||||
<Button
|
||||
size="sm"
|
||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
Nouvel emplacement
|
||||
{t("Nouvel emplacement")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
@@ -509,7 +522,7 @@ export const AdminStorage = () => {
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : 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">
|
||||
{locations.map((location) => (
|
||||
@@ -519,17 +532,20 @@ export const AdminStorage = () => {
|
||||
<span className="truncate text-sm font-medium text-foreground">
|
||||
{location.name}
|
||||
</span>
|
||||
{!location.is_active ? <Badge tone="danger">Inactif</Badge> : null}
|
||||
{!location.is_active ? <Badge tone="danger">{t("Inactif")}</Badge> : null}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{location.slug} · {location.mount_path} ·{" "}
|
||||
{location.quota_bytes
|
||||
? `${toGb(location.used_bytes)} / ${toGb(location.quota_bytes)} Go`
|
||||
: `${toGb(location.used_bytes)} Go utilisés`}
|
||||
? t("{used} / {quota} Go", {
|
||||
used: toGb(location.used_bytes),
|
||||
quota: toGb(location.quota_bytes),
|
||||
})
|
||||
: t("{used} Go utilisés", { used: toGb(location.used_bytes) })}
|
||||
</span>
|
||||
</span>
|
||||
<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>
|
||||
</li>
|
||||
))}
|
||||
@@ -556,6 +572,7 @@ const CreateLocationDialog = ({
|
||||
onClose: () => void;
|
||||
onCreated: () => void;
|
||||
}) => {
|
||||
const { t } = useI18n();
|
||||
const [name, setName] = useState("");
|
||||
const [slug, setSlug] = useState("");
|
||||
const [mountPath, setMountPath] = useState("");
|
||||
@@ -576,24 +593,24 @@ const CreateLocationDialog = ({
|
||||
});
|
||||
onCreated();
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Création impossible."));
|
||||
setError(messageOf(caught, t("Création impossible.")));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
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)}>
|
||||
<Input
|
||||
label="Nom"
|
||||
label={t("Nom")}
|
||||
required
|
||||
autoFocus
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Identifiant technique"
|
||||
label={t("Identifiant technique")}
|
||||
required
|
||||
placeholder="principal"
|
||||
pattern="[a-z0-9][a-z0-9-]*"
|
||||
@@ -601,14 +618,14 @@ const CreateLocationDialog = ({
|
||||
onChange={(event) => setSlug(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Chemin de montage"
|
||||
label={t("Chemin de montage")}
|
||||
required
|
||||
placeholder="/data/cloud"
|
||||
value={mountPath}
|
||||
onChange={(event) => setMountPath(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Quota (Go, optionnel)"
|
||||
label={t("Quota (Go, optionnel)")}
|
||||
type="number"
|
||||
min={1}
|
||||
value={quotaGb}
|
||||
@@ -617,10 +634,10 @@ const CreateLocationDialog = ({
|
||||
{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>
|
||||
@@ -629,65 +646,111 @@ const CreateLocationDialog = ({
|
||||
};
|
||||
|
||||
export const AdminAudit = () => {
|
||||
const { t } = useI18n();
|
||||
const [entries, setEntries] = useState<AuditEntry[] | null>(null);
|
||||
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 [loadingMore, setLoadingMore] = useState(false);
|
||||
|
||||
const load = async (term: string) => {
|
||||
const load = async (nextAction: string, nextUser: string) => {
|
||||
setError(null);
|
||||
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);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setError(messageOf(caught, t("Chargement impossible.")));
|
||||
setEntries([]);
|
||||
}
|
||||
};
|
||||
|
||||
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 () => {
|
||||
if (!entries) return;
|
||||
setLoadingMore(true);
|
||||
setError(null);
|
||||
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]);
|
||||
} catch (caught) {
|
||||
setError(messageOf(caught, "Chargement impossible."));
|
||||
setError(messageOf(caught, t("Chargement impossible.")));
|
||||
} finally {
|
||||
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 (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Journal d'activité"
|
||||
description="Dernières actions enregistrées."
|
||||
title={t("Journal d'activité")}
|
||||
description={t("Dernières actions enregistrées.")}
|
||||
toolbar={
|
||||
<form
|
||||
className="flex items-end gap-2"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void load(action);
|
||||
}}
|
||||
>
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
label="Filtrer par action"
|
||||
placeholder="auth.login, file.upload…"
|
||||
<div className="flex flex-wrap items-end gap-3">
|
||||
<label className="flex min-w-48 flex-col gap-1.5">
|
||||
<span className={fieldClass}>{t("Utilisateur")}</span>
|
||||
<select
|
||||
value={userId}
|
||||
onChange={(event) => apply(action, event.target.value)}
|
||||
className={selectClass}
|
||||
>
|
||||
<option value="">{t("Tous les utilisateurs")}</option>
|
||||
{filters.users.map((user) => (
|
||||
<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}
|
||||
onChange={(event) => setAction(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" variant="secondary" size="md">
|
||||
Filtrer
|
||||
</Button>
|
||||
</form>
|
||||
onChange={(event) => apply(event.target.value, userId)}
|
||||
className={selectClass}
|
||||
>
|
||||
<option value="">{t("Toutes les actions")}</option>
|
||||
{filters.actions.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -698,7 +761,7 @@ export const AdminAudit = () => {
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
) : 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">
|
||||
@@ -713,7 +776,7 @@ export const AdminAudit = () => {
|
||||
</span>
|
||||
</span>
|
||||
<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}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
@@ -728,7 +791,7 @@ export const AdminAudit = () => {
|
||||
isLoading={loadingMore}
|
||||
onClick={() => void loadMore()}
|
||||
>
|
||||
Charger plus
|
||||
{t("Charger plus")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
+121
-47
@@ -1,5 +1,5 @@
|
||||
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 {
|
||||
ApiError,
|
||||
api,
|
||||
@@ -8,7 +8,10 @@ import {
|
||||
type UploadedFile,
|
||||
} from "../lib/api.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 { MediaViewer } from "../components/MediaViewer.js";
|
||||
import { MediaThumb } from "../components/MediaThumb.js";
|
||||
@@ -48,8 +51,19 @@ type Dialog =
|
||||
| { kind: "share"; folder: Folder }
|
||||
| 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 = () => {
|
||||
const { user, refresh } = useSession();
|
||||
const { t } = useI18n();
|
||||
const confirm = useConfirm();
|
||||
const [path, setPath] = useState<Crumb[]>([{ id: null, name: "Racine" }]);
|
||||
const [folders, setFolders] = useState<Folder[]>([]);
|
||||
@@ -61,6 +75,8 @@ export const Browser = () => {
|
||||
const [dialog, setDialog] = useState<Dialog>(null);
|
||||
const [viewer, setViewer] = useState<number | 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 current = path[path.length - 1] ?? { id: null, name: "Racine" };
|
||||
@@ -76,18 +92,37 @@ export const Browser = () => {
|
||||
setFolders(folderResult.folders);
|
||||
setFiles(fileResult.files);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
setFolders([]);
|
||||
setFiles([]);
|
||||
} finally {
|
||||
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(() => {
|
||||
void load(current.id);
|
||||
}, [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 open = (folder: Folder) => {
|
||||
@@ -107,7 +142,7 @@ export const Browser = () => {
|
||||
void refresh();
|
||||
await reload();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Envoi impossible."));
|
||||
} finally {
|
||||
setUploading(false);
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
@@ -115,16 +150,11 @@ export const Browser = () => {
|
||||
};
|
||||
|
||||
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({
|
||||
title: "Mettre à la corbeille",
|
||||
message: (
|
||||
<>
|
||||
Placer <span className="font-semibold text-foreground">{target.name}</span> ({label}) dans la
|
||||
corbeille ?
|
||||
</>
|
||||
),
|
||||
confirmLabel: "Corbeille",
|
||||
title: t("Mettre à la corbeille"),
|
||||
message: t("Placer {name} ({kind}) dans la corbeille ?", { name: target.name, kind }),
|
||||
confirmLabel: t("Corbeille"),
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
@@ -139,7 +169,7 @@ export const Browser = () => {
|
||||
}
|
||||
await reload();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Suppression impossible."));
|
||||
} finally {
|
||||
setRemoving(null);
|
||||
}
|
||||
@@ -151,12 +181,19 @@ export const Browser = () => {
|
||||
const { file: updated } = await api.starFile(file.id);
|
||||
setFiles((previous) => previous.map((item) => (item.id === updated.id ? updated : item)));
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
||||
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 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 =
|
||||
user && user.quota_bytes > 0
|
||||
? 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">
|
||||
<PageHeader
|
||||
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={
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{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"
|
||||
>
|
||||
<ArrowLeftIcon className="h-3.5 w-3.5" />
|
||||
Retour
|
||||
{t("Retour")}
|
||||
</button>
|
||||
) : 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">
|
||||
{path.map((crumb, index) => (
|
||||
<li key={`${crumb.id ?? "root"}-${index}`} className="flex items-center gap-1.5">
|
||||
@@ -191,7 +228,7 @@ export const Browser = () => {
|
||||
) : null}
|
||||
{index === path.length - 1 ? (
|
||||
<span className="font-medium text-foreground" aria-current="page">
|
||||
{crumb.name}
|
||||
{t(crumb.name)}
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
@@ -199,7 +236,7 @@ export const Browser = () => {
|
||||
onClick={() => goTo(index)}
|
||||
className="text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
|
||||
>
|
||||
{crumb.name}
|
||||
{t(crumb.name)}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
@@ -214,7 +251,10 @@ export const Browser = () => {
|
||||
iconLeading={<ChatIcon className="h-3.5 w-3.5" />}
|
||||
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>
|
||||
) : null}
|
||||
</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="min-w-0 flex-1">
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<span className="text-xs font-medium text-foreground">Espace utilisé</span>
|
||||
<span className="text-xs font-medium text-foreground">{t("Espace utilisé")}</span>
|
||||
<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>
|
||||
</div>
|
||||
<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}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
>
|
||||
Envoyer
|
||||
{t("Envoyer")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
@@ -262,13 +305,35 @@ export const Browser = () => {
|
||||
iconLeading={<PlusIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setDialog({ kind: "create" })}
|
||||
>
|
||||
Nouveau dossier
|
||||
{t("Nouveau dossier")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</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}
|
||||
|
||||
{loading ? (
|
||||
@@ -278,15 +343,15 @@ export const Browser = () => {
|
||||
) : empty ? (
|
||||
<EmptyState
|
||||
icon={<FolderIcon className="h-8 w-8" />}
|
||||
title="Emplacement vide"
|
||||
description="Créez un sous-dossier ou envoyez un fichier pour commencer."
|
||||
title={t("Emplacement vide")}
|
||||
description={t("Créez un sous-dossier ou envoyez un fichier pour commencer.")}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6">
|
||||
{folders.length > 0 ? (
|
||||
<section aria-label="Dossiers">
|
||||
<section aria-label={t("Dossiers")}>
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Dossiers
|
||||
{t("Dossiers")}
|
||||
</h2>
|
||||
<ul className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{folders.map((folder) => (
|
||||
@@ -307,24 +372,25 @@ export const Browser = () => {
|
||||
{folder.name}
|
||||
</span>
|
||||
<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>
|
||||
</button>
|
||||
<IconAction
|
||||
label={`Discussion ${folder.name}`}
|
||||
label={t("Discussion {name}", { name: folder.name })}
|
||||
icon={<ChatIcon className="h-4 w-4" />}
|
||||
badge={unread[folder.id] ?? 0}
|
||||
onClick={() => setChat({ id: folder.id, name: folder.name })}
|
||||
/>
|
||||
{canWrite ? (
|
||||
<div className="flex shrink-0 items-center gap-0.5">
|
||||
<IconAction
|
||||
label={`Partager ${folder.name}`}
|
||||
label={t("Partager {name}", { name: folder.name })}
|
||||
icon={<ShareIcon className="h-4 w-4" />}
|
||||
onClick={() => setDialog({ kind: "share", folder })}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Renommer ${folder.name}`}
|
||||
label={t("Renommer {name}", { name: folder.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
@@ -334,7 +400,7 @@ export const Browser = () => {
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Déplacer ${folder.name}`}
|
||||
label={t("Déplacer {name}", { name: folder.name })}
|
||||
icon={<MoveIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
@@ -344,7 +410,7 @@ export const Browser = () => {
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer ${folder.name}`}
|
||||
label={t("Supprimer {name}", { name: folder.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === folder.id}
|
||||
tone="danger"
|
||||
@@ -361,18 +427,21 @@ export const Browser = () => {
|
||||
) : null}
|
||||
|
||||
{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">
|
||||
Fichiers
|
||||
{t("Fichiers")}
|
||||
</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">
|
||||
{files.map((file, index) => (
|
||||
{visibleFiles.map((file, index) => (
|
||||
<li key={file.id} className="flex items-center gap-2 px-3 py-2.5">
|
||||
<button
|
||||
type="button"
|
||||
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"
|
||||
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} />
|
||||
</button>
|
||||
@@ -382,12 +451,16 @@ export const Browser = () => {
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(file.size_bytes)} ·{" "}
|
||||
{new Date(file.created_at).toLocaleDateString("fr-FR")}
|
||||
{new Date(file.created_at).toLocaleDateString(getLocale())}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<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={
|
||||
<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"
|
||||
>
|
||||
<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>
|
||||
|
||||
{canWrite ? (
|
||||
<>
|
||||
<IconAction
|
||||
label={`Renommer ${file.name}`}
|
||||
label={t("Renommer {name}", { name: file.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
@@ -416,7 +489,7 @@ export const Browser = () => {
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Déplacer ${file.name}`}
|
||||
label={t("Déplacer {name}", { name: file.name })}
|
||||
icon={<MoveIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
@@ -426,7 +499,7 @@ export const Browser = () => {
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer ${file.name}`}
|
||||
label={t("Supprimer {name}", { name: file.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === file.id}
|
||||
tone="danger"
|
||||
@@ -439,6 +512,7 @@ export const Browser = () => {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -483,14 +557,14 @@ export const Browser = () => {
|
||||
|
||||
{viewer !== null ? (
|
||||
<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}
|
||||
onClose={() => setViewer(null)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{chat ? (
|
||||
<FolderChat key={chat.id} folder={chat} onClose={() => setChat(null)} />
|
||||
<FolderChat key={chat.id} folder={chat} onClose={closeChat} />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,9 +4,11 @@ import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Inpu
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
export const ChangePassword = () => {
|
||||
const { user, refresh, logout } = useSession();
|
||||
const { t } = useI18n();
|
||||
const navigate = useNavigate();
|
||||
const [current, setCurrent] = useState("");
|
||||
const [next, setNext] = useState("");
|
||||
@@ -17,7 +19,7 @@ export const ChangePassword = () => {
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (next !== confirm) {
|
||||
setError("Les deux mots de passe ne correspondent pas.");
|
||||
setError(t("Les deux mots de passe ne correspondent pas."));
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
@@ -27,7 +29,7 @@ export const ChangePassword = () => {
|
||||
await refresh();
|
||||
navigate("/files", { replace: true });
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Changement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Changement impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -48,27 +50,26 @@ export const ChangePassword = () => {
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Nouveau mot de passe
|
||||
{t("Nouveau mot de passe")}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
Bienvenue {user?.first_name ?? ""}. Ce mot de passe a été défini par un
|
||||
administrateur : choisissez le vôtre.
|
||||
{t("Bienvenue {name}. Ce mot de passe a été défini par un administrateur : choisissez le vôtre.", { name: user?.first_name ?? "" })}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Changement requis</CardTitle>
|
||||
<CardTitle>{t("Changement requis")}</CardTitle>
|
||||
<CardDescription>
|
||||
Les autres sessions ouvertes sur ce compte seront fermées.
|
||||
{t("Les autres sessions ouvertes sur ce compte seront fermées.")}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Mot de passe actuel"
|
||||
label={t("Mot de passe actuel")}
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
@@ -77,17 +78,17 @@ export const ChangePassword = () => {
|
||||
onChange={(event) => setCurrent(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nouveau mot de passe"
|
||||
label={t("Nouveau mot de passe")}
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
hint="8 caractères minimum."
|
||||
hint={t("8 caractères minimum.")}
|
||||
value={next}
|
||||
onChange={(event) => setNext(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Confirmation"
|
||||
label={t("Confirmation")}
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
@@ -97,7 +98,7 @@ export const ChangePassword = () => {
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Enregistrer
|
||||
{t("Enregistrer")}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -106,7 +107,7 @@ export const ChangePassword = () => {
|
||||
fullWidth
|
||||
onClick={() => void logout()}
|
||||
>
|
||||
Se déconnecter
|
||||
{t("Se déconnecter")}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
|
||||
@@ -4,11 +4,13 @@ import { Button, Card, CardContent, CardHeader, CardTitle, Spinner } from "../ui
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
export const ConfirmEmail = () => {
|
||||
const [params] = useSearchParams();
|
||||
const token = params.get("token") ?? "";
|
||||
const { refresh } = useSession();
|
||||
const { t } = useI18n();
|
||||
const [state, setState] = useState<"loading" | "success" | "error">("loading");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const started = useRef(false);
|
||||
@@ -18,7 +20,7 @@ export const ConfirmEmail = () => {
|
||||
started.current = true;
|
||||
if (!token) {
|
||||
setState("error");
|
||||
setError("Ce lien est incomplet ou invalide.");
|
||||
setError(t("Ce lien est incomplet ou invalide."));
|
||||
return;
|
||||
}
|
||||
api
|
||||
@@ -29,7 +31,7 @@ export const ConfirmEmail = () => {
|
||||
})
|
||||
.catch((caught: unknown) => {
|
||||
setState("error");
|
||||
setError(caught instanceof ApiError ? caught.message : "Confirmation impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Confirmation impossible."));
|
||||
});
|
||||
}, [token, refresh]);
|
||||
|
||||
@@ -48,7 +50,7 @@ export const ConfirmEmail = () => {
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Changement d'adresse
|
||||
{t("Changement d'adresse")}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
@@ -56,7 +58,7 @@ export const ConfirmEmail = () => {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Confirmation</CardTitle>
|
||||
<CardTitle>{t("Confirmation")}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{state === "loading" ? (
|
||||
@@ -65,10 +67,10 @@ export const ConfirmEmail = () => {
|
||||
</div>
|
||||
) : 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">
|
||||
<Button size="lg" fullWidth>
|
||||
Accéder à mes fichiers
|
||||
{t("Accéder à mes fichiers")}
|
||||
</Button>
|
||||
</Link>
|
||||
</>
|
||||
@@ -77,7 +79,7 @@ export const ConfirmEmail = () => {
|
||||
<Alert>{error}</Alert>
|
||||
<Link to="/profile">
|
||||
<Button size="lg" fullWidth>
|
||||
Mon compte
|
||||
{t("Mon compte")}
|
||||
</Button>
|
||||
</Link>
|
||||
</>
|
||||
|
||||
@@ -6,8 +6,10 @@ import { MediaViewer } from "../components/MediaViewer.js";
|
||||
import { MediaThumb } from "../components/MediaThumb.js";
|
||||
import { IconAction } from "../components/IconAction.js";
|
||||
import { DownloadIcon, FolderIcon, StarIcon } from "../components/icons.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
export const Favorites = () => {
|
||||
const { t } = useI18n();
|
||||
const [files, setFiles] = useState<FavoriteFile[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -22,7 +24,7 @@ export const Favorites = () => {
|
||||
setError(null);
|
||||
})
|
||||
.catch((caught: unknown) => {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
setFiles([]);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
@@ -34,15 +36,15 @@ export const Favorites = () => {
|
||||
await api.starFile(file.id);
|
||||
setFiles((previous) => previous.filter((item) => item.id !== file.id));
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Action impossible."));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Favoris"
|
||||
description="Les fichiers que vous avez étoilés, tous dossiers confondus."
|
||||
title={t("Favoris")}
|
||||
description={t("Les fichiers que vous avez étoilés, tous dossiers confondus.")}
|
||||
/>
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
@@ -54,8 +56,8 @@ export const Favorites = () => {
|
||||
) : files.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<StarIcon className="h-8 w-8" />}
|
||||
title="Aucun favori"
|
||||
description="Étoilez un fichier dans l'explorateur pour le retrouver ici."
|
||||
title={t("Aucun favori")}
|
||||
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">
|
||||
@@ -65,7 +67,7 @@ export const Favorites = () => {
|
||||
type="button"
|
||||
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"
|
||||
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} />
|
||||
</button>
|
||||
@@ -75,14 +77,14 @@ export const Favorites = () => {
|
||||
</span>
|
||||
<span className="flex items-center gap-1.5 text-[0.6875rem] text-subtle-foreground">
|
||||
<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 className="shrink-0">{formatBytes(file.size_bytes)}</span>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<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 />}
|
||||
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"
|
||||
>
|
||||
<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>
|
||||
</li>
|
||||
))}
|
||||
|
||||
@@ -3,8 +3,10 @@ import { Link } from "react-router-dom";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
||||
import { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
export const ForgotPassword = () => {
|
||||
const { t } = useI18n();
|
||||
const [email, setEmail] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -18,7 +20,7 @@ export const ForgotPassword = () => {
|
||||
await api.forgotPassword(email);
|
||||
setSent(true);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Demande impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Demande impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -39,7 +41,7 @@ export const ForgotPassword = () => {
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Mot de passe oublié
|
||||
{t("Mot de passe oublié")}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
@@ -47,23 +49,22 @@ export const ForgotPassword = () => {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Réinitialisation</CardTitle>
|
||||
<CardTitle>{t("Réinitialisation")}</CardTitle>
|
||||
<CardDescription>
|
||||
Nous vous enverrons un lien valable une heure.
|
||||
{t("Nous vous enverrons un lien valable une heure.")}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{sent ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert tone="success">
|
||||
Si cette adresse correspond à un compte, un message contenant le lien de
|
||||
réinitialisation vient d'être envoyé.
|
||||
{t("Si cette adresse correspond à un compte, un message contenant le lien de réinitialisation vient d'être envoyé.")}
|
||||
</Alert>
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Retour à la connexion
|
||||
{t("Retour à la connexion")}
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
@@ -72,7 +73,7 @@ export const ForgotPassword = () => {
|
||||
onSubmit={(event) => void submit(event)}
|
||||
>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
label={t("Adresse e-mail")}
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
@@ -82,13 +83,13 @@ export const ForgotPassword = () => {
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Envoyer le lien
|
||||
{t("Envoyer le lien")}
|
||||
</Button>
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Retour à la connexion
|
||||
{t("Retour à la connexion")}
|
||||
</Link>
|
||||
</form>
|
||||
)}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { MediaViewer } from "../components/MediaViewer.js";
|
||||
import { MediaThumb } from "../components/MediaThumb.js";
|
||||
import { ImageIcon } from "../components/icons.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
const KINDS = [
|
||||
{ value: "", label: "Tout" },
|
||||
@@ -19,6 +20,7 @@ const KINDS = [
|
||||
const PAGE = 60;
|
||||
|
||||
export const Gallery = () => {
|
||||
const { t } = useI18n();
|
||||
const [kind, setKind] = useState<string>("image");
|
||||
const [items, setItems] = useState<MediaItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -35,7 +37,7 @@ export const Gallery = () => {
|
||||
setError(null);
|
||||
})
|
||||
.catch((caught: unknown) => {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
setItems([]);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
@@ -48,7 +50,7 @@ export const Gallery = () => {
|
||||
const { items: more } = await api.gallery(kind, PAGE, items.length);
|
||||
setItems((previous) => [...previous, ...more]);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
} finally {
|
||||
setLoadingMore(false);
|
||||
}
|
||||
@@ -57,10 +59,10 @@ export const Gallery = () => {
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Galerie"
|
||||
description="Parcourez les médias auxquels vous avez accès."
|
||||
title={t("Galerie")}
|
||||
description={t("Parcourez les médias auxquels vous avez accès.")}
|
||||
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) => (
|
||||
<button
|
||||
key={option.value}
|
||||
@@ -78,7 +80,7 @@ export const Gallery = () => {
|
||||
: "border-border-control text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{option.label}
|
||||
{t(option.label)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -94,8 +96,8 @@ export const Gallery = () => {
|
||||
) : items.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<ImageIcon className="h-8 w-8" />}
|
||||
title="Aucun média"
|
||||
description="Rien à afficher pour ce filtre."
|
||||
title={t("Aucun média")}
|
||||
description={t("Rien à afficher pour ce filtre.")}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
@@ -131,7 +133,7 @@ export const Gallery = () => {
|
||||
{items.length >= PAGE ? (
|
||||
<div className="flex justify-center">
|
||||
<Button variant="secondary" size="md" isLoading={loadingMore} onClick={() => void loadMore()}>
|
||||
Charger plus
|
||||
{t("Charger plus")}
|
||||
</Button>
|
||||
</div>
|
||||
) : 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 { ApiError, api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
export const Login = () => {
|
||||
const { user, setUser } = useSession();
|
||||
const { t } = useI18n();
|
||||
const navigate = useNavigate();
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
@@ -23,7 +25,7 @@ export const Login = () => {
|
||||
setUser(current);
|
||||
navigate(current.must_change_password ? "/change-password" : "/files", { replace: true });
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Connexion impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Connexion impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -49,19 +51,19 @@ export const Login = () => {
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Connexion</CardTitle>
|
||||
<CardDescription>Votre session reste ouverte 14 jours.</CardDescription>
|
||||
<CardTitle>{t("Connexion")}</CardTitle>
|
||||
<CardDescription>{t("Votre session reste ouverte 14 jours.")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
label={t("Adresse e-mail")}
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
required
|
||||
@@ -70,7 +72,7 @@ export const Login = () => {
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mot de passe"
|
||||
label={t("Mot de passe")}
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
@@ -80,7 +82,7 @@ export const Login = () => {
|
||||
/>
|
||||
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Se connecter
|
||||
{t("Se connecter")}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
@@ -91,7 +93,7 @@ export const Login = () => {
|
||||
to="/forgot-password"
|
||||
className="underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Mot de passe oublié ?
|
||||
{t("Mot de passe oublié ?")}
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
+132
-42
@@ -1,13 +1,26 @@
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, Spinner } from "../ui/index.js";
|
||||
import { ApiError, api, formatDate, type SessionInfo } from "../lib/api.js";
|
||||
import { ApiError, api, formatDate, type Language, type SessionInfo, type Theme } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { Alert, Badge, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.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 = () => {
|
||||
const { user, refresh } = useSession();
|
||||
const { t } = useI18n();
|
||||
const confirm = useConfirm();
|
||||
|
||||
const [firstName, setFirstName] = useState(user?.first_name ?? "");
|
||||
@@ -16,7 +29,12 @@ export const Profile = () => {
|
||||
const [profileError, setProfileError] = useState<string | null>(null);
|
||||
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 avatarInput = useRef<HTMLInputElement>(null);
|
||||
|
||||
@@ -34,6 +52,8 @@ export const Profile = () => {
|
||||
if (user) {
|
||||
setFirstName((current) => (current === "" ? user.first_name : current));
|
||||
setLastName((current) => (current === "" ? user.last_name : current));
|
||||
setTheme(user.theme);
|
||||
setLanguage(user.language);
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
@@ -43,13 +63,14 @@ export const Profile = () => {
|
||||
const { sessions: list } = await api.sessions();
|
||||
setSessions(list);
|
||||
} catch (caught) {
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
setSessions([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void loadSessions();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const saveProfile = async (event: FormEvent<HTMLFormElement>) => {
|
||||
@@ -60,14 +81,30 @@ export const Profile = () => {
|
||||
try {
|
||||
await api.updateProfile(firstName.trim(), lastName.trim());
|
||||
await refresh();
|
||||
setProfileMessage("Informations enregistrées.");
|
||||
setProfileMessage(t("Informations enregistrées."));
|
||||
} catch (caught) {
|
||||
setProfileError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
setProfileError(caught instanceof ApiError ? caught.message : t("Enregistrement impossible."));
|
||||
} finally {
|
||||
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>) => {
|
||||
event.preventDefault();
|
||||
setSendingEmail(true);
|
||||
@@ -77,9 +114,9 @@ export const Profile = () => {
|
||||
await api.requestEmailChange(password, newEmail.trim());
|
||||
setPassword("");
|
||||
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) {
|
||||
setEmailError(caught instanceof ApiError ? caught.message : "Demande impossible.");
|
||||
setEmailError(caught instanceof ApiError ? caught.message : t("Demande impossible."));
|
||||
} finally {
|
||||
setSendingEmail(false);
|
||||
}
|
||||
@@ -90,10 +127,9 @@ export const Profile = () => {
|
||||
setAvatarError(null);
|
||||
try {
|
||||
await api.uploadAvatar(file);
|
||||
setAvatarNonce((value) => value + 1);
|
||||
await refresh();
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : t("Envoi impossible."));
|
||||
} finally {
|
||||
if (avatarInput.current) avatarInput.current.value = "";
|
||||
}
|
||||
@@ -103,19 +139,18 @@ export const Profile = () => {
|
||||
setAvatarError(null);
|
||||
try {
|
||||
await api.deleteAvatar();
|
||||
setAvatarNonce((value) => value + 1);
|
||||
await refresh();
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : t("Suppression impossible."));
|
||||
}
|
||||
};
|
||||
|
||||
const revokeSession = async (session: SessionInfo) => {
|
||||
if (session.current) {
|
||||
const ok = await confirm({
|
||||
title: "Fermer la session",
|
||||
message: "Fermer la session en cours vous déconnectera immédiatement.",
|
||||
confirmLabel: "Fermer",
|
||||
title: t("Fermer la session"),
|
||||
message: t("Fermer la session en cours vous déconnectera immédiatement."),
|
||||
confirmLabel: t("Fermer"),
|
||||
});
|
||||
if (!ok) return;
|
||||
}
|
||||
@@ -129,7 +164,7 @@ export const Profile = () => {
|
||||
}
|
||||
setSessions((previous) => (previous ?? []).filter((item) => item.id !== session.id));
|
||||
} catch (caught) {
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : "Révocation impossible.");
|
||||
setSessionsError(caught instanceof ApiError ? caught.message : t("Révocation impossible."));
|
||||
} finally {
|
||||
setRevoking(null);
|
||||
}
|
||||
@@ -141,7 +176,7 @@ export const Profile = () => {
|
||||
await api.revokeOtherSessions();
|
||||
setSessions((previous) => (previous ?? []).filter((item) => item.current));
|
||||
} 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 (
|
||||
<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>
|
||||
<CardHeader>
|
||||
<CardTitle>Identité</CardTitle>
|
||||
<CardDescription>Informations affichées dans l'interface.</CardDescription>
|
||||
<CardTitle>{t("Identité")}</CardTitle>
|
||||
<CardDescription>{t("Informations affichées dans l'interface.")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void saveProfile(event)}>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<Input
|
||||
label="Prénom"
|
||||
label={t("Prénom")}
|
||||
required
|
||||
maxLength={255}
|
||||
value={firstName}
|
||||
onChange={(event) => setFirstName(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom"
|
||||
label={t("Nom")}
|
||||
required
|
||||
maxLength={255}
|
||||
value={lastName}
|
||||
@@ -184,7 +272,7 @@ export const Profile = () => {
|
||||
{profileMessage ? <Alert tone="success">{profileMessage}</Alert> : null}
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="md" isLoading={savingProfile}>
|
||||
Enregistrer
|
||||
{t("Enregistrer")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -193,14 +281,14 @@ export const Profile = () => {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Photo de profil</CardTitle>
|
||||
<CardDescription>Image carrée, format PNG ou JPEG.</CardDescription>
|
||||
<CardTitle>{t("Photo de profil")}</CardTitle>
|
||||
<CardDescription>{t("Image carrée, format PNG ou JPEG.")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex items-center gap-4">
|
||||
<span className="flex h-16 w-16 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface-muted">
|
||||
<img
|
||||
src={`${api.avatarUrl(user.id)}?v=${avatarNonce}`}
|
||||
src={`${api.avatarUrl(user.id)}?v=${user.avatar_updated_at ?? ""}`}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
onError={(event) => {
|
||||
@@ -218,14 +306,14 @@ export const Profile = () => {
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="secondary" size="sm" onClick={() => avatarInput.current?.click()}>
|
||||
Choisir une image
|
||||
{t("Choisir une image")}
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={() => void removeAvatar()}>
|
||||
Retirer
|
||||
{t("Retirer")}
|
||||
</Button>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@@ -235,21 +323,21 @@ export const Profile = () => {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Adresse e-mail</CardTitle>
|
||||
<CardDescription>Adresse actuelle : {user.email}</CardDescription>
|
||||
<CardTitle>{t("Adresse e-mail")}</CardTitle>
|
||||
<CardDescription>{t("Adresse actuelle : {email}", { email: user.email })}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void requestEmail(event)}>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Input
|
||||
label="Nouvelle adresse"
|
||||
label={t("Nouvelle adresse")}
|
||||
type="email"
|
||||
required
|
||||
value={newEmail}
|
||||
onChange={(event) => setNewEmail(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mot de passe actuel"
|
||||
label={t("Mot de passe actuel")}
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
@@ -261,17 +349,17 @@ export const Profile = () => {
|
||||
{emailMessage ? <Alert tone="success">{emailMessage}</Alert> : null}
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="md" isLoading={sendingEmail}>
|
||||
Demander le changement
|
||||
{t("Demander le changement")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<Card className="lg:col-span-2">
|
||||
<CardHeader>
|
||||
<CardTitle>Sessions ouvertes</CardTitle>
|
||||
<CardDescription>Appareils actuellement connectés à votre compte.</CardDescription>
|
||||
<CardTitle>{t("Sessions ouvertes")}</CardTitle>
|
||||
<CardDescription>{t("Appareils actuellement connectés à votre compte.")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{sessionsError ? <Alert>{sessionsError}</Alert> : null}
|
||||
@@ -280,7 +368,7 @@ export const Profile = () => {
|
||||
<Spinner size="sm" />
|
||||
</div>
|
||||
) : 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">
|
||||
{sessions.map((session) => (
|
||||
@@ -288,17 +376,18 @@ export const Profile = () => {
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="truncate text-xs font-medium text-foreground">
|
||||
{session.user_agent ? session.user_agent.slice(0, 60) : "Appareil inconnu"}
|
||||
{session.user_agent ? session.user_agent.slice(0, 60) : t("Appareil inconnu")}
|
||||
</span>
|
||||
{session.current ? <Badge tone="accent">Cette session</Badge> : null}
|
||||
{session.current ? <Badge tone="accent">{t("Cette session")}</Badge> : null}
|
||||
</span>
|
||||
<span className="block truncate text-[0.6875rem] text-subtle-foreground">
|
||||
{session.ip_address ?? "IP inconnue"} · vue le {formatDate(session.last_seen_at)}
|
||||
{session.ip_address ?? t("IP inconnue")} ·{" "}
|
||||
{t("vue le {date}", { date: formatDate(session.last_seen_at) })}
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Fermer cette session"
|
||||
aria-label={t("Fermer cette session")}
|
||||
disabled={revoking === session.id}
|
||||
onClick={() => void revokeSession(session)}
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-destructive disabled:opacity-50"
|
||||
@@ -317,11 +406,12 @@ export const Profile = () => {
|
||||
disabled={sessions === null || sessions.length <= 1}
|
||||
onClick={() => void revokeOthers()}
|
||||
>
|
||||
Fermer les autres sessions
|
||||
{t("Fermer les autres sessions")}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</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 { Alert } from "../components/feedback.js";
|
||||
import { ApiError, api } from "../lib/api.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
export const ResetPassword = () => {
|
||||
const { t } = useI18n();
|
||||
const [params] = useSearchParams();
|
||||
const token = params.get("token") ?? "";
|
||||
const [password, setPassword] = useState("");
|
||||
@@ -16,7 +18,7 @@ export const ResetPassword = () => {
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (password !== confirm) {
|
||||
setError("Les deux mots de passe ne correspondent pas.");
|
||||
setError(t("Les deux mots de passe ne correspondent pas."));
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
@@ -25,7 +27,7 @@ export const ResetPassword = () => {
|
||||
await api.resetPassword(token, password);
|
||||
setDone(true);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Réinitialisation impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Réinitialisation impossible."));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -46,7 +48,7 @@ export const ResetPassword = () => {
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Nouveau mot de passe
|
||||
{t("Nouveau mot de passe")}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
@@ -54,46 +56,46 @@ export const ResetPassword = () => {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Réinitialisation</CardTitle>
|
||||
<CardDescription>Choisissez un mot de passe robuste.</CardDescription>
|
||||
<CardTitle>{t("Réinitialisation")}</CardTitle>
|
||||
<CardDescription>{t("Choisissez un mot de passe robuste.")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{!token ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert>Ce lien est incomplet ou invalide.</Alert>
|
||||
<Alert>{t("Ce lien est incomplet ou invalide.")}</Alert>
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
||||
>
|
||||
Demander un nouveau lien
|
||||
{t("Demander un nouveau lien")}
|
||||
</Link>
|
||||
</div>
|
||||
) : done ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Alert tone="success">
|
||||
Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.
|
||||
{t("Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.")}
|
||||
</Alert>
|
||||
<Link to="/login">
|
||||
<Button size="lg" fullWidth>
|
||||
Se connecter
|
||||
{t("Se connecter")}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nouveau mot de passe"
|
||||
label={t("Nouveau mot de passe")}
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
autoFocus
|
||||
hint="8 caractères minimum."
|
||||
hint={t("8 caractères minimum.")}
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Confirmation"
|
||||
label={t("Confirmation")}
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
@@ -103,7 +105,7 @@ export const ResetPassword = () => {
|
||||
/>
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Réinitialiser
|
||||
{t("Réinitialiser")}
|
||||
</Button>
|
||||
</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 { Alert, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { DownloadIcon, FileIcon, FolderIcon, SearchIcon } from "../components/icons.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
interface Results {
|
||||
folders: Folder[];
|
||||
@@ -10,6 +11,7 @@ interface Results {
|
||||
}
|
||||
|
||||
export const Search = () => {
|
||||
const { t } = useI18n();
|
||||
const [q, setQ] = useState("");
|
||||
const [results, setResults] = useState<Results | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -19,7 +21,7 @@ export const Search = () => {
|
||||
event.preventDefault();
|
||||
const query = q.trim();
|
||||
if (query.length < 2) {
|
||||
setError("Saisissez au moins deux caractères.");
|
||||
setError(t("Saisissez au moins deux caractères."));
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
@@ -28,7 +30,7 @@ export const Search = () => {
|
||||
const { folders, files } = await api.search(query);
|
||||
setResults({ folders, files });
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Recherche impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Recherche impossible."));
|
||||
setResults(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -40,16 +42,16 @@ export const Search = () => {
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Recherche"
|
||||
description="Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès."
|
||||
title={t("Recherche")}
|
||||
description={t("Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès.")}
|
||||
toolbar={
|
||||
<form className="flex items-end gap-2" onSubmit={(event) => void submit(event)}>
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
label="Terme recherché"
|
||||
label={t("Terme recherché")}
|
||||
type="search"
|
||||
autoFocus
|
||||
placeholder="facture, rapport…"
|
||||
placeholder={t("facture, rapport…")}
|
||||
value={q}
|
||||
onChange={(event) => setQ(event.target.value)}
|
||||
/>
|
||||
@@ -60,7 +62,7 @@ export const Search = () => {
|
||||
isLoading={loading}
|
||||
iconLeading={<SearchIcon className="h-3.5 w-3.5" />}
|
||||
>
|
||||
Rechercher
|
||||
{t("Rechercher")}
|
||||
</Button>
|
||||
</form>
|
||||
}
|
||||
@@ -75,15 +77,15 @@ export const Search = () => {
|
||||
) : results === null ? null : total === 0 ? (
|
||||
<EmptyState
|
||||
icon={<SearchIcon className="h-8 w-8" />}
|
||||
title="Aucun résultat"
|
||||
description={`Rien ne correspond à « ${q.trim()} ».`}
|
||||
title={t("Aucun résultat")}
|
||||
description={t("Rien ne correspond à « {q} ».", { q: q.trim() })}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6">
|
||||
{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">
|
||||
Dossiers
|
||||
{t("Dossiers")}
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{results.folders.map((folder) => (
|
||||
@@ -101,9 +103,9 @@ export const Search = () => {
|
||||
) : null}
|
||||
|
||||
{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">
|
||||
Fichiers
|
||||
{t("Fichiers")}
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{results.files.map((file) => (
|
||||
@@ -122,7 +124,7 @@ export const Search = () => {
|
||||
<a
|
||||
href={api.downloadUrl(file.id)}
|
||||
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"
|
||||
>
|
||||
<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 { IconAction } from "../components/IconAction.js";
|
||||
import { FileIcon, FolderIcon, RestoreIcon, TrashIcon } from "../components/icons.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
|
||||
interface TrashData {
|
||||
retentionDays: number;
|
||||
@@ -20,6 +21,7 @@ interface TrashData {
|
||||
}
|
||||
|
||||
export const Trash = () => {
|
||||
const { t } = useI18n();
|
||||
const confirm = useConfirm();
|
||||
const [data, setData] = useState<TrashData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -32,7 +34,7 @@ export const Trash = () => {
|
||||
try {
|
||||
setData(await api.trash());
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Chargement impossible."));
|
||||
setData(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -50,7 +52,7 @@ export const Trash = () => {
|
||||
await action();
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Action impossible.");
|
||||
setError(caught instanceof ApiError ? caught.message : t("Action impossible."));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
@@ -58,9 +60,9 @@ export const Trash = () => {
|
||||
|
||||
const emptyTrash = async () => {
|
||||
const ok = await confirm({
|
||||
title: "Vider la corbeille",
|
||||
message: "Tous les éléments seront définitivement supprimés. Cette action est irréversible.",
|
||||
confirmLabel: "Vider",
|
||||
title: t("Vider la corbeille"),
|
||||
message: t("Tous les éléments seront définitivement supprimés. Cette action est irréversible."),
|
||||
confirmLabel: t("Vider"),
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
@@ -69,14 +71,9 @@ export const Trash = () => {
|
||||
|
||||
const purge = async (key: string, name: string, action: () => Promise<unknown>) => {
|
||||
const ok = await confirm({
|
||||
title: "Supprimer définitivement",
|
||||
message: (
|
||||
<>
|
||||
Supprimer définitivement <span className="font-semibold text-foreground">{name}</span> ?
|
||||
Cette action est irréversible.
|
||||
</>
|
||||
),
|
||||
confirmLabel: "Supprimer",
|
||||
title: t("Supprimer définitivement"),
|
||||
message: t("Supprimer définitivement {name} ? Cette action est irréversible.", { name }),
|
||||
confirmLabel: t("Supprimer"),
|
||||
tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
@@ -88,16 +85,18 @@ export const Trash = () => {
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<PageHeader
|
||||
title="Corbeille"
|
||||
title={t("Corbeille")}
|
||||
description={
|
||||
data
|
||||
? `Les éléments sont définitivement supprimés après ${data.retentionDays} jours.`
|
||||
: "Éléments supprimés récemment."
|
||||
? t("Les éléments sont définitivement supprimés après {days} jours.", {
|
||||
days: data.retentionDays,
|
||||
})
|
||||
: t("Éléments supprimés récemment.")
|
||||
}
|
||||
actions={
|
||||
data && !empty ? (
|
||||
<Button variant="destructive" size="sm" isLoading={busy === "empty"} onClick={emptyTrash}>
|
||||
Vider la corbeille
|
||||
{t("Vider la corbeille")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
@@ -112,15 +111,15 @@ export const Trash = () => {
|
||||
) : empty ? (
|
||||
<EmptyState
|
||||
icon={<TrashIcon className="h-8 w-8" />}
|
||||
title="Corbeille vide"
|
||||
description="Aucun élément supprimé pour le moment."
|
||||
title={t("Corbeille vide")}
|
||||
description={t("Aucun élément supprimé pour le moment.")}
|
||||
/>
|
||||
) : data ? (
|
||||
<div className="flex flex-col gap-6">
|
||||
{data.folders.length > 0 ? (
|
||||
<section aria-label="Dossiers supprimés">
|
||||
<section aria-label={t("Dossiers supprimés")}>
|
||||
<h2 className="mb-2 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
Dossiers
|
||||
{t("Dossiers")}
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{data.folders.map((folder) => (
|
||||
@@ -133,11 +132,11 @@ export const Trash = () => {
|
||||
{folder.name}
|
||||
</span>
|
||||
<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>
|
||||
<IconAction
|
||||
label={`Restaurer ${folder.name}`}
|
||||
label={t("Restaurer {name}", { name: folder.name })}
|
||||
icon={<RestoreIcon className="h-4 w-4" />}
|
||||
isLoading={busy === `restore-${folder.id}`}
|
||||
onClick={() =>
|
||||
@@ -145,7 +144,7 @@ export const Trash = () => {
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer définitivement ${folder.name}`}
|
||||
label={t("Supprimer définitivement {name}", { name: folder.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
tone="danger"
|
||||
isLoading={busy === `purge-${folder.id}`}
|
||||
@@ -162,9 +161,9 @@ export const Trash = () => {
|
||||
) : null}
|
||||
|
||||
{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">
|
||||
Fichiers
|
||||
{t("Fichiers")}
|
||||
</h2>
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{data.files.map((file) => (
|
||||
@@ -177,11 +176,12 @@ export const Trash = () => {
|
||||
{file.name}
|
||||
</span>
|
||||
<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>
|
||||
<IconAction
|
||||
label={`Restaurer ${file.name}`}
|
||||
label={t("Restaurer {name}", { name: file.name })}
|
||||
icon={<RestoreIcon className="h-4 w-4" />}
|
||||
isLoading={busy === `restore-${file.id}`}
|
||||
onClick={() =>
|
||||
@@ -189,7 +189,7 @@ export const Trash = () => {
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={`Supprimer définitivement ${file.name}`}
|
||||
label={t("Supprimer définitivement {name}", { name: file.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={busy === `purge-${file.id}`}
|
||||
tone="danger"
|
||||
|
||||
Reference in New Issue
Block a user