All files / src/features/Merchants/MerchantSidePanel/Modals/MatchReport/components ReportDetailsView.tsx

71.42% Statements 20/28
42.85% Branches 15/35
33.33% Functions 3/9
85.71% Lines 18/21

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 174 175 176 177 178 179 180 181 182 183 184 185 186 187                                      4x                                     4x         1x 1x   1x 1x 1x         1x       1x 1x                                       1x   1x   1x                                                                                                                         4x                                   4x               4x               4x           4x      
import { Stack } from "@mui/system";
import { Icon as StatusIcon } from "@shared/Popup/GivePopupIcons";
import React, { useMemo, useState } from "react";
import GiveText from "@shared/Text/GiveText";
import { styled, useAppTheme } from "@theme/v2/Provider";
import GiveUploadStack from "@shared/FileUpload/GiveUploadStack";
import { FileTextIcon } from "@phosphor-icons/react";
import { ReportType } from "../types";
import { statusOptions } from "../utils";
import { Skeleton } from "@mui/material";
import { useGetSingleMATCHReport } from "@features/Merchants/MerchantSidePanel/Modals/MatchReport/hooks/useMATCHReports";
import moment from "moment";
import { PLATFORM_TIMEZONE } from "@utils/timezones";
import { GiveUploadItemProps } from "@shared/FileUpload/types";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import TaskCard from "@features/Merchants/MerchantSidePanel/UnderwritingTasks/components/TaskCard";
import { AttachmentsContent } from "@features/Merchants/MerchantSidePanel/UnderwritingTasks/components/Sections";
import MastercardResponse from "./MastercardResponse";
 
const MAX_TEXT_LENGTH = 1301; // Value calculated from mockups, can be changed
 
interface IComponentProps {
  reportDetailsViewData: ReportType;
  merchantID: number;
}
 
type EvidenceFileItem = {
  fileName: string;
  fileType: string;
  fileURL: string;
  id: number;
  updatedAt: number;
  userFullName: string;
  isUploaded: boolean;
  tag?: string;
  label?: string;
};
 
const ReportDetailsView = ({
  reportDetailsViewData,
  merchantID,
}: IComponentProps) => {
  const { statusName, findings, ID, matchResult, aiSummary } =
    reportDetailsViewData;
  const { isMastercardMatchEnabled } = useGetFeatureFlagValues();
  const isLargeDescription =
    findings.length > MAX_TEXT_LENGTH || isMastercardMatchEnabled;
  const [showAllFindings, setShowAllFindings] = useState(!isLargeDescription);
  const { data: extraData, isLoading } = useGetSingleMATCHReport(
    merchantID,
    ID,
  );
 
  const showFindingsSection = isMastercardMatchEnabled
    ? Boolean(findings)
    : true;
 
  const evidenceList: GiveUploadItemProps[] = useMemo(() => {
    Eif (!extraData?.files) return [];
 
    return extraData.files.map((item: EvidenceFileItem) => ({
      merchantId: merchantID,
      state: item.isUploaded ? "uploaded" : "",
      value: item.tag ?? "MATCH Evidence",
      byMessage: `by ${item.userFullName}`,
      dateMessage: moment(item.updatedAt * 1000).tz(PLATFORM_TIMEZONE).format("MMM DD YYYY, HH:mm"),
      fileData: {
        fileName: item.fileName,
        id: item.id,
        fileType: item.fileType,
        fileURL: item.fileURL,
        tag: item.tag ?? "MATCH Evidence",
      },
      tagType: "form-field",
    }));
  }, [extraData]);
 
  const showEvidenceSection =
    evidenceList.length > 0 && isMastercardMatchEnabled;
 
  const toggleFindingsTextLength = () => setShowAllFindings((curr) => !curr);
 
  return (
    <Stack gap="20px">
      <StyledStatusContainerStack>
        <StatusIcon
          type={statusName === "clear" ? "success-regular" : "warning"}
        />
        <GiveText variant="h5">{statusOptions[statusName].label}</GiveText>
      </StyledStatusContainerStack>
      {showFindingsSection && (
        <Stack gap="12px">
          <GiveText variant="bodyS">Findings</GiveText>
          <GiveText variant="bodyS" color="secondary">
            {showAllFindings
              ? findings
              : findings.slice(0, MAX_TEXT_LENGTH + 1)}
          </GiveText>
          {isLargeDescription && !isMastercardMatchEnabled && (
            <ReadText
              variant="bodyS"
              color="link"
              onClick={toggleFindingsTextLength}
            >
              Read {showAllFindings ? "Less" : "More"}
            </ReadText>
          )}
        </Stack>
      )}
      {showEvidenceSection && (
        <TaskCard title="Evidence" sx={{ padding: 0 }}>
          <AttachmentsContent
            merchantID={merchantID}
            uploadedItems={evidenceList}
            isEnterprise={false}
            attachmentType="underwriting_match_report"
          />
        </TaskCard>
      )}
      {!isMastercardMatchEnabled && (
        <Stack gap={1.5}>
          <GiveText variant="bodyS">Evidence</GiveText>
          {isLoading ? (
            <StyledEvidenceLoadingSkeleton variant="rectangular" />
          ) : evidenceList.length ? (
            <GiveUploadStack items={evidenceList} isHideDelete />
          ) : (
            <NoEvidenceAttached />
          )}
        </Stack>
      )}
      {isMastercardMatchEnabled && (
        <MastercardResponse
          title="API Response"
          response={matchResult}
          merchantID={merchantID}
          existingSummary={aiSummary}
        />
      )}
    </Stack>
  );
};
 
const NoEvidenceAttached = () => {
  const theme = useAppTheme();
  return (
    <Stack justifyContent="center" alignItems="center" gap={2.5}>
      <StyledIconBox>
        <FileTextIcon
          width={24}
          height={24}
          color={theme.palette.icon?.["icon-primary"]}
        />
      </StyledIconBox>
      <GiveText variant="bodyS" color="secondary">
        No evidence document was attached
      </GiveText>
    </Stack>
  );
};
 
const StyledIconBox = styled(Stack)(({ theme }) => ({
  padding: theme.spacing(2),
  width: 56,
  height: 56,
  borderRadius: "100%",
  backgroundColor: theme.palette.primitive?.transparent["darken-5"],
}));
 
const StyledStatusContainerStack = styled(Stack)(({ theme }) => ({
  flexDirection: "row",
  gap: theme.spacing(2.5),
  paddingBottom: theme.spacing(2.5),
  alignItems: "center",
  borderBottom: `1px solid ${theme.palette.border?.primary}`,
}));
 
const StyledEvidenceLoadingSkeleton = styled(Skeleton)(({ theme }) => ({
  width: "100%",
  height: 200,
  borderRadius: theme.spacing(1.5),
}));
 
const ReadText = styled(GiveText)({ cursor: "pointer", width: "fit-content" });
 
export default ReportDetailsView;