All files / src/features/GiveOnboarding/components/StackedNavigator StepItem.tsx

81.25% Statements 13/16
73.68% Branches 14/19
75% Functions 3/4
81.25% Lines 13/16

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                          9x 144x   144x 144x   144x             144x                                         9x 585x         144x 144x 144x   144x   144x                                          
import { Stack, Box } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import { styled } from "@theme/v2/Provider";
import { IStep, ISubStep } from "../../types";
import { CheckSvg } from "./CheckSvg";
import { useDispatch } from "react-redux";
import { setCurrentSubstep } from "@redux/slices/onboardingWizard";
 
type Props = {
  item: ISubStep;
  persistFormData: () => void;
};
 
const StepItem = ({ item, persistFormData }: Props) => {
  const dispatch = useDispatch();
 
  const { completed, isActive, label, isNextInLine, forceOnClick } = item;
  const splittedLabel = label.split("-")[1];
 
  const handleSelectStep = () => {
    if (completed || isNextInLine || forceOnClick) {
      dispatch(setCurrentSubstep(item.key as IStep));
      persistFormData();
    }
  };
 
  return (
    <Stack marginLeft="20px">
      <StyledStepItemBox
        isActive={isActive}
        isCompleted={completed}
        onClick={handleSelectStep}
      >
        <GiveText
          variant="bodyS"
          color={isActive ? "link" : completed ? "success" : "secondary"}
        >
          {splittedLabel}
        </GiveText>
        {completed && <CheckSvg />}
      </StyledStepItemBox>
    </Stack>
  );
};
 
export default StepItem;
 
const StyledStepItemBox = styled(Box, {
  shouldForwardProp: (prop) => prop !== "isActive" && prop !== "isCompleted",
})<{
  isActive?: boolean;
  isCompleted?: boolean;
}>(({ theme, isActive, isCompleted }) => {
  const completedStepBorderColor = theme.palette.primitive?.success[50];
  const activeStepBorderColor = theme.palette.primitive?.blue[50];
  const borderSecondaryColor = theme.palette.border?.secondary;
 
  const activeBgColor = theme.palette.primitive?.blue[10];
 
  return {
    gap: "4px",
    fontSize: 14,
    fontWeight: 350,
    padding: "12px 16px 12px 16px",
    display: "flex",
    alignItems: "center",
    justifyContent: "space-between",
    flexDirection: "row",
    textDecoration: "none",
    cursor: "pointer",
    backgroundColor: isActive ? activeBgColor : "transparent",
    borderLeft: `2px solid ${
      isActive
        ? activeStepBorderColor
        : isCompleted
        ? completedStepBorderColor
        : borderSecondaryColor
    }`,
  };
});