Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/9295-refactor-auto-update-ban…
Browse files Browse the repository at this point in the history
…ner.
  • Loading branch information
jimmymadon committed Feb 25, 2025
2 parents 9021101 + 6090286 commit cac1e28
Show file tree
Hide file tree
Showing 51 changed files with 1,502 additions and 369 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- '.github/workflows/e2e-tests.yml'
- '.babelrc'
- 'assets/**'
- 'blocks/**'
- 'includes/**'
- '/*.php'
- 'jest-puppeteer.config.js'
Expand Down Expand Up @@ -46,6 +47,7 @@ on:
- '.github/workflows/e2e-tests.yml'
- '.babelrc'
- 'assets/**'
- 'blocks/**'
- 'includes/**'
- '/*.php'
- 'jest-puppeteer.config.js'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'blocks/**'
- '.storybook/**'
- '**.scss'
- '.nvmrc'
Expand All @@ -29,6 +30,7 @@ on:
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'blocks/**'
- '.storybook/**'
- '**.scss'
- '.nvmrc'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/visual-regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'blocks/**'
- '**.stories.js'
- 'tests/backstop/**'
- '.storybook/**'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/zips.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'blocks/**'
- 'includes/**'
- 'google-site-kit.php'
- 'scoper.inc.php'
Expand All @@ -41,6 +42,7 @@ on:
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'blocks/**'
- 'includes/**'
- 'google-site-kit.php'
- 'scoper.inc.php'
Expand Down
159 changes: 159 additions & 0 deletions assets/js/modules/ads/components/common/WooCommerceRedirectModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* WooCommerce Redirect Modal component.
*
* Site Kit by Google, Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useCallback, useMemo } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { useDispatch, useSelect } from 'googlesitekit-data';
import {
Button,
Dialog,
DialogContent,
DialogFooter,
DialogTitle,
} from 'googlesitekit-components';
import { ADS_WOOCOMMERCE_REDIRECT_MODAL_DISMISS_KEY } from '../../datastore/constants';
import { CORE_SITE } from '../../../../googlesitekit/datastore/site/constants';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import { CORE_LOCATION } from '../../../../googlesitekit/datastore/location/constants';
import { HOUR_IN_SECONDS } from '../../../../util';
import WooLogoIcon from '../../../../../svg/graphics/woo-logo.svg';
import ExternalIcon from '../../../../../svg/icons/external.svg';
import useActivateModuleCallback from '../../../../hooks/useActivateModuleCallback';

export default function WooCommerceRedirectModal( {
dialogActive,
onDismiss,
} ) {
const adminURL = useSelect( ( select ) =>
select( CORE_SITE ).getAdminURL()
);
const isWooCommerceActive = useSelect( ( select ) =>
select( CORE_SITE ).isWooCommerceActivated()
);
const isGoogleForWooCommerceActive = useSelect( ( select ) =>
select( CORE_SITE ).isGoogleForWooCommerceActivated()
);
const isModalDismissed = useSelect( ( select ) =>
select( CORE_USER ).isItemDismissed(
ADS_WOOCOMMERCE_REDIRECT_MODAL_DISMISS_KEY
)
);

const googleForWooCommerceRedirectURI = useMemo( () => {
if ( ! adminURL || ! isWooCommerceActive ) {
return undefined;
}

if ( isGoogleForWooCommerceActive === false ) {
return addQueryArgs( `${ adminURL }/plugin-install.php`, {
s: 'google-listings-and-ads',
tab: 'search',
type: 'term',
} );
}

const googleDashboardPath = encodeURIComponent( '/google/dashboard' );
return `${ adminURL }/admin.php?page=wc-admin&path=${ googleDashboardPath }`;
}, [ adminURL, isWooCommerceActive, isGoogleForWooCommerceActive ] );

const { dismissItem } = useDispatch( CORE_USER );

const markModalDismissed = useCallback( () => {
onDismiss?.();
dismissItem( ADS_WOOCOMMERCE_REDIRECT_MODAL_DISMISS_KEY, {
expiresInSeconds: HOUR_IN_SECONDS,
} );
}, [ onDismiss, dismissItem ] );

const { navigateTo } = useDispatch( CORE_LOCATION );

const getGoogleForWooCommerceRedirectURI = useCallback( () => {
markModalDismissed();

navigateTo( googleForWooCommerceRedirectURI );
}, [ markModalDismissed, navigateTo, googleForWooCommerceRedirectURI ] );

const onSetupCallback = useActivateModuleCallback( 'ads' );

const onContinueWithSiteKit = useCallback( () => {
markModalDismissed();
onSetupCallback();
}, [ markModalDismissed, onSetupCallback ] );

if ( isModalDismissed ) {
return null;
}

return (
<Dialog
open={ dialogActive }
aria-describedby={ undefined }
tabIndex="-1"
className="googlesitekit-dialog-woocommerce-redirect"
onClose={ markModalDismissed }
>
<div className="googlesitekit-dialog-woocommerce-redirect__svg-wrapper">
<WooLogoIcon width={ 110 } height={ 46 } />
</div>
<DialogTitle>
{ __( 'Using the WooCommerce plugin?', 'google-site-kit' ) }
</DialogTitle>
<DialogContent>
<p>
{ __(
'The Google for WooCommerce plugin can utilize your provided business information for advertising on Google and may be more suitable for your business.',
'google-site-kit'
) }
</p>
</DialogContent>
<DialogFooter>
<Button
className="mdc-dialog__cancel-button"
tertiary
onClick={ onContinueWithSiteKit }
>
{ __( 'Continue with Site Kit', 'google-site-kit' ) }
</Button>
<Button
trailingIcon={ <ExternalIcon width={ 13 } height={ 13 } /> }
onClick={ getGoogleForWooCommerceRedirectURI }
>
{ __( 'Use Google for WooCommerce', 'google-site-kit' ) }
</Button>
</DialogFooter>
</Dialog>
);
}

WooCommerceRedirectModal.propTypes = {
dialogActive: PropTypes.bool.isRequired,
onDismiss: PropTypes.func,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Ads WooCommerceRedirectModal component stories.
*
* Site Kit by Google, Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import WooCommerceRedirectModal from './WooCommerceRedirectModal';

function Template() {
return <WooCommerceRedirectModal dialogActive />;
}

export const Default = Template.bind( null );
Default.storyName = 'Default';
Default.scenario = {};
Default.parameters = {
features: [ 'adsPax' ],
};

export default {
title: 'Modules/Ads/WooCommerceRedirectModal',
};
Loading

0 comments on commit cac1e28

Please sign in to comment.