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 | 12x 12x 12x 12x 2x 2x 12x 12x 1x 1x 12x 16x 2x 2x 16x 1x 1x 12x 12x | import React from "react"; import OurTable from "main/components/OurTable"; import { toast } from "react-toastify"; import { useBackendMutation } from "main/utils/useBackend"; import { useQueryClient } from "react-query"; export default function AliasTable({ alias }) { const testid = "AliasTable"; const queryClient = useQueryClient(); const objectToAxiosParamsApprove = (user) => ({ // Stryker disable next-line all url: `/api/currentUser/updateAliasModeration`, method: "PUT", /* Stryker disable all */ //not tested because it is mocked params: { id: user.id, approved: true, }, /* Stryker restore all */ }); const approveMutation = useBackendMutation(objectToAxiosParamsApprove, { onSuccess: (user, propAlias) => { //Stryker disable next-line all queryClient.invalidateQueries(["/api/admin/usersWithProposedAlias"]); toast(`Alias ${propAlias.proposedAlias} for id ${user.id} approved!`); }, }); const objectToAxiosParamsReject = (user) => ({ // Stryker disable next-line all url: `/api/currentUser/updateAliasModeration`, method: "PUT", /* Stryker disable all */ //not tested because it is mocked params: { id: user.id, approved: false, }, /* Stryker restore all */ }); const rejectMutation = useBackendMutation(objectToAxiosParamsReject, { onSuccess: (user, propAlias) => { //Stryker disable next-line all queryClient.invalidateQueries(["/api/admin/usersWithProposedAlias"]); //refresh the table toast(`Alias ${propAlias.proposedAlias} for id ${user.id} rejected!`); }, }); const columns = [ { Header: "Proposed Alias", accessor: "proposedAlias", // accessor is the "key" in the data }, { Header: "Approve", accessor: "approve", // green button to approve the alias Cell: (cell) => ( <button className="btn btn-success" onClick={() => { const user = cell.row.original; approveMutation.mutate(user, user.proposedAlias); }} > Approve </button> ), }, { Header: "Reject", accessor: "reject", Cell: (cell) => ( <button className="btn btn-danger" onClick={() => { const user = cell.row.original; rejectMutation.mutate(user, user.proposedAlias); }} > Reject </button> ), }, ]; const displayedColumns = columns; return <OurTable data={alias} columns={displayedColumns} testid={testid} />; } |