All files / pages AdminUsersPage.js

100% Statements 21/21
100% Branches 4/4
100% Functions 4/4
100% Lines 21/21

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            1x     49x             49x 49x 49x 49x 2x 2x 2x   49x 2x 2x 2x   49x 3x 3x 3x           49x             49x           49x 49x                                                                                
import {React, useState} from "react";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import UsersTable from "main/components/Users/UsersTable"
 
 
import { useBackend } from "main/utils/useBackend";
const AdminUsersPage = () => {
 
    const { data: allUsers, error: _error, status: _status } =
        useBackend(
            // Stryker disable next-line all : don't test internal caching of React Query
            ["/api/admin/users"],
            // Stryker disable next-line StringLiteral,ObjectLiteral : since "GET" is default, "" is an equivalent mutation
            { method: "GET", url: "/api/admin/users" },
            []
        );
    const [isCheckedAll, setIsCheckedAll] = useState(true);
    const [isCheckedDrivers, setIsCheckedDrivers] = useState(false);
    const [isCheckedRiders, setIsCheckedRiders] = useState(false);
    const handleOnChangeAll = () => {
      setIsCheckedAll(true);
      setIsCheckedDrivers(false);
      setIsCheckedRiders(false);
    };
    const handleOnChangeDrivers = () => {
        setIsCheckedDrivers(true);
        setIsCheckedAll(false);
        setIsCheckedRiders(false);
      };
    const handleOnChangeRiders = () => {
        setIsCheckedRiders(true);
        setIsCheckedAll(false);
        setIsCheckedDrivers(false);
    };
 
 
    // Stryker disable all
    const { data: allRiders, error: __error1, status: __status1 } =
        useBackend(
            ["/api/admin/users/riders"],
            { method: "GET", url: "/api/admin/users/riders" },
            []
        );
 
    const { data: allDrivers, error: _error2, status: _statu2 } =
        useBackend(
            ["/api/admin/users/drivers"],
            { method: "GET", url: "/api/admin/users/drivers" },
            []
        );
    // Stryker restore all
    var tableContent = isCheckedAll ? allUsers : (isCheckedDrivers ? allDrivers : allRiders);
    return (
        <BasicLayout>
            <h1>Users</h1>
            <div className="userType">
                <h5>User Type:
                <input
                type="checkbox"
                id="all"
                name="all"
                value="All"
                checked={isCheckedAll}
                onChange={handleOnChangeAll}
                />
                <label htmlFor="all">All</label>
                <input
                type="checkbox"
                id="drivers"
                name="drivers"
                value="Drivers"
                checked={isCheckedDrivers}
                onChange={handleOnChangeDrivers}
                />
                <label htmlFor="drivers">Drivers</label>
                <input
                type="checkbox"
                id="riders"
                name="riders"
                value="Riders"
                checked={isCheckedRiders}
                onChange={handleOnChangeRiders}
                />
                <label htmlFor="riders">Riders</label>
                </h5>
            </div>
            <UsersTable users={tableContent} />
        </BasicLayout>
    );
};
 
export default AdminUsersPage;