All files / src/features/MerchantPortal/Customer/Modals CustomerPanelContent.tsx

81.81% Statements 9/11
100% Branches 0/0
33.33% Functions 1/3
81.81% Lines 9/11

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                                          53x                 23x 23x 23x       23x       23x             23x                             23x         23x                                  
import SidePanelHeaderVariant from "@shared/SidePanel/components/SidePanelHeader/SidePanelHeaderVariant";
import { SidePanelContainerWrapper } from "@shared/SidePanel/SidePanelAtoms";
import CustomerPanelBody from "./components/CustomerPanelBody";
import { checkPortals } from "@utils/routing";
import { useGetCustomerById } from "@services/api/customer";
import { GiveWithMissingPermissionModule } from "@common/GiveWithMissingPermissionModule";
import {
  composePermission,
  useAccessControl,
} from "@features/Permissions/AccessControl";
import RESOURCE_BASE, { OPERATIONS } from "@constants/permissions";
 
type Props = {
  isFirst?: boolean;
  isLast?: boolean;
  setSelectedRow?: (row: string) => void;
  onClose: () => void;
  data: any;
  merchantID?: number;
};
 
const CustomerPanelContent = ({
  isFirst,
  isLast,
  setSelectedRow,
  onClose,
  data,
  merchantID,
}: Props) => {
  const { isManageMoney, isAnyPaymentForm, isProcessing, isDisputes } =
    checkPortals();
  const { isDataLoading } = useGetCustomerById(data?.id);
  const handleNext = () => {
    setSelectedRow?.("next");
  };
 
  const handlePrevious = () => {
    setSelectedRow?.("prev");
  };
 
  const hiddenStepper = [
    isManageMoney,
    isAnyPaymentForm,
    isProcessing,
    isDisputes,
  ].some(Boolean);
 
  const headerProps = {
    actions: [],
    nextPrevState: {
      isFirst: Boolean(isFirst),
      isLast: Boolean(isLast),
      isPanelLoading: isDataLoading,
    },
    handlers: {
      handleClose: onClose,
      handlePrevious,
      handleNext,
    } as any,
    isHiddenNextPrev: hiddenStepper,
  };
 
  const isAllowedRead = useAccessControl({
    resource: composePermission(RESOURCE_BASE.MERCHANT, RESOURCE_BASE.CUSTOMER),
    operation: OPERATIONS.READ,
  });
 
  return (
    <SidePanelContainerWrapper>
      <GiveWithMissingPermissionModule
        sectionName="Customer section"
        notAuthorized={!isAllowedRead}
      >
        <SidePanelHeaderVariant
          variant="transaction"
          HeaderProps={headerProps}
        />
        <CustomerPanelBody id={data.id} merchantID={merchantID} />
      </GiveWithMissingPermissionModule>
    </SidePanelContainerWrapper>
  );
};
 
export default CustomerPanelContent;