|
|
@@ -10,9 +10,14 @@ import ExplorerEmpty from "@/components/explorer/states/ExplorerEmpty";
|
|
|
import ForbiddenView from "@/components/system/ForbiddenView";
|
|
|
|
|
|
import AdminUsersFilters from "@/components/admin/users/AdminUsersFilters";
|
|
|
+import AdminUsersTableToolbar from "@/components/admin/users/AdminUsersTableToolbar";
|
|
|
import UsersTable from "@/components/admin/users/UsersTable";
|
|
|
import CreateUserDialog from "@/components/admin/users/CreateUserDialog";
|
|
|
import { normalizeBranchIdDraft } from "@/components/admin/users/usersUi";
|
|
|
+import {
|
|
|
+ ADMIN_USERS_SORT,
|
|
|
+ sortAdminUsers,
|
|
|
+} from "@/lib/frontend/admin/users/usersSorting";
|
|
|
|
|
|
import { ApiClientError } from "@/lib/frontend/apiClient";
|
|
|
import { buildLoginUrl, LOGIN_REASONS } from "@/lib/frontend/authRedirect";
|
|
|
@@ -34,6 +39,7 @@ export default function AdminUsersClient() {
|
|
|
q: null,
|
|
|
role: null,
|
|
|
branchId: null,
|
|
|
+ sort: ADMIN_USERS_SORT.DEFAULT,
|
|
|
});
|
|
|
|
|
|
const {
|
|
|
@@ -70,6 +76,10 @@ export default function AdminUsersClient() {
|
|
|
}
|
|
|
|
|
|
const disabled = status === "loading" || isLoadingMore;
|
|
|
+ const effectiveSortMode = query.sort || ADMIN_USERS_SORT.DEFAULT;
|
|
|
+ const visibleItems = React.useMemo(() => {
|
|
|
+ return sortAdminUsers(items, effectiveSortMode);
|
|
|
+ }, [items, effectiveSortMode]);
|
|
|
|
|
|
function onDraftChange(patch) {
|
|
|
setDraft((prev) => ({ ...prev, ...(patch || {}) }));
|
|
|
@@ -80,12 +90,25 @@ export default function AdminUsersClient() {
|
|
|
q: draft.q.trim() ? draft.q.trim() : null,
|
|
|
role: draft.role.trim() ? draft.role.trim() : null,
|
|
|
branchId: normalizeBranchIdDraft(draft.branchId) || null,
|
|
|
+ sort: query.sort || ADMIN_USERS_SORT.DEFAULT,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function resetFilters() {
|
|
|
setDraft({ q: "", role: "", branchId: "" });
|
|
|
- setQuery({ q: null, role: null, branchId: null });
|
|
|
+ setQuery((prev) => ({
|
|
|
+ q: null,
|
|
|
+ role: null,
|
|
|
+ branchId: null,
|
|
|
+ sort: prev.sort || ADMIN_USERS_SORT.DEFAULT,
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ function onSortModeChange(nextSortMode) {
|
|
|
+ setQuery((prev) => ({
|
|
|
+ ...prev,
|
|
|
+ sort: nextSortMode || ADMIN_USERS_SORT.DEFAULT,
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
const actions = (
|
|
|
@@ -120,7 +143,13 @@ export default function AdminUsersClient() {
|
|
|
onDraftChange={onDraftChange}
|
|
|
onApply={applyFilters}
|
|
|
onReset={resetFilters}
|
|
|
- loadedCount={items.length}
|
|
|
+ disabled={disabled}
|
|
|
+ />
|
|
|
+
|
|
|
+ <AdminUsersTableToolbar
|
|
|
+ loadedCount={visibleItems.length}
|
|
|
+ sortMode={effectiveSortMode}
|
|
|
+ onSortModeChange={onSortModeChange}
|
|
|
disabled={disabled}
|
|
|
/>
|
|
|
|
|
|
@@ -145,7 +174,7 @@ export default function AdminUsersClient() {
|
|
|
/>
|
|
|
) : (
|
|
|
<UsersTable
|
|
|
- items={items}
|
|
|
+ items={visibleItems}
|
|
|
disabled={disabled}
|
|
|
onUserUpdated={refresh}
|
|
|
/>
|