import colorStudio from '@automattic/color-studio'; import { JetpackIcon } from '@automattic/jetpack-components'; import { Button } from '@wordpress/components'; import { createInterpolateElement } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import semver from 'semver'; import IntegrationCard from '../../blocks/contact-form/components/jetpack-integrations-modal/integration-card'; import type { IntegrationCardProps } from './types'; const COLOR_JETPACK = colorStudio.colors[ 'Jetpack Green 40' ]; const JetpackCRMDashboardCard = ( { isExpanded, onToggle, data, refreshStatus, }: IntegrationCardProps ) => { const { settingsUrl = '', version = '', details = {} } = data || {}; const { hasExtension = false, canActivateExtension = false } = details; const crmVersion = semver.coerce( version ); const isRecentVersion = crmVersion && semver.gte( crmVersion, '4.9.1' ); const cardData = { ...data, showHeaderToggle: false, // Always off for dashboard isLoading: ! data || typeof data.isInstalled === 'undefined', refreshStatus, trackEventName: 'jetpack_forms_upsell_crm_click', notInstalledMessage: __( 'You can save your form contacts in Jetpack CRM. To get started, please install the plugin.', 'jetpack-forms' ), notActivatedMessage: __( 'Jetpack CRM is installed. To start saving contacts, simply activate the plugin.', 'jetpack-forms' ), }; const renderContent = () => { // Jetpack CRM installed and active, but not recent version if ( ! isRecentVersion ) { return (

{ __( 'Please update to the latest version of the Jetpack CRM plugin to integrate your contact form with your CRM.', 'jetpack-forms' ) }

); } // Jetpack CRM installed, active, and recent, but no extension if ( ! hasExtension ) { return (

{ createInterpolateElement( __( "You can integrate Jetpack CRM by enabling Jetpack CRM's Jetpack Forms extension.", 'jetpack-forms' ), { a: ( ) }

); } // All conditions met, show Jetpack CRM connected message return (

{ __( 'Jetpack CRM is connected.', 'jetpack-forms' ) }

); }; return ( } isExpanded={ isExpanded } onToggle={ onToggle } cardData={ cardData } > { renderContent() } ); }; export default JetpackCRMDashboardCard;