Skip to content

Forms: Add integrations status to block sidebar #43178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Forms: Added integration status to block sidebar.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { plugins } from '@wordpress/icons';
import IntegrationsModal from './jetpack-integrations-modal';
import ActiveIntegrations from './jetpack-integrations-modal/active-integrations';
import { useIntegrationsStatus } from './jetpack-integrations-modal/hooks/useIntegrationsStatus';

/**
Expand All @@ -17,7 +18,7 @@ import { useIntegrationsStatus } from './jetpack-integrations-modal/hooks/useInt
*/
export default function IntegrationControls( { attributes, setAttributes } ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
const { integrations, refreshIntegrations } = useIntegrationsStatus();
const { integrations, refreshIntegrations, isLoading } = useIntegrationsStatus();
const { tracks } = useAnalytics();

const handleOpenModal = entry_point => {
Expand All @@ -28,10 +29,15 @@ export default function IntegrationControls( { attributes, setAttributes } ) {
return (
<>
<PanelBody
title={ __( 'Manage integrations', 'jetpack-forms' ) }
title={ __( 'Integrations', 'jetpack-forms' ) }
className="jetpack-contact-form__integrations-panel"
initialOpen={ false }
>
<ActiveIntegrations
integrations={ integrations }
attributes={ attributes }
isLoading={ isLoading }
/>
<Button
variant="secondary"
onClick={ () => handleOpenModal( 'block-sidebar' ) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import colorStudio from '@automattic/color-studio';
import { JetpackIcon } from '@automattic/jetpack-components';
import { Spinner, Tooltip } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import AkismetIcon from '../../../../../icons/akismet-icon';
import './style.scss';

const COLOR_JETPACK = colorStudio.colors[ 'Jetpack Green 40' ];

export default function ActiveIntegrations( { integrations, attributes, isLoading } ) {
const activeIntegrations = integrations.reduce( ( acc, integration ) => {
switch ( integration.id ) {
case 'akismet':
if ( integration.isConnected ) {
acc.push( {
...integration,
icon: <AkismetIcon width={ 30 } height={ 30 } />,
tooltip: __( 'Akismet is connected for this form', 'jetpack-forms' ),
} );
}
break;
case 'zero-bs-crm':
if ( integration.isActive && integration.details?.hasExtension && attributes.jetpackCRM ) {
acc.push( {
...integration,
icon: <JetpackIcon size={ 30 } color={ COLOR_JETPACK } />,
tooltip: __( 'Jetpack CRM is connected for this form', 'jetpack-forms' ),
} );
}
break;
}
return acc;
}, [] );
Copy link
Contributor Author

@edanzer edanzer Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reduce method takes in the list of integrations, and returns:
(a) just those that are active/enabled for this form and
(b) includes the icon so it can be output below
(c) the tooltip text for each active integration


if ( isLoading ) {
return (
<div className="jetpack-forms-active-integrations">
<Spinner />
</div>
);
}

if ( ! activeIntegrations?.length ) {
return null;
}

return (
<div className="jetpack-forms-active-integrations">
{ activeIntegrations.map( integration => (
<Tooltip key={ integration.id } text={ integration.tooltip }>
<span className="jetpack-forms-active-integrations__item">
{ integration.icon }
<span className="jetpack-forms-active-integrations__status" />
</span>
</Tooltip>
) ) }
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.jetpack-forms-active-integrations {
margin: 8px 0 10px;

&__item {
position: relative;
margin-right: 8px;
}

&__status {
position: absolute;
bottom: 1px;
right: 1px;
width: 9px;
height: 9px;
background-color: #4AB866;
box-shadow: 0 0 0 1px #fff;
border-radius: 50%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const AkismetCard = ( { isExpanded, onToggle, data, refreshStatus } ) => {
const cardData = {
...data,
showHeaderToggle: true,
headerToggleValue: data?.isConnected,
headerToggleValue: akismetActiveWithKey,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated. It's just a small improvement I saw that didn't warrant it's own PR. We already define akismetActiveWithKey as data.isConnected further up in the component, and use it elsewhere. For consistency, we should use it here.

isHeaderToggleEnabled: false,
isLoading: ! data || typeof data.isInstalled === 'undefined',
refreshStatus,
Expand Down
Loading