Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 2x 2x 2x 36x 36x 36x 36x 36x 36x 36x 4x 4x 36x 4x 4x 36x 1x 1x 36x 1x 1x 36x 354x 278x 278x 36x 1x 36x 1x 36x | import React, { useState } from "react";
import OurTable, { ButtonColumn } from "main/components/OurTable";
import PageSizeSelector from "main/components/Utils/PageSizeSelector";
import { formatTime } from "main/utils/dateUtils";
import { useRestoreUser, useSuspendUser } from "main/utils/users";
import usePageSize from "main/utils/usePageSize";
import { Button, Modal } from "react-bootstrap";
const PAGE_SIZE_OPTIONS = [20, 50, 100, 200, 500];
const DEFAULT_PAGE_SIZE = 20;
const PAGE_SIZE_STORAGE_KEY = "users-page-size";
export default function UsersTable({ users }) {
const { mutate: suspendUser } = useSuspendUser();
const { mutate: restoreUser } = useRestoreUser();
const [showSuspendModal, setShowSuspendModal] = useState(false);
const [showRestoreModal, setShowRestoreModal] = useState(false);
const [selectedCell, setSelectedCell] = useState(null);
const [pageSize, handlePageSizeChange] = usePageSize({
storageKey: PAGE_SIZE_STORAGE_KEY,
options: PAGE_SIZE_OPTIONS,
defaultPageSize: DEFAULT_PAGE_SIZE,
});
const suspendCallback = async (cell) => {
setSelectedCell(cell);
setShowSuspendModal(true);
};
const restoreCallback = async (cell) => {
setSelectedCell(cell);
setShowRestoreModal(true);
};
const confirmSuspend = async () => {
suspendUser(selectedCell);
setShowSuspendModal(false);
};
const confirmRestore = async () => {
restoreUser(selectedCell);
setShowRestoreModal(false);
};
const columns = [
{
Header: "id",
accessor: "id", // accessor is the "key" in the data
},
{
Header: "First Name",
accessor: "givenName",
},
{
Header: "Last Name",
accessor: "familyName",
},
{
Header: "Email",
accessor: "email",
},
{
Header: "Last Online",
accessor: "lastOnline",
Cell: ({ value }) => formatTime(value),
},
{
Header: "Admin",
id: "admin",
accessor: (row, _rowIndex) => String(row.admin), // hack needed for boolean values to show up
},
{
Header: "Suspended",
id: "suspended",
accessor: (row, _rowIndex) => String(row.suspended), // hack needed for boolean values to show up
},
ButtonColumn("Suspend", "danger", suspendCallback, "UsersTable"),
ButtonColumn("Restore", "primary", restoreCallback, "UsersTable"),
];
const suspendModal = (
<Modal show={showSuspendModal} onHide={() => setShowSuspendModal(false)}>
<Modal.Header closeButton>
<Modal.Title>Suspend User</Modal.Title>
</Modal.Header>
<Modal.Body>
Are you sure you want to suspend {selectedCell?.row.values.email}?
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShowSuspendModal(false)}>
Cancel
</Button>
<Button variant="danger" onClick={confirmSuspend}>
Confirm Suspend
</Button>
</Modal.Footer>
</Modal>
);
const restoreModal = (
<Modal show={showRestoreModal} onHide={() => setShowRestoreModal(false)}>
<Modal.Header closeButton>
<Modal.Title>Restore User</Modal.Title>
</Modal.Header>
<Modal.Body>
Are you sure you want to restore {selectedCell?.row.values.email}?
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShowRestoreModal(false)}>
Cancel
</Button>
<Button variant="primary" onClick={confirmRestore}>
Confirm Restore
</Button>
</Modal.Footer>
</Modal>
);
return (
<>
<PageSizeSelector
value={pageSize}
onChange={handlePageSizeChange}
options={PAGE_SIZE_OPTIONS}
testid={"UsersTable-page-size-selector"}
/>
<OurTable
data={users}
columns={columns}
testid={"UsersTable"}
pageSize={pageSize}
/>
{suspendModal}
{restoreModal}
</>
);
}
|