Skip to content

Commit

Permalink
Merge pull request #8636 from google/issue/8564-pax-extend-ads-settin…
Browse files Browse the repository at this point in the history
…gs-edit-view

Issue / 8564 PAX Extend Ads Settings Edit View
  • Loading branch information
tofumatt committed May 2, 2024
2 parents 985410a + ad64027 commit 5ae9cc2
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 1 deletion.
14 changes: 14 additions & 0 deletions assets/js/modules/ads/components/settings/SettingsEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ import { ProgressBar } from 'googlesitekit-components';
import { MODULES_ADS } from '../../datastore/constants';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import SettingsForm from './SettingsForm';
import SettingsView from './SettingsView';
import AdBlockerWarning from '../common/AdBlockerWarning';
import { useFeature } from './../../../../hooks/useFeature';
const { useSelect } = Data;

export default function SettingsEdit() {
const paxEnabled = useFeature( 'adsPax' );

const isDoingSubmitChanges = useSelect( ( select ) =>
select( MODULES_ADS ).isDoingSubmitChanges()
);
Expand All @@ -36,9 +40,19 @@ export default function SettingsEdit() {
select( CORE_USER ).isAdBlockerActive()
);

const paxConversionID = useSelect( ( select ) =>
select( MODULES_ADS ).getPaxConversionID()
);

const extCustomerID = useSelect( ( select ) =>
select( MODULES_ADS ).getExtCustomerID()
);

let viewComponent;
if ( isAdBlockerActive ) {
viewComponent = <AdBlockerWarning />;
} else if ( paxEnabled && ( paxConversionID || extCustomerID ) ) {
viewComponent = <SettingsView />;
} else if ( isDoingSubmitChanges ) {
viewComponent = <ProgressBar />;
} else {
Expand Down
124 changes: 124 additions & 0 deletions assets/js/modules/ads/components/settings/SettingsEdit.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Ads SettingsEdit component stories.
*
* Site Kit by Google, Copyright 2024 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 SettingsEdit from './SettingsEdit';
import { Cell, Grid, Row } from '../../../../material-components';
import { MODULES_ADS } from '../../datastore/constants';
import { provideModules } from '../../../../../../tests/js/utils';
import WithRegistrySetup from '../../../../../../tests/js/WithRegistrySetup';

function Template( args ) {
return (
<div className="googlesitekit-layout">
<div className="googlesitekit-settings-module googlesitekit-settings-module--active googlesitekit-settings-module--ads">
<div className="googlesitekit-setup-module">
<div className="googlesitekit-settings-module__content googlesitekit-settings-module__content--open">
<Grid>
<Row>
<Cell size={ 12 }>
<SettingsEdit { ...args } />
</Cell>
</Row>
</Grid>
</div>
</div>
</div>
</div>
);
}

export const Default = Template.bind( null );
Default.storyName = 'Default';
Default.scenario = {
label: 'Modules/Ads/Settings/SettingsEdit/Default',
delay: 250,
};
Default.decorators = [
( Story ) => {
const setupRegistry = ( registry ) => {
registry.dispatch( MODULES_ADS ).receiveGetSettings( {
conversionID: 'AW-123456789',
} );
};

return (
<WithRegistrySetup func={ setupRegistry }>
<Story />
</WithRegistrySetup>
);
},
];

export default {
title: 'Modules/Ads/Settings/SettingsEdit',
decorators: [
( Story ) => {
const setupRegistry = ( registry ) => {
provideModules( registry, [
{
slug: 'ads',
active: true,
connected: true,
},
] );
};

return (
<WithRegistrySetup func={ setupRegistry }>
<Story />
</WithRegistrySetup>
);
},
],
features: [ 'adsModule' ],
};

export const PaxConnected = Template.bind( null );
PaxConnected.storyName = 'With PAX onboarding';
PaxConnected.scenario = {
label: 'Modules/Ads/Settings/SettingsEdit/PAX',
delay: 250,
};
PaxConnected.parameters = {
features: [ 'adsPax' ],
};
PaxConnected.decorators = [
( Story, { parameters } ) => {
const setupRegistry = ( registry ) => {
// Unset the value set in the prrevious scenario.
registry.dispatch( MODULES_ADS ).setConversionID( null );

registry.dispatch( MODULES_ADS ).receiveGetSettings( {
paxConversionID: 'AW-54321',
extCustomerID: 'C-872756827HGFSD',
} );
};

return (
<WithRegistrySetup
func={ setupRegistry }
features={ parameters.features || [] }
>
<Story />
</WithRegistrySetup>
);
},
];
2 changes: 1 addition & 1 deletion includes/Modules/Ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected function setup_settings() {
public function is_connected() {
$options = $this->get_settings()->get();

return parent::is_connected() && ! empty( $options['conversionID'] );
return parent::is_connected() && ( ! empty( $options['conversionID'] ) || ! empty( $options['paxConversionID'] ) || ! empty( $options['extCustomerID'] ) );
}

/**
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5ae9cc2

Please sign in to comment.