All files / src/components/common/Modal Progress.tsx

18.18% Statements 2/11
0% Branches 0/6
0% Functions 0/4
20% Lines 2/10

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                      86x       86x                                                  
import { TickIcon } from "@assets/icons";
import { Text } from "@common/Text";
import { Box } from "@mui/material";
import { palette } from "@palette";
import { useCallback } from "react";
 
type Props = {
  title?: string;
  progressValues?: Record<string, number>;
};
 
const formatKey = (key: string) => {
  return key.replace(/([A-Z])/g, " $1").trim();
};
 
const Progress = ({ title, progressValues }: Props) => {
  const renderProgressText = useCallback(() => {
    if (!progressValues) return <></>;
    return Object.keys(progressValues).map((key) => {
      const currentKey = progressValues[key];
      const color =
        currentKey === 100 ? palette.filled.green : palette.filled.grey;
 
      return (
        <Text key={key} sx={{ color }} py={0.5}>
          {
            <TickIcon
              stroke={currentKey === 100 ? color : palette.filled.lightGrey}
            />
          }{" "}
          {formatKey(key)}: {currentKey}%
        </Text>
      );
    });
  }, [progressValues]);
 
  return <Box textAlign="left">{renderProgressText()}</Box>;
};
 
export default Progress;