-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Checkout: Add the “Number of licenses” dropdown in Akismet checkout #84393
Checkout: Add the “Number of licenses” dropdown in Akismet checkout #84393
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~785 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~785 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
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.
Tested following the instructions and it works as described! I don't have any specific concerns, but I did notice some untranslated strings which I noted inline.
client/my-sites/checkout/src/components/akismet-pro-quantity-dropdown/index.tsx
Outdated
Show resolved
Hide resolved
with the logic & functionality to adjust the licensed-quantity value of the Akismet Pro 500 product.
9c9178e
to
15f4e2b
Compare
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.
Looks fine to me although I don't know the details of your project so I leave final review to your team.
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.
Left some comments, mostly nitpicks. I think my biggest thought is about trying to determine the akismet specific values later on rather than at the top layer of the checkout
import { FunctionComponent, useEffect, useCallback, useState } from 'react'; | ||
import FormLabel from 'calypso/components/forms/form-label'; | ||
import FormSelect, { FormSelectProps } from 'calypso/components/forms/form-select'; |
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.
Nitpick, you can import the FormSelectProps and FunctionComponent types separately as a type like as is done below with AkismetProQuantityDropDownProps
import type { AkismetProQuantityDropDownProps } from './types'; | ||
|
||
const AkismetSitesSelectHeading = styled.div` | ||
font-size: 1.1em; |
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 think we should probably use rem
here right? I guess I am not sure but that's generally what I see being used
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.
Yeah I'm not sure... I was thinking that too, but looking at the rest of the checkout package, it seems to be using em
's . For example, all throughout this file: https://github.com/Automattic/wp-calypso/blob/trunk/packages/wpcom-checkout/src/checkout-line-items.tsx#L89
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.
rem
is probably more ideal to ensure a consistent styling across the interface, but I think em
was just used enough that it took root in the package. This could be something we consider going forward with the checkout redesign.
} ) => { | ||
const translate = useTranslate(); | ||
|
||
const [ quantityState, setQuantityState ] = useState( responseCart.products[ 0 ].quantity ?? 1 ); |
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 looks like this default state sets the quantity to 1 if the parameter is any higher than for (i.e. :-q-9
) I think we might want to just default it to the highest quantity possible, in this case 4, if this is the case. It's probably not a big deal since the user would have to manually change the URL but I think that default makes more sense in that specific scenario
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.
No, I believe I have this as intended. I want the initial state of the dropdown to be the quantity value of Akismet Pro product that is currently in the cart (for example if the user has 3 sites selected (quantity: 3) and the user reloads/refreshes the checkout page), or if the current quantity is 0 or undefined (non truthy) for whatever reason, then it should default to 1 site (quantity 1).
<option key="quantity-1" value="1"> | ||
{ translate( '1 Site' ) } | ||
</option> | ||
<option key="quantity-2" value="2"> | ||
{ translate( '2 Sites' ) } | ||
</option> | ||
<option key="quantity-3" value="3"> | ||
{ translate( '3 Sites' ) } | ||
</option> | ||
<option key="quantity-4" value="4"> | ||
{ translate( '4 Sites' ) } | ||
</option> |
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 is opinionated, but i'd put this into some sort of mapping function since they're all exactly the same except for the number. So like for i from 1 to 4 return <option>
.... etc
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.
Yeah good point, thanks for the feedback. I'll go ahead and do that. 👍
I didn't do that initially because in a followup PR I'll be adding "Unlimited sites (Akismet Business)" as a 5th option in the dropdown, but I can still map through the first 4 and then append the "Unlimited sites (Akismet Business)" option to the end (in a followup PR).
recordTracksEvent( 'calypso_checkout_akismet_pro_quantity_change', { | ||
product_slug: productSlug, | ||
new_quantity: newQuantity, | ||
} ) |
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.
Would it be possible to track previous quantity here as well? I am not sure but it seems like it might be useful info
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.
Yeah good point! Might be useful info. Will do. 👍
isAkPro500Cart={ isAkismetProMultipleLicensesCart } | ||
onChangeAkProQuantity={ changeAkismetPro500CartQuantity } |
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 think we should try and avoid passing these values in so early and then passing them 2-3 more components. Would it be possible to determine these values from the component that uses them? (i.e. wp-order-review-line-items)
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.
Yes, I'll move them to wp-order-review-line-items.tsx
.
Is there a reason the new dropdown for the number of licenses differs so much from the existing dropdowns found in checkout? Original dropdown New dropdown You could perhaps lift the styles off of the existing ItemVariationDropDown component to get a closer approximation. |
@jjchrisdiehl, Thanks for reviewing and for your feedback! 🙂
Yeah, the billing-term variation picker is actually made with a combination of HTML buttons and react state that make it look and behave like an HTML Select dropdown element, except that opposed to an actual Select element, it does not take on the default styles and unique browser behavior than an HTML Select dropdown element has (especially when using a mobile device). |
Just like the billing-term variant picker.
Re: translating strings Some of the strings, like |
`; | ||
|
||
const AkismetSitesSelectHeading = styled.div` | ||
font-size: ${ hasCheckoutVersion( '2' ) ? '14px' : 'inherit' }; |
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.
The ${ hasCheckoutVersion( '2' ) }
code is actually only temporarily added for our recent Checkout Redesign project, since this doesn't include Akismet or Jetpack checkout it may be good to remove these ternaries. @sirbrillig I'm not sure this would harm the end user experience at all, it may just be something we have to remember to clean up later if this PR is merged with the function in place.
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've removed the hasCheckoutVersion
ternaries (and import). 👍
Thanks so much for reviewing and for your feedback @jjchrisdiehl! 🙌
@@ -0,0 +1,253 @@ | |||
import { Gridicon } from '@automattic/components'; | |||
import { hasCheckoutVersion } from '@automattic/wpcom-checkout'; |
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.
The import can be removed too
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
padding: ${ hasCheckoutVersion( '2' ) ? '4px 16px' : '14px 16px' }; |
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.
Here too
const Dropdown = styled.div` | ||
position: relative; | ||
width: 100%; | ||
margin: ${ hasCheckoutVersion( '2' ) ? '6px 0' : '16px 0' }; |
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.
Here too
Ahh yes, I see! Thank you @jjchrisdiehl! TIL! |
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.
Tests good to me, seems like all feedback was addressed 👍
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/10069676 Some locales (Hebrew, Japanese) have been temporarily machine-translated due to translator availability. All other translations are usually ready within a few days. Untranslated and machine-translated strings will be sent for translation next Monday and are expected to be completed by the following Friday. Thank you @elliottprogrammer for including a screenshot in the description! This is really helpful for our translators. |
Translation for this Pull Request has now been finished. |
In this PR we add the "Number of licenses" dropdown in Akismet checkout, along with the logic & functionality to adjust the Akismet Pro 500 product's licensed-quantity value. (see image and project links below)
Related to:
Still TODO in a follow-up PR(s):
Possibly refactor the dropdown into dropdown-like buttons (like the billing-term variation picker) as opposed to an HTML Select element (because the default styles and behavior of an HTML Select element is possibly undesired (especially in mobile view) in checkout).Testing Instructions
public-api.wordpress.com
.yarn-start
https://wordpress.com
withhttp://calypso.localhost:3000
and press enter.Enter
orspace
opens the dropdown.up
anddown
arrows to change the quantity,Enter
to select.)Pre-merge Checklist