Skip to content

refactor(availability): remove dead reducer, export SkuAvailability, add hook tests & stories#745

Merged
acasazza merged 2 commits intov5.0.0from
v5/availability-refactor
Apr 10, 2026
Merged

refactor(availability): remove dead reducer, export SkuAvailability, add hook tests & stories#745
acasazza merged 2 commits intov5.0.0from
v5/availability-refactor

Conversation

@acasazza
Copy link
Copy Markdown
Member

@acasazza acasazza commented Apr 10, 2026

Summary

Closes #744

Completes the Availability refactor to use hooks and core packages exclusively, plus adds Storybook stories to the document package.

Changes

🗑️ Deleted

  • packages/react-components/src/reducers/AvailabilityReducer.ts — dead code with zero references; all types and logic have been superseded by @commercelayer/core and @commercelayer/hooks

📦 Exports

  • Re-exports SkuAvailability type from @commercelayer/core in the public index.ts, making it available to consumers of @commercelayer/react-components

✅ Tests

  • Adds packages/hooks/src/availability/useAvailability.test.ts with 8 unit tests covering:
    • Initial state (null availability, not loading)
    • Fetch by skuCode → returns mocked SkuAvailability
    • Clear after fetch → resets to null
    • Error handling (fetcher throws → error is set)
    • isLoading transitions during fetch
    • null return for unknown SKU
    • No-op when neither skuCode nor skuId provided

📖 Stories (packages/document)

  • Fixes Storybook stories glob path (../stories/**../src/stories/**)
  • Adds explicit resolve.alias entries in .storybook/main.ts so #components/*, #context/*, #hooks/*, #typings/*, #utils/*, #config/*, #reducers/* aliases resolve correctly for files outside the react-components package scope
  • Adds packages/document/src/stories/availability/001.availability.mdx — full MDX documentation page
  • Adds packages/document/src/stories/availability/availability.stories.tsx — 9 interactive stories covering AvailabilityContainer, AvailabilityTemplate, DeliveryLeadTime, and SkusContainer integration

Test results

All 46 @commercelayer/react-components tests pass ✅
All 36 @commercelayer/hooks tests pass ✅

…add hook tests

- Delete AvailabilityReducer.ts (dead code, zero references)
- Re-export SkuAvailability from @commercelayer/core in public index
- Add useAvailability.test.ts with 8 test cases covering initial state,
  fetch by skuCode, clear, error handling, isLoading state, and null return

Closes #744
Storybook stories in the document package use internal helpers
(CommerceLayer, OrderStorage) that import via '#components/*' and
other path aliases defined in the react-components tsconfig. Because
those files live in the document package, vite-tsconfig-paths could
not match them to the react-components project scope and failed to
resolve the imports at pre-bundling time.

Fix by adding explicit 'resolve.alias' entries in viteFinal so all
'#components/*', '#context/*', '#hooks/*', '#typings/*', '#utils/*',
'#config/*', '#reducers/*' and '#components-utils/*' paths are
reliably resolved to the react-components source tree regardless of
which file triggers the import.

Also includes:
- Fix stories glob path (../stories → ../src/stories)
- New availability MDX docs and 9 interactive stories
- Add missing npm dependencies (@commercelayer/react-components,
  @commercelayer/js-auth, js-cookie, jwt-decode, @types/js-cookie)
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

npm i https://pkg.pr.new/@commercelayer/react-components@745

commit: 665b8c5

@acasazza acasazza changed the title refactor(availability): remove dead reducer, export SkuAvailability, add hook tests refactor(availability): remove dead reducer, export SkuAvailability, add hook tests & stories Apr 10, 2026
@acasazza acasazza merged commit f1bc0a2 into v5.0.0 Apr 10, 2026
2 checks passed
@acasazza acasazza deleted the v5/availability-refactor branch April 10, 2026 10:20
@acasazza acasazza self-assigned this Apr 10, 2026
@acasazza acasazza added enhancement New feature or request labels Apr 10, 2026
@acasazza acasazza linked an issue Apr 10, 2026 that may be closed by this pull request
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Availability components and reducer using hooks and core packages

1 participant