All files / pages/HelpRequest HelpRequestIndexPage.jsx

100% Statements 3/3
100% Branches 4/4
100% Functions 1/1
100% Lines 3/3

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                26x 26x           26x                              
import { Link } from "react-router";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import HelpRequestTable from "main/components/HelpRequest/HelpRequestTable";
import { Alert, Button } from "react-bootstrap";
import { useBackend } from "main/utils/useBackend";
import { hasRole, useCurrentUser } from "main/utils/useCurrentUser";
 
export default function HelpRequestIndexPage() {
  const currentUser = useCurrentUser();
  const { data: helpRequests, error } = useBackend(
    ["/api/helprequests/all"],
    { method: "GET", url: "/api/helprequests/all" },
    [],
  );
 
  return (
    <BasicLayout>
      <h1>HelpRequests</h1>
      {hasRole(currentUser, "ROLE_ADMIN") && (
        <p>
          <Button as={Link} to="/helprequest/create" variant="primary">
            Create HelpRequest
          </Button>
        </p>
      )}
      {error && <Alert variant="danger">Unable to load help requests.</Alert>}
      <HelpRequestTable helpRequests={helpRequests} currentUser={currentUser} />
    </BasicLayout>
  );
}