Skip to content
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

Update RRM SettingsEdit to handle missing ID error. #10222

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ import SettingsNotice, {
TYPE_INFO,
} from '../../../../components/SettingsNotice';
import WarningIcon from '../../../../../../assets/svg/icons/warning-icon.svg';
import StoreErrorNotices from '../../../../components/StoreErrorNotices';

export default function SettingsEdit() {
const isRRMv2Enabled = useFeature( 'rrmModuleV2' );

const isDoingSubmitChanges = useSelect( ( select ) =>
select( MODULES_READER_REVENUE_MANAGER ).isDoingSubmitChanges()
);

const hasModuleAccess = useSelect( ( select ) => {
const { hasModuleOwnershipOrAccess, getErrorForAction } =
select( CORE_MODULES );
Expand Down Expand Up @@ -83,9 +85,35 @@ export default function SettingsEdit() {

return false;
} );

const publicationID = useSelect( ( select ) =>
select( MODULES_READER_REVENUE_MANAGER ).getPublicationID()
);

const missingProductID = useSelect( ( select ) => {
const productID = select(
MODULES_READER_REVENUE_MANAGER
).getProductID();

if ( productID === undefined ) {
return undefined;
}

if ( 'openaccess' === productID ) {
return null;
}

const productIDs = select(
MODULES_READER_REVENUE_MANAGER
).getProductIDs();

if ( productIDs === undefined ) {
return undefined;
}

return productIDs.includes( productID ) ? null : productID;
} );

const publicationAvailable = useSelect( ( select ) => {
if ( hasModuleAccess === undefined ) {
return undefined;
Expand Down Expand Up @@ -128,6 +156,11 @@ export default function SettingsEdit() {
return (
<div className="googlesitekit-setup-module googlesitekit-setup-module--reader-revenue-manager googlesitekit-rrm-settings-edit">
<div className="googlesitekit-settings-module__fields-group">
<StoreErrorNotices
moduleSlug={ READER_REVENUE_MANAGER_MODULE_SLUG }
storeName={ MODULES_READER_REVENUE_MANAGER }
/>

{ hasModuleAccess && false === publicationAvailable && (
<ErrorText
message={ sprintf(
Expand All @@ -140,6 +173,23 @@ export default function SettingsEdit() {
) }
/>
) }

{ isRRMv2Enabled &&
hasModuleAccess &&
publicationAvailable &&
missingProductID && (
<ErrorText
message={ sprintf(
/* translators: 1: Product ID. */
__(
'The previously selected product ID %s was not found. Please select a new product ID.',
'google-site-kit'
),
missingProductID
) }
/>
) }

<div className="googlesitekit-setup-module__inputs">
<PublicationSelect hasModuleAccess={ hasModuleAccess } />
</div>
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the remaining product IDs in this file :)

The calls to setProductId() need updating, and so does the MissingProductID story.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ function Template() {
export const Default = Template.bind( {} );
Default.storyName = 'Default';
Default.scenario = {};
Default.args = {
setupRegistry: ( registry ) => {
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.setProductID( 'product-b' );
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.setProductIDs( [ 'product-a', 'product-b', 'product-c' ] );
},
};

export const PendingVerification = Template.bind( {} );
PendingVerification.storyName = 'PendingVerification';
Expand All @@ -65,6 +75,11 @@ PendingVerification.args = {
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( publications[ 1 ] );

registry.dispatch( MODULES_READER_REVENUE_MANAGER ).setProductID( 1 );
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.setProductIDs( [ 'product-a', 'product-b', 'product-c' ] );
},
};

Expand All @@ -76,6 +91,10 @@ ActionRequired.args = {
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( publications[ 2 ] );
registry.dispatch( MODULES_READER_REVENUE_MANAGER ).setProductID( 1 );
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.setProductIDs( [ 'product-a', 'product-b', 'product-c' ] );
},
};

Expand All @@ -93,6 +112,11 @@ WithoutModuleAccess.args = {
{ slug: READER_REVENUE_MANAGER_MODULE_SLUG }
);

registry.dispatch( MODULES_READER_REVENUE_MANAGER ).setProductID( 1 );
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.setProductIDs( [ 'product-a', 'product-b', 'product-c' ] );

registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( publications[ 2 ] );
Expand All @@ -114,6 +138,19 @@ PublicationUnavailable.args = {
},
};

export const MissingProductID = Template.bind( {} );
MissingProductID.storyName = 'MissingProductID';
MissingProductID.scenario = {};
MissingProductID.args = {
setupRegistry: ( registry ) => {
registry.dispatch( MODULES_READER_REVENUE_MANAGER ).setOwnerID( 1 );
registry.dispatch( MODULES_READER_REVENUE_MANAGER ).setProductID( 1 );
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.setProductIDs( [ 0, 3 ] );
},
};

export default {
title: 'Modules/ReaderRevenueManager/Settings/SettingsEdit',
decorators: [
Expand Down
Loading