Modal offer

The modal offer is a UI component representing Evy offers along with the list of coverage options.

This component can be triggered on-demand.

Display of the component

The modal component may also be used as a sidebar.

Usage

Props

ParameterTypeDescription
productIdstringThe product ID, as uploaded to the Evy API
pricenumberThe quantity of product
openbooleanTrue when it should open
placementstring = left, right, centerThe type of modal layout. The default value is center.
onClose() => voidCallback called when the modal is closed

Example

import { ModalOffer, useEvyContext } from "@getevy/react-sdk";
import { useCallback, useState } from "react";

export const AddToCart = ({ addProductToCart, productId, price }) => {
  const { stately } = useEvyContext();
  const [open, setOpen] = useState(false);

  const handleButtonClick = useCallback(() => {
    const selectedOffer = stately?.getSelectedOffer(productId);

    if (stately && selectedOffer) {
      stately.attachSelectedOffer(productId, 1);
      addProductToCart();
    } else {
      setOpen(true);
    }
  }, [stately]);

  const onCloseHandler = useCallback(() => {
    setOpen(false);
  }, []);

  return (
    <>
      <button onClick={handleButtonClick}>Add to cart</button>
      <ModalOffer
        productId="saw"
        price={5000}
        open={open}
        onClose={onCloseHandler}
      />
    </>
  );
};