All files / src/pages/Checkout InvoiceCheckoutPage.tsx

10% Statements 1/10
0% Branches 0/10
0% Functions 0/1
10% Lines 1/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                      12x                                                                              
import InvoiceCommonMetadata from "@sections/PayBuilder/components/InvoicePreview/InvoiceCommonMetadata";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
import { Content } from "./CheckoutContent";
import { useCart } from "@sections/PayBuilder/provider/CartContext";
import { getCustomerLabel } from "@sections/PayBuilder/utils";
import { useCreateInvoiceCart } from "@sections/PayBuilder/Checkout/hooks/useCreateInvoiceCart";
import { DEFAULT_INVOICE_REFERENCE } from "@sections/PayBuilder/consts";
import { Box } from "@mui/material";
import { checkoutScrollbarStyles } from "@sections/PayBuilder/Checkout/helpers";
import { useIsPreviewMode } from "@sections/PayBuilder/provider/useIsPreviewMode";
 
const InvoiceCheckoutPage = ({ from }: { from?: string }) => {
  const { data, customer: customerFromForm, methods } = usePayBuilderForm();
  const { isPreviewMode } = useIsPreviewMode();
  const { merchantName, reference, customer: customerFromAPI } = data;
  const { totalAmount } = useCart();
 
  const customer = customerFromForm || customerFromAPI;
  const isPaidInvoice = data?.statusDisplayName
    ? data?.statusDisplayName === "Paid"
    : true;
  const values = methods.getValues();
  useCreateInvoiceCart(isPaidInvoice);
 
  return (
    <Box
      sx={{
        overflow: "scroll",
        ...checkoutScrollbarStyles,
        ...(!isPreviewMode && { scrollbarWidth: "none" }),
      }}
    >
      <Content
        showBreadCrumbs={false}
        overRideCustomThemeBG
        previewHeader={
          <InvoiceCommonMetadata
            from={from || merchantName}
            dueDate={values.About.endsAt}
            amount={totalAmount as string}
            to={getCustomerLabel(customer)}
            invoiceKVNumber={reference || DEFAULT_INVOICE_REFERENCE}
          />
        }
      />
    </Box>
  );
};
 
export default InvoiceCheckoutPage;