All files / src/features/MerchantPortal/ManageMoney/modals/SendMoneyModal ProcessorBalanceItem.tsx

65% Statements 13/20
41.17% Branches 7/17
50% Functions 2/4
76.47% Lines 13/17

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                                      15x 15x 15x 15x 15x   15x   15x 15x 15x 15x 15x     15x                                                                                                 1x                                            
import { Box, Stack } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import { useAppTheme } from "@theme/v2/Provider";
import { ProcessorBalanceType } from "./types";
import { CheckIcon } from "@phosphor-icons/react";
import { useFormContext } from "react-hook-form";
import { number } from "prop-types";
 
export default function ProcessorBalanaceItem({
  icon,
  label,
  value,
  name,
  enableWorldpay,
}: ProcessorBalanceType) {
  const {
    watch,
    setValue,
    formState: { errors },
  } = useFormContext();
  const { palette } = useAppTheme();
  const processor = watch("processor");
  const isSelected = processor === name;
  const isError = !!errors?.processor;
 
  const isDisabled = Number(value) <= 0;
 
  const border = (() => {
    Iif (isDisabled) return `1px solid ${palette.border?.primary}`;
    Iif (isError) return `1.5px solid ${palette.primitive?.error[50]}`;
    Iif (isSelected) return `1.5px solid ${palette.border?.active}`;
    return `1px solid ${palette.border?.secondary}`;
  })();
 
  return (
    <Stack
      position="relative"
      direction="row"
      alignItems="center"
      gap="12px"
      padding="16px"
      borderRadius="12px"
      width="100%"
      border={border}
      sx={{
        cursor: isDisabled ? "auto" : "pointer",
      }}
      onClick={() => {
        if (!isDisabled) {
          setValue("processor", name, { shouldValidate: true });
        }
      }}
    >
      <Box
        padding="8px"
        borderRadius="8px"
        width="40px"
        height="40px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        border={`1px solid ${palette.border?.primary}`}
        sx={{
          opacity: isDisabled ? 0.5 : 1,
        }}
      >
        {icon}
      </Box>
      <Stack
        direction="column"
        gap="4px"
        sx={{ opacity: isDisabled ? 0.5 : 1 }}
      >
        <GiveText variant="bodyS">{value}</GiveText>
        <GiveText variant="bodyS" color="secondary">
          {label}
        </GiveText>
      </Stack>
      {isSelected && !isDisabled && <SelectionCheck />}
    </Stack>
  );
}
 
const SelectionCheck = () => {
  const { palette } = useAppTheme();
 
  return (
    <Stack
      sx={{
        zIndex: 1,
        position: "absolute",
        right: "10px",
        top: "10px",
        background: palette.text.primary,
        width: "20px",
        height: "20px",
        borderRadius: "50%",
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      <CheckIcon color={palette.primitive?.neutral[0]} size={16} />
    </Stack>
  );
};