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

Add support phone and email in the admin settings page #5471

Merged
merged 17 commits into from
Feb 4, 2023

Conversation

htdat
Copy link
Member

@htdat htdat commented Jan 27, 2023

Fixes #3981

Changes proposed in this Pull Request

  • Extract two new components SupportEmailInput and SupportPhoneInput from client/card-readers/settings/sections/contacts-details.js.
  • With that, we can use them for both Card Readers setting page and WCPay general settings pages.
  • Add tests for the new components.
Before After
settings-before settings-after-with-arrow

Testing instructions

  • Checkout this PR, and run npm start.
  • Visit wp-admin > Payments > Settings.
  • See two new input fields.
  • Edit and update them.

If possible, try to test with Card Readers settings page:

  • In your local server, return true for has_card_readers_available flag/method, like this 2ef2d-pb
  • Visit wp-admin > Payments > Card Readers > Receipt Details.
  • Edit and update the same fields before and after this PR.

Note 1

GitHub action throws a SOS warning about increasing sizes of JS and CSS for the admin settings page. I think this is fine as it brings a nice UI and validation for the phone input. Under the hood, it uses the PhoneNumberInput component, which is based on 'intl-tel-input' package.

Note 2

Full Stripe accounts allow the phone to be toggled off, so it would be great if WooCommerce Payments can offer that also.

With the connected account, there is no option for this. Stripe always requires this number and here is the most detail I can get when trying to update this number via curl, Stripe Dashboard, and via API call through local server:

Markup on 2023-01-31 at 16:00:16


  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2023

Size Change: +69.7 kB (+6%) 🔍

Total Size: 1.29 MB

Filename Size Change
release/woocommerce-payments/dist/index.css 36.1 kB +11 B (0%)
release/woocommerce-payments/dist/index.js 383 kB +109 B (0%)
release/woocommerce-payments/dist/platform-checkout.css 4.02 kB +12 B (0%)
release/woocommerce-payments/dist/settings.css 51.1 kB +3.67 kB (+8%) 🔍
release/woocommerce-payments/dist/settings.js 179 kB +65.9 kB (+58%) 🆘
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 913 B
release/woocommerce-payments/assets/css/success.css 401 B
release/woocommerce-payments/dist/blocks-checkout.css 2.13 kB
release/woocommerce-payments/dist/blocks-checkout.js 37.4 kB
release/woocommerce-payments/dist/checkout.css 2.21 kB
release/woocommerce-payments/dist/checkout.js 27.9 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 56.3 kB
release/woocommerce-payments/dist/multi-currency.css 14.7 kB
release/woocommerce-payments/dist/multi-currency.js 72.7 kB
release/woocommerce-payments/dist/order.css 248 B
release/woocommerce-payments/dist/order.js 12.7 kB
release/woocommerce-payments/dist/payment-gateways.css 1.2 kB
release/woocommerce-payments/dist/payment-gateways.js 47.2 kB
release/woocommerce-payments/dist/payment-request.js 11.9 kB
release/woocommerce-payments/dist/platform-checkout-express-button.js 14.1 kB
release/woocommerce-payments/dist/platform-checkout.js 75.3 kB
release/woocommerce-payments/dist/subscription-edit-page.js 668 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 7.18 kB
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 12.8 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 703 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 298 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 44.3 kB
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 15.7 kB
release/woocommerce-payments/dist/upe_checkout.css 2.21 kB
release/woocommerce-payments/dist/upe_checkout.js 32.8 kB
release/woocommerce-payments/dist/upe-blocks-checkout.css 2.13 kB
release/woocommerce-payments/dist/upe-blocks-checkout.js 38.9 kB
release/woocommerce-payments/includes/platform-checkout/assets/css/platform-checkout-express-button.css 247 B
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 633 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 720 B
release/woocommerce-payments/vendor/automattic/jetpack-admin-ui/src/css/jetpack-icon.css 224 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.43 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.27 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.3 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.27 kB
release/woocommerce-payments/vendor/automattic/jetpack-tracking/src/js/tracks-ajax.js 789 B
release/woocommerce-payments/vendor/automattic/jetpack-tracking/src/js/tracks-callables.js 925 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.56 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.07 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 387 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.06 kB

compressed-size-action

@htdat htdat force-pushed the add/3981-support-phone-number branch from 1119ef0 to 30b511d Compare January 30, 2023 09:42
@htdat htdat force-pushed the add/3981-support-phone-number branch from 30b511d to 0b69c12 Compare January 31, 2023 05:58
@htdat htdat changed the title Add/3981 support phone number Add support phone and email in the admin settings page Jan 31, 2023
@htdat htdat requested review from a team and elazzabi January 31, 2023 09:03
@htdat htdat self-assigned this Jan 31, 2023
@htdat htdat marked this pull request as ready for review January 31, 2023 09:04
@htdat
Copy link
Member Author

htdat commented Jan 31, 2023

Ready to review!

@elazzabi - I've added you as an optional reviewer as you worked on a relevant PR #4355

Copy link
Member

@elazzabi elazzabi left a comment

Choose a reason for hiding this comment

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

The code looks good. Thank you for working on this!

@kalessil
Copy link
Contributor

Out of curiosity, is there an opportunity to use TypeScript for new files?

Context: paJDYF-6MV-p2

@htdat
Copy link
Member Author

htdat commented Feb 1, 2023

Out of curiosity, is there an opportunity to use TypeScript for new files?

@kalessil - I tried to use TypeScript but the new files use some non-TypeScript functions such as useAccountBusinessSupportEmail, useGetSavingError so that it requires more effort in other files to have the new files fully TypeScript-supported.

@kalessil
Copy link
Contributor

kalessil commented Feb 1, 2023

@kalessil - I tried to use TypeScript but the new files use some non-TypeScript functions such as useAccountBusinessSupportEmail, useGetSavingError so that it requires more effort in other files to have the new files fully TypeScript-supported.

Gotcha, thanks for sharing the details!

Copy link
Contributor

@RadoslavGeorgiev RadoslavGeorgiev left a comment

Choose a reason for hiding this comment

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

Great job @htdat , code looks clean and excellent, and also tests well! 👏

Not marking this as a request for changes, as I'm not certain they're needed, but I have a couple things to discuss.

One weird issue I encountered was not being able to save settings at all initially. After digging a bit, it turned out that Stripe rejects my valid phone number as invalid. Afterwards the server return an exception, however the exception/error is not bubbled up from WC_REST_Payments_Settings_Controller::update_account, and I see a success pill, stating settings were saved correctly. This is an issue, but not one for this PR.

@htdat
Copy link
Member Author

htdat commented Feb 2, 2023

Afterwards the server return an exception, however the exception/error is not bubbled up from WC_REST_Payments_Settings_Controller::update_account, and I see a success pill, stating settings were saved correctly. This is an issue, but not one for this PR.

I've debugged a bit and it seems that WC_Payment_Gateway_WCPay::update_account use add_error to display admin error notices in the old way rather than expose the error message from Stripe API to the rest request.

I will debug a bit more and add a new issue for this.


@RadoslavGeorgiev - I've addressed other concerns in your inline comments too. Ready to review again.

Copy link
Contributor

@RadoslavGeorgiev RadoslavGeorgiev left a comment

Choose a reason for hiding this comment

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

I will debug a bit more and add a new issue for this.

Thanks for digging into this! I'm not sure if it's applicable in contexts outside of the new fields, but in any case it would be nice to have another issue to keep track of it! 🤝


The rest of the PR looks excellent, there's just one detail that remains to be fixed :)

@@ -80,6 +84,9 @@ const Transactions = () => {
<span className="input-help-text" aria-hidden="true">
{ `${ accountStatementDescriptor.length } / ${ ACCOUNT_STATEMENT_MAX_LENGTH }` }
</span>

<SupportEmailInput onErrorMessage={ setSaveDisabled } />
<SupportPhoneInput onErrorMessage={ setSaveDisabled } />
Copy link
Contributor

Choose a reason for hiding this comment

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

The state of both inputs needs to be stored separately in order to determine whether saving is disabled or not. Right now:

  1. I opened the page with valid values in both fields.
  2. Deleted the email ➡️ The save button got disabled.
  3. Deleted the phone number ➡️ The save button remain disabled.
  4. Started typing an email (which is not validated) ➡️ The save button immediately got enabled, even though the phone number remains empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another great catch! Fixed in this commit a6a3b89

I've also updated Card Reader settings page too as it has the same issue. 404fde2

@htdat
Copy link
Member Author

htdat commented Feb 3, 2023

The rest of the PR looks excellent, there's just one detail that remains to be fixed :)

@RadoslavGeorgiev - ready for review again.

@htdat
Copy link
Member Author

htdat commented Feb 3, 2023

I will debug a bit more and add a new issue for this.

Added this issue #5516
From my observation, it seems that Stripe only allows phone numbers respective to the country of the store - #5516 (comment)

Copy link
Contributor

@RadoslavGeorgiev RadoslavGeorgiev left a comment

Choose a reason for hiding this comment

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

Looks amazing! Thank you for the polished PR, :shipit:!

@htdat htdat merged commit ebb4b40 into develop Feb 4, 2023
@htdat htdat deleted the add/3981-support-phone-number branch February 4, 2023 03:42
Copy link
Contributor

@naman03malhotra naman03malhotra left a comment

Choose a reason for hiding this comment

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

@htdat is is possible to load the <PhoneNumberInput component in a lazy fashion so that it doesn't effect the load times of the page?

@htdat
Copy link
Member Author

htdat commented Feb 21, 2023

@naman03malhotra - as discussed with you via DM. I am summarizing the discussion here.

I don’t see much slower in the page load time. In fact, the new package adds up the size of dist/settings.js but it is mostly about that size only, i.e. merchants' browsers need to fetch more ~66KB. It does not use any external fetch/request, therefore, the rendering time will not be affected much. With your question about the lazy fashion, I am not sure how to achieve (or if there is any significant benefit with that laziness) because there is no async function insides this component.

Since it was validated to use in two other places (below), I think it’s generally fine. What I am doing here is to just abstract the existing component so that it can be reused.

  • WooPay checkout page (for shoppers) - code ref.
  • wp-admin > Payments > Card Readers > Receipt Details (for merchants) - code ref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Feature for Merchants To Update Their Support Phone Number
5 participants