Skip to content

Commit a92d969

Browse files
authored
Forms: Hide Google export card if disabled (#45375)
1 parent e984275 commit a92d969

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Forms: hide Google export card if disabled.

projects/packages/forms/src/dashboard/components/export-responses-modal/index.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
* External dependencies
33
*/
44
import { Modal, __experimentalVStack as VStack } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
5+
import { useSelect } from '@wordpress/data';
56
import { __ } from '@wordpress/i18n';
67
/**
78
* Internal dependencies
89
*/
10+
import { INTEGRATIONS_STORE } from '../../../store/integrations';
911
import CSVExport from '../../inbox/export-responses/csv';
1012
import GoogleDriveExport from '../../inbox/export-responses/google-drive';
13+
import type { SelectIntegrations } from '../../../store/integrations';
14+
import type { Integration } from '../../../types';
1115

1216
type ExportResponsesModalProps = {
1317
onRequestClose: () => void;
@@ -20,6 +24,16 @@ const ExportResponsesModal = ( {
2024
onExport,
2125
autoConnectGdrive,
2226
}: ExportResponsesModalProps ) => {
27+
const { integrations } = useSelect( ( select: SelectIntegrations ) => {
28+
const store = select( INTEGRATIONS_STORE );
29+
return {
30+
integrations: store.getIntegrations() || [],
31+
};
32+
}, [] ) as { integrations: Integration[] };
33+
34+
const isGoogleDriveEnabled = integrations.some(
35+
integration => integration.id === 'google-drive'
36+
);
2337
return (
2438
<Modal
2539
title={ __( 'Export responses', 'jetpack-forms' ) }
@@ -28,7 +42,9 @@ const ExportResponsesModal = ( {
2842
>
2943
<VStack spacing={ 8 }>
3044
<CSVExport onExport={ onExport } />
31-
<GoogleDriveExport onExport={ onExport } autoConnect={ autoConnectGdrive } />
45+
{ isGoogleDriveEnabled && (
46+
<GoogleDriveExport onExport={ onExport } autoConnect={ autoConnectGdrive } />
47+
) }
3248
</VStack>
3349
</Modal>
3450
);

projects/packages/forms/src/dashboard/inbox/export-responses/google-drive.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,30 @@ import { isSimpleSite } from '@automattic/jetpack-script-data';
66
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils';
77
import requestExternalAccess from '@automattic/request-external-access';
88
import { Button, Path, Spinner, SVG } from '@wordpress/components';
9+
import { useSelect, useDispatch } from '@wordpress/data';
910
import { useCallback, useRef, useState } from '@wordpress/element';
1011
import { __, _x } from '@wordpress/i18n';
1112
import clsx from 'clsx';
1213
/**
1314
* Internal dependencies
1415
*/
1516
import { config } from '../..';
16-
import { useIntegrationStatus } from '../../../blocks/contact-form/components/jetpack-integrations-modal/hooks/use-integration-status';
17+
import { INTEGRATIONS_STORE } from '../../../store/integrations';
1718
import { PARTIAL_RESPONSES_PATH } from '../../../util/get-preferred-responses-view';
19+
/**
20+
* Internal dependencies
21+
*/
22+
import type { SelectIntegrations, IntegrationsDispatch } from '../../../store/integrations';
23+
import type { Integration } from '../../../types';
1824

1925
const GoogleDriveExport = ( { onExport, autoConnect = false } ) => {
2026
const [ isExporting, setIsExporting ] = useState( false );
21-
const { integration, refreshStatus } = useIntegrationStatus( 'google-drive' );
27+
const { integration } = useSelect( ( select: SelectIntegrations ) => {
28+
const store = select( INTEGRATIONS_STORE );
29+
const list = store.getIntegrations() || [];
30+
return { integration: list.find( ( i: Integration ) => i.id === 'google-drive' ) };
31+
}, [] ) as { integration?: Integration };
32+
const { refreshIntegrations } = useDispatch( INTEGRATIONS_STORE ) as IntegrationsDispatch;
2233
const isConnectedToGoogleDrive = !! integration?.isConnected;
2334
const { tracks } = useAnalytics();
2435
const autoConnectOpened = useRef( false );
@@ -58,12 +69,12 @@ const GoogleDriveExport = ( { onExport, autoConnect = false } ) => {
5869
setIsTogglingConnection( true );
5970
requestExternalAccess( integration?.settingsUrl, ( { keyring_id: keyringId } ) => {
6071
if ( keyringId ) {
61-
refreshStatus();
72+
refreshIntegrations();
6273
} else {
6374
setIsTogglingConnection( false );
6475
}
6576
} );
66-
}, [ tracks, integration?.settingsUrl, refreshStatus ] );
77+
}, [ tracks, integration?.settingsUrl, refreshIntegrations ] );
6778

6879
if ( isOfflineMode ) {
6980
return null;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: enhancement
3+
4+
Forms: hide Google export card if disabled.

0 commit comments

Comments
 (0)