mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
AdjusteD
This commit is contained in:
@@ -14,10 +14,11 @@ import { buildRowActions } from "../config/rowActions.config";
|
||||
import { getTimestamp } from "@/utils/timestamp.util";
|
||||
|
||||
export default function UsersTable() {
|
||||
const [archiveTarget, setArchiveTarget] = useState(null);
|
||||
const tableRefsRef = useRef({ getFilters: () => [], getSort: () => [] });
|
||||
const [archiveTarget, setArchiveTarget] = useState(null); // single: row object
|
||||
const [archiveIds, setArchiveIds] = useState(null); // bulk: array of ids
|
||||
const tableRefsRef = useRef({ getFilters: () => [], getSort: () => [], resetSelection: () => {} });
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
||||
const {
|
||||
users,
|
||||
attributes,
|
||||
@@ -26,7 +27,6 @@ export default function UsersTable() {
|
||||
loading,
|
||||
fetchUsers,
|
||||
fetchUserFieldValues,
|
||||
deactivateUser
|
||||
} = useUsers();
|
||||
|
||||
// Shared export config — passed into toolbar + selection configs
|
||||
@@ -43,9 +43,20 @@ export default function UsersTable() {
|
||||
getFilters: () => tableRefsRef.current.getFilters(),
|
||||
getSort: () => tableRefsRef.current.getSort(),
|
||||
});
|
||||
const selectionActions = buildSelectionActions({ exportConfig, deactivateUser });
|
||||
const selectionActions = buildSelectionActions({
|
||||
exportConfig,
|
||||
archiveUser: (row) => setArchiveTarget(row), // single
|
||||
archiveUsers: (ids) => setArchiveIds(ids), // bulk
|
||||
});
|
||||
const columns = useMemo(() => buildUserColumns(attributes, rowActions), [attributes]);
|
||||
|
||||
const handleArchiveSuccess = () => {
|
||||
setArchiveTarget(null);
|
||||
setArchiveIds(null);
|
||||
tableRefsRef.current.resetSelection?.(); // ← clear selection
|
||||
fetchUsers({ page: 1, limit: pagination.limit });
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<DataTable
|
||||
@@ -75,14 +86,20 @@ export default function UsersTable() {
|
||||
recordLabel="user"
|
||||
emptyMessage="No users match the current filters."
|
||||
/>
|
||||
{/* Single archive */}
|
||||
<ArchiveUserDialog
|
||||
open={!!archiveTarget}
|
||||
onOpenChange={(v) => !v && setArchiveTarget(null)}
|
||||
user={archiveTarget}
|
||||
onSuccess={() => {
|
||||
setArchiveTarget(null);
|
||||
fetchUsers({ page: 1, limit: pagination.limit });
|
||||
}}
|
||||
onSuccess={handleArchiveSuccess}
|
||||
/>
|
||||
|
||||
{/* Bulk archive */}
|
||||
<ArchiveUserDialog
|
||||
open={!!archiveIds}
|
||||
onOpenChange={(v) => !v && setArchiveIds(null)}
|
||||
ids={archiveIds ?? []}
|
||||
onSuccess={handleArchiveSuccess}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user