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

Consolidate Ad Creation #2575

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions js/src/components/paid-ads/ads-campaign.js

This file was deleted.

2 changes: 2 additions & 0 deletions js/src/components/paid-ads/ads-campaign/constants.js
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';
187 changes: 187 additions & 0 deletions js/src/components/paid-ads/ads-campaign/index.js
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 )

Check warning on line 64 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L54-L64

Added lines #L54 - L64 were not covered by tests
);

useEffect( () => {

Check warning on line 67 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L67

Added line #L67 was not covered by tests
if ( error ) {
setCompleting( null );

Check warning on line 69 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L69

Added line #L69 was not covered by tests
}
}, [ error ] );

const handleOnStatesReceived = ( paidAdsValues ) => {
setPaidAds( paidAdsValues );

Check warning on line 74 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L73-L74

Added lines #L73 - L74 were not covered by tests

const { amount, countryCodes } = paidAdsValues;
setValue( 'amount', amount );
setValue( 'countryCodes', countryCodes );

Check warning on line 78 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L76-L78

Added lines #L76 - L78 were not covered by tests
};

const handleCreateCampaignClick = () => {
setShowPaidAdsSetup( true );

Check warning on line 82 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L81-L82

Added lines #L81 - L82 were not covered by tests

clientSession.setShowPaidAdsSetup( true );

Check warning on line 84 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L84

Added line #L84 was not covered by tests
};

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

Check warning on line 88 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L87-L88

Added lines #L87 - L88 were not covered by tests

onSkip();

Check warning on line 90 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L90

Added line #L90 was not covered by tests
};

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

Check warning on line 94 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L93-L94

Added lines #L93 - L94 were not covered by tests

onContinue( paidAds );

Check warning on line 96 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L96

Added line #L96 was not covered by tests
};

// 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;
Copy link
Collaborator

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?


let continueButtonProps = {

Check warning on line 105 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L105

Added line #L105 was not covered by tests
text: __( 'Continue', 'google-listings-and-ads' ),
};

if ( onboardingSetup ) {
continueButtonProps = {

Check warning on line 110 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L110

Added line #L110 was not covered by tests
'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(

Check warning on line 123 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L123

Added line #L123 was not covered by tests
__(
'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 (

Check warning on line 139 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L139

Added line #L139 was not covered by tests
<StepContent>
<StepContentHeader
title={ headerTitle }
description={ description }
/>

{ onboardingSetup && (
<PaidAdsFeaturesSection

Check warning on line 147 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L146-L147

Added lines #L146 - L147 were not covered by tests
hidePaidAdsSetupFooterButtons={ shouldShowPaidAdsSetup }
onSkipClick={ handleSkipClick }
onCreateCampaignClick={ handleCreateCampaignClick }
disableCreateButton={ completing === ACTION_SKIP }
/>
) }

{ shouldShowPaidAdsSetup && (
<PaidAdsSetupSections

Check warning on line 156 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L155-L156

Added lines #L155 - L156 were not covered by tests
onStatesReceived={ handleOnStatesReceived }
campaign={ campaign }
/>
) }

<FaqsSection />
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Check warning on line 167 in js/src/components/paid-ads/ads-campaign/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/index.js#L164-L167

Added lines #L164 - L167 were not covered by tests
text={ __(
'Skip paid ads creation',
'google-listings-and-ads'
) }
onClick={ handleSkipClick }
/>
) }

<AppButton
isPrimary
disabled={ disabledComplete }
onClick={ handleCompleteClick }
loading={ completing === ACTION_COMPLETE }
{ ...continueButtonProps }
/>
</StepContentFooter>
) }
</StepContent>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Flex, FlexItem, FlexBlock } from '@wordpress/components';
import { Pill } from '@woocommerce/components';
import { noop } from 'lodash';
import GridiconCheckmark from 'gridicons/dist/checkmark';
import GridiconGift from 'gridicons/dist/gift';

Expand All @@ -13,6 +14,9 @@
import Section from '.~/wcdl/section';
import AppDocumentationLink from '.~/components/app-documentation-link';
import CampaignPreview from '.~/components/paid-ads/campaign-preview';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import AppButton from '.~/components/app-button';
import SkipButton from './skip-button';
import './paid-ads-features-section.scss';

function FeatureList( { hideBudgetContent } ) {
Expand Down Expand Up @@ -57,17 +61,23 @@
* for the next actions: skip or continue the paid ads setup.
*
* @param {Object} props React props.
* @param {boolean} props.hideBudgetContent Whether to hide the content about the ad budget.
* @param {boolean} props.hideFooterButtons Whether to hide the buttons at the card footer.
* @param {JSX.Element} props.skipButton Button to skip paid ads setup.
* @param {JSX.Element} props.continueButton Button to continue paid ads setup.
* @param {boolean} props.hidePaidAdsSetupFooterButtons Whether to hide the buttons at the section footer.
* @param {() => void} props.onSkipClick Callback called when the skip button is clicked.
* @param {() => void} props.onCreateCampaignClick Callback called when the create campaign button is clicked.
* @param {boolean} [props.disableCreateButton=false] Whether to disable the create campaign button.
*/
export default function PaidAdsFeaturesSection( {
hideBudgetContent,
hideFooterButtons,
skipButton,
continueButton,
hidePaidAdsSetupFooterButtons,
onSkipClick = noop,
onCreateCampaignClick = noop,
disableCreateButton = false,

Check warning on line 73 in js/src/components/paid-ads/ads-campaign/paid-ads-features-section.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/paid-ads-features-section.js#L71-L73

Added lines #L71 - L73 were not covered by tests
} ) {
const { hasGoogleAdsConnection } = useGoogleAdsAccount();

Check warning on line 75 in js/src/components/paid-ads/ads-campaign/paid-ads-features-section.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/paid-ads-features-section.js#L75

Added line #L75 was not covered by tests

const hideBudgetContent = ! hasGoogleAdsConnection;

Check warning on line 77 in js/src/components/paid-ads/ads-campaign/paid-ads-features-section.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/paid-ads/ads-campaign/paid-ads-features-section.js#L77

Added line #L77 was not covered by tests
const hideFooterButtons =
! hasGoogleAdsConnection || hidePaidAdsSetupFooterButtons;

return (
<Section
className="gla-paid-ads-features-section"
Expand Down Expand Up @@ -131,8 +141,24 @@
</Flex>
</Section.Card.Body>
<Section.Card.Footer hidden={ hideFooterButtons }>
{ skipButton }
{ continueButton }
<SkipButton
text={ __(
'Skip this step for now',
'google-listings-and-ads'
) }
onClick={ onSkipClick }
/>

<AppButton
isPrimary
text={ __(
'Create campaign',
'google-listings-and-ads'
) }
disabled={ disableCreateButton }
onClick={ onCreateCampaignClick }
eventName="gla_onboarding_open_paid_ads_setup_button_click"
/>
</Section.Card.Footer>
</Section.Card>
</Section>
Expand Down
Loading