-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new component SetupPaidAds as the Paid Ads setup step in the on…
…boarding flow
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
98
js/src/setup-mc/setup-stepper/setup-paid-ads/setup-paid-ads.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |