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 | 32x 32x 32x 32x 5x 4x 4x 1x 32x 2x 2x 32x 32x 1x 1x 5x 5x 32x 31x 29x | import React from "react"; import OurTable, { ButtonColumn } from "main/components/OurTable"; import { useBackendMutation, useBackend } from "main/utils/useBackend"; import { toast } from "react-toastify"; import { useQueryClient } from "react-query"; export default function AliasApprovalTable() { const testid = "AliasApprovalTable"; const queryClient = useQueryClient(); const { data: users, error, status, } = useBackend( ["/api/admin/usersWithProposedAlias"], { method: "GET", url: "/api/admin/usersWithProposedAlias" }, [], ); const objectToAxiosParams = (variables) => { if ( !variables || typeof variables.id === "undefined" || typeof variables.approved === "undefined" ) { console.error("Missing id or approved in mutation variables:", variables); return {}; } return { url: "/api/currentUser/updateAliasModeration", method: "PUT", params: { id: variables.id, approved: variables.approved, }, }; }; const onSuccess = (returnedUser, variables) => { toast( `${variables.approved ? "Approved" : "Rejected"} alias: ${returnedUser.alias}`, ); queryClient.invalidateQueries("/api/admin/usersWithProposedAlias"); }; const mutation = useBackendMutation(objectToAxiosParams, { onSuccess }); const columns = [ { Header: "Alias", accessor: "alias" }, { Header: "Proposed Alias", accessor: "proposedAlias" }, ButtonColumn("Approve", "success", (cell) => { const user = cell.row.original; mutation.mutate({ id: user.id, approved: true }); }), ButtonColumn("Reject", "danger", (cell) => { const user = cell.row.original; mutation.mutate({ id: user.id, approved: false }); }), ]; if (status === "loading") return <div>Loading...</div>; if (error) return <div>Error loading aliases</div>; return <OurTable data={users} columns={columns} testid={testid} />; } |