diff --git a/js/src/components/free-listings/configure-product-listings/__snapshots__/checkErrors.test.js.snap b/js/src/components/free-listings/configure-product-listings/__snapshots__/checkErrors.test.js.snap index 0deed2c1ad..3bfb80e0bf 100644 --- a/js/src/components/free-listings/configure-product-listings/__snapshots__/checkErrors.test.js.snap +++ b/js/src/components/free-listings/configure-product-listings/__snapshots__/checkErrors.test.js.snap @@ -6,26 +6,6 @@ exports[`checkErrors For tax rate, if selected country codes include 'US' When t exports[`checkErrors For tax rate, if selected country codes include 'US' When the tax rate option is an invalid value or missing, should not pass 3`] = `"Please specify tax rate option."`; -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 1`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 2`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 3`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 4`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 5`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 6`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 7`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 8`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 9`] = `"Please check the requirement."`; - -exports[`checkErrors Requirements When there are any requirements are not true, should not pass 10`] = `"Please check the requirement."`; - exports[`checkErrors Shipping rates For flat type When the free shipping threshold is an invalid value or missing, should not pass 1`] = `"Please specify a valid minimum order price for free shipping"`; exports[`checkErrors Shipping rates For flat type When the free shipping threshold is an invalid value or missing, should not pass 2`] = `"Please specify a valid minimum order price for free shipping"`; diff --git a/js/src/components/free-listings/configure-product-listings/checkErrors.js b/js/src/components/free-listings/configure-product-listings/checkErrors.js index 8b64feabbb..bf47eb5715 100644 --- a/js/src/components/free-listings/configure-product-listings/checkErrors.js +++ b/js/src/components/free-listings/configure-product-listings/checkErrors.js @@ -82,44 +82,6 @@ const checkErrors = ( ); } - /** - * Pre-launch checklist. - */ - if ( values.website_live !== true ) { - errors.website_live = __( - 'Please check the requirement.', - 'google-listings-and-ads' - ); - } - - if ( values.checkout_process_secure !== true ) { - errors.checkout_process_secure = __( - 'Please check the requirement.', - 'google-listings-and-ads' - ); - } - - if ( values.payment_methods_visible !== true ) { - errors.payment_methods_visible = __( - 'Please check the requirement.', - 'google-listings-and-ads' - ); - } - - if ( values.refund_tos_visible !== true ) { - errors.refund_tos_visible = __( - 'Please check the requirement.', - 'google-listings-and-ads' - ); - } - - if ( values.contact_info_visible !== true ) { - errors.contact_info_visible = __( - 'Please check the requirement.', - 'google-listings-and-ads' - ); - } - return errors; }; diff --git a/js/src/components/free-listings/configure-product-listings/checkErrors.test.js b/js/src/components/free-listings/configure-product-listings/checkErrors.test.js index 43aeed1923..bbc4fc8d0b 100644 --- a/js/src/components/free-listings/configure-product-listings/checkErrors.test.js +++ b/js/src/components/free-listings/configure-product-listings/checkErrors.test.js @@ -33,11 +33,6 @@ describe( 'checkErrors', () => { offers_free_shipping: true, free_shipping_threshold: 100, tax_rate: 'manual', - website_live: true, - checkout_process_secure: true, - payment_methods_visible: true, - refund_tos_visible: true, - contact_info_visible: true, }; const rates = toRates( [ 'US', 10 ], [ 'JP', 30 ] ); const times = toTimes( [ 'US', 3 ], [ 'JP', 10 ] ); @@ -53,7 +48,6 @@ describe( 'checkErrors', () => { expect( errors ).toHaveProperty( 'shipping_rate' ); expect( errors ).toHaveProperty( 'shipping_time' ); - expect( errors ).toHaveProperty( 'website_live' ); } ); describe( 'Shipping rates', () => { @@ -322,70 +316,4 @@ describe( 'checkErrors', () => { expect( errors ).not.toHaveProperty( 'tax_rate' ); } ); } ); - - describe( 'Requirements', () => { - it( 'When there are any requirements are not true, should not pass', () => { - // Not set yet - let errors = checkErrors( {}, [], [], [] ); - - expect( errors ).toHaveProperty( 'website_live' ); - expect( errors.website_live ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'checkout_process_secure' ); - expect( errors.checkout_process_secure ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'payment_methods_visible' ); - expect( errors.payment_methods_visible ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'refund_tos_visible' ); - expect( errors.refund_tos_visible ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'contact_info_visible' ); - expect( errors.contact_info_visible ).toMatchSnapshot(); - - // Invalid value - const values = { - website_live: false, - checkout_process_secure: 1, - payment_methods_visible: 'true', - refund_tos_visible: [], - contact_info_visible: {}, - }; - - errors = checkErrors( values, [], [], [] ); - - expect( errors ).toHaveProperty( 'website_live' ); - expect( errors.website_live ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'checkout_process_secure' ); - expect( errors.checkout_process_secure ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'payment_methods_visible' ); - expect( errors.payment_methods_visible ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'refund_tos_visible' ); - expect( errors.refund_tos_visible ).toMatchSnapshot(); - - expect( errors ).toHaveProperty( 'contact_info_visible' ); - expect( errors.contact_info_visible ).toMatchSnapshot(); - } ); - - it( 'When all requirements are true, should pass', () => { - const values = { - website_live: true, - checkout_process_secure: true, - payment_methods_visible: true, - refund_tos_visible: true, - contact_info_visible: true, - }; - - const errors = checkErrors( values, [], [], [] ); - - expect( errors ).not.toHaveProperty( 'website_live' ); - expect( errors ).not.toHaveProperty( 'checkout_process_secure' ); - expect( errors ).not.toHaveProperty( 'payment_methods_visible' ); - expect( errors ).not.toHaveProperty( 'refund_tos_visible' ); - expect( errors ).not.toHaveProperty( 'contact_info_visible' ); - } ); - } ); } ); diff --git a/js/src/data/reducer.js b/js/src/data/reducer.js index d0666d90ae..e6e04e5b71 100644 --- a/js/src/data/reducer.js +++ b/js/src/data/reducer.js @@ -143,10 +143,16 @@ const reducer = ( state = DEFAULT_STATE, action ) => { case TYPES.RECEIVE_SETTINGS: case TYPES.SAVE_SETTINGS: { - const { settings } = action; - const newState = cloneDeep( state ); - newState.mc.settings = settings; - return newState; + return { + ...state, + mc: { + ...state.mc, + settings: { + ...state.mc.settings, + ...action.settings, + }, + }, + }; } case TYPES.RECEIVE_ACCOUNTS_JETPACK: { diff --git a/js/src/setup-mc/setup-stepper/setup-free-listings/form-content.js b/js/src/setup-mc/setup-stepper/setup-free-listings/form-content.js index df23fe896d..104fd43207 100644 --- a/js/src/setup-mc/setup-stepper/setup-free-listings/form-content.js +++ b/js/src/setup-mc/setup-stepper/setup-free-listings/form-content.js @@ -5,7 +5,6 @@ import StepContent from '.~/components/stepper/step-content'; import StepContentFooter from '.~/components/stepper/step-content-footer'; import CombinedShipping from './combined-shipping'; import TaxRate from '.~/components/free-listings/configure-product-listings/tax-rate'; -import PreLaunchChecklist from './pre-launch-checklist'; import useAutoSaveSettingsEffect from './useAutoSaveSettingsEffect'; import useDisplayTaxRate from '.~/components/free-listings/configure-product-listings/useDisplayTaxRate'; import useTargetAudienceFinalCountryCodes from '.~/hooks/useTargetAudienceFinalCountryCodes'; @@ -32,7 +31,6 @@ const FormContent = ( props ) => { - { submitButton } ); diff --git a/js/src/setup-mc/setup-stepper/setup-free-listings/index.js b/js/src/setup-mc/setup-stepper/setup-free-listings/index.js index f046da0429..1f333c94d7 100644 --- a/js/src/setup-mc/setup-stepper/setup-free-listings/index.js +++ b/js/src/setup-mc/setup-stepper/setup-free-listings/index.js @@ -75,11 +75,6 @@ const SetupFreeListings = ( props ) => { free_shipping_threshold: settings.free_shipping_threshold, shipping_time: settings.shipping_time, tax_rate: settings.tax_rate, - website_live: settings.website_live, - checkout_process_secure: settings.checkout_process_secure, - payment_methods_visible: settings.payment_methods_visible, - refund_tos_visible: settings.refund_tos_visible, - contact_info_visible: settings.contact_info_visible, } } validate={ handleValidate } onSubmitCallback={ handleSubmitCallback } diff --git a/js/src/setup-mc/setup-stepper/store-requirements/index.js b/js/src/setup-mc/setup-stepper/store-requirements/index.js index c01da4c4b0..ab913c491f 100644 --- a/js/src/setup-mc/setup-stepper/store-requirements/index.js +++ b/js/src/setup-mc/setup-stepper/store-requirements/index.js @@ -14,28 +14,33 @@ import { useAppDispatch } from '.~/data'; import useAdminUrl from '.~/hooks/useAdminUrl'; import useGoogleMCPhoneNumber from '.~/hooks/useGoogleMCPhoneNumber'; import useStoreAddress from '.~/hooks/useStoreAddress'; +import useSettings from '.~/components/free-listings/configure-product-listings/useSettings'; import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; import StepContent from '.~/components/stepper/step-content'; import StepContentHeader from '.~/components/stepper/step-content-header'; import StepContentFooter from '.~/components/stepper/step-content-footer'; import ContactInformation from '.~/components/contact-information'; import AppButton from '.~/components/app-button'; +import AppSpinner from '.~/components/app-spinner'; +import PreLaunchChecklist from './pre-launch-checklist'; +import checkErrors from './pre-launch-checklist/checkErrors'; export default function StoreRequirements() { const adminUrl = useAdminUrl(); - const { updateGoogleMCContactInformation } = useAppDispatch(); + const { updateGoogleMCContactInformation, saveSettings } = useAppDispatch(); const { createNotice } = useDispatchCoreNotices(); const { data: initPhoneNumber } = useGoogleMCPhoneNumber(); const { data: address } = useStoreAddress(); + const { settings } = useSettings(); + const [ completing, setCompleting ] = useState( false ); const [ phoneNumber, setPhoneNumber ] = useState( { isValid: false, isDirty: false, } ); - const handleValidate = () => { - // TODO: [lite-contact-info] add validation for pre-launch checklist - return {}; + const handleChangeCallback = ( _, values ) => { + saveSettings( values ); }; const handleSubmitCallback = async () => { @@ -71,6 +76,10 @@ export default function StoreRequirements() { } }; + if ( ! settings ) { + return ; + } + return (
@@ -108,7 +125,7 @@ export default function StoreRequirements() { view="setup-mc" onPhoneNumberChange={ setPhoneNumber } /> -
TODO: move pre-lauch checklist to here
+ { + describe( 'Should check the presence of required properties in the given object. Returned object should have error messages for respective properties.', () => { + for ( const property of [ + 'website_live', + 'checkout_process_secure', + 'payment_methods_visible', + 'refund_tos_visible', + 'contact_info_visible', + ] ) { + it( `${ property } === true`, () => { + expect( checkErrors( {} ) ).toHaveProperty( + property, + 'Please check the requirement.' + ); + + expect( checkErrors( { [ property ]: 'foo' } ) ).toHaveProperty( + property, + 'Please check the requirement.' + ); + + expect( + checkErrors( { [ property ]: true } ) + ).not.toHaveProperty( property ); + } ); + } + it( 'When there are many missing/invalid properties, should report them all.', () => { + const values = { + website_live: false, + payment_methods_visible: 'true', + refund_tos_visible: [], + contact_info_visible: {}, + }; + + const errorMessage = 'Please check the requirement.'; + expect( checkErrors( values ) ).toEqual( { + website_live: errorMessage, + checkout_process_secure: errorMessage, + payment_methods_visible: errorMessage, + refund_tos_visible: errorMessage, + contact_info_visible: errorMessage, + } ); + } ); + + it( 'When all properties are valid, should return an empty object.', () => { + const values = { + website_live: true, + checkout_process_secure: true, + payment_methods_visible: true, + refund_tos_visible: true, + contact_info_visible: true, + }; + + expect( checkErrors( values ) ).toEqual( {} ); + } ); + } ); +} ); diff --git a/js/src/setup-mc/setup-stepper/setup-free-listings/pre-launch-checklist/index.js b/js/src/setup-mc/setup-stepper/store-requirements/pre-launch-checklist/index.js similarity index 100% rename from js/src/setup-mc/setup-stepper/setup-free-listings/pre-launch-checklist/index.js rename to js/src/setup-mc/setup-stepper/store-requirements/pre-launch-checklist/index.js diff --git a/js/src/setup-mc/setup-stepper/setup-free-listings/pre-launch-checklist/index.scss b/js/src/setup-mc/setup-stepper/store-requirements/pre-launch-checklist/index.scss similarity index 100% rename from js/src/setup-mc/setup-stepper/setup-free-listings/pre-launch-checklist/index.scss rename to js/src/setup-mc/setup-stepper/store-requirements/pre-launch-checklist/index.scss