-
Notifications
You must be signed in to change notification settings - Fork 21
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
Consolidate Ad Creation #2575
Closed
asvinb
wants to merge
18
commits into
feature/2460-simplify-paid-ads-setup
from
update/2535-consolidate-ad-creation
Closed
Consolidate Ad Creation #2575
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b207569
Move PaidAdsFeaturesSection and PaidAdsSetupSections components.
asvinb f65fbee
Save Work in progress.
asvinb 1b8abc9
Consolidate AdsCampaign component.
asvinb 3f8ac23
Revert local test changes.
asvinb 101412b
Remove comments.
asvinb 620b183
Clean up comments.
asvinb 84879b8
Remove unused imports.
asvinb a3b50fe
Editing a campaign working.
asvinb a9b7f13
Fix condition to render paid ads sections.
asvinb c76a128
Address linting errors.
asvinb dcea1d6
Add headerDescription prop.
asvinb 522e635
Remove unused comment.
asvinb 388fddb
Remove onClick prop (?)
asvinb 8ddde21
Show banner in create mode only.
asvinb ff7f281
Remove unused event prop
asvinb 5200727
Remove unecessary isCreation prop.
asvinb d93bc1d
Add countryCodes field.
asvinb 8e95434
Remove country code from edit screen.
asvinb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,2 @@ | ||
export const ACTION_COMPLETE = 'complete-ads'; | ||
export const ACTION_SKIP = 'skip-ads'; |
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,187 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
createInterpolateElement, | ||
useState, | ||
useEffect, | ||
} from '@wordpress/element'; | ||
import { noop } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useAdaptiveFormContext } from '.~/components/adaptive-form'; | ||
import StepContent from '.~/components/stepper/step-content'; | ||
import StepContentHeader from '.~/components/stepper/step-content-header'; | ||
import StepContentFooter from '.~/components/stepper/step-content-footer'; | ||
import AppDocumentationLink from '.~/components/app-documentation-link'; | ||
import AppButton from '.~/components/app-button'; | ||
import FaqsSection from '../faqs-section'; | ||
import PaidAdsFeaturesSection from './paid-ads-features-section'; | ||
import PaidAdsSetupSections from './paid-ads-setup-sections'; | ||
import SkipButton from './skip-button'; | ||
import clientSession from './clientSession'; | ||
import { ACTION_SKIP, ACTION_COMPLETE } from './constants'; | ||
|
||
/** | ||
* @typedef {import('.~/data/actions').Campaign} Campaign | ||
*/ | ||
|
||
/** | ||
* Renders the container of the form content for campaign management. | ||
* | ||
* Please note that this component relies on an CampaignAssetsForm's context and custom adapter, | ||
* so it expects a `CampaignAssetsForm` to existing in its parents. | ||
* | ||
* @fires gla_documentation_link_click with `{ context: 'create-ads' | 'edit-ads' | 'setup-ads', link_id: 'see-what-ads-look-like', href: 'https://support.google.com/google-ads/answer/6275294' }` | ||
* @param {Object} props React props. | ||
* @param {Campaign} [props.campaign] Campaign data to be edited. If not provided, this component will show campaign creation UI. | ||
* @param {() => void} props.onContinue Callback called once continue button is clicked. | ||
* @param {string} props.headerTitle The title of the step. | ||
* @param {string} [props.headerDescription] The description of the step. | ||
* @param {() => void} props.onSkip Callback called once skip button is clicked. | ||
* @param {boolean} [props.error=false] Whether there's an error to reset the complete state. | ||
* @param {boolean} [props.onboardingSetup=false] Whether this component is used in onboarding setup. | ||
* @param {'create-ads'|'edit-ads'|'setup-ads'} props.trackingContext A context indicating which page this component is used on. This will be the value of `context` in the track event properties. | ||
*/ | ||
export default function AdsCampaign( { | ||
campaign, | ||
trackingContext, | ||
headerTitle, | ||
headerDescription, | ||
onContinue = noop, | ||
onSkip = noop, | ||
error = false, | ||
onboardingSetup = false, | ||
} ) { | ||
const formContext = useAdaptiveFormContext(); | ||
const { isValidForm, setValue } = formContext; | ||
const [ completing, setCompleting ] = useState( null ); | ||
const [ paidAds, setPaidAds ] = useState( {} ); | ||
const [ showPaidAdsSetup, setShowPaidAdsSetup ] = useState( () => | ||
clientSession.getShowPaidAdsSetup( false ) | ||
); | ||
|
||
useEffect( () => { | ||
if ( error ) { | ||
setCompleting( null ); | ||
} | ||
}, [ error ] ); | ||
|
||
const handleOnStatesReceived = ( paidAdsValues ) => { | ||
setPaidAds( paidAdsValues ); | ||
|
||
const { amount, countryCodes } = paidAdsValues; | ||
setValue( 'amount', amount ); | ||
setValue( 'countryCodes', countryCodes ); | ||
}; | ||
|
||
const handleCreateCampaignClick = () => { | ||
setShowPaidAdsSetup( true ); | ||
|
||
clientSession.setShowPaidAdsSetup( true ); | ||
}; | ||
|
||
const handleSkipClick = ( event ) => { | ||
setCompleting( event.target.dataset.action ); | ||
|
||
onSkip(); | ||
}; | ||
|
||
const handleCompleteClick = ( event ) => { | ||
setCompleting( event.target.dataset.action ); | ||
|
||
onContinue( paidAds ); | ||
}; | ||
|
||
// The status check of Google Ads account connection is included in `paidAds.isReady`, | ||
// because when there is no connected account, it will disable the budget section and set the `amount` to `undefined`. | ||
const disabledComplete = | ||
completing === ACTION_SKIP || ! paidAds.isReady || ! isValidForm; | ||
const shouldShowPaidAdsSetup = ! onboardingSetup || showPaidAdsSetup; | ||
|
||
let continueButtonProps = { | ||
text: __( 'Continue', 'google-listings-and-ads' ), | ||
}; | ||
|
||
if ( onboardingSetup ) { | ||
continueButtonProps = { | ||
'data-action': ACTION_COMPLETE, | ||
text: __( 'Complete setup', 'google-listings-and-ads' ), | ||
eventName: 'gla_onboarding_complete_with_paid_ads_button_click', | ||
eventProps: { | ||
budget: paidAds.amount, | ||
audiences: paidAds.countryCodes?.join( ',' ), | ||
}, | ||
}; | ||
} | ||
|
||
const description = | ||
headerDescription || | ||
createInterpolateElement( | ||
__( | ||
'Paid Performance Max campaigns are automatically optimized for you by Google. <link>See what your ads will look like.</link>', | ||
'google-listings-and-ads' | ||
), | ||
{ | ||
link: ( | ||
<AppDocumentationLink | ||
context={ trackingContext } | ||
linkId="see-what-ads-look-like" | ||
href="https://support.google.com/google-ads/answer/6275294" | ||
/> | ||
), | ||
} | ||
); | ||
|
||
return ( | ||
<StepContent> | ||
<StepContentHeader | ||
title={ headerTitle } | ||
description={ description } | ||
/> | ||
|
||
{ onboardingSetup && ( | ||
<PaidAdsFeaturesSection | ||
hidePaidAdsSetupFooterButtons={ shouldShowPaidAdsSetup } | ||
onSkipClick={ handleSkipClick } | ||
onCreateCampaignClick={ handleCreateCampaignClick } | ||
disableCreateButton={ completing === ACTION_SKIP } | ||
/> | ||
) } | ||
|
||
{ shouldShowPaidAdsSetup && ( | ||
<PaidAdsSetupSections | ||
onStatesReceived={ handleOnStatesReceived } | ||
campaign={ campaign } | ||
/> | ||
) } | ||
|
||
<FaqsSection /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes to the AdsCampaign component in #2531 need to be preserved here. |
||
|
||
{ shouldShowPaidAdsSetup && ( | ||
<StepContentFooter> | ||
{ onboardingSetup && ( | ||
<SkipButton | ||
text={ __( | ||
'Skip paid ads creation', | ||
'google-listings-and-ads' | ||
) } | ||
onClick={ handleSkipClick } | ||
/> | ||
) } | ||
|
||
<AppButton | ||
isPrimary | ||
disabled={ disabledComplete } | ||
onClick={ handleCompleteClick } | ||
loading={ completing === ACTION_COMPLETE } | ||
{ ...continueButtonProps } | ||
/> | ||
</StepContentFooter> | ||
) } | ||
</StepContent> | ||
); | ||
} |
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
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shouldShowPaidAdsSetup logic was removed in #2533. Is there a reason it needs to be added back here?