From 469989609229d33a9d3442a9e884e8bf397e9f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Mon, 20 Jul 2026 07:19:27 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=91=A4=20profile=20dialog=20r?= =?UTF-8?q?eplaces=20standalone=20/profile=20page=20and=20inline=20prefs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sidebar-account/user-menu: Edit profile now opens AccountProfileDialog instead of navigating to /profile route - admin-users-page: row click opens FormDialog with ProfileForm, reuses patchUserProfile (covers all fields incl theme/language) - UserTable: onRowClick prop + DataTable row-level click handler - delete patchUserPreferences and UserPreferencesActions (replaced by patchUserProfile + ProfileForm reuse) - profile-form: optional onSave prop for admin use - dialog overlay: backdrop-blur-[2px] --- src/api/patchUserPreferences.ts | 16 -------- src/api/patchUserProfile.ts | 6 +++ src/components/layout/sidebar-account.tsx | 23 ++++++----- src/components/layout/user-menu.tsx | 21 ++++++---- src/components/ui/data-table.tsx | 17 +++++++- src/components/ui/dialog.tsx | 2 +- .../users/account-profile-dialog.tsx | 26 ++++++++++++ src/components/users/profile-form.tsx | 4 +- .../users/user-preferences-actions.tsx | 40 ------------------- src/components/users/user-table.tsx | 15 ++----- src/pages/admin-users-page.tsx | 35 +++++++++------- 11 files changed, 102 insertions(+), 103 deletions(-) delete mode 100644 src/api/patchUserPreferences.ts create mode 100644 src/api/patchUserProfile.ts create mode 100644 src/components/users/account-profile-dialog.tsx delete mode 100644 src/components/users/user-preferences-actions.tsx diff --git a/src/api/patchUserPreferences.ts b/src/api/patchUserPreferences.ts deleted file mode 100644 index 33c0b48..0000000 --- a/src/api/patchUserPreferences.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { client } from "./client"; -import type { User, UserLanguage, UserTheme } from "./types"; - -/** Omit to keep; empty string clears back to the device default. Null also - * means keep on the backend, so it is deliberately not allowed here. */ -export type PatchUserPreferencesBody = { - theme?: UserTheme | ""; - language?: UserLanguage | ""; -}; - -export function patchUserPreferences(id: string, body: PatchUserPreferencesBody): Promise { - return client(`/users/${id}/preferences`, { - method: "PATCH", - body, - }); -} diff --git a/src/api/patchUserProfile.ts b/src/api/patchUserProfile.ts new file mode 100644 index 0000000..ec2f176 --- /dev/null +++ b/src/api/patchUserProfile.ts @@ -0,0 +1,6 @@ +import { client } from "@/api/client"; +import type { ProfileUpdate, User } from "@/api/types"; + +export function patchUserProfile(id: string, body: ProfileUpdate): Promise { + return client(`/users/${id}/profile`, { method: "PATCH", body }); +} diff --git a/src/components/layout/sidebar-account.tsx b/src/components/layout/sidebar-account.tsx index 30b9f60..835793a 100644 --- a/src/components/layout/sidebar-account.tsx +++ b/src/components/layout/sidebar-account.tsx @@ -1,7 +1,8 @@ import { useNavigate } from "@tanstack/solid-router"; -import { Show } from "solid-js"; +import { Show, createSignal } from "solid-js"; import type { User } from "@/api/types"; import type { MessageKey } from "@/i18n/messages"; +import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; import { DropdownMenu, DropdownMenuContent, @@ -30,12 +31,14 @@ export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => voi const prefs = usePreferences(); const t = useT(); const navigate = useNavigate(); + const [profileOpen, setProfileOpen] = createSignal(false); return ( - - {(u) => { - const name = () => displayName(u()); - return ( + <> + + {(u) => { + const name = () => displayName(u()); + return (
voi - void navigate({ to: "/profile" })}> + setProfileOpen(true)}> {t("profile.edit")} @@ -97,8 +100,10 @@ export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => voi
- ); - }} -
+ ); + }} +
+ + ); } diff --git a/src/components/layout/user-menu.tsx b/src/components/layout/user-menu.tsx index 49271ab..52e9265 100644 --- a/src/components/layout/user-menu.tsx +++ b/src/components/layout/user-menu.tsx @@ -1,7 +1,8 @@ -import { Show } from "solid-js"; +import { Show, createSignal } from "solid-js"; import { useNavigate } from "@tanstack/solid-router"; import type { Locale, MessageKey } from "@/i18n/messages"; import { RoleBadge } from "@/components/layout/role-badge"; +import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; import { DropdownMenu, DropdownMenuContent, @@ -70,6 +71,7 @@ export function UserMenu() { const prefs = usePreferences(); const t = useT(); const navigate = useNavigate(); + const [profileOpen, setProfileOpen] = createSignal(false); const onLogout = async () => { await auth.logout(); @@ -77,9 +79,10 @@ export function UserMenu() { }; return ( - - {(u) => ( - + <> + + {(u) => ( + - void navigate({ to: "/profile" })}> + setProfileOpen(true)}> {t("profile.edit")} @@ -188,8 +191,10 @@ export function UserMenu() { {t("nav.logout")} - - )} - + + )} + + + ); } diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index be1205d..27751b9 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -53,6 +53,7 @@ export type DataTableProps = { total: number; onPageChange: (pageIndex: number) => void; }; + onRowClick?: (row: TData) => void; onSearchInput?: (value: string) => void; pageSize?: number; searchPredicate?: (row: TData, query: string) => boolean; @@ -125,6 +126,7 @@ export function DataTable(props: DataTableProps target instanceof Element && target.closest("button,a,input,select,textarea,[role='button']") != null; const renderHeader = (header: ReturnType[number]["headers"][number]) => { const content = flexRender(header.column.columnDef.header, header.getContext()); if (!(props.enableSorting ?? true) || !header.column.getCanSort()) return content; @@ -216,7 +218,20 @@ export function DataTable(props: DataTableProps {(row) => ( - + { + if (!props.onRowClick || isInteractiveTarget(event.target)) return; + props.onRowClick(row.original); + }} + onKeyDown={(event) => { + if (!props.onRowClick || isInteractiveTarget(event.target) || (event.key !== "Enter" && event.key !== " ")) return; + event.preventDefault(); + props.onRowClick(row.original); + }} + > {(cell) => ( diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx index 0442187..edd5fb2 100644 --- a/src/components/ui/dialog.tsx +++ b/src/components/ui/dialog.tsx @@ -17,7 +17,7 @@ export function DialogContent( ]); return ( - + {/* flex center — animate-fade-up must not own transform positioning */}
void }) { + const auth = useAuth(); + const t = useT(); + + return ( + + {(user) => ( + + { + await auth.refresh(); + props.onOpenChange(false); + }} + /> + + )} + + ); +} diff --git a/src/components/users/profile-form.tsx b/src/components/users/profile-form.tsx index 1f921b1..7ccdd31 100644 --- a/src/components/users/profile-form.tsx +++ b/src/components/users/profile-form.tsx @@ -38,7 +38,7 @@ function isoFromDateInput(value: string): string { return `${year}-${month}-${day}`; } -export function ProfileForm(props: { user: User; onSaved: () => void }) { +export function ProfileForm(props: { user: User; onSaved: () => void; onSave?: (body: ProfileUpdate) => Promise }) { const t = useT(); const [name, setName] = createSignal(props.user.name ?? ""); const [surname, setSurname] = createSignal(props.user.surname ?? ""); @@ -83,7 +83,7 @@ export function ProfileForm(props: { user: User; onSaved: () => void }) { if (Object.keys(body).length === 0) { props.onSaved(); return; } setPending(true); try { - await patchMe(body); + await (props.onSave ?? patchMe)(body); props.onSaved(); setFlash(t("common.saved")); } catch (err) { diff --git a/src/components/users/user-preferences-actions.tsx b/src/components/users/user-preferences-actions.tsx deleted file mode 100644 index 48341df..0000000 --- a/src/components/users/user-preferences-actions.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { Show, createSignal } from "solid-js"; -import type { User, UserLanguage, UserTheme } from "@/api/types"; -import { Button } from "@/components/ui/button"; -import { IconCheck } from "@/components/ui/icons"; -import { Select } from "@/components/ui/select"; -import { useT } from "@/stores/preferences-context"; - -export function UserPreferencesActions(props: { - user: User; - onPreferencesChange: (userId: string, body: { theme?: UserTheme | ""; language?: UserLanguage | "" }) => Promise; -}) { - const t = useT(); - const [theme, setTheme] = createSignal(props.user.theme ?? ""); - const [language, setLanguage] = createSignal(props.user.language ?? ""); - const dirty = () => theme() !== (props.user.theme ?? "") || language() !== (props.user.language ?? ""); - - return ( -
-
- - -
- - {/* "" clears the preference on the backend; null would silently keep it. */} - - -
- ); -} diff --git a/src/components/users/user-table.tsx b/src/components/users/user-table.tsx index aa535f4..6b644d0 100644 --- a/src/components/users/user-table.tsx +++ b/src/components/users/user-table.tsx @@ -1,6 +1,6 @@ import { createMemo, createSignal, Show } from "solid-js"; import type { ColumnDef } from "@tanstack/solid-table"; -import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; +import type { Role, User } from "@/api/types"; import type { MessageKey } from "@/i18n/messages"; import { Select } from "@/components/ui/select"; import { Button } from "@/components/ui/button"; @@ -8,7 +8,6 @@ import { Badge } from "@/components/ui/badge"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { DataTable } from "@/components/ui/data-table"; import { IconCheck } from "@/components/ui/icons"; -import { UserPreferencesActions } from "@/components/users/user-preferences-actions"; import { ROLES } from "@/lib/roles"; import { cn } from "@/lib/cn"; import { useT } from "@/stores/preferences-context"; @@ -75,7 +74,7 @@ export function UserTable(props: { users: User[]; currentUserId: string; onRoleChange: (userId: string, role: Role) => Promise; - onPreferencesChange?: (userId: string, body: { theme?: UserTheme | ""; language?: UserLanguage | "" }) => Promise; + onUserClick?: (user: User) => void; }) { const t = useT(); const searchUser = (user: User, query: string) => @@ -116,14 +115,6 @@ export function UserTable(props: { header: t("admin.id"), meta: { cellClass: "mono truncate text-xs text-muted-foreground" }, }, - { - id: "preferences", - header: t("nav.preferences"), - meta: { headerClass: "w-56", cellClass: "w-56" }, - cell: (cell) => props.onPreferencesChange - ? - : "—", - }, { id: "update", header: t("common.update"), @@ -135,6 +126,6 @@ export function UserTable(props: { ]); return ( - + ); } diff --git a/src/pages/admin-users-page.tsx b/src/pages/admin-users-page.tsx index 8b1d8a2..f721280 100644 --- a/src/pages/admin-users-page.tsx +++ b/src/pages/admin-users-page.tsx @@ -1,15 +1,17 @@ import { For, Show, Suspense, createResource, createSignal } from "solid-js"; import { getUsers } from "@/api/getUsers"; -import { patchUserPreferences } from "@/api/patchUserPreferences"; +import { patchUserProfile } from "@/api/patchUserProfile"; import { patchUserRole } from "@/api/patchUserRole"; import { formatApiError } from "@/api/client"; -import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; +import type { Role, User } from "@/api/types"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; +import { ProfileForm } from "@/components/users/profile-form"; import { UserTable } from "@/components/users/user-table"; import { Alert } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { DataTableEmpty, DataTableSkeleton } from "@/components/ui/data-table"; +import { FormDialog } from "@/components/ui/form-dialog"; import { createFlash } from "@/lib/flash"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; @@ -28,6 +30,7 @@ function AdminUsersContent() { const auth = useAuth(); const t = useT(); const [error, setError] = createSignal(""); + const [editUser, setEditUser] = createSignal(null); const [list, { refetch }] = createResource(async () => (await getUsers()).items); const visibleUsers = () => list() ?? []; @@ -46,17 +49,6 @@ function AdminUsersContent() { } }; - const onPreferencesChange = async (userId: string, body: { theme?: UserTheme | ""; language?: UserLanguage | "" }) => { - setError(""); - try { - await patchUserPreferences(userId, body); - await refetch(); - setFlash(t("common.saved")); - } catch (err) { - setError(formatApiError(err)); - } - }; - return (
@@ -88,11 +80,26 @@ function AdminUsersContent() { }> 0} fallback={{t("admin.noUsers")}}> - +
+ + {(user) => ( + !open && setEditUser(null)} title={user.username} description={t("profile.subtitle")}> + patchUserProfile(user.id, body)} + onSaved={async () => { + await refetch(); + setEditUser(null); + setFlash(t("common.saved")); + }} + /> + + )} +
); }