import React, {useState} from 'react'; import styles from './style.module.scss'; import {__} from '@wordpress/i18n'; import {RecommendedProductData, useRecommendations} from '@givewp/promotions/hooks/useRecommendations'; interface ProductRecommendationsProps { apiSettings: {table; pluginUrl}; options: any; } /** * @since 2.27.1 */ export default function ProductRecommendations({apiSettings, options}: ProductRecommendationsProps) { const {getRandomRecommendation, getRecommendation, removeRecommendation} = useRecommendations(apiSettings, options); const selectedOption = apiSettings === window.GiveDonors ? getRecommendation() : getRandomRecommendation(); const [showRecommendation, setShowRecommendation] = useState(!!selectedOption); const closeMessage = async (async) => { setShowRecommendation(false); await removeRecommendation({ option: selectedOption.enum, }); }; if (!showRecommendation) { return null; } return ( ); } interface RotatingMessageProps { selectedOption: RecommendedProductData; closeMessage: (async: any) => Promise; pluginUrl: string; columns: Array<{visible: boolean}>; } /** * @since 4.10.0 Refactor html structure to use a single p tag with a span and a link. * @since 2.27.1 */ function RotatingMessage({selectedOption, closeMessage, pluginUrl, columns}: RotatingMessageProps) { const {message = '', documentationPage = '', innerHtml = ''} = selectedOption; const visibleColumns = columns?.filter((column) => column.visible || column.visible === undefined); return (

{__('PRO TIP: ', 'give')} {message} {innerHtml}

); }