// #region [Imports] =================================================================================================== // Libraries import { useState, useEffect } from 'react'; // Components import PluginInstallerButton from '../../components/PluginInstallerButton'; // #endregion [Imports] // #region [Variables] ================================================================================================= declare var acfwAdminApp: any; // #endregion [Variables] // #region [Interfaces]================================================================================================= interface IProduct { key: string; name: string; slug: string; description: string; logo: string; badges: string[]; is_active: boolean; } interface IProps { className?: string; } // #endregion [Interfaces] // #region [Component] ================================================================================================= const CrossPromo = (props: IProps) => { const { className } = props; const [currentProduct, setCurrentProduct] = useState(null); const [isVisible, setIsVisible] = useState(true); // Get products from backend const crossPromoProducts = acfwAdminApp?.dashboard_page?.cross_promo_products; // Select a random product on component mount useEffect(() => { if (crossPromoProducts && crossPromoProducts.length > 0) { // Filter only inactive products const inactiveProducts = crossPromoProducts.filter((product: IProduct) => !product.is_active); if (inactiveProducts.length > 0) { const randomIndex = Math.floor(Math.random() * inactiveProducts.length); setCurrentProduct(inactiveProducts[randomIndex]); } } }, []); // Don't show if no products available or not visible if (!isVisible || !currentProduct) return null; return (
{/* Badge and Title Section - Inline */}
{currentProduct.badges.map((badgeType) => ( {acfwAdminApp?.dashboard_page?.labels?.[badgeType === 'free' ? 'free_plugin' : badgeType] || badgeType} ))}
{/* Title Section */}
{currentProduct.name} { const target = e.target as HTMLImageElement; target.style.display = 'none'; }} />

{currentProduct.name}

{/* Description Section */}

{currentProduct.description}

{/* Button Section */} {acfwAdminApp?.dashboard_page?.labels?.install_and_activate} } nonce={acfwAdminApp?.nonces?.install_plugin} successMessage={`${currentProduct.name} ${acfwAdminApp?.dashboard_page?.labels?.installed_successfully}`} className="install-button" />
); }; export default CrossPromo; // #endregion [Component]