-
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.
Merge pull request #2682 from woocommerce/feature/2458-2459-2460-2509
Streamline onboarding, post-onboarding and campaign setup
- Loading branch information
Showing
226 changed files
with
5,905 additions
and
7,672 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
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
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,64 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { getSetting } from '@woocommerce/settings'; // eslint-disable-line import/no-unresolved | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AppSelectControl from '.~/components/app-select-control'; | ||
import useExistingGoogleAdsAccounts from '.~/hooks/useExistingGoogleAdsAccounts'; | ||
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount'; | ||
|
||
/** | ||
* @param {Object} props The component props | ||
* @return {JSX.Element} An enhanced AppSelectControl component. | ||
*/ | ||
const AdsAccountSelectControl = ( props ) => { | ||
const { existingAccounts } = useExistingGoogleAdsAccounts(); | ||
const { googleAdsAccount, hasGoogleAdsConnection } = useGoogleAdsAccount(); | ||
|
||
const accountIdExists = existingAccounts?.some( | ||
( existingAccount ) => existingAccount.id === googleAdsAccount?.id | ||
); | ||
|
||
// If the account ID is not in the list of existing accounts, fake the select options by displaying the connected account ID only. | ||
if ( ! accountIdExists && hasGoogleAdsConnection ) { | ||
const domain = new URL( getSetting( 'homeUrl' ) ).host; | ||
|
||
return ( | ||
<AppSelectControl | ||
autoSelectFirstOption | ||
nonInteractive | ||
value={ googleAdsAccount.id } | ||
options={ [ | ||
{ | ||
value: googleAdsAccount.id, | ||
label: sprintf( | ||
// translators: 1: account domain, 2: account ID. | ||
__( '%1$s (%2$s)', 'google-listings-and-ads' ), | ||
domain, | ||
googleAdsAccount.id | ||
), | ||
}, | ||
] } | ||
/> | ||
); | ||
} | ||
|
||
const options = existingAccounts?.map( ( acc ) => ( { | ||
value: acc.id, | ||
label: `${ acc.name } (${ acc.id })`, | ||
} ) ); | ||
|
||
return ( | ||
<AppSelectControl | ||
options={ options } | ||
autoSelectFirstOption | ||
{ ...props } | ||
/> | ||
); | ||
}; | ||
|
||
export default AdsAccountSelectControl; |
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
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
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
Oops, something went wrong.