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

feat(core): Add currency selector to header #1912

Merged
merged 6 commits into from
Jan 22, 2025
Merged

Conversation

bookernath
Copy link
Contributor

@bookernath bookernath commented Jan 16, 2025

What/Why?

  • Adds currency selector following the same pattern used for locale selector
  • Establishes new currencyCode httpOnly cookie
  • New lib functions to customize/extend currency selection
  • Moved cart to a lib as well while I was at it
  • Decorates all queries that touch pricing to include currency code
    • ... except Cart and Orders, as currency lives on those models directly

Only transactional currencies are supported for now, because we don't have a way to render prices for the cart for a display currency from the API. Theoretically we could use the exchange rate we have access to in the API to calculate the prices within next.js, but my preference would be for all monetary values, even estimates, to come from the API. So for now, I have filtered the list of currencies to only the transactional ones.

Todo

  • Handle default currency properly once exposed in GQL API
  • Run the mutation to change the currency of an active cart if the currency is changed (handle display vs transactional currencies properly)
  • Update VIBES Add currency form makeswift/vibes#472
  • Consider adding a middleware to set this cookie with a query param such as ?setCurrency=USD for the benefit of deep linking and crawlers
    • Can be a future PR
  • Add translations

Testing

Preview deployment:

currency.mov

@bookernath bookernath requested a review from a team as a code owner January 16, 2025 04:16
Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 8ba35ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-canary ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2025 3:25am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
catalyst ⬜️ Ignored (Inspect) Jan 22, 2025 3:25am
catalyst-au ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 3:25am
catalyst-soul ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 3:25am
catalyst-uk ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 3:25am

core/components/header/schema.ts Outdated Show resolved Hide resolved
core/components/header/schema.ts Outdated Show resolved Hide resolved
core/vibes/soul/primitives/navigation/index.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 Just make sure we have a corresponding PR in VIBES

core/components/header/index.tsx Outdated Show resolved Hide resolved
@chanceaclark
Copy link
Contributor

When it's ready to merge, don't forget a changelog 🙏

bookernath added a commit to bookernath/vibes that referenced this pull request Jan 22, 2025
bookernath added a commit to bookernath/vibes that referenced this pull request Jan 22, 2025
@bookernath bookernath added this pull request to the merge queue Jan 22, 2025
Merged via the queue into canary with commit da2a462 Jan 22, 2025
9 checks passed
@bookernath bookernath deleted the currency-selector branch January 22, 2025 04:27
@github-actions github-actions bot mentioned this pull request Jan 21, 2025
Copy link
Contributor

⚡️🏠 Lighthouse report

Lighthouse ran against https://catalyst-canary-1f3eij9x7-bigcommerce-platform.vercel.app

🖥️ Desktop

We ran Lighthouse against the changes on a desktop and produced this report. Here's the summary:

Category Score
🟢 Performance 99
🟢 Accessibility 92
🟠 Best practices 78
🟠 SEO 82

📱 Mobile

We ran Lighthouse against the changes on a mobile and produced this report. Here's the summary:

Category Score
🟠 Performance 89
🟢 Accessibility 92
🟠 Best practices 78
🟠 SEO 85

BC-krasnoshapka pushed a commit that referenced this pull request Jan 23, 2025
* Add currency selector

Co-Authored-By: Chancellor Clark <[email protected]>

* Abstract cart cookie handling to a common lib

* Change currency of cart

* Only show transactional currencies in switcher (for now)

* Use default currency when there is no preference specified in cookie

* Add cart ID + version to key to invalidate cart on currency change

---------

Co-authored-by: Chancellor Clark <[email protected]>
kathir-arizon pushed a commit to Arizon-Digital/catalyst-cuts-metal that referenced this pull request Feb 4, 2025
* Add currency selector

Co-Authored-By: Chancellor Clark <[email protected]>

* Abstract cart cookie handling to a common lib

* Change currency of cart

* Only show transactional currencies in switcher (for now)

* Use default currency when there is no preference specified in cookie

* Add cart ID + version to key to invalidate cart on currency change

---------

Co-authored-by: Chancellor Clark <[email protected]>
chanceaclark added a commit that referenced this pull request Feb 5, 2025
* Add currency selector

Co-Authored-By: Chancellor Clark <[email protected]>

* Abstract cart cookie handling to a common lib

* Change currency of cart

* Only show transactional currencies in switcher (for now)

* Use default currency when there is no preference specified in cookie

* Add cart ID + version to key to invalidate cart on currency change

---------

Co-authored-by: Chancellor Clark <[email protected]>
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