feat(header): afficher la photo de profil a la place des initiales #6
@@ -46,6 +46,7 @@ interface UserRow {
|
||||
max_file_bytes: number;
|
||||
must_change_password: number;
|
||||
is_active: number;
|
||||
avatar_updated_at: Date | null;
|
||||
}
|
||||
|
||||
const publicUser = (row: UserRow) => ({
|
||||
@@ -58,15 +59,19 @@ const publicUser = (row: UserRow) => ({
|
||||
quota_bytes: row.quota_bytes,
|
||||
used_bytes: row.used_bytes,
|
||||
max_file_bytes: row.max_file_bytes,
|
||||
must_change_password: row.must_change_password === 1,
|
||||
must_change_password: row.must_change_password,
|
||||
has_avatar: row.avatar_updated_at !== null,
|
||||
avatar_updated_at: row.avatar_updated_at,
|
||||
});
|
||||
|
||||
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.quota_bytes, u.used_bytes, u.max_file_bytes, u.must_change_password, u.is_active,
|
||||
ua.updated_at AS avatar_updated_at
|
||||
FROM users u
|
||||
JOIN roles r ON r.id = u.role_id`;
|
||||
JOIN roles r ON r.id = u.role_id
|
||||
LEFT JOIN user_avatars ua ON ua.user_id = u.id`;
|
||||
|
||||
export const registerAuthRoutes = (app: App, db: Db, config: Config): void => {
|
||||
app.use("/api/cloud/*", attachUser(db));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { NavLink, Outlet } from "react-router-dom";
|
||||
import { Button, cn } from "../ui/index.js";
|
||||
import { api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
@@ -127,10 +128,20 @@ export const AppShell = () => {
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-border bg-surface text-xs font-semibold text-foreground"
|
||||
className="relative flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface text-xs font-semibold text-foreground"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{initials(user.first_name, user.last_name)}
|
||||
{user.has_avatar ? (
|
||||
<img
|
||||
src={`${api.avatarUrl(user.id)}?v=${encodeURIComponent(user.avatar_updated_at ?? "")}`}
|
||||
alt=""
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
onError={(event) => {
|
||||
event.currentTarget.style.display = "none";
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<Button
|
||||
variant="secondary"
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface User {
|
||||
used_bytes: number;
|
||||
max_file_bytes: number;
|
||||
must_change_password: boolean;
|
||||
has_avatar: boolean;
|
||||
avatar_updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface Folder {
|
||||
|
||||
@@ -91,6 +91,7 @@ export const Profile = () => {
|
||||
try {
|
||||
await api.uploadAvatar(file);
|
||||
setAvatarNonce((value) => value + 1);
|
||||
await refresh();
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
} finally {
|
||||
@@ -103,6 +104,7 @@ export const Profile = () => {
|
||||
try {
|
||||
await api.deleteAvatar();
|
||||
setAvatarNonce((value) => value + 1);
|
||||
await refresh();
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user