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 | 106x 106x 38x 58x 58x 18x 80x 80x 80x 80x 34x 18x 18x 106x 39x 17x 55x 106x 62x 187x | import { UserRole } from "shared-types/events/legacy-user";
import { StateAccess } from "@/api";
import { convertStateAbbrToFullName } from "@/utils";
// TODO: rename? all roles should see either a State or Status Access Card
export const stateAccessRoles: UserRole[] = [
"statesubmitter",
"statesystemadmin",
"cmsroleapprover",
"helpdesk",
"defaultcmsuser",
"cmsreviewer",
"norole",
];
// In the backend we named the prop "StateAcess", but this is used for both state and CMS users
// it is confusing me so on the frontend we will convert StateAcess -> RoleStatus as that is the more appropriate name
export const orderRoleStatus = (accesses: StateAccess[]) => {
if (!accesses || !accesses.length) return;
// sort revoked states seprately and add to
const activeStates = accesses.filter((x: StateAccess) => x.status != "revoked");
const revokedStates = accesses.filter((x: StateAccess) => x.status == "revoked");
const compare = (a: StateAccess, b: StateAccess) => {
Eif (a.territory !== "N/A" && b.territory !== "N/A") {
const stateA = convertStateAbbrToFullName(a.territory);
const stateB = convertStateAbbrToFullName(b.territory);
if (stateA < stateB) return -1;
Eif (stateA > stateB) return 1;
return 0;
}
if (a.role === "defaultcmsuser") return 1;
if (b.role === "defaultcmsuser") return -1;
return 0;
};
const sorted = activeStates.sort(compare).concat(revokedStates.sort(compare));
return sorted;
};
// if user has no active roles, show pending state(s)
// show state(s) for latest active role
export const filterRoleStatus = (userDetails, userProfile) => {
if (!userProfile?.stateAccess || userProfile.stateAccess.length < 1) return [];
return userDetails?.role && userDetails?.role !== "norole"
? userProfile.stateAccess.filter((access: StateAccess) => access.role === userDetails.role)
: userProfile.stateAccess;
};
export const hasPendingRequests = (stateAccess) => {
if (!stateAccess || stateAccess.length < 1) return false;
return stateAccess.some((role) => role.status === "pending");
};
|