All files / pages ModerateReviewsPage.jsx

100% Statements 11/11
100% Branches 2/2
100% Functions 3/3
100% Lines 11/11

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                        1x 21x         21x                       21x                 21x             21x             21x 1x     21x 1x     21x                                                        
import React from "react";
import { useBackend, useBackendMutation } from "main/utils/useBackend";
import { useCurrentUser, hasRole } from "main/utils/currentUser";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import ReviewsTable from "main/components/Reviews/ReviewsTable";
import AliasApprovalTable from "main/components/AliasApproval/AliasApprovalTable";
import {
  cellToAxiosParamsApprove,
  cellToAxiosParamsReject,
  onModerateSuccess,
} from "main/utils/Aliases";
 
const ModerateReviews = () => {
  const currentUser = useCurrentUser();
 
  //
  // Reviews needing moderation
  //
  const { data: reviews } = useBackend(
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/reviews/needsmoderation"],
    // Stryker disable next-line all : don't test internal caching of React Query
    { method: "GET", url: "/api/reviews/needsmoderation" },
    // Stryker disable next-line all : don't test internal caching of React Query
    [],
  );
 
  //
  // Aliases needing moderation
  //
  const { data: aliases } = useBackend(
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/admin/users/needsmoderation"],
    // Stryker disable next-line all : don't test internal caching of React Query
    { method: "GET", url: "/api/admin/users/needsmoderation" },
    // Stryker disable next-line all : don't test internal caching of React Query
    [],
  );
 
  const approveAliasMutation = useBackendMutation(
    cellToAxiosParamsApprove,
    { onSuccess: onModerateSuccess },
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/admin/users/needsmoderation"],
  );
 
  const rejectAliasMutation = useBackendMutation(
    cellToAxiosParamsReject,
    { onSuccess: onModerateSuccess },
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/admin/users/needsmoderation"],
  );
 
  const approveAliasCallback = (alias) => {
    approveAliasMutation.mutate(alias);
  };
 
  const rejectAliasCallback = (alias) => {
    rejectAliasMutation.mutate(alias);
  };
 
  const moderateReviewsOptions =
    hasRole(currentUser, "ROLE_ADMIN") ||
    hasRole(currentUser, "ROLE_MODERATOR");
 
  return (
    <BasicLayout>
      <div className="pt-2">
        <h1>Moderation Page</h1>
 
        <h2>Reviews Needing Moderation</h2>
        <ReviewsTable
          reviews={reviews}
          moderatorOptions={moderateReviewsOptions}
        />
 
        <h2 className="mt-4">Aliases Needing Moderation</h2>
        <AliasApprovalTable
          aliases={aliases}
          approveCallback={approveAliasCallback}
          rejectCallback={rejectAliasCallback}
          moderatorOptions={moderateReviewsOptions}
        />
      </div>
    </BasicLayout>
  );
};
 
export default ModerateReviews;