Skip to content

Commit

Permalink
Add a new component SetupPaidAds as the Paid Ads setup step in the on…
Browse files Browse the repository at this point in the history
…boarding flow
  • Loading branch information
eason9487 committed Aug 8, 2022
1 parent ab1c7eb commit 893b943
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/src/setup-mc/setup-stepper/setup-paid-ads/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './setup-paid-ads';
98 changes: 98 additions & 0 deletions js/src/setup-mc/setup-stepper/setup-paid-ads/setup-paid-ads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import { useState } from '@wordpress/element';
import { Flex } from '@wordpress/components';

/**
* Internal dependencies
*/
import useAdminUrl from '.~/hooks/useAdminUrl';
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 FaqsSection from '.~/components/paid-ads/faqs-section';
import AppButton from '.~/components/app-button';
import { getProductFeedUrl } from '.~/utils/urls';
import { GUIDE_NAMES } from '.~/constants';
import { API_NAMESPACE } from '.~/data/constants';

export default function SetupPaidAds() {
const adminUrl = useAdminUrl();
const { createNotice } = useDispatchCoreNotices();
const [ completing, setCompleting ] = useState( null );

const finishFreeListingsSetup = async ( event ) => {
setCompleting( event.target.dataset.action );

try {
await apiFetch( {
path: `${ API_NAMESPACE }/mc/settings/sync`,
method: 'POST',
} );
} catch ( e ) {
setCompleting( null );

createNotice(
'error',
__(
'Unable to complete your setup.',
'google-listings-and-ads'
)
);
}

// Force reload WC admin page to initiate the relevant dependencies of the Dashboard page.
const query = { guide: GUIDE_NAMES.SUBMISSION_SUCCESS };
window.location.href = adminUrl + getProductFeedUrl( query );
};

const handleCompleteClick = async ( event ) => {
// TODO: Implement the compaign creation and paid ads completion.
await finishFreeListingsSetup( event );
};

return (
<StepContent>
<StepContentHeader
title={ __(
'Complete your campaign with paid ads',
'google-listings-and-ads'
) }
description={ __(
'As soon as your products are approved, your listings and ads will be live. In the meantime, let’s set up your ads.',
'google-listings-and-ads'
) }
/>
<FaqsSection />
<StepContentFooter>
<Flex justify="right" gap={ 4 }>
<AppButton
isTertiary
data-action="skip-ads"
loading={ completing === 'skip-ads' }
disabled={ completing === 'complete-ads' }
onClick={ finishFreeListingsSetup }
>
{ __(
'Skip paid ads creation',
'google-listings-and-ads'
) }
</AppButton>
<AppButton
isPrimary
data-action="complete-ads"
loading={ completing === 'complete-ads' }
disabled={ completing === 'skip-ads' }
onClick={ handleCompleteClick }
>
{ __( 'Complete setup', 'google-listings-and-ads' ) }
</AppButton>
</Flex>
</StepContentFooter>
</StepContent>
);
}

0 comments on commit 893b943

Please sign in to comment.