All files / src/components/TicketSales EventsBanner.tsx

0% Statements 0/19
0% Branches 0/10
0% Functions 0/4
0% Lines 0/19

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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158                                                                                                                                                                                                                                                                                                                           
import NiceModal from "@ebay/nice-modal-react";
// components
import {
  EDIT_EVENT_MODAL,
  MERCHANT_PORTAL_SHARE_MODAL,
  DELETE_CONFIRMATION_MODAL,
} from "modals/modal_names";
import { useNavigate } from "react-router";
import { StatProps } from "@common/NewStats/Stat";
import { DonationType } from "@customTypes/products/fundraiser.types";
import { usePublicFormUrl } from "@components/DonationList/DonationsBanner";
import NewProductListingBanner from "@components/Product/NewProductListingBanner/NewProductListingBanner";
import { MenuItem } from "@common/Menu/NewDropdownMenu";
import { palette } from "@palette";
import { roundToNearestTenth } from "@utils/index";
import { checkEnd } from "@utils/date.helpers";
import { memo } from "react";
import { useProductPermission } from "features/Permissions/AccessControl/hooks";
import { DELETE_DENY_MESSAGE, EDIT_DENY_MESSAGE } from "@constants/permissions";
import { buildMerchantEndpoints } from "@services/api/utils.api";
import { useGetRebrandedFormTypes } from "@sections/PayBuilder/utils";
import PublicURLShareModal from "@sections/PayBuilder/LaunchStep/PublicURLShare/PublicURLShareModal";
import { useExpandedActions } from "@sections/PayBuilder/hooks/useExpandedActions";
 
type EventsBannerProps = {
  data: DonationType;
  numSoldSum?: number;
};
 
const EventsBanner = ({ data, numSoldSum }: EventsBannerProps) => {
  const { id, textToCopy } = usePublicFormUrl();
  const navigate = useNavigate();
  const rebrandedFormTypes = useGetRebrandedFormTypes();
  const { editPaymentForm } = useExpandedActions(data, EDIT_EVENT_MODAL);
 
  const url = buildMerchantEndpoints(`products/${id}`);
  const handleDelete = () => {
    NiceModal.show(DELETE_CONFIRMATION_MODAL, {
      variant: "product",
      itemName: data?.name,
      productVariant: data?.typeName,
      url: url,
    });
  };
 
  // const handleOpenRevenues = () => {
  //   NiceModal.show(REVENUES_PRODUCT_MODAL, {
  //     type: "Event",
  //     VisitorsViews: true,
  //     Visitors: true,
  //   });
  // };
 
  const endOfEvent =
    checkEnd(data.startsAt, data.endsAt, data.includeTime) < Date.now();
 
  const { isEditProductAllowed, isDeleteProductAllowed } =
    useProductPermission();
 
  const isDisabledEdit = !isEditProductAllowed || endOfEvent;
 
  const menuItems: MenuItem[] = [
    {
      label: "Edit",
      disabled: isDisabledEdit,
      onSelect: editPaymentForm,
      tooltipProps: {
        show: !isEditProductAllowed,
        message: EDIT_DENY_MESSAGE,
      },
    },
    {
      label: "Open",
      onSelect: () => navigate(textToCopy, { state: { preview: true } }),
    },
    {
      label: "Share",
      onSelect: () => {
        if (rebrandedFormTypes.includes(data?.typeName)) {
          return NiceModal.show(PublicURLShareModal, {
            idFromProps: id,
            typeFromProps: "event",
          });
        }
        NiceModal.show(MERCHANT_PORTAL_SHARE_MODAL, {
          type: "event",
          title: "Share Event",
          productId: id,
        });
      },
    },
    // {
    //   label: "Revenue Sources",
    //   onSelect: handleOpenRevenues,
    // },
    // {
    //   label: "Developer API",
    //   onSelect: handleOpenDeveloperAPI,
    // },
    {
      label: "Delete",
      onSelect: handleDelete,
      labelProps: {
        color: palette.error.hover,
      },
      disabled: !isDeleteProductAllowed,
      tooltipProps: {
        show: !isDeleteProductAllowed,
        message: DELETE_DENY_MESSAGE,
      },
    },
  ];
 
  const parseStats: StatProps[] = [
    {
      isAmount: true,
      title: "Total Amount",
      value: data?.sumApprovedPurchases / 100,
      isTotal: true,
    },
    {
      isAmount: true,
      title: "Average",
      value: data?.averageApprovedPurchases / 100,
    },
    { title: "Purchases", value: data?.totalApprovedPurchases || 0 },
    {
      title: "Tickets Sold",
      value: numSoldSum || 0,
    },
 
    { title: "Visitors", value: data?.visitors },
    {
      title: "Conversion",
      value: roundToNearestTenth(data?.conversionRate ?? 0),
      percent: true,
    },
  ];
 
  const previewLink = ["events", id].join("/");
 
  return (
    <NewProductListingBanner
      handleEdit={editPaymentForm}
      previewLink={previewLink}
      type="Event"
      stats={parseStats}
      textToCopy={textToCopy}
      data={data}
      menuItems={menuItems}
      parseStats={parseStats}
      endOfEvent={endOfEvent}
    />
  );
};
 
export default memo(EventsBanner);