All files / react-app/src/features/sign-up sign-up.tsx

100% Statements 7/7
100% Branches 0/0
100% Functions 3/3
100% Lines 6/6

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                            2x 1x     1x   1x                                                               1x 6x                                          
import { UserRole } from "shared-types/events/legacy-user";
 
import { useGetUserDetails } from "@/api";
import { LoadingSpinner, OptionCard, OptionFieldset, SubNavHeader } from "@/components";
 
type UserRoleWithNoRole = UserRole;
type RoleOptions = {
  key: UserRoleWithNoRole;
  title: string;
  description: string;
  rolesWhoCanView: UserRoleWithNoRole[];
  link: string;
};
 
export const SignUp = () => {
  const { data: userDetails } = useGetUserDetails();
  if (!userDetails) return <LoadingSpinner />;
 
  const role = userDetails.role;
  // helpdesk, system admins, and cms reviewer users don't even see request role as an option
  const roleOptions = [
    {
      key: "statesubmitter",
      title: "State Submitter",
      description: "Responsible for submitting packages",
      rolesWhoCanView: ["statesystemadmin", "norole"],
      link: "/signup/state?role=statesubmitter",
    },
    {
      key: "statesystemadmin",
      title: "State System Administrator",
      description: "Ability to approve state submitters and submit packages",
      rolesWhoCanView: ["statesubmitter", "norole"],
      link: "/signup/state?role=statesystemadmin",
    },
    // TODO: Get language from HCD/CMS. This used to be "CMS Reviewer" in legacy
    {
      key: "defaultcmsuser",
      title: "CMS Read-only",
      description: "Responsible for viewing packages",
      rolesWhoCanView: ["cmsroleapprover"],
      link: "/signup/cms",
    },
    {
      key: "cmsroleapprover",
      title: "CMS Role Approver",
      description: "Responsible for managing CMS Read-only Users and State System Admins",
      rolesWhoCanView: ["defaultcmsuser", "cmsreviewer"],
      link: "/signup/cms",
    },
  ] satisfies RoleOptions[];
 
  const displayRoleOptions = roleOptions.filter((roleOption) => {
    return roleOption.rolesWhoCanView.find((validRole) => validRole === role);
  });
 
  return (
    <div>
      <SubNavHeader>
        <h1 className="text-xl font-medium">Registration: User Role</h1>
      </SubNavHeader>
      <OptionFieldset legend={"Select the role for which you are registering"}>
        {displayRoleOptions.map((role) => (
          <OptionCard
            description={role.description}
            title={role.title}
            to={role.link}
            key={role.key}
          />
        ))}
      </OptionFieldset>
    </div>
  );
};