All files / src/sections/PayBuilder/components GiveTabsHeader.tsx

90% Statements 9/10
58.33% Branches 7/12
50% Functions 1/2
90% Lines 9/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 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137          12x                     12x                                         12x                         531x     531x 531x 531x 531x   531x                                                                                                                                                            
import { Stack } from "@mui/material";
import GiveTabs from "@shared/Tabs/GiveTabs";
import { ReactNode, useState } from "react";
import { useAppTheme } from "@theme/v2/Provider";
 
const previewTabs = [
  {
    label: "Payment Form",
    value: "Payment Form",
  },
  {
    label: "Email",
    value: "email",
  },
];
 
const previewTabsInvoice = [
  {
    label: "Email",
    value: "email",
  },
  {
    label: "PDF",
    value: "pdf",
  },
  {
    label: "Payment Page",
    value: "Payment Form",
  },
];
 
enum PreviewTabs {
  PAYMENT_FORM = "Payment Form",
  EMAIL = "email",
  PDF = "pdf",
}
 
export const GiveTabHeader = ({
  emailComponent,
  paymentFormComponent,
  pdfComponent,
  isInvoice,
  isMobileView,
}: {
  emailComponent: ReactNode;
  paymentFormComponent: ReactNode;
  pdfComponent?: ReactNode;
  isInvoice?: boolean;
  isMobileView?: boolean;
}) => {
  const [selectedTab, setSelectedTab] = useState(
    isInvoice ? PreviewTabs.EMAIL : PreviewTabs.PAYMENT_FORM,
  );
  const { palette } = useAppTheme();
  const isPaymentFormPageTab = selectedTab === PreviewTabs.PAYMENT_FORM;
  const isEmailTab = selectedTab === PreviewTabs.EMAIL;
  const isPDFTab = selectedTab === PreviewTabs.PDF;
 
  return (
    <Stack
      spacing={2}
      sx={{
        display: "flex",
        flexDirection: "column",
        width: "100%",
        height: "100%",
        overflow: "hidden",
      }}
    >
      <Stack
        direction="row"
        width="100%"
        sx={{
          ...(isMobileView && {
            paddingTop: `${20 - 4}px`,
            paddingBottom: `${20 - 16}px`,
            paddingLeft: "16px",
          }),
        }}
      >
        <GiveTabs
          selected={selectedTab}
          items={isInvoice ? previewTabsInvoice : previewTabs}
          onClick={(value) => {
            setSelectedTab(value as PreviewTabs);
          }}
          containerSx={
            {
              // width: "179px",
            }
          }
          tabSx={{
            fontSize: "14px",
          }}
          type="pill"
          selectedTabSx={{
            "& p": {
              color: palette.primitive?.blue?.[100],
              zIndex: 2,
            },
            /* Tab - Pill */
 
            /* Auto layout */
            display: "flex",
            flexDirection: "row",
            justifyContent: "flex-end",
            alignItems: "center",
            padding: "8px 16px",
            gap: "8px",
 
            /* Ocean Blue Highlight */
            background: "linear-gradient(223.56deg, #E8F9FC 0%, #E9E8F7 100%)",
            borderRadius: "40px",
 
            /* Inside auto layout */
            flex: "none",
            order: 0,
            flexGrow: 0,
 
            // borderBottom: `2px solid ${palette.primitive?.blue?.[100]}`,
          }}
        />
      </Stack>
      <Stack
        sx={{
          flexGrow: 1,
          overflowY: "hidden",
        }}
      >
        {isEmailTab && emailComponent}
        {isPaymentFormPageTab && paymentFormComponent}
        {isPDFTab && pdfComponent}
      </Stack>
    </Stack>
  );
};