🎯 Summary
Complete the refactor of the Availability feature by removing the legacy AvailabilityReducer (now dead code) and consolidating all logic and types around the @commercelayer/hooks and @commercelayer/core workspace packages.
🔍 Current state
AvailabilityContainer has already been migrated to use useAvailability from @commercelayer/hooks, which internally calls getSkuAvailability from @commercelayer/core. However, the legacy reducer has not been cleaned up and the useAvailability hook is missing tests.
| File |
Status |
src/components/skus/AvailabilityContainer.tsx |
✅ Already uses useAvailability from @commercelayer/hooks |
src/components/skus/AvailabilityTemplate.tsx |
✅ Already imports types from @commercelayer/core |
src/context/AvailabilityContext.ts |
✅ Already imports DeliveryLeadTime / LeadTimes from @commercelayer/core |
src/reducers/AvailabilityReducer.ts |
❌ Dead code — no longer referenced anywhere |
packages/hooks/src/availability/useAvailability.ts |
⚠️ No test file |
💡 What needs to be done
🗑️ 1. Remove AvailabilityReducer.ts
The reducer (getAvailability, availabilityReducer, availabilityInitialState) is no longer called by any component or utility. All its logic has been superseded by:
getSkuAvailability in packages/core
useAvailability in packages/hooks
🏷️ 2. Remove duplicated local types
The reducer still defines local copies of types now owned by @commercelayer/core:
| Local type |
Replace with |
DeliveryLeadTime |
DeliveryLeadTime from @commercelayer/core |
LeadTimes |
LeadTimes from @commercelayer/core |
SkuInventory, AvailabilityPayload, AvailabilityState |
SkuAvailability from @commercelayer/core |
📤 3. Verify public API exports
Ensure all types needed by consumers (SkuAvailability, DeliveryLeadTime, LeadTimes) are re-exported from the main index.ts.
🧪 4. Add tests for useAvailability hook
packages/hooks/src/availability/ has no test file. Add useAvailability.test.ts following the pattern of existing hook tests (usePrices.test.ts, useSkus.test.ts). The test should cover:
- Fetching availability by
skuCode
- Fetching availability by
skuId
clearAvailability resets state
- Loading/error states
📦 Relevant packages
@commercelayer/core
export type { SkuAvailability, DeliveryLeadTime, LeadTimes } from "./availability"
export { getSkuAvailability } from "./availability"
@commercelayer/hooks
export { useAvailability } from "./availability/useAvailability"
// returns: { availability, fetchAvailability, clearAvailability, isLoading, isValidating, error, mutate }
✅ Acceptance criteria
🎯 Summary
Complete the refactor of the Availability feature by removing the legacy
AvailabilityReducer(now dead code) and consolidating all logic and types around the@commercelayer/hooksand@commercelayer/coreworkspace packages.🔍 Current state
AvailabilityContainerhas already been migrated to useuseAvailabilityfrom@commercelayer/hooks, which internally callsgetSkuAvailabilityfrom@commercelayer/core. However, the legacy reducer has not been cleaned up and theuseAvailabilityhook is missing tests.src/components/skus/AvailabilityContainer.tsxuseAvailabilityfrom@commercelayer/hookssrc/components/skus/AvailabilityTemplate.tsx@commercelayer/coresrc/context/AvailabilityContext.tsDeliveryLeadTime/LeadTimesfrom@commercelayer/coresrc/reducers/AvailabilityReducer.tspackages/hooks/src/availability/useAvailability.ts💡 What needs to be done
🗑️ 1. Remove
AvailabilityReducer.tsThe reducer (
getAvailability,availabilityReducer,availabilityInitialState) is no longer called by any component or utility. All its logic has been superseded by:getSkuAvailabilityinpackages/coreuseAvailabilityinpackages/hooks🏷️ 2. Remove duplicated local types
The reducer still defines local copies of types now owned by
@commercelayer/core:DeliveryLeadTimeDeliveryLeadTimefrom@commercelayer/coreLeadTimesLeadTimesfrom@commercelayer/coreSkuInventory,AvailabilityPayload,AvailabilityStateSkuAvailabilityfrom@commercelayer/core📤 3. Verify public API exports
Ensure all types needed by consumers (
SkuAvailability,DeliveryLeadTime,LeadTimes) are re-exported from the mainindex.ts.🧪 4. Add tests for
useAvailabilityhookpackages/hooks/src/availability/has no test file. AdduseAvailability.test.tsfollowing the pattern of existing hook tests (usePrices.test.ts,useSkus.test.ts). The test should cover:skuCodeskuIdclearAvailabilityresets state📦 Relevant packages
@commercelayer/core@commercelayer/hooks✅ Acceptance criteria
src/reducers/AvailabilityReducer.tsis deleted.@commercelayer/core.useAvailability.test.tsadded inpackages/hooks/src/availability/.