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

cc-pricing-*: handle multi-currency, add state, typecheck, fix small issues & cleanup #1218

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

florian-sanders-cc
Copy link
Contributor

@florian-sanders-cc florian-sanders-cc commented Oct 24, 2024

What does this PR do?

  • Adapt pricing components to support currency data coming from the priceSystem endpoint:
    • currency is now a simple string ("EUR", "USD", etc.),
    • the hard coded change rate has been removed,
    • components no longer compute the price related to the selected currency using the hard coded change rate,
    • instead they rely on prices provided by the priceSystem endpoint,
    • this also means that smart components showing prices (cc-pricing-product, cc-pricing-product-consumption & cc-pricing-estimation) support an optional currency context parameter.
    • a cc-pricing-estimation.smart has been created because everytime the currency changed, it used to compute the new prices based on the hard coded change rate,
    • now that the change rate is gone, the cc-pricing-estimation relies on the priceSystem to find the product prices for the selected currency and compute the total price based on quantity.
    • this also impacts cc-pricing-product-consumption because prices for "countable" products (consumption based products) rely on intervals.
      • Each interval corresponds to a price range to which a specific price applies (check pulsar / cellar products for instance). Some intervals are progressive (like taxes in France) and some are not (as soon as you reach a threshold, the previous threshold no longer applies). Ping me if you need explanation about this but playing with the prod pricing page should help too.
      • All of this means that computing prices for consumption based products is a lot more complex than for others, which is why you'll see that I've reused the whole logic (PricingSimulator class) used by the cc-pricing-product-consumption for the cc-pricing-estimation.
  • Fix a few other things:
    • in cc-pricing-product.smart-addon.js, the addonFeatures was mandatory even though it had a default value which doesn't make sense. It is now optional.
    • in every pricing smart component, the zoneId was mandatory even though it had a default value which doesn't make sense. It is now optional.
    • Reintroduce apiConfig as an optional context parameter for all pricing smart components:
      • it wasn't possible to add it before because we didn't support optional context params,
      • the apiConfig param is optional because these components require no authentication.
  • Typecheck everything and move things around (especially for stories, to avoid duplicating too much code).

How to review?

Some stuff was left unchanged, for instance temporality features, responsive & CSS overall.
You should focus on currency, states, smart, and how the components work / interact together when adding / removing product / changing currency, etc.
If you don't have much time, it's better to spend it playing with the component as stated above than actually checking the code thoroughly.

  • check the code (by commit seems doable but you can do whatever you prefer),
  • check the stories of each pricing component,
  • check the demo-smart/cc-pricing-page page (this is where you should play the most with the component).

@florian-sanders-cc florian-sanders-cc self-assigned this Oct 24, 2024
@florian-sanders-cc florian-sanders-cc marked this pull request as draft October 24, 2024 16:54
@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch 6 times, most recently from 3666269 to 62af712 Compare October 30, 2024 09:35
Copy link
Contributor

🔎 A preview has been automatically published : https://clever-components-preview.cellar-c2.services.clever-cloud.com/cc-pricing-components/states-typecheck-and-multicurrency/index.html.

This preview will be deleted once this PR is closed.

@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch 4 times, most recently from aa58745 to b6f5fed Compare October 30, 2024 10:44
@florian-sanders-cc florian-sanders-cc marked this pull request as ready for review October 30, 2024 11:09
@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch from b6f5fed to 1430178 Compare October 30, 2024 11:15
@florian-sanders-cc florian-sanders-cc changed the title --wip-- [skip ci] cc-pricing-*: handle multi-currency, add state, typecheck, fix small issues & cleanup Oct 30, 2024
Copy link
Contributor

@pdesoyres-cc pdesoyres-cc left a comment

Choose a reason for hiding this comment

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

What an awesome PR! So much things tackeled in a very complex component. So, well done Florian.

During my tests, I did not encountered any problems.

However, I left some comments (and some questions too).

src/stories/cc-pricing-page-sandbox.js Outdated Show resolved Hide resolved
src/stories/cc-pricing-page-sandbox.js Outdated Show resolved Hide resolved
src/stories/cc-pricing-page-sandbox.js Outdated Show resolved Hide resolved
src/stories/cc-pricing-page-sandbox.js Show resolved Hide resolved
src/stories/fixtures/price-system.js Show resolved Hide resolved
src/lib/utils.js Show resolved Hide resolved
@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch 2 times, most recently from 1a54752 to 09730b7 Compare November 25, 2024 17:14
Copy link
Member

@Galimede Galimede left a comment

Choose a reason for hiding this comment

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

Thanks Florian for handling this, that's nice GG! 💪 🤗

  • No problem found on Safari
  • Apart of Pierre's nitpicks, I've just a very small one

As we discussed in sync, the +/- buttons on the pricing-estimation lack a cursor: pointer on hover

image

@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch 2 times, most recently from e1760e4 to af21fd9 Compare November 29, 2024 16:22
@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch 2 times, most recently from 373e4c6 to abed39d Compare November 29, 2024 16:39
Copy link
Member

@Galimede Galimede left a comment

Choose a reason for hiding this comment

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

Small question but LGTM, thanks Florian! 💪

The new fetch is triggered by changing the context of their common smart container when the zone or currency changes.
The typical HTML for a basic `cc-pricing-page` implementation looks like this:
```html
<cc-smart-container context='{
Copy link
Member

Choose a reason for hiding this comment

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

question: now that apiConfig is mandatory, shouldn't it appear here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, forgot about that, thanks!

Copy link
Contributor

@pdesoyres-cc pdesoyres-cc left a comment

Choose a reason for hiding this comment

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

LGTM. well done for this huge work!

BREAKING CHANGE: the component no longer supports hard coded change rate
Prices displayed in pricing components are no longer computed based on
hard coded change rate.
Prices related to the selected currency come from the API priceSytem
endpoint.

This means that some types for the component properties have changed:
- `currency` is now a `string` (ISO 4217 currency code),
- `selectedCurrency` is now a `string` (ISO 4217 currency code).

Fixes #1167
Smart components:
- The `addonFeatures` context parameter of the `cc-pricing-product.smart-addon`
component is now optional as it should always have been
(default value: `[]` meaning that all features are displayed by default).
- The `zoneId` context parameter of both `cc-pricing-product.smart-addon` &
`cc-pricing-product.smart-runtime` is now optional (default value: `'par'`).

BREAKING CHANGE: the component no longer supports hard coded change rate
Prices displayed in pricing components are no longer computed based on
hard coded change rate.
Prices related to the selected currency come from the API priceSytem
endpoint.
The component also relies on the new `state` prop for data coming from
the API.

This means that some types for the component properties have changed:
- `currency` is now a `string` (ISO 4217 currency code),
- `product` has been removed,
- `state` has been added to replace `product`,
  - `product.state` is now `state.type`.

The payload type of the `cc-pricing-product:add-plan` dispatched event has changed.
Plans must now include a `priceId` property to be handled by the
`cc-pricing-estimation` correctly. This also means that custom products
/ plans can no longer be added to the estimation because they are not
part of the priceSystem and have no `priceId`.

The payload type of the `cc-pricing-product:add-plan` dispatched event has changed.
Plans must now include a `priceId` property to be handled by the
`cc-pricing-estimation` correctly. This also means that custom products
/ plans can no longer be added to the estimation because they are not
part of the priceSystem and have no `priceId`.

Fixes #1167
Fixes #1109
Fixes #1174
Fixes #1176
…urrency

Smart components:
- The `zoneId` context parameter of `cc-pricing-product-consumption.smart`
is now optional (default value: `'par'`).

BREAKING CHANGE: the component no longer supports hard coded change rate
Prices displayed in pricing components are no longer computed based on
hard coded change rate.
Prices related to the selected currency come from the API priceSytem
endpoint.
The component also relies on the new `state` prop for data coming from
the API.

This means that some types for the component properties have changed:
- `currency` is now a `string` (ISO 4217 currency code),
- `product` has been removed,
- `state` has been added to replace `product`,
  - `product.state` is now `state.type`.

The type of the payload dispatched with the event
`cc-pricing-product:add-plan` has changed:
- `sections` (`Array<PricingSection>`) are now part of the payload so
  that prices can be computed by the `cc-pricing-estimation` component
  everytime the currency changes.

Fixes #1167
Fixes #1176
Fixes #1109
…em currency

BREAKING CHANGE: the component no longer supports hard coded change rate
Prices displayed in pricing components are no longer computed based on
hard coded change rate.
Prices related to the selected currency come from the API priceSytem
endpoint.
This means the component now has a dedicated smart component (
`cc-pricing-estimation.smart`) to fetch the `priceSystem` corresponding to
the selected currency everytime it changes.

The component also relies on the new `state` prop for data coming from
the API.

This means that some types for the component properties have changed:
- `selectedCurrency` is now a `string` (ISO 4217 currency code),
- `currency` is now a `string` (ISO 4217 currency code),
- `state` has been added to receive data from the `priceSystem`.

Fixes #1167
BREAKING CHANGE: the component no longer supports hard coded change rate
Prices displayed in pricing components are no longer computed based on
hard coded change rate.
Prices related to the selected currency come from the API priceSytem
endpoint.

This means that some types for the component properties have changed:
- `selectedCurrency` is now a `string` (ISO 4217 currency code),
- `selectedPlans` now handles plans differently (they must have a
  `priceId` if they come from `cc-pricing-product` or `sections` if they
  come from `cc-pricing-product-consumption`).

Fixes #1167
@florian-sanders-cc florian-sanders-cc force-pushed the cc-pricing-components/states-typecheck-and-multicurrency branch from abed39d to 458dce3 Compare December 4, 2024 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants