-
Notifications
You must be signed in to change notification settings - Fork 21
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
Detect the verification status of the phone number to the contact information settings #1717
Conversation
…_contact_information_setup
…PhoneNumber` hook
… the previous steps
@@ -117,14 +117,27 @@ const PhoneNumberCard = ( { | |||
} ) => { | |||
const { loaded, data } = phoneNumber; | |||
const [ isEditing, setEditing ] = useState( initEditing ); | |||
const onPhoneNumberVerifiedRef = useRef(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 inuseEffect
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 } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrased in 0ae56ea.
// 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this 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 ] ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 290da41.
* `true`: initialize with the editing UI. | ||
* `false`: initialize with the viewing UI. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…tInformation component since it's the same as the default value. Address #1717 (comment)
…'s `initEditing` prop and related processing. Address - #1717 (comment) - #1717 (comment)
…onPhoneNumberVerified in PhoneNumberCard. Address #1717 (comment)
…tInformationController. Address #1717 (comment)
…er_verified` in MerchantCenterService. Address #1717 (comment)
Changes proposed in this Pull Request:
Closes #1033
mc/contact-information
.mc/setup
.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:
mc/setup
API should consider step 3 was completed.Changelog entry