All files / react-app/src/features/package/package-details hooks.tsx

80% Statements 28/35
59.64% Branches 34/57
79.31% Functions 23/29
80.64% Lines 25/31

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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173                      72x                                                         72x       3x         3x           3x           3x         3x         3x               3x                 3x             3x             3x           3x             3x           3x         72x   3x         3x             3x         72x       3x       72x       3x           3x           3x      
import { formatActionType, formatSeatoolDate, isCmsUser, isStateUser } from "shared-utils";
 
import { OneMacUser } from "@/api/useGetUser";
import { BLANK_VALUE } from "@/consts";
import { FC, ReactNode } from "react";
import { Authority, opensearch } from "shared-types";
 
import { convertStateAbbrToFullName } from "@/utils";
import { format } from "date-fns";
import { useMemo, useState } from "react";
 
export const ReviewTeamList: FC<opensearch.main.Document> = (props) => {
  const [expanded, setExpanded] = useState(false);
  const displayTeam = useMemo(
    () => (expanded ? props.reviewTeam : props.reviewTeam?.slice(0, 3)),
    [expanded, props.reviewTeam],
  );
  return !displayTeam || !displayTeam.length ? (
    BLANK_VALUE
  ) : (
    <ul>
      {displayTeam.map((reviewer, idx) => (
        <li key={`reviewteam-ul-${reviewer.name}-${idx}`}>{reviewer.name}</li>
      ))}
      {props.reviewTeam && props.reviewTeam?.length > 3 && (
        <li className={"text-xs text-sky-700 hover:cursor-pointer"}>
          <button onClick={() => setExpanded((prev) => !prev)}>
            {expanded ? "Show less" : "Show more"}
          </button>
        </li>
      )}
    </ul>
  );
};
 
export type DetailSectionItem = {
  label: string;
  value: ReactNode;
  canView: (u: OneMacUser | undefined) => boolean;
};
export const recordDetails = (data: opensearch.main.Document): DetailSectionItem[] => [
  {
    label: "Submission ID",
    value: data.id,
    canView: () => true,
  },
  {
    label: "Authority",
    value: data?.authority,
    canView: () => true,
  },
  {
    label: "Action Type",
    value: formatActionType(data.actionType),
    canView: () => {
      return ([Authority["1915b"], Authority["1915c"]] as string[]).includes(data.authority);
    },
  },
  {
    label: "State",
    value: convertStateAbbrToFullName(data.state),
    canView: () => true,
  },
  {
    label: "Amendment Title",
    value: <p>{data?.title || BLANK_VALUE}</p>,
    canView: () => !!data.title,
  },
  {
    label: "Subject",
    value: <p>{data?.subject || BLANK_VALUE}</p>,
    canView: (u) => (!u || !u.user ? false : isCmsUser(u.user) && !(data.actionType === "Extend")),
  },
  {
    label: "Type",
    value: data.types
      ? data.types.map((T) => <p key={T?.SPA_TYPE_ID}>{T?.SPA_TYPE_NAME}</p>)
      : BLANK_VALUE,
    canView: ({ user }) => {
      return !(data.actionType === "Extend") && isStateUser(user) === false;
    },
  },
  {
    label: "Subtype",
    value: data.subTypes
      ? data.subTypes.map((T) => <p key={T?.TYPE_ID}>{T?.TYPE_NAME}</p>)
      : BLANK_VALUE,
    canView: ({ user }) => {
      return !(data.actionType === "Extend") && isStateUser(user) === false;
    },
  },
  {
    label: "Approved Initial or Renewal Number",
    value: data.originalWaiverNumber,
    canView: () => {
      return data.actionType === "Extend";
    },
  },
  {
    label: "Proposed effective date",
    value: data.proposedDate ? formatSeatoolDate(data.proposedDate) : "Pending",
    canView: () => {
      return !(data.actionType === "Extend");
    },
  },
  {
    label: "Initial submission date",
    value: data.submissionDate ? formatSeatoolDate(data.submissionDate) : BLANK_VALUE,
    canView: () => true,
  },
  {
    label: "Latest package activity",
    value: data.makoChangedDate
      ? format(new Date(data.makoChangedDate).getTime(), "eee, MMM d yyyy, hh:mm:ss a")
      : BLANK_VALUE,
    canView: () => true,
  },
  {
    label: "Formal RAI response date",
    value: data.raiReceivedDate ? formatSeatoolDate(data.raiReceivedDate) : BLANK_VALUE,
    canView: () => {
      return !(data.actionType === "Extend");
    },
  },
];
 
export const approvedAndAEffectiveDetails = (
  data: opensearch.main.Document,
): DetailSectionItem[] => [
  {
    label: "Final disposition date",
    value: data.finalDispositionDate ? formatSeatoolDate(data.finalDispositionDate) : BLANK_VALUE,
    canView: () => {
      return !(data.actionType === "Extend");
    },
  },
  {
    label: "Approved effective date",
    value: data.approvedEffectiveDate ? formatSeatoolDate(data.approvedEffectiveDate) : BLANK_VALUE,
    canView: () => {
      return !(data.actionType === "Extend");
    },
  },
];
 
export const descriptionDetails = (data: opensearch.main.Document): DetailSectionItem[] => [
  {
    label: "Description",
    value: data.description ?? BLANK_VALUE,
    canView: (u) => (!u || !u.user ? false : isCmsUser(u.user) && !(data.actionType === "Extend")),
  },
];
 
export const submissionDetails = (data: opensearch.main.Document): DetailSectionItem[] => [
  {
    label: "Submitted by",
    value: <p className="text-lg">{data?.submitterName || BLANK_VALUE}</p>,
    canView: () => true,
  },
  {
    label: "CPOC",
    value: <p className="text-lg">{data?.leadAnalystName || BLANK_VALUE}</p>,
    canView: () => {
      return !(data.actionType === "Extend");
    },
  },
  {
    label: "Review Team (SRT)",
    value: <ReviewTeamList {...data} />,
    canView: (u) => (!u || !u.user ? false : isCmsUser(u.user) && !(data.actionType === "Extend")),
  },
];