From 9fa7d176fe63c440bbed55ad7185df7a683114c9 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Thu, 28 Oct 2021 02:31:11 +0800 Subject: [PATCH 1/9] Add wp-logo.svg. --- .../setup-accounts/wpcom-account-card/wp-logo.svg | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/wp-logo.svg diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/wp-logo.svg b/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/wp-logo.svg new file mode 100644 index 0000000000..905023f000 --- /dev/null +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/wp-logo.svg @@ -0,0 +1,5 @@ + + + + + From 4f82292dcaf25b61ee542c2fe099d33e3132ad2c Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Thu, 28 Oct 2021 02:31:52 +0800 Subject: [PATCH 2/9] Add early test version of WPComAccountCard. --- .../setup-stepper/setup-accounts/index.js | 2 + .../wpcom-account-card/index.js | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/index.js diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/index.js index 0033041144..8c8e4b7319 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/index.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/index.js @@ -20,6 +20,7 @@ import WordPressDotComAccount from './wordpressdotcom-account'; import GoogleAccountCard from '.~/components/google-account-card'; import GoogleMCAccount from './google-mc-account'; import Faqs from './faqs'; +import WPComAccountCard from './wpcom-account-card'; const SetupAccounts = ( props ) => { const { onContinue = () => {} } = props; @@ -63,6 +64,7 @@ const SetupAccounts = ( props ) => { > + diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/index.js new file mode 100644 index 0000000000..9fade8bf1b --- /dev/null +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/index.js @@ -0,0 +1,70 @@ +/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import AccountCard from '.~/components/account-card'; +import AppButton from '.~/components/app-button'; +import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; +import useApiFetchCallback from '.~/hooks/useApiFetchCallback'; +import wpLogoURL from './wp-logo.svg'; + +const WPComAccountCard = () => { + const { createNotice } = useDispatchCoreNotices(); + const [ fetchJetpackConnect, { loading, data } ] = useApiFetchCallback( { + path: '/wc/gla/jetpack/connect', + } ); + + const handleConnectClick = async () => { + try { + const d = await fetchJetpackConnect(); + window.location.href = d.url; + } catch ( error ) { + createNotice( + 'error', + __( + 'Unable to connect your WordPress.com account. Please try again later.', + 'google-listings-and-ads' + ) + ); + } + }; + + return ( + + ), + title: 'WordPress.com', + } } + description={ __( + 'Required to connect with Google', + 'google-listings-and-ads' + ) } + indicator={ + + { __( 'Connect', 'google-listings-and-ads' ) } + + } + /> + ); +}; + +export default WPComAccountCard; From 70ca60b654c51191d887ea83953d11ab5caaecd7 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Fri, 29 Oct 2021 01:26:57 +0800 Subject: [PATCH 3/9] Move WPComAccountCard. --- js/src/setup-mc/setup-stepper/setup-accounts/index.js | 2 +- .../{ => wordpressdotcom-account}/wpcom-account-card/index.js | 0 .../wpcom-account-card/wp-logo.svg | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename js/src/setup-mc/setup-stepper/setup-accounts/{ => wordpressdotcom-account}/wpcom-account-card/index.js (100%) rename js/src/setup-mc/setup-stepper/setup-accounts/{ => wordpressdotcom-account}/wpcom-account-card/wp-logo.svg (100%) diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/index.js index 8c8e4b7319..88187d31c9 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/index.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/index.js @@ -20,7 +20,7 @@ import WordPressDotComAccount from './wordpressdotcom-account'; import GoogleAccountCard from '.~/components/google-account-card'; import GoogleMCAccount from './google-mc-account'; import Faqs from './faqs'; -import WPComAccountCard from './wpcom-account-card'; +import WPComAccountCard from './wordpressdotcom-account/wpcom-account-card'; const SetupAccounts = ( props ) => { const { onContinue = () => {} } = props; diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/index.js similarity index 100% rename from js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/index.js rename to js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/index.js diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/wp-logo.svg b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/wp-logo.svg similarity index 100% rename from js/src/setup-mc/setup-stepper/setup-accounts/wpcom-account-card/wp-logo.svg rename to js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/wp-logo.svg From 86705dab9412b3cac61bd07cdb6159afe92271b5 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Fri, 29 Oct 2021 01:34:15 +0800 Subject: [PATCH 4/9] Code refactor with ConnectWPComAccountCard. --- .../setup-stepper/setup-accounts/index.js | 4 +- .../connect-wpcom-account-card.js | 55 +++++++++++++++++++ .../wpcom-account-card/index.js | 40 +------------- 3 files changed, 59 insertions(+), 40 deletions(-) create mode 100644 js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-wpcom-account-card.js diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/index.js index 88187d31c9..68ec858e97 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/index.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/index.js @@ -20,7 +20,7 @@ import WordPressDotComAccount from './wordpressdotcom-account'; import GoogleAccountCard from '.~/components/google-account-card'; import GoogleMCAccount from './google-mc-account'; import Faqs from './faqs'; -import WPComAccountCard from './wordpressdotcom-account/wpcom-account-card'; +import ConnectWPComAccountCard from './wordpressdotcom-account/connect-wpcom-account-card'; const SetupAccounts = ( props ) => { const { onContinue = () => {} } = props; @@ -64,7 +64,7 @@ const SetupAccounts = ( props ) => { > - + diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-wpcom-account-card.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-wpcom-account-card.js new file mode 100644 index 0000000000..c938d08885 --- /dev/null +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-wpcom-account-card.js @@ -0,0 +1,55 @@ +/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import AppButton from '.~/components/app-button'; +import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; +import useApiFetchCallback from '.~/hooks/useApiFetchCallback'; +import WPComAccountCard from './wpcom-account-card'; + +const ConnectWPComAccountCard = () => { + const { createNotice } = useDispatchCoreNotices(); + const [ fetchJetpackConnect, { loading, data } ] = useApiFetchCallback( { + path: '/wc/gla/jetpack/connect', + } ); + + const handleConnectClick = async () => { + try { + const d = await fetchJetpackConnect(); + window.location.href = d.url; + } catch ( error ) { + createNotice( + 'error', + __( + 'Unable to connect your WordPress.com account. Please try again later.', + 'google-listings-and-ads' + ) + ); + } + }; + + return ( + + { __( 'Connect', 'google-listings-and-ads' ) } + + } + /> + ); +}; + +export default ConnectWPComAccountCard; diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/index.js index 9fade8bf1b..11f1fc99cf 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/index.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/wpcom-account-card/index.js @@ -7,32 +7,9 @@ import { __ } from '@wordpress/i18n'; * Internal dependencies */ import AccountCard from '.~/components/account-card'; -import AppButton from '.~/components/app-button'; -import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; -import useApiFetchCallback from '.~/hooks/useApiFetchCallback'; import wpLogoURL from './wp-logo.svg'; -const WPComAccountCard = () => { - const { createNotice } = useDispatchCoreNotices(); - const [ fetchJetpackConnect, { loading, data } ] = useApiFetchCallback( { - path: '/wc/gla/jetpack/connect', - } ); - - const handleConnectClick = async () => { - try { - const d = await fetchJetpackConnect(); - window.location.href = d.url; - } catch ( error ) { - createNotice( - 'error', - __( - 'Unable to connect your WordPress.com account. Please try again later.', - 'google-listings-and-ads' - ) - ); - } - }; - +const WPComAccountCard = ( props ) => { return ( { ), title: 'WordPress.com', } } - description={ __( - 'Required to connect with Google', - 'google-listings-and-ads' - ) } - indicator={ - - { __( 'Connect', 'google-listings-and-ads' ) } - - } + { ...props } /> ); }; From 54d043a47c6cff1721e8129821bc78cc55673379 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Fri, 29 Oct 2021 01:49:43 +0800 Subject: [PATCH 5/9] Add ConnectedWPComAccountCard. --- .../connected-wpcom-account-card.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js new file mode 100644 index 0000000000..eb9e73abe1 --- /dev/null +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js @@ -0,0 +1,25 @@ +/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import getConnectedJetpackInfo from '.~/utils/getConnectedJetpackInfo'; +import WPComAccountCard from './wpcom-account-card'; + +const ConnectedWPComAccountCard = ( { jetpack } ) => { + return ( + + TODO: { __( 'Connected', 'google-listings-and-ads' ) } + + } + /> + ); +}; + +export default ConnectedWPComAccountCard; From 828c3cf14020ff12ea1a052bb1a2e5428aba6ef4 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Fri, 29 Oct 2021 01:54:23 +0800 Subject: [PATCH 6/9] Code refactor with new component structure. Remove old CardContent and ConnectAccount, and use new ConnectWPComAccountCard and ConnectedWPComAccountCard instead. Also simplify code by passing down jetpack as props to WordPressDotComAccount, so we don't need to use useJetpackAccount hook and check for isResolving, it was never called anyway because the check has been done in SetupAccounts. --- .../setup-stepper/setup-accounts/index.js | 4 +- .../wordpressdotcom-account/card-content.js | 46 ---------------- .../connect-account.js | 55 ------------------- .../wordpressdotcom-account/index.js | 18 +++--- 4 files changed, 9 insertions(+), 114 deletions(-) delete mode 100644 js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/card-content.js delete mode 100644 js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-account.js diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/index.js index 68ec858e97..807251fccc 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/index.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/index.js @@ -20,7 +20,6 @@ import WordPressDotComAccount from './wordpressdotcom-account'; import GoogleAccountCard from '.~/components/google-account-card'; import GoogleMCAccount from './google-mc-account'; import Faqs from './faqs'; -import ConnectWPComAccountCard from './wordpressdotcom-account/connect-wpcom-account-card'; const SetupAccounts = ( props ) => { const { onContinue = () => {} } = props; @@ -63,8 +62,7 @@ const SetupAccounts = ( props ) => { ) } > - - + diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/card-content.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/card-content.js deleted file mode 100644 index 392f5480d3..0000000000 --- a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/card-content.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * External dependencies - */ -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ -import getConnectedJetpackInfo from '.~/utils/getConnectedJetpackInfo'; -import AppSpinner from '.~/components/app-spinner'; -import TitleButtonLayout from '.~/components/title-button-layout'; -import ConnectAccount from './connect-account'; -import useJetpackAccount from '.~/hooks/useJetpackAccount'; - -const CardContent = () => { - const { jetpack, isResolving } = useJetpackAccount(); - - if ( isResolving ) { - return ; - } - - if ( ! jetpack ) { - return ( - - ); - } - - if ( jetpack.active === 'yes' ) { - return ( - - ); - } - - if ( jetpack.active === 'no' ) { - return ; - } - - return null; -}; - -export default CardContent; diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-account.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-account.js deleted file mode 100644 index db7dc9dd42..0000000000 --- a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connect-account.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * External dependencies - */ -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ -import AppButton from '.~/components/app-button'; -import TitleButtonLayout from '.~/components/title-button-layout'; -import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; -import useApiFetchCallback from '.~/hooks/useApiFetchCallback'; - -const ConnectAccount = () => { - const { createNotice } = useDispatchCoreNotices(); - const [ fetchJetpackConnect, { loading, data } ] = useApiFetchCallback( { - path: '/wc/gla/jetpack/connect', - } ); - - const handleConnectClick = async () => { - try { - const d = await fetchJetpackConnect(); - window.location.href = d.url; - } catch ( error ) { - createNotice( - 'error', - __( - 'Unable to connect your WordPress.com account. Please try again later.', - 'google-listings-and-ads' - ) - ); - } - }; - - return ( - - { __( 'Connect', 'google-listings-and-ads' ) } - - } - /> - ); -}; - -export default ConnectAccount; diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/index.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/index.js index 76a4df974a..ea8116945c 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/index.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/index.js @@ -1,17 +1,15 @@ /** * Internal dependencies */ -import Section from '.~/wcdl/section'; -import CardContent from './card-content'; +import ConnectedWPComAccountCard from './connected-wpcom-account-card'; +import ConnectWPComAccountCard from './connect-wpcom-account-card'; -const WordPressDotComAccount = () => { - return ( - - - - - - ); +const WordPressDotComAccount = ( { jetpack } ) => { + if ( jetpack.active === 'yes' ) { + return ; + } + + return ; }; export default WordPressDotComAccount; From 6ffab4f9d210641337f576deb38f8781d6b20239 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Fri, 29 Oct 2021 02:39:03 +0800 Subject: [PATCH 7/9] Display ConnectedIconLabel in ConnectedWPComAccountCard. --- .../components/connected-icon-label/index.js | 31 +++++++++++++++++++ .../connected-icon-label/index.scss | 8 +++++ .../connected-wpcom-account-card.js | 12 ++----- 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 js/src/components/connected-icon-label/index.js create mode 100644 js/src/components/connected-icon-label/index.scss diff --git a/js/src/components/connected-icon-label/index.js b/js/src/components/connected-icon-label/index.js new file mode 100644 index 0000000000..e355a59ef6 --- /dev/null +++ b/js/src/components/connected-icon-label/index.js @@ -0,0 +1,31 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; +import { __ } from '@wordpress/i18n'; +import { Flex, FlexItem } from '@wordpress/components'; +import GridiconCheckmarkCircle from 'gridicons/dist/checkmark-circle'; + +/** + * Internal dependencies + */ +import './index.scss'; + +const ConnectedIconLabel = ( props ) => { + const { className } = props; + + return ( +
+ + + + + + { __( 'Connected', 'google-listings-and-ads' ) } + + +
+ ); +}; + +export default ConnectedIconLabel; diff --git a/js/src/components/connected-icon-label/index.scss b/js/src/components/connected-icon-label/index.scss new file mode 100644 index 0000000000..f97feb40d5 --- /dev/null +++ b/js/src/components/connected-icon-label/index.scss @@ -0,0 +1,8 @@ +.gla-connected-icon-label { + fill: currentColor; + color: #23A713; + + svg { + display: block; + } +} diff --git a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js index eb9e73abe1..5a1afa2684 100644 --- a/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js +++ b/js/src/setup-mc/setup-stepper/setup-accounts/wordpressdotcom-account/connected-wpcom-account-card.js @@ -1,23 +1,15 @@ -/** - * External dependencies - */ -import { __ } from '@wordpress/i18n'; - /** * Internal dependencies */ import getConnectedJetpackInfo from '.~/utils/getConnectedJetpackInfo'; import WPComAccountCard from './wpcom-account-card'; +import ConnectedIconLabel from '.~/components/connected-icon-label'; const ConnectedWPComAccountCard = ( { jetpack } ) => { return ( - TODO: { __( 'Connected', 'google-listings-and-ads' ) } - - } + indicator={ } /> ); }; From c21b63dd233e816b68b8372762959da3403342f1 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Fri, 29 Oct 2021 02:57:35 +0800 Subject: [PATCH 8/9] Fix css linting. --- js/src/components/connected-icon-label/index.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/components/connected-icon-label/index.scss b/js/src/components/connected-icon-label/index.scss index f97feb40d5..441efedd7e 100644 --- a/js/src/components/connected-icon-label/index.scss +++ b/js/src/components/connected-icon-label/index.scss @@ -1,6 +1,6 @@ .gla-connected-icon-label { fill: currentColor; - color: #23A713; + color: #23a713; svg { display: block; From c0e5b96e2026b40c760c1cecfe33ef127d571ec2 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Sat, 30 Oct 2021 02:02:37 +0800 Subject: [PATCH 9/9] Remove unnecessary div in ConnectedIconLabel. --- .../components/connected-icon-label/index.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/js/src/components/connected-icon-label/index.js b/js/src/components/connected-icon-label/index.js index e355a59ef6..c25836ede5 100644 --- a/js/src/components/connected-icon-label/index.js +++ b/js/src/components/connected-icon-label/index.js @@ -15,16 +15,18 @@ const ConnectedIconLabel = ( props ) => { const { className } = props; return ( -
- - - - - - { __( 'Connected', 'google-listings-and-ads' ) } - - -
+ + + + + + { __( 'Connected', 'google-listings-and-ads' ) } + + ); };