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

78.57% Statements 11/14
60% Branches 9/15
100% Functions 4/4
91.66% Lines 11/12

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                                          72x 6x                   57x                                 72x 3x 2x   2x       2x 2x   2x     2x                                          
import { DetailsSection } from "@/components";
import {
  approvedAndAEffectiveDetails,
  descriptionDetails,
  recordDetails,
  submissionDetails,
} from "./hooks";
 
import { FC, useMemo } from "react";
 
import { DetailSectionItem } from "./hooks";
import { useGetUser } from "@/api/useGetUser";
import { AppK } from "./appk";
import { cn } from "@/utils";
import { Authority } from "shared-types";
import { ItemResult } from "shared-types/opensearch/main";
 
export const DetailItemsGrid: FC<{
  displayItems: DetailSectionItem[];
  fullWidth?: boolean;
  containerStyle?: string;
}> = (props) => {
  const { data: user } = useGetUser();
 
  return (
    <div
      className={cn(
        `${props.fullWidth ? "max-w-xl" : "grid grid-cols-2 gap-6"}`,
        props.containerStyle,
      )}
    >
      {props.displayItems.map(({ label, value, canView }) => {
        return canView(user) ? (
          <div key={label}>
            <h3 style={{ fontWeight: 700 }}>{label}</h3>
            <div style={{ fontWeight: 400 }} className="py-2">
              {value}
            </div>
          </div>
        ) : null;
      })}
    </div>
  );
};
 
type PackageDetailsProps = {
  itemResult: ItemResult;
};
 
export const PackageDetails = ({ itemResult }: PackageDetailsProps) => {
  const title = useMemo(() => {
    const { _source: source } = itemResult;
 
    switch (source.authority) {
      case Authority["1915b"]:
      case Authority["1915c"]:
      case undefined: // Some TEs have no authority
        Iif (source.id === "NOASDFASDFASDF") return "1915(c) Appendix K Package Details";
        Iif (source.actionType == "Amend" && source.authority === Authority["1915c"])
          return "1915(c) Appendix K Amendment Package Details";
        Iif (source.actionType == "Extend") return "Temporary Extension Request Details";
    }
 
    return `${source.authority} Package Details`;
  }, [itemResult]);
 
  return (
    <DetailsSection id="package_details" title={title}>
      <div className="flex-col gap-4 max-w-2xl">
        <DetailItemsGrid
          displayItems={[
            ...recordDetails(itemResult._source),
            ...approvedAndAEffectiveDetails(itemResult._source),
            ...descriptionDetails(itemResult._source),
          ]}
          containerStyle="py-4"
        />
        <hr className="my-4" />
        <DetailItemsGrid displayItems={submissionDetails(itemResult._source)} />
        <AppK />
      </div>
    </DetailsSection>
  );
};