All files / react-app/src/features/dashboard/Lists/spas consts.tsx

100% Statements 43/43
100% Branches 46/46
100% Functions 22/22
100% Lines 40/40

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                      5x 18x 1x   17x   17x                             28x           28x 956x         28x   956x           28x 28x 21x 7x   14x       28x           28x     956x 956x 718x 473x                                     28x                     84x               28x                   56x           28x                   28x 28x         28x 956x         5x 78x 78x   78x   78x 23x 5x   18x 18x       78x    
import { useEffect, useState } from "react";
import { CMS_READ_ONLY_ROLES, SEATOOL_STATUS, UserRoles } from "shared-types";
import { formatDateToET, formatDateToUTC } from "shared-utils";
 
import { useGetUser } from "@/api";
import { OsTableColumn } from "@/components";
import { BLANK_VALUE } from "@/consts";
import { removeUnderscoresAndCapitalize } from "@/utils";
 
import { CellDetailsLink, renderCellActions, renderCellDate } from "../renderCells";
 
const getColumns = (props) => {
  if (!props?.user || props.user === null) {
    return [];
  }
  return [
    // hide actions column for: readonly,help desk
    ...(!CMS_READ_ONLY_ROLES.some((UR) => props.user?.role === UR)
      ? [
          {
            locked: true,
            isSystem: true,
            label: "Actions",
            cell: renderCellActions(props.user),
          },
        ]
      : []),
    {
      props: { className: "w-[150px]" },
      field: "id.keyword",
      label: "SPA ID",
      locked: true,
      transform: (data) => data.id,
      cell: ({ id, authority }) => <CellDetailsLink id={id} authority={authority} />,
    },
    {
      field: "state.keyword",
      label: "State",
      transform: (data) => data.state ?? BLANK_VALUE,
      cell: (data) => data.state,
    },
    {
      field: "authority.keyword",
      label: "Authority",
      transform: (data) => data.authority ?? BLANK_VALUE,
      cell: (data) =>
        data?.authority ? removeUnderscoresAndCapitalize(data.authority) : BLANK_VALUE,
    },
    {
      field: props?.isCms ? "cmsStatus.keyword" : "stateStatus.keyword",
      label: "Status",
      transform: (data) => {
        const status = (() => {
          if (!props?.isCms) return data.stateStatus;
          if (props?.user?.role === UserRoles.HELPDESK) {
            return data.stateStatus;
          }
          return data.cmsStatus;
        })();
 
        const subStatusRAI =
          data.raiWithdrawEnabled &&
          data.seatoolStatus !== SEATOOL_STATUS.PENDING_APPROVAL &&
          data.seatoolStatus !== SEATOOL_STATUS.PENDING_CONCURRENCE
            ? " (Withdraw Formal RAI Response - Enabled)"
            : "";
 
        return `${status}${subStatusRAI}`;
      },
      cell: (data) => {
        const status = (() => {
          if (!props?.isCms) return data.stateStatus;
          if (props.user?.role === UserRoles.HELPDESK) return data.stateStatus;
          return data.cmsStatus;
        })();
 
        return (
          <>
            <p>{status}</p>
            {data.raiWithdrawEnabled &&
              data.seatoolStatus !== SEATOOL_STATUS.PENDING_APPROVAL &&
              data.seatoolStatus !== SEATOOL_STATUS.PENDING_CONCURRENCE && (
                <p className="text-xs opacity-65">ยท Withdraw Formal RAI Response - Enabled</p>
              )}
          </>
        );
      },
    },
    {
      field: "submissionDate",
      label: "Initial Submission",
      transform: (data) => {
        return data?.submissionDate
          ? formatDateToET(data.submissionDate, "MM/dd/yyyy", false)
          : BLANK_VALUE;
      },
      cell: renderCellDate("submissionDate"),
    },
    {
      field: "finalDispositionDate",
      label: "Final Disposition",
      hidden: true,
      cell: (data) =>
        data?.finalDispositionDate
          ? formatDateToUTC(data.finalDispositionDate, "MM/dd/yyyy")
          : BLANK_VALUE,
    },
    {
      field: "makoChangedDate",
      label: "Latest Package Activity",
      transform: (data) =>
        data.makoChangedDate
          ? formatDateToET(data.makoChangedDate, "MM/dd/yyyy", false)
          : BLANK_VALUE,
      cell: renderCellDate("makoChangedDate"),
    },
    {
      field: "raiRequestedDate",
      label: "Formal RAI Requested",
      hidden: true,
      cell: (data) =>
        data?.raiRequestedDate ? formatDateToUTC(data.raiRequestedDate, "MM/dd/yyyy") : BLANK_VALUE,
    },
    {
      field: "raiReceivedDate",
      label: "Formal RAI Response",
      transform: (data) => {
        return data.raiReceivedDate
          ? formatDateToET(data.raiReceivedDate, "MM/dd/yyyy", false)
          : BLANK_VALUE;
      },
      cell: renderCellDate("raiReceivedDate"),
    },
    {
      field: "leadAnalystName.keyword",
      label: "CPOC Name",
      hidden: true,
      transform: (data) => data.leadAnalystName ?? BLANK_VALUE,
      cell: (data) => data.leadAnalystName,
    },
    {
      field: "submitterName.keyword",
      label: "Submitted By",
      transform: (data) => data.submitterName ?? BLANK_VALUE,
      cell: (data) => data.submitterName,
    },
  ];
};
 
export const useSpaTableColumns = (): { columns?: OsTableColumn[]; isLoading: boolean } => {
  const [columns, setColumns] = useState(undefined);
  const [isLoading, setIsLoading] = useState(true);
 
  const { data: props, isLoading: isUserLoading } = useGetUser();
 
  useEffect(() => {
    if (isUserLoading === true) {
      setIsLoading(true);
    } else {
      setIsLoading(false);
      setColumns(getColumns(props));
    }
  }, [props, isUserLoading]);
 
  return { columns, isLoading };
};