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

Handle all loading states within the PhoneNumberCard component #934

Merged
merged 5 commits into from
Aug 6, 2021

Conversation

eason9487
Copy link
Member

@eason9487 eason9487 commented Aug 5, 2021

Changes proposed in this Pull Request:

It's a follow-up for #917 (comment).

  • Handle all loading states within the PhoneNumberCard component to show more card content as soon as possible.

This's a refactor PR and didn't affect the functionality of the Contact Information feature. It could be reviewed and (maybe) merged after the Contact Information is released.

Screenshots:

MC setup

  • When the phone number is empty
    Kapture 2021-08-05 at 12 19 19
  • When the phone number exists
    Kapture 2021-08-05 at 12 21 30

Settings

  • When refreshing the edit contact info page
    Kapture 2021-08-05 at 12 23 15

Detailed test instructions:

To enter the MC setup step 4 directly, it could replace this line in js/src/setup-mc/setup-stepper/saved-setup-stepper.js by

const [ step, setStep ] = useState( '4' );

To mock the API response of phone number and add more delay to view the loading state, it could add PHP snippet in google-listings-and-ads.php.

add_filter(
	'woocommerce_gla_prepared_response_mc-contact-information',
	function( $response ) {
		sleep( 1 );
		return [
			'is_mc_address_different' => false,
			'phone_number' => '+12133734253',
			'wc_address' => [
				'street_address' => '',
			],
		];
	},
);
  1. Go to the MC setup and settings pages with empty/existed phone number
  2. Check the loading spinner is shown within the PhoneNumberCard component instead of the parent layer for all cases

Changelog entry

@eason9487 eason9487 requested a review from a team August 5, 2021 05:03
@eason9487 eason9487 self-assigned this Aug 5, 2021
@eason9487 eason9487 added the category: refactor The issue/PR is related to refactoring. label Aug 5, 2021
@ecgan
Copy link
Member

ecgan commented Aug 5, 2021

@eason9487 , for the settings page:

Do we want to show the "horizontal divider" line when the loading is in progress? I think it would look nicer, and it would be consistent with the store address UI below it too.

Copy link
Member

@ecgan ecgan left a comment

Choose a reason for hiding this comment

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

Tested, working as expected. Left a few 💅 comments. Approving. 👍

Comment on lines +159 to +172
/**
* Renders phone number data in Card UI and is able to edit.
*
* @param {Object} props React props.
* @param {PhoneNumber} props.phoneNumber Phone number data.
* @param {boolean} [props.isPreview=false] Whether to display as preview UI.
* @param {boolean|null} [props.initEditing=null] Specify the inital UI state. This prop would be ignored if `isPreview` is true.
* `true`: initialize with the editing UI.
* `false`: initialize with the viewing UI.
* `null`: determine the initial UI state according to the `data.isValid` after the `phoneNumber` loaded.
* @param {Function} [props.onEditClick] Called when clicking on "Edit" button.
* If this callback is omitted, it will enter edit mode when clicking on "Edit" button.
* @param {onPhoneNumberChange} [props.onPhoneNumberChange] Called when inputs of phone number are changed in edit mode.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the JSDoc! 😻

Comment on lines +185 to +189
useEffect( () => {
if ( loaded && isEditing === null ) {
setEditing( ! data.isValid );
}
}, [ loaded, data.isValid, isEditing ] );
Copy link
Member

Choose a reason for hiding this comment

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

💅 It took me a while to figure out this relates to your JSDoc comment "determine the initial UI state according to the `data.isValid` after the `phoneNumber` loaded.". Would be good to have a comment to explain this, or even refactor it.

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 a comment by 63460f7.

@eason9487
Copy link
Member Author

eason9487 commented Aug 6, 2021

@ecgan

Do we want to show the "horizontal divider" line when the loading is in progress? I think it would look nicer, and it would be consistent with the store address UI below it too.

Thank you for noticing this. I added by 3897636 and it looks nicer. 👍

Kapture 2021-08-06 at 10 22 18

eason9487 added a commit that referenced this pull request Aug 6, 2021
Address #934 (comment)

Co-authored-by: Gan Eng Chin <ecgan@users.noreply.github.com>
Address #934 (comment)

Co-authored-by: Gan Eng Chin <ecgan@users.noreply.github.com>
@eason9487 eason9487 force-pushed the feature/phone-number-card-loading branch from 537da07 to 968ab62 Compare August 6, 2021 02:45
@eason9487 eason9487 merged commit 967e010 into feature/contact-info Aug 6, 2021
@eason9487 eason9487 deleted the feature/phone-number-card-loading branch August 6, 2021 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: refactor The issue/PR is related to refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants