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

Detect the verification status of the phone number to the contact information settings #1717

Conversation

eason9487
Copy link
Member

Changes proposed in this Pull Request:

Closes #1033

  • Add the verification status of the phone number to the API GET mc/contact-information.
  • Add a phone verification status check to the API GET mc/setup.
  • Detect the verification status of the phone number in the onboarding flow.
  • Add the verification status of the phone number to PhoneNumberCardPreview component.

Screenshots:

💡 The phone numbers shown in the following videos were temporarily changed to mocks in my local env. It still uses a real phone number when communicating with APIs.

📹 Onboarding flow

Kapture.2022-10-05.at.14.17.30.mp4

📹 Settings page

Kapture.2022-10-05.at.14.21.49.mp4

Detailed test instructions:

  1. Go to the admin page of Google Merchant Center and save an Unverified phone number. https://merchants.google.com/mc/merchantprofile/businessinfo
  2. Go to the onboarding flow of GLA.
  3. When entering step 3, the phone number card in the contact info settings should be in editing mode.
  4. Verify a phone number and complete step 3.
  5. After refreshing page, it should start with step 4 since the mc/setup API should consider step 3 was completed.
  6. Back to step 3, the phone number card in the contact info settings should not be in editing mode.
  7. Finish the onboarding flow and go to GLA settings page.
  8. Check if there is a "Verified" status shown under the phone number.
  9. Revisit the admin page of Google Merchant Center and save an Unverified phone number again.
  10. Refresh GLA settings page to see if the verification status is changed to "Unverified".

Changelog entry

Update - Detect the verification status of the phone number in the contact information settings.

@eason9487 eason9487 requested a review from a team October 5, 2022 07:33
@eason9487 eason9487 self-assigned this Oct 5, 2022
@github-actions github-actions bot added the changelog: update Big changes to something that wasn't broken. label Oct 5, 2022
@@ -117,14 +117,27 @@ const PhoneNumberCard = ( {
} ) => {
const { loaded, data } = phoneNumber;
const [ isEditing, setEditing ] = useState( initEditing );
const onPhoneNumberVerifiedRef = useRef();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ What is the advantage of useRef vs useCallback?

(I take as granted this is for avoiding error as onPhoneNumberVerified needs to be a dependency in useEffect

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage of useRef vs useCallback?

I think it's probably not a choice about advantages, but rather what the concern is to be addressed here. useCallback is used when needing a callback with stable reference based on deps array. useRef has plenty of use scenarios and one of them is the need of ignoring the reference changes such as the use case here.

I take as granted this is for avoiding error as onPhoneNumberVerified needs to be a dependency in useEffect

Yes, it avoids the possibility of infinity re-rendering loop.

@@ -127,7 +116,7 @@ const ContactInformation = ( { onPhoneNumberVerified } ) => {
<PhoneNumberCard
view="setup-mc"
phoneNumber={ phone }
initEditing={ initEditing }
initEditing={ null }
Copy link
Contributor

@puntope puntope Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 We can just omit this prop initEditing. Since the default value is null

Copy link
Member Author

@eason9487 eason9487 Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in e3f4d79.

const onPhoneNumberVerifiedRef = useRef();
onPhoneNumberVerifiedRef.current = onPhoneNumberVerified;

const { isVerified } = data;

// Handle the initial UI state of `initEditing = null`.
// The `isEditing` state is on hold. Determine it after the `phoneNumber` loaded.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ don't understand this line tbh. What does it mean "The isEditing state is on hold"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased in 0ae56ea.

Comment on lines +133 to +135
// If `initEditing` is true, EditPhoneNumberCard takes care of the call of `onPhoneNumberVerified`
// after the phone number is verified. If `initEditing` is false or null, this useEffect handles
// the call of `onPhoneNumberVerified` when the loaded phone number has already been verified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ This was a bit confusing for me.

Suggestion:

When initEditing prop is not true we call onPhoneNumberVerified when the loaded phone number has already been verified.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intended to illustrate how onPhoneNumberVerified calls are handled under different conditions. I'd like to keep the explicit mention of "If initEditing is false or null" to clarify why the conditional below is a shorter one initEditing ! == true rather than a longer one ( initEditing === false || initEditing === null ), and to avoid the appearance that it could be changed to initEditing === false.

Copy link
Contributor

@puntope puntope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working good. Thanks @eason9487

I left tho a few comments regarding code :)

}
}, [ loaded, data.isValid, isEditing ] );
}, [ loaded, isVerified, initEditing ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Could be possible to have isVerified but not loaded phoneNumber?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 290da41.

Comment on lines 102 to 103
* `true`: initialize with the editing UI.
* `false`: initialize with the viewing UI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I don't understand well this concept of initialize with the editing UI and initialize with the viewing UI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased in 0ae56ea.

@@ -228,7 +234,8 @@ protected function get_contact_information_response( ?AccountBusinessInformation
if ( $contact_information instanceof AccountBusinessInformation ) {
if ( ! empty( $contact_information->getPhoneNumber() ) ) {
try {
$phone_number = PhoneNumber::cast( $contact_information->getPhoneNumber() )->get();
$phone_number = PhoneNumber::cast( $contact_information->getPhoneNumber() )->get();
$phone_verification_status = strtolower( $contact_information->getPhoneVerificationStatus() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 Maybe we can have 'VERIFIED' as well in the frontend and get rid of this strtolower function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the status fields returned by the other GLA APIs are almost always lowercase, the idea here was to keep them consistent.

@@ -310,7 +311,8 @@ protected function is_mc_contact_information_setup(): bool {
}

if ( $contact_info instanceof AccountBusinessInformation ) {
$is_setup['phone_number'] = ! empty( $contact_info->getPhoneNumber() );
$is_setup['phone_number'] = ! empty( $contact_info->getPhoneNumber() );
$is_setup['phone_verification_status'] = 'VERIFIED' === $contact_info->getPhoneVerificationStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 phone_verification_status seems not accurate naming for me. It sounds like we expect a status (like 'verified'. However we just want a booean.

So I would suggest 'phone_number_verified' or 'is_verified' or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed in 32df87f.

'type' => 'string',
'description' => __( 'The phone number associated with the Merchant Center account.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'mc_address' => [
'phone_verification_status' => [
'type' => 'string',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I guess this is an enum 'verified'|'unverified' ?? Or it could be more things?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in bba9fa3.

…step

Change the Stepper in the onboarding flow to only allow going back to the previous steps
Copy link
Member

@ianlin ianlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @puntope fo reviewing, I have checked the code and tested the PR again and there is nothing needs to be updated immediately. I created a followup issue #1724 so Eason can take a look when he gets back.

@ianlin ianlin merged commit b47ad11 into feature/1610-streamlined-onboarding Oct 12, 2022
@ianlin ianlin deleted the update/1033-phone-number-verification-status branch October 12, 2022 05:07
eason9487 added a commit that referenced this pull request Oct 17, 2022
…tInformation component since it's the same as the default value.

Address #1717 (comment)
eason9487 added a commit that referenced this pull request Oct 17, 2022
eason9487 added a commit that referenced this pull request Oct 17, 2022
eason9487 added a commit that referenced this pull request Oct 17, 2022
eason9487 added a commit that referenced this pull request Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: update Big changes to something that wasn't broken.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Submit business contact information - after phone verification status is available
3 participants