Skip to content

Commit efeb172

Browse files
authored
Revert "Forms: Integrations to CTA + Modal (#45662)"
This reverts commit b2d9287.
1 parent 3ffff1e commit efeb172

File tree

19 files changed

+985
-132
lines changed

19 files changed

+985
-132
lines changed

projects/packages/forms/changelog/update-integrations-button-modal

Lines changed: 0 additions & 4 deletions
This file was deleted.

projects/packages/forms/src/blocks/contact-form/components/jetpack-integrations-modal/index.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ import { __ } from '@wordpress/i18n';
88
*/
99
import IntegrationsList from './integrations-list';
1010
import './style.scss';
11-
/**
12-
* Types
13-
*/
14-
import type { Integration } from '../../../../types';
15-
16-
type BlockAttributes = Record< string, unknown >;
17-
18-
type IntegrationsModalProps = {
19-
isOpen: boolean;
20-
onClose: () => void;
21-
attributes?: BlockAttributes;
22-
setAttributes?: ( attributes: BlockAttributes ) => void;
23-
integrationsData: Integration[];
24-
refreshIntegrations: () => Promise< void >;
25-
context?: 'block-editor' | 'dashboard';
26-
};
2711

2812
const IntegrationsModal = ( {
2913
isOpen,
@@ -32,8 +16,7 @@ const IntegrationsModal = ( {
3216
setAttributes,
3317
integrationsData,
3418
refreshIntegrations,
35-
context = 'block-editor',
36-
}: IntegrationsModalProps ) => {
19+
} ) => {
3720
if ( ! isOpen ) {
3821
return null;
3922
}
@@ -49,7 +32,7 @@ const IntegrationsModal = ( {
4932
<IntegrationsList
5033
integrations={ integrationsData }
5134
refreshIntegrations={ refreshIntegrations }
52-
context={ context }
35+
context="block-editor"
5336
attributes={ attributes }
5437
setAttributes={ setAttributes }
5538
/>

projects/packages/forms/src/blocks/contact-form/components/jetpack-integrations-modal/integrations-list.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ interface ExpandedCardsState {
1717
const IntegrationsList = ( {
1818
integrations = [],
1919
refreshIntegrations,
20-
context,
2120
handlers,
2221
attributes,
2322
setAttributes,
2423
}: IntegrationsListProps ) => {
2524
const items = useIntegrationCardsData( {
2625
integrations,
2726
refreshIntegrations,
28-
context,
27+
context: 'block-editor',
2928
handlers,
3029
attributes,
3130
setAttributes,
@@ -42,21 +41,18 @@ const IntegrationsList = ( {
4241
const [ expandedCards, setExpandedCards ] =
4342
useState< ExpandedCardsState >( initialCardsExpandedState );
4443

45-
const toggleCard = useCallback(
46-
( id: string ) => {
47-
setExpandedCards( prev => {
48-
const isExpanding = ! prev[ id ];
49-
if ( isExpanding ) {
50-
jetpackAnalytics.tracks.recordEvent( 'jetpack_forms_integrations_card_expand', {
51-
card: id,
52-
origin: context,
53-
} );
54-
}
55-
return { ...prev, [ id ]: isExpanding };
56-
} );
57-
},
58-
[ context ]
59-
);
44+
const toggleCard = useCallback( ( id: string ) => {
45+
setExpandedCards( prev => {
46+
const isExpanding = ! prev[ id ];
47+
if ( isExpanding ) {
48+
jetpackAnalytics.tracks.recordEvent( 'jetpack_forms_integrations_card_expand', {
49+
card: id,
50+
origin: 'block-editor',
51+
} );
52+
}
53+
return { ...prev, [ id ]: isExpanding };
54+
} );
55+
}, [] );
6056

6157
return (
6258
<>

projects/packages/forms/src/dashboard/components/create-form-button/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import useCreateForm from '../../hooks/use-create-form';
1414
type CreateFormButtonProps = {
1515
label?: string;
1616
showPatterns?: boolean;
17-
variant?: 'primary' | 'secondary';
1817
};
1918

2019
/**
@@ -23,13 +22,11 @@ type CreateFormButtonProps = {
2322
* @param {object} props - The component props.
2423
* @param {string} props.label - The label for the button.
2524
* @param {boolean} props.showPatterns - Whether to show the patterns on the editor immediately.
26-
* @param {string} props.variant - The button variant (primary or secondary).
2725
* @return {JSX.Element} The button to create a new form.
2826
*/
2927
export default function CreateFormButton( {
3028
label = __( 'Create a free form', 'jetpack-forms' ),
3129
showPatterns = false,
32-
variant = 'secondary',
3330
}: CreateFormButtonProps ): JSX.Element {
3431
const { openNewForm } = useCreateForm();
3532

@@ -49,7 +46,7 @@ export default function CreateFormButton( {
4946
return (
5047
<Button
5148
__next40pxDefaultSize
52-
variant={ variant }
49+
variant="primary"
5350
onClick={ onButtonClickHandler }
5451
icon={ plus }
5552
className="create-form-button"

projects/packages/forms/src/dashboard/components/integrations-button/index.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

projects/packages/forms/src/dashboard/components/layout/index.tsx

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
import jetpackAnalytics from '@automattic/jetpack-analytics';
55
import { useBreakpointMatch, JetpackLogo } from '@automattic/jetpack-components';
66
import { NavigableRegion, Page } from '@wordpress/admin-ui';
7+
import { TabPanel } from '@wordpress/components';
78
import { useSelect } from '@wordpress/data';
8-
import { useEffect } from '@wordpress/element';
9+
import { useCallback, useEffect, useMemo } from '@wordpress/element';
910
import { __ } from '@wordpress/i18n';
10-
import { Outlet, useLocation } from 'react-router';
11+
import { Outlet, useLocation, useNavigate } from 'react-router';
1112
/**
1213
* Internal dependencies
1314
*/
1415
import useConfigValue from '../../../hooks/use-config-value';
1516
import EmptySpamButton from '../../components/empty-spam-button';
1617
import EmptyTrashButton from '../../components/empty-trash-button';
1718
import ExportResponsesButton from '../../inbox/export-responses';
18-
import Integrations from '../../integrations';
1919
import { store as dashboardStore } from '../../store';
2020
import ActionsDropdownMenu from '../actions-dropdown-menu';
2121
import CreateFormButton from '../create-form-button';
22-
import IntegrationsButton from '../integrations-button';
2322

2423
import './style.scss';
2524
// eslint-disable-next-line import/no-unresolved -- aliased to the package's built asset in webpack config.
2625
import '@wordpress/admin-ui/build-style/style.css';
2726
const Layout = () => {
2827
const location = useLocation();
28+
const navigate = useNavigate();
2929
const [ isSm ] = useBreakpointMatch( 'sm' );
3030

3131
const enableIntegrationsTab = useConfigValue( 'isIntegrationsEnabled' );
@@ -40,32 +40,78 @@ const Layout = () => {
4040

4141
const isResponsesTrashView = currentStatus.includes( 'trash' );
4242
const isResponsesSpamView = currentStatus.includes( 'spam' );
43-
const isIntegrationsOpen = location.pathname === '/integrations';
4443

4544
useEffect( () => {
4645
jetpackAnalytics.tracks.recordEvent( 'jetpack_forms_dashboard_page_view', {
4746
viewport: isSm ? 'mobile' : 'desktop',
4847
} );
4948
}, [ isSm ] );
5049

50+
const tabs = useMemo(
51+
() => [
52+
{
53+
name: 'responses',
54+
title: __( 'Responses', 'jetpack-forms' ),
55+
},
56+
...( enableIntegrationsTab
57+
? [ { name: 'integrations', title: __( 'Integrations', 'jetpack-forms' ) } ]
58+
: [] ),
59+
],
60+
[ enableIntegrationsTab ]
61+
);
62+
63+
const getCurrentTab = useCallback( () => {
64+
const path = location.pathname.split( '/' )[ 1 ];
65+
const validTabNames = tabs.map( tab => tab.name );
66+
67+
if ( validTabNames.includes( path ) ) {
68+
return path;
69+
}
70+
71+
return 'responses';
72+
}, [ location.pathname, tabs ] );
73+
74+
const isResponsesTab = getCurrentTab() === 'responses';
75+
76+
const handleTabSelect = useCallback(
77+
( tabName: string ) => {
78+
if ( ! tabName ) {
79+
tabName = 'responses';
80+
}
81+
82+
const currentTab = getCurrentTab();
83+
84+
if ( currentTab !== tabName ) {
85+
jetpackAnalytics.tracks.recordEvent( 'jetpack_forms_dashboard_tab_change', {
86+
tab: tabName,
87+
viewport: isSm ? 'mobile' : 'desktop',
88+
previous_tab: currentTab,
89+
} );
90+
}
91+
92+
navigate( {
93+
pathname: `/${ tabName }`,
94+
search: tabName === 'responses' ? location.search : '',
95+
} );
96+
},
97+
[ navigate, location.search, isSm, getCurrentTab ]
98+
);
99+
51100
const headerActions = isSm ? (
52101
<>
53-
{ isResponsesTrashView && <EmptyTrashButton /> }
54-
{ isResponsesSpamView && <EmptySpamButton /> }
55-
<ActionsDropdownMenu exportData={ { show: true } } />
102+
{ isResponsesTab && isResponsesTrashView && <EmptyTrashButton /> }
103+
{ isResponsesTab && isResponsesSpamView && <EmptySpamButton /> }
104+
<ActionsDropdownMenu exportData={ { show: isResponsesTab } } />
56105
</>
57106
) : (
58-
<>
59-
{ isResponsesTrashView && <EmptyTrashButton /> }
60-
{ isResponsesSpamView && <EmptySpamButton /> }
107+
<div className="jp-forms__layout-header-actions">
108+
{ isResponsesTab && <ExportResponsesButton /> }
109+
{ isResponsesTab && isResponsesTrashView && <EmptyTrashButton /> }
110+
{ isResponsesTab && isResponsesSpamView && <EmptySpamButton /> }
61111
{ ! isResponsesTrashView && ! isResponsesSpamView && (
62-
<>
63-
{ enableIntegrationsTab && <IntegrationsButton /> }
64-
<CreateFormButton label={ __( 'Create form', 'jetpack-forms' ) } />
65-
</>
112+
<CreateFormButton label={ __( 'Create form', 'jetpack-forms' ) } />
66113
) }
67-
<ExportResponsesButton />
68-
</>
114+
</div>
69115
);
70116

71117
return (
@@ -82,9 +128,18 @@ const Layout = () => {
82128
className="admin-ui-page__content"
83129
ariaLabel={ __( 'Forms dashboard content', 'jetpack-forms' ) }
84130
>
85-
{ ! isLoadingConfig && <Outlet /> }
131+
{ ! isLoadingConfig && (
132+
<TabPanel
133+
className="jp-forms__dashboard-tabs"
134+
tabs={ tabs }
135+
initialTabName={ getCurrentTab() }
136+
onSelect={ handleTabSelect }
137+
key={ getCurrentTab() }
138+
>
139+
{ () => <Outlet /> }
140+
</TabPanel>
141+
) }
86142
</NavigableRegion>
87-
{ isIntegrationsOpen && <Integrations /> }
88143
</Page>
89144
);
90145
};

0 commit comments

Comments
 (0)