Skip to content

✨ feat(skus): migrate SkuListsContainer and AvailabilityContainer to hooks#731

Draft
acasazza wants to merge 143 commits intov5.0.0from
v5/feat/skus/migrate-containers-to-hooks
Draft

✨ feat(skus): migrate SkuListsContainer and AvailabilityContainer to hooks#731
acasazza wants to merge 143 commits intov5.0.0from
v5/feat/skus/migrate-containers-to-hooks

Conversation

@acasazza
Copy link
Copy Markdown
Member

Summary

Closes #730

Migrates all remaining skus-folder components to use dedicated hooks from @commercelayer/hooks, removing direct API calls from reducers — following the same pattern established in #720 for SkusContainer.

  • Add getSkuList / retrieveSkuList functions to @commercelayer/core
  • Add getSkuInventory function to @commercelayer/core
  • Create useSkuLists hook in @commercelayer/hooks
  • Create useAvailability hook in @commercelayer/hooks
  • Refactor SkuListsContainer to use useSkuLists
  • Refactor AvailabilityContainer to use useAvailability
  • Write tests for all components under the skus folder

Test plan

  • Core functions unit tests pass
  • Hook tests pass
  • SkuListsContainer component tests pass
  • AvailabilityContainer component tests pass

🤖 Generated with Claude Code

pfferrari and others added 30 commits December 4, 2025 10:55
…source-delete-button

Add `PaymentSourceDeleteButton`
Fix disable place order button and givex show errors
acasazza and others added 22 commits March 13, 2026 02:19
Brings in bug fixes from v4.29.4→v4.29.6: PlaceOrderButton gift card error handling,
PlaceOrderReducer org config fetch fix, PrivacyAndTermsCheckbox org config fallback,
payment component validation fixes, Adyen dropin fix, and security dep upgrades.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- 📦 Add getSkus, retrieveSku, updateSku functions to core package
- 🪝 Add useSkus hook to hooks package with full test coverage
- 🐛 Fix extender.ts accessToken type and use() call
- 📈 Improve usePrices/useSkus coverage: dataRef tracks get-action data only
- 🔒 Replace non-null assertions with null guards in SWR fetcher
- 🧪 Add vitest setup file with extended asyncUtilTimeout for coverage runs
- 🔧 Update pre-commit hook to scope build/test to core and hooks only
- 🐶 Fix husky deprecated shell preamble in pre-commit hook
…ucer

Closes #727. Replaces useReducer + getSku manual SDK calls with the useSkus
hook from @commercelayer/hooks. SkuReducer now only exports the SkuState type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…drop old tests

Closes #728. Updates peerDependencies to react >=19.0.0, adds
babel-plugin-react-compiler to the vitest config, and removes all legacy
specs written against the React 18 + reducer architecture. New tests will
be added incrementally per feature.
- Add specs/skus/skus-container.spec.tsx with 6 tests covering code fields,
  count, name, image_url, empty skus, and queryParams filter
- Wrap each render with SWRConfig provider for isolated cache per test
- Fix clearSkus unhandled promise rejection by chaining .catch() on mutate
- Add babel-plugin-react-compiler and SWR to react-components vitest config
- Add workspace aliases for @commercelayer/hooks and @commercelayer/core
@acasazza acasazza added this to the v5.0.0 milestone Mar 26, 2026
@acasazza acasazza added enhancement New feature or request components Components package labels Mar 26, 2026
@acasazza acasazza self-assigned this Mar 26, 2026
…hooks

- Add getSkuLists/retrieveSkuList functions to @commercelayer/core
- Add getSkuAvailability function to @commercelayer/core
- Create useSkuLists hook in @commercelayer/hooks (with SWR caching)
- Create useAvailability hook in @commercelayer/hooks (with SWR caching)
- Refactor SkuListsContainer to use useSkuLists — proper registration
  pattern via registerListId callback instead of direct array mutation
- Refactor AvailabilityContainer to use useAvailability, removing
  useReducer and AvailabilityReducer dependency
- Update SkuList to call registerListId instead of mutating listIds
- Update AvailabilityTemplate to import DeliveryLeadTime from core
- Fix Skus component to use sku.id as key instead of array index
- Fix AddToCartButton to use sku.code from typed Sku[] context
- Add sku_lists* to MSW bypass handlers
- Add tests: availability-container, sku-lists-container, core specs
- Add AvailabilityContext and SkuListsContext types

Closes #730
- Add specs for CommerceLayer auth component
- Add unit tests for SkusContainer, SkuListsContainer, AvailabilityContainer, AvailabilityTemplate, DeliveryLeadTime, SkuField, Parent components
- Add unit tests for useCustomContext hook
- Migrate vitest config to vitest.config.mts (drop _vitest.config.mts prefix)
- Remove outdated e2e specs replaced by unit tests
@acasazza
Copy link
Copy Markdown
Member Author

Updates

✅ Unit tests & coverage

  • Added unit tests for CommerceLayer auth component
  • Added unit tests for SkusContainer, SkuListsContainer, AvailabilityContainer, AvailabilityTemplate, DeliveryLeadTime, SkuField, Parent
  • Added unit tests for useCustomContext hook
  • Removed outdated Playwright e2e specs (replaced by faster unit tests)
  • Migrated vitest config to vitest.config.mts

🔨 Build: migrate from tsc to tsup

  • Added tsup.config.ts with CJS + ESM output, code splitting, "use client" banner, and babel-plugin-react-compiler
  • Added @commercelayer/core and @commercelayer/hooks as declared devDependencies
  • Fixed DTS generation: override types: ["node"] to make require() (used in BraintreePayment) available
  • Fixed PlaceOrderButton.tsx: removed duplicate dead if (isDraftOrder) block (esbuild parse error)
  • Fixed StripePayment.tsx: removed duplicate import block (lines 21–27)
  • Bridged rapid-form v2→v3 API mismatch in address/customer form components (useRapidForm as any) pending a proper migration

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

Labels

components Components package enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants