👤 profile dialog replaces standalone /profile page and inline prefs
Browse files at this commit469989609229d33a9d3442a9e884e8bf397e9f7aParent: 8aa8ff2- refactor
- 👤 profile dialog replaces standalone /profile page and inline prefs
11 changed files +102 -103
- src/api/patchUserPreferences.ts +0 -16
- src/api/patchUserProfile.ts +6 -0
- src/components/layout/sidebar-account.tsx +14 -9
- src/components/layout/user-menu.tsx +13 -8
- src/components/ui/data-table.tsx +16 -1
- src/components/ui/dialog.tsx +1 -1
- src/components/users/account-profile-dialog.tsx +26 -0
- src/components/users/profile-form.tsx +2 -2
- src/components/users/user-preferences-actions.tsx +0 -40
- src/components/users/user-table.tsx +3 -12
- src/pages/admin-users-page.tsx +21 -14
src/api/patchUserPreferences.tsdeleted+0 -16
| @@ -1,16 +0,0 @@ | |||
| 1 | -import { client } from "./client"; | ||
| 2 | -import type { User, UserLanguage, UserTheme } from "./types"; | ||
| 3 | - | ||
| 4 | -/** Omit to keep; empty string clears back to the device default. Null also | ||
| 5 | - * means keep on the backend, so it is deliberately not allowed here. */ | ||
| 6 | -export type PatchUserPreferencesBody = { | ||
| 7 | - theme?: UserTheme | ""; | ||
| 8 | - language?: UserLanguage | ""; | ||
| 9 | -}; | ||
| 10 | - | ||
| 11 | -export function patchUserPreferences(id: string, body: PatchUserPreferencesBody): Promise<User> { | ||
| 12 | - return client<User>(`/users/${id}/preferences`, { | ||
| 13 | - method: "PATCH", | ||
| 14 | - body, | ||
| 15 | - }); | ||
| 16 | -} | ||
src/api/patchUserProfile.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "@/api/client"; | ||
| 2 | +import type { ProfileUpdate, User } from "@/api/types"; | ||
| 3 | + | ||
| 4 | +export function patchUserProfile(id: string, body: ProfileUpdate): Promise<User> { | ||
| 5 | + return client<User>(`/users/${id}/profile`, { method: "PATCH", body }); | ||
| 6 | +} | ||
src/components/layout/sidebar-account.tsxmodified+14 -9
| @@ -1,7 +1,8 @@ | |||
| 1 | import { useNavigate } from "@tanstack/solid-router"; | 1 | import { useNavigate } from "@tanstack/solid-router"; |
| 2 | -import { Show } from "solid-js"; | 2 | +import { Show, createSignal } from "solid-js"; |
| 3 | import type { User } from "@/api/types"; | 3 | import type { User } from "@/api/types"; |
| 4 | import type { MessageKey } from "@/i18n/messages"; | 4 | import type { MessageKey } from "@/i18n/messages"; |
| 5 | +import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; | ||
| 5 | import { | 6 | import { |
| 6 | DropdownMenu, | 7 | DropdownMenu, |
| 7 | DropdownMenuContent, | 8 | DropdownMenuContent, |
| @@ -30,12 +31,14 @@ export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => voi | |||
| 30 | const prefs = usePreferences(); | 31 | const prefs = usePreferences(); |
| 31 | const t = useT(); | 32 | const t = useT(); |
| 32 | const navigate = useNavigate(); | 33 | const navigate = useNavigate(); |
| 34 | + const [profileOpen, setProfileOpen] = createSignal(false); | ||
| 33 | 35 | ||
| 34 | return ( | 36 | return ( |
| 35 | - <Show when={auth.user()}> | 37 | + <> |
| 36 | - {(u) => { | 38 | + <Show when={auth.user()}> |
| 37 | - const name = () => displayName(u()); | 39 | + {(u) => { |
| 38 | - return ( | 40 | + const name = () => displayName(u()); |
| 41 | + return ( | ||
| 39 | <div class={cn("shrink-0 border-t border-border/80 p-2", props.collapsed && "px-2 py-2") }> | 42 | <div class={cn("shrink-0 border-t border-border/80 p-2", props.collapsed && "px-2 py-2") }> |
| 40 | <DropdownMenu placement="right-end" gutter={8}> | 43 | <DropdownMenu placement="right-end" gutter={8}> |
| 41 | <DropdownMenuTrigger | 44 | <DropdownMenuTrigger |
| @@ -68,7 +71,7 @@ export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => voi | |||
| 68 | </DropdownMenuTrigger> | 71 | </DropdownMenuTrigger> |
| 69 | 72 | ||
| 70 | <DropdownMenuContent class="w-52 rounded-lg border-border/80 bg-popover p-1 shadow-soft"> | 73 | <DropdownMenuContent class="w-52 rounded-lg border-border/80 bg-popover p-1 shadow-soft"> |
| 71 | - <DropdownMenuItem class="rounded-md gap-2" onSelect={() => void navigate({ to: "/profile" })}> | 74 | + <DropdownMenuItem class="rounded-md gap-2" onSelect={() => setProfileOpen(true)}> |
| 72 | <IconEdit class="h-4 w-4 shrink-0 text-muted-foreground" /> | 75 | <IconEdit class="h-4 w-4 shrink-0 text-muted-foreground" /> |
| 73 | <span>{t("profile.edit")}</span> | 76 | <span>{t("profile.edit")}</span> |
| 74 | </DropdownMenuItem> | 77 | </DropdownMenuItem> |
| @@ -97,8 +100,10 @@ export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => voi | |||
| 97 | </DropdownMenuContent> | 100 | </DropdownMenuContent> |
| 98 | </DropdownMenu> | 101 | </DropdownMenu> |
| 99 | </div> | 102 | </div> |
| 100 | - ); | 103 | + ); |
| 101 | - }} | 104 | + }} |
| 102 | - </Show> | 105 | + </Show> |
| 106 | + <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} /> | ||
| 107 | + </> | ||
| 103 | ); | 108 | ); |
| 104 | } | 109 | } |
src/components/layout/user-menu.tsxmodified+13 -8
| @@ -1,7 +1,8 @@ | |||
| 1 | -import { Show } from "solid-js"; | 1 | +import { Show, createSignal } from "solid-js"; |
| 2 | import { useNavigate } from "@tanstack/solid-router"; | 2 | import { useNavigate } from "@tanstack/solid-router"; |
| 3 | import type { Locale, MessageKey } from "@/i18n/messages"; | 3 | import type { Locale, MessageKey } from "@/i18n/messages"; |
| 4 | import { RoleBadge } from "@/components/layout/role-badge"; | 4 | import { RoleBadge } from "@/components/layout/role-badge"; |
| 5 | +import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; | ||
| 5 | import { | 6 | import { |
| 6 | DropdownMenu, | 7 | DropdownMenu, |
| 7 | DropdownMenuContent, | 8 | DropdownMenuContent, |
| @@ -70,6 +71,7 @@ export function UserMenu() { | |||
| 70 | const prefs = usePreferences(); | 71 | const prefs = usePreferences(); |
| 71 | const t = useT(); | 72 | const t = useT(); |
| 72 | const navigate = useNavigate(); | 73 | const navigate = useNavigate(); |
| 74 | + const [profileOpen, setProfileOpen] = createSignal(false); | ||
| 73 | 75 | ||
| 74 | const onLogout = async () => { | 76 | const onLogout = async () => { |
| 75 | await auth.logout(); | 77 | await auth.logout(); |
| @@ -77,9 +79,10 @@ export function UserMenu() { | |||
| 77 | }; | 79 | }; |
| 78 | 80 | ||
| 79 | return ( | 81 | return ( |
| 80 | - <Show when={auth.user()}> | 82 | + <> |
| 81 | - {(u) => ( | 83 | + <Show when={auth.user()}> |
| 82 | - <DropdownMenu placement="bottom-end" gutter={8}> | 84 | + {(u) => ( |
| 85 | + <DropdownMenu placement="bottom-end" gutter={8}> | ||
| 83 | <DropdownMenuTrigger | 86 | <DropdownMenuTrigger |
| 84 | class={cn( | 87 | class={cn( |
| 85 | "inline-flex h-11 max-w-[16rem] items-center gap-2.5 rounded-lg border border-input bg-background px-2.5 pr-3 text-sm shadow-sm outline-none transition-colors sm:max-w-[22rem]", | 88 | "inline-flex h-11 max-w-[16rem] items-center gap-2.5 rounded-lg border border-input bg-background px-2.5 pr-3 text-sm shadow-sm outline-none transition-colors sm:max-w-[22rem]", |
| @@ -176,7 +179,7 @@ export function UserMenu() { | |||
| 176 | 179 | ||
| 177 | <DropdownMenuSeparator /> | 180 | <DropdownMenuSeparator /> |
| 178 | 181 | ||
| 179 | - <DropdownMenuItem onSelect={() => void navigate({ to: "/profile" })}> | 182 | + <DropdownMenuItem onSelect={() => setProfileOpen(true)}> |
| 180 | <IconEdit class="h-4 w-4 shrink-0" /> | 183 | <IconEdit class="h-4 w-4 shrink-0" /> |
| 181 | <span>{t("profile.edit")}</span> | 184 | <span>{t("profile.edit")}</span> |
| 182 | </DropdownMenuItem> | 185 | </DropdownMenuItem> |
| @@ -188,8 +191,10 @@ export function UserMenu() { | |||
| 188 | <span>{t("nav.logout")}</span> | 191 | <span>{t("nav.logout")}</span> |
| 189 | </DropdownMenuItem> | 192 | </DropdownMenuItem> |
| 190 | </DropdownMenuContent> | 193 | </DropdownMenuContent> |
| 191 | - </DropdownMenu> | 194 | + </DropdownMenu> |
| 192 | - )} | 195 | + )} |
| 193 | - </Show> | 196 | + </Show> |
| 197 | + <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} /> | ||
| 198 | + </> | ||
| 194 | ); | 199 | ); |
| 195 | } | 200 | } |
src/components/ui/data-table.tsxmodified+16 -1
| @@ -53,6 +53,7 @@ export type DataTableProps<TData, TValue = unknown> = { | |||
| 53 | total: number; | 53 | total: number; |
| 54 | onPageChange: (pageIndex: number) => void; | 54 | onPageChange: (pageIndex: number) => void; |
| 55 | }; | 55 | }; |
| 56 | + onRowClick?: (row: TData) => void; | ||
| 56 | onSearchInput?: (value: string) => void; | 57 | onSearchInput?: (value: string) => void; |
| 57 | pageSize?: number; | 58 | pageSize?: number; |
| 58 | searchPredicate?: (row: TData, query: string) => boolean; | 59 | searchPredicate?: (row: TData, query: string) => boolean; |
| @@ -125,6 +126,7 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | |||
| 125 | if (props.manualPagination) props.manualPagination.onPageChange(next); | 126 | if (props.manualPagination) props.manualPagination.onPageChange(next); |
| 126 | else table.setPageIndex(next); | 127 | else table.setPageIndex(next); |
| 127 | }; | 128 | }; |
| 129 | + const isInteractiveTarget = (target: EventTarget | null) => target instanceof Element && target.closest("button,a,input,select,textarea,[role='button']") != null; | ||
| 128 | const renderHeader = (header: ReturnType<typeof table.getHeaderGroups>[number]["headers"][number]) => { | 130 | const renderHeader = (header: ReturnType<typeof table.getHeaderGroups>[number]["headers"][number]) => { |
| 129 | const content = flexRender(header.column.columnDef.header, header.getContext()); | 131 | const content = flexRender(header.column.columnDef.header, header.getContext()); |
| 130 | if (!(props.enableSorting ?? true) || !header.column.getCanSort()) return content; | 132 | if (!(props.enableSorting ?? true) || !header.column.getCanSort()) return content; |
| @@ -216,7 +218,20 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | |||
| 216 | > | 218 | > |
| 217 | <For each={table.getRowModel().rows}> | 219 | <For each={table.getRowModel().rows}> |
| 218 | {(row) => ( | 220 | {(row) => ( |
| 219 | - <TableRow data-state={row.getIsSelected() ? "selected" : undefined}> | 221 | + <TableRow |
| 222 | + data-state={row.getIsSelected() ? "selected" : undefined} | ||
| 223 | + tabIndex={props.onRowClick ? 0 : undefined} | ||
| 224 | + class={props.onRowClick ? "cursor-pointer" : undefined} | ||
| 225 | + onClick={(event) => { | ||
| 226 | + if (!props.onRowClick || isInteractiveTarget(event.target)) return; | ||
| 227 | + props.onRowClick(row.original); | ||
| 228 | + }} | ||
| 229 | + onKeyDown={(event) => { | ||
| 230 | + if (!props.onRowClick || isInteractiveTarget(event.target) || (event.key !== "Enter" && event.key !== " ")) return; | ||
| 231 | + event.preventDefault(); | ||
| 232 | + props.onRowClick(row.original); | ||
| 233 | + }} | ||
| 234 | + > | ||
| 220 | <For each={row.getVisibleCells()}> | 235 | <For each={row.getVisibleCells()}> |
| 221 | {(cell) => ( | 236 | {(cell) => ( |
| 222 | <TableCell class={cn(actionColumnClass(cell.column.id), cell.column.columnDef.meta?.cellClass)}> | 237 | <TableCell class={cn(actionColumnClass(cell.column.id), cell.column.columnDef.meta?.cellClass)}> |
src/components/ui/dialog.tsxmodified+1 -1
| @@ -17,7 +17,7 @@ export function DialogContent<T extends ValidComponent = "div">( | |||
| 17 | ]); | 17 | ]); |
| 18 | return ( | 18 | return ( |
| 19 | <DialogPrimitive.Portal> | 19 | <DialogPrimitive.Portal> |
| 20 | - <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/40 dark:bg-black/60" /> | 20 | + <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/40 backdrop-blur-[2px] dark:bg-black/60" /> |
| 21 | {/* flex center — animate-fade-up must not own transform positioning */} | 21 | {/* flex center — animate-fade-up must not own transform positioning */} |
| 22 | <div class="pointer-events-none fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"> | 22 | <div class="pointer-events-none fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"> |
| 23 | <DialogPrimitive.Content | 23 | <DialogPrimitive.Content |
src/components/users/account-profile-dialog.tsxadded+26 -0
| @@ -0,0 +1,26 @@ | |||
| 1 | +import { Show } from "solid-js"; | ||
| 2 | +import { FormDialog } from "@/components/ui/form-dialog"; | ||
| 3 | +import { ProfileForm } from "@/components/users/profile-form"; | ||
| 4 | +import { useAuth } from "@/stores/auth-context"; | ||
| 5 | +import { useT } from "@/stores/preferences-context"; | ||
| 6 | + | ||
| 7 | +export function AccountProfileDialog(props: { open: boolean; onOpenChange: (open: boolean) => void }) { | ||
| 8 | + const auth = useAuth(); | ||
| 9 | + const t = useT(); | ||
| 10 | + | ||
| 11 | + return ( | ||
| 12 | + <Show when={auth.user()} keyed> | ||
| 13 | + {(user) => ( | ||
| 14 | + <FormDialog open={props.open} onOpenChange={props.onOpenChange} title={user.username} description={t("profile.edit")}> | ||
| 15 | + <ProfileForm | ||
| 16 | + user={user} | ||
| 17 | + onSaved={async () => { | ||
| 18 | + await auth.refresh(); | ||
| 19 | + props.onOpenChange(false); | ||
| 20 | + }} | ||
| 21 | + /> | ||
| 22 | + </FormDialog> | ||
| 23 | + )} | ||
| 24 | + </Show> | ||
| 25 | + ); | ||
| 26 | +} | ||
src/components/users/profile-form.tsxmodified+2 -2
| @@ -38,7 +38,7 @@ function isoFromDateInput(value: string): string { | |||
| 38 | return `${year}-${month}-${day}`; | 38 | return `${year}-${month}-${day}`; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | -export function ProfileForm(props: { user: User; onSaved: () => void }) { | 41 | +export function ProfileForm(props: { user: User; onSaved: () => void; onSave?: (body: ProfileUpdate) => Promise<User> }) { |
| 42 | const t = useT(); | 42 | const t = useT(); |
| 43 | const [name, setName] = createSignal(props.user.name ?? ""); | 43 | const [name, setName] = createSignal(props.user.name ?? ""); |
| 44 | const [surname, setSurname] = createSignal(props.user.surname ?? ""); | 44 | const [surname, setSurname] = createSignal(props.user.surname ?? ""); |
| @@ -83,7 +83,7 @@ export function ProfileForm(props: { user: User; onSaved: () => void }) { | |||
| 83 | if (Object.keys(body).length === 0) { props.onSaved(); return; } | 83 | if (Object.keys(body).length === 0) { props.onSaved(); return; } |
| 84 | setPending(true); | 84 | setPending(true); |
| 85 | try { | 85 | try { |
| 86 | - await patchMe(body); | 86 | + await (props.onSave ?? patchMe)(body); |
| 87 | props.onSaved(); | 87 | props.onSaved(); |
| 88 | setFlash(t("common.saved")); | 88 | setFlash(t("common.saved")); |
| 89 | } catch (err) { | 89 | } catch (err) { |
src/components/users/user-preferences-actions.tsxdeleted+0 -40
| @@ -1,40 +0,0 @@ | |||
| 1 | -import { Show, createSignal } from "solid-js"; | ||
| 2 | -import type { User, UserLanguage, UserTheme } from "@/api/types"; | ||
| 3 | -import { Button } from "@/components/ui/button"; | ||
| 4 | -import { IconCheck } from "@/components/ui/icons"; | ||
| 5 | -import { Select } from "@/components/ui/select"; | ||
| 6 | -import { useT } from "@/stores/preferences-context"; | ||
| 7 | - | ||
| 8 | -export function UserPreferencesActions(props: { | ||
| 9 | - user: User; | ||
| 10 | - onPreferencesChange: (userId: string, body: { theme?: UserTheme | ""; language?: UserLanguage | "" }) => Promise<void>; | ||
| 11 | -}) { | ||
| 12 | - const t = useT(); | ||
| 13 | - const [theme, setTheme] = createSignal<UserTheme | "">(props.user.theme ?? ""); | ||
| 14 | - const [language, setLanguage] = createSignal<UserLanguage | "">(props.user.language ?? ""); | ||
| 15 | - const dirty = () => theme() !== (props.user.theme ?? "") || language() !== (props.user.language ?? ""); | ||
| 16 | - | ||
| 17 | - return ( | ||
| 18 | - <div class="grid gap-2"> | ||
| 19 | - <div class="grid grid-cols-2 gap-2"> | ||
| 20 | - <Select class="h-8 rounded-sm text-xs" value={theme()} aria-label={t("theme.toggle")} onChange={(e) => setTheme(e.currentTarget.value as UserTheme | "")}> | ||
| 21 | - <option value="">—</option> | ||
| 22 | - <option value="light">{t("theme.light")}</option> | ||
| 23 | - <option value="dark">{t("theme.dark")}</option> | ||
| 24 | - </Select> | ||
| 25 | - <Select class="h-8 rounded-sm text-xs" value={language()} aria-label={t("lang.label")} onChange={(e) => setLanguage(e.currentTarget.value as UserLanguage | "")}> | ||
| 26 | - <option value="">—</option> | ||
| 27 | - <option value="tr">{t("lang.tr")}</option> | ||
| 28 | - <option value="en">{t("lang.en")}</option> | ||
| 29 | - </Select> | ||
| 30 | - </div> | ||
| 31 | - <Show when={dirty()}> | ||
| 32 | - {/* "" clears the preference on the backend; null would silently keep it. */} | ||
| 33 | - <Button type="button" size="sm" class="h-7 rounded-sm px-2" onClick={() => props.onPreferencesChange(props.user.id, { theme: theme(), language: language() })}> | ||
| 34 | - <IconCheck /> | ||
| 35 | - {t("common.save")} | ||
| 36 | - </Button> | ||
| 37 | - </Show> | ||
| 38 | - </div> | ||
| 39 | - ); | ||
| 40 | -} | ||
src/components/users/user-table.tsxmodified+3 -12
| @@ -1,6 +1,6 @@ | |||
| 1 | import { createMemo, createSignal, Show } from "solid-js"; | 1 | import { createMemo, createSignal, Show } from "solid-js"; |
| 2 | import type { ColumnDef } from "@tanstack/solid-table"; | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | -import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; | 3 | +import type { Role, User } from "@/api/types"; |
| 4 | import type { MessageKey } from "@/i18n/messages"; | 4 | import type { MessageKey } from "@/i18n/messages"; |
| 5 | import { Select } from "@/components/ui/select"; | 5 | import { Select } from "@/components/ui/select"; |
| 6 | import { Button } from "@/components/ui/button"; | 6 | import { Button } from "@/components/ui/button"; |
| @@ -8,7 +8,6 @@ import { Badge } from "@/components/ui/badge"; | |||
| 8 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 8 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 9 | import { DataTable } from "@/components/ui/data-table"; | 9 | import { DataTable } from "@/components/ui/data-table"; |
| 10 | import { IconCheck } from "@/components/ui/icons"; | 10 | import { IconCheck } from "@/components/ui/icons"; |
| 11 | -import { UserPreferencesActions } from "@/components/users/user-preferences-actions"; | ||
| 12 | import { ROLES } from "@/lib/roles"; | 11 | import { ROLES } from "@/lib/roles"; |
| 13 | import { cn } from "@/lib/cn"; | 12 | import { cn } from "@/lib/cn"; |
| 14 | import { useT } from "@/stores/preferences-context"; | 13 | import { useT } from "@/stores/preferences-context"; |
| @@ -75,7 +74,7 @@ export function UserTable(props: { | |||
| 75 | users: User[]; | 74 | users: User[]; |
| 76 | currentUserId: string; | 75 | currentUserId: string; |
| 77 | onRoleChange: (userId: string, role: Role) => Promise<void>; | 76 | onRoleChange: (userId: string, role: Role) => Promise<void>; |
| 78 | - onPreferencesChange?: (userId: string, body: { theme?: UserTheme | ""; language?: UserLanguage | "" }) => Promise<void>; | 77 | + onUserClick?: (user: User) => void; |
| 79 | }) { | 78 | }) { |
| 80 | const t = useT(); | 79 | const t = useT(); |
| 81 | const searchUser = (user: User, query: string) => | 80 | const searchUser = (user: User, query: string) => |
| @@ -116,14 +115,6 @@ export function UserTable(props: { | |||
| 116 | header: t("admin.id"), | 115 | header: t("admin.id"), |
| 117 | meta: { cellClass: "mono truncate text-xs text-muted-foreground" }, | 116 | meta: { cellClass: "mono truncate text-xs text-muted-foreground" }, |
| 118 | }, | 117 | }, |
| 119 | - { | ||
| 120 | - id: "preferences", | ||
| 121 | - header: t("nav.preferences"), | ||
| 122 | - meta: { headerClass: "w-56", cellClass: "w-56" }, | ||
| 123 | - cell: (cell) => props.onPreferencesChange | ||
| 124 | - ? <UserPreferencesActions user={cell.row.original} onPreferencesChange={props.onPreferencesChange} /> | ||
| 125 | - : "—", | ||
| 126 | - }, | ||
| 127 | { | 118 | { |
| 128 | id: "update", | 119 | id: "update", |
| 129 | header: t("common.update"), | 120 | header: t("common.update"), |
| @@ -135,6 +126,6 @@ export function UserTable(props: { | |||
| 135 | ]); | 126 | ]); |
| 136 | 127 | ||
| 137 | return ( | 128 | return ( |
| 138 | - <DataTable columns={columns()} data={props.users} tableClass="table-fixed min-w-[70rem]" searchPredicate={searchUser} enablePagination pageSize={20} /> | 129 | + <DataTable columns={columns()} data={props.users} tableClass="table-fixed min-w-[54rem]" searchPredicate={searchUser} enablePagination pageSize={20} onRowClick={props.onUserClick} /> |
| 139 | ); | 130 | ); |
| 140 | } | 131 | } |
src/pages/admin-users-page.tsxmodified+21 -14
| @@ -1,15 +1,17 @@ | |||
| 1 | import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | 1 | import { For, Show, Suspense, createResource, createSignal } from "solid-js"; |
| 2 | import { getUsers } from "@/api/getUsers"; | 2 | import { getUsers } from "@/api/getUsers"; |
| 3 | -import { patchUserPreferences } from "@/api/patchUserPreferences"; | 3 | +import { patchUserProfile } from "@/api/patchUserProfile"; |
| 4 | import { patchUserRole } from "@/api/patchUserRole"; | 4 | import { patchUserRole } from "@/api/patchUserRole"; |
| 5 | import { formatApiError } from "@/api/client"; | 5 | import { formatApiError } from "@/api/client"; |
| 6 | -import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; | 6 | +import type { Role, User } from "@/api/types"; |
| 7 | import { RouteGuard } from "@/components/layout/route-guard"; | 7 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 8 | import { PageHeader } from "@/components/layout/page-header"; | 8 | import { PageHeader } from "@/components/layout/page-header"; |
| 9 | +import { ProfileForm } from "@/components/users/profile-form"; | ||
| 9 | import { UserTable } from "@/components/users/user-table"; | 10 | import { UserTable } from "@/components/users/user-table"; |
| 10 | import { Alert } from "@/components/ui/alert"; | 11 | import { Alert } from "@/components/ui/alert"; |
| 11 | import { Badge } from "@/components/ui/badge"; | 12 | import { Badge } from "@/components/ui/badge"; |
| 12 | import { DataTableEmpty, DataTableSkeleton } from "@/components/ui/data-table"; | 13 | import { DataTableEmpty, DataTableSkeleton } from "@/components/ui/data-table"; |
| 14 | +import { FormDialog } from "@/components/ui/form-dialog"; | ||
| 13 | import { createFlash } from "@/lib/flash"; | 15 | import { createFlash } from "@/lib/flash"; |
| 14 | import { useAuth } from "@/stores/auth-context"; | 16 | import { useAuth } from "@/stores/auth-context"; |
| 15 | import { useT } from "@/stores/preferences-context"; | 17 | import { useT } from "@/stores/preferences-context"; |
| @@ -28,6 +30,7 @@ function AdminUsersContent() { | |||
| 28 | const auth = useAuth(); | 30 | const auth = useAuth(); |
| 29 | const t = useT(); | 31 | const t = useT(); |
| 30 | const [error, setError] = createSignal(""); | 32 | const [error, setError] = createSignal(""); |
| 33 | + const [editUser, setEditUser] = createSignal<User | null>(null); | ||
| 31 | 34 | ||
| 32 | const [list, { refetch }] = createResource(async () => (await getUsers()).items); | 35 | const [list, { refetch }] = createResource(async () => (await getUsers()).items); |
| 33 | const visibleUsers = () => list() ?? []; | 36 | const visibleUsers = () => list() ?? []; |
| @@ -46,17 +49,6 @@ function AdminUsersContent() { | |||
| 46 | } | 49 | } |
| 47 | }; | 50 | }; |
| 48 | 51 | ||
| 49 | - const onPreferencesChange = async (userId: string, body: { theme?: UserTheme | ""; language?: UserLanguage | "" }) => { | ||
| 50 | - setError(""); | ||
| 51 | - try { | ||
| 52 | - await patchUserPreferences(userId, body); | ||
| 53 | - await refetch(); | ||
| 54 | - setFlash(t("common.saved")); | ||
| 55 | - } catch (err) { | ||
| 56 | - setError(formatApiError(err)); | ||
| 57 | - } | ||
| 58 | - }; | ||
| 59 | - | ||
| 60 | return ( | 52 | return ( |
| 61 | <div class="space-y-6"> | 53 | <div class="space-y-6"> |
| 62 | <div class="space-y-2"> | 54 | <div class="space-y-2"> |
| @@ -88,11 +80,26 @@ function AdminUsersContent() { | |||
| 88 | <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}> | 80 | <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}> |
| 89 | <Show when={list()}> | 81 | <Show when={list()}> |
| 90 | <Show when={visibleUsers().length > 0} fallback={<DataTableEmpty>{t("admin.noUsers")}</DataTableEmpty>}> | 82 | <Show when={visibleUsers().length > 0} fallback={<DataTableEmpty>{t("admin.noUsers")}</DataTableEmpty>}> |
| 91 | - <UserTable users={visibleUsers() as User[]} currentUserId={auth.user()!.id} onRoleChange={onRoleChange} onPreferencesChange={onPreferencesChange} /> | 83 | + <UserTable users={visibleUsers() as User[]} currentUserId={auth.user()!.id} onRoleChange={onRoleChange} onUserClick={setEditUser} /> |
| 92 | </Show> | 84 | </Show> |
| 93 | </Show> | 85 | </Show> |
| 94 | </Suspense> | 86 | </Suspense> |
| 95 | </div> | 87 | </div> |
| 88 | + <Show when={editUser()} keyed> | ||
| 89 | + {(user) => ( | ||
| 90 | + <FormDialog open onOpenChange={(open) => !open && setEditUser(null)} title={user.username} description={t("profile.subtitle")}> | ||
| 91 | + <ProfileForm | ||
| 92 | + user={user} | ||
| 93 | + onSave={(body) => patchUserProfile(user.id, body)} | ||
| 94 | + onSaved={async () => { | ||
| 95 | + await refetch(); | ||
| 96 | + setEditUser(null); | ||
| 97 | + setFlash(t("common.saved")); | ||
| 98 | + }} | ||
| 99 | + /> | ||
| 100 | + </FormDialog> | ||
| 101 | + )} | ||
| 102 | + </Show> | ||
| 96 | </div> | 103 | </div> |
| 97 | ); | 104 | ); |
| 98 | } | 105 | } |