All files / src/shared/UnderwritingScore GiveUnderwritingScore.tsx

100% Statements 7/7
71.42% Branches 10/14
100% Functions 2/2
100% Lines 7/7

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                                      33x               24x   24x 24x       24x   24x                                         33x      
import GiveProgressBar from "@shared/ProgressBar/GiveProgressBar";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import React, { useMemo } from "react";
import CircularScore from "./CircularScore";
 
type Props = {
  score: number | undefined;
  pendingScore: number;
  merchant_underwriting?: boolean;
  isViewUnderwritingAllowed?: boolean;
  handleClick?: () => void;
  statusDisplayName?: string;
  canProcessMoney?: boolean;
  canTransferMoney?: boolean;
  pendingChallenges?: number;
  hideIcons?: boolean;
  alwaysDisplayProgressBars?: boolean;
};
 
const GiveUnderwritingScore = React.memo(
  ({
    score = 0,
    pendingScore = 0,
    merchant_underwriting,
    isViewUnderwritingAllowed,
    handleClick,
  }: Props) => {
    const { isDesktopView } = useCustomThemeV2();
 
    const barVariant = useMemo(() => {
      return !score || score < 80 ? "incomplete" : "completed";
    }, [score]);
 
    const isUnderwritingDisabled =
      !merchant_underwriting || !isViewUnderwritingAllowed;
 
    return (
      <>
        {!isDesktopView ? (
          <CircularScore
            disabled={isUnderwritingDisabled}
            handleClick={handleClick}
            score={score}
            pendingScore={pendingScore}
          />
        ) : (
          <GiveProgressBar
            value={(score ?? 0) + pendingScore}
            innerValue={score}
            variant={isUnderwritingDisabled ? "disabled" : barVariant}
            type="default"
          />
        )}
      </>
    );
  },
);
GiveUnderwritingScore.displayName = "GiveUnderwritingScore";
 
export default GiveUnderwritingScore;