-
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 #2480 from woocommerce/feature/google-api-project
Google API Project
- Loading branch information
Showing
86 changed files
with
7,367 additions
and
247 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,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import { Notice } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './index.scss'; | ||
|
||
/** | ||
* Renders a Notice component with extra props. | ||
* | ||
* It supports all the props from @wordpress/components - Notice Component | ||
* | ||
* ## Usage | ||
* | ||
* ```jsx | ||
* <AppNotice > | ||
* My Notice | ||
* </AppButton> | ||
* ``` | ||
* | ||
* @param {*} props Props to be forwarded to {@link Notice}. | ||
*/ | ||
const AppNotice = ( props ) => { | ||
const { className, ...rest } = props; | ||
const classes = [ 'app-notice', className ]; | ||
return <Notice className={ classnames( ...classes ) } { ...rest } />; | ||
}; | ||
|
||
export default AppNotice; |
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,6 @@ | ||
.app-notice { | ||
border: 0; | ||
font-size: $helptext-font-size; | ||
margin: 0 var(--large-gap) var(--main-gap); | ||
padding: $grid-unit-20; | ||
} |
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,58 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AppButton from '.~/components/app-button'; | ||
import { glaData } from '.~/constants'; | ||
import { API_NAMESPACE } from '.~/data/constants'; | ||
import useApiFetchCallback from '.~/hooks/useApiFetchCallback'; | ||
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; | ||
|
||
/** | ||
* Button to initiate auth process for WP Rest API | ||
* | ||
* @param {Object} params The component params | ||
* @return {JSX.Element} The button. | ||
*/ | ||
const EnableNewProductSyncButton = ( params ) => { | ||
const { createNotice } = useDispatchCoreNotices(); | ||
const [ loading, setLoading ] = useState( false ); | ||
const nextPageName = glaData.mcSetupComplete ? 'settings' : 'setup-mc'; | ||
const query = { next_page_name: nextPageName }; | ||
const path = addQueryArgs( `${ API_NAMESPACE }/rest-api/authorize`, query ); | ||
const [ fetchRestAPIAuthorize ] = useApiFetchCallback( { path } ); | ||
const handleEnableClick = async () => { | ||
try { | ||
setLoading( true ); | ||
const d = await fetchRestAPIAuthorize(); | ||
setLoading( false ); | ||
window.location.href = d.auth_url; | ||
} catch ( error ) { | ||
setLoading( false ); | ||
createNotice( | ||
'error', | ||
__( | ||
'Unable to enable new product sync. Please try again later.', | ||
'google-listings-and-ads' | ||
) | ||
); | ||
} | ||
}; | ||
|
||
return ( | ||
<AppButton | ||
isSecondary | ||
loading={ loading } | ||
onClick={ handleEnableClick } | ||
{ ...params } | ||
/> | ||
); | ||
}; | ||
|
||
export default EnableNewProductSyncButton; |
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,56 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Notice } from '@wordpress/components'; | ||
import { createInterpolateElement } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount'; | ||
import EnableNewProductSyncButton from '.~/components/enable-new-product-sync-button'; | ||
|
||
/** | ||
* Shows info {@link Notice} | ||
* about enabling new product sync when the feature flag is turned on and hasn't switched to new product sync. | ||
* | ||
* @return {JSX.Element} {@link Notice} element with the info message and the button to enable new product sync. | ||
*/ | ||
const EnableNewProductSyncNotice = () => { | ||
const { | ||
hasFinishedResolution: hasGoogleMCAccountFinishedResolution, | ||
googleMCAccount, | ||
} = useGoogleMCAccount(); | ||
|
||
// Do not render if already switch to new product sync. | ||
if ( | ||
! hasGoogleMCAccountFinishedResolution || | ||
! googleMCAccount.notification_service_enabled || | ||
googleMCAccount.wpcom_rest_api_status | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Notice status="info" isDismissible={ false }> | ||
{ createInterpolateElement( | ||
__( | ||
'<p>We will soon transition to a new and improved method for synchronizing product data with Google.</p><enableButton>Get early access</enableButton>', | ||
'google-listings-and-ads' | ||
), | ||
{ | ||
enableButton: ( | ||
<EnableNewProductSyncButton | ||
eventName="gla_enable_product_sync_click" | ||
eventProps={ { context: 'banner' } } | ||
/> | ||
), | ||
p: <p />, | ||
} | ||
) } | ||
</Notice> | ||
); | ||
}; | ||
|
||
export default EnableNewProductSyncNotice; |
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.