refactor(arch): eliminate direct service calls in components — route all through hooks
New hook files: - useAuth.ts: useLogin, useSwitchDemoRole, useSwitchOrganization - useAI.ts: useParseNeed, useGenerateOfferEmail, useGenerateDecisionBrief, useParseListingText - useAssistant.ts: useAssistantSuggestions (useQuery), useAssistantAnswer (useMutation) - useOfferReport.ts: useOfferReportByInquiry, useCreateOfferReport, useUpdateOfferReport, useGenerateOfferReportPdf - useInquiryReport.ts: useInquiryReportByInquiry, useCreateInquiryReport, useUpdateInquiryReport, useFinalizeInquiryReport - useMarketReport.ts: useMarketReport - useWeighting.ts: useDefaultWeights (synchronous wrapper) - useUnitMatches.ts: useUnitMatchesMap, useUnitBundle, useBundleMatches (useMemo wrappers) Extended hooks: useProperties (add update/create/remove mutations), useNeeds (add useCreateNeed), useMatches (add useNeedMatchesForProperty, useAdditionalMatchesForInquiry), useReviewQueue (add useCreateReviewTask) Updated 21 components/pages: all direct service imports replaced with hooks. Deliberate exception: getRecommendedActions in DataQuality.tsx (pure sync utility, no provider access). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useMemo } from 'react'
|
||||
import { unitMatchService } from '../services/unitMatchService'
|
||||
import type { Property, PropertyUnit } from '../domain/property'
|
||||
|
||||
/**
|
||||
* Synchronous wrappers — unitMatchService methods are pure synchronous computations.
|
||||
* useMemo ensures we don't recompute on every render unnecessarily.
|
||||
*/
|
||||
|
||||
export function useUnitMatchesMap(freeUnits: PropertyUnit[], property: Property) {
|
||||
return useMemo(
|
||||
() =>
|
||||
Object.fromEntries(
|
||||
freeUnits.map(u => [u.id, unitMatchService.getMatchesForUnit(u, property)]),
|
||||
),
|
||||
[freeUnits, property],
|
||||
)
|
||||
}
|
||||
|
||||
export function useUnitBundle(selectedUnits: PropertyUnit[]) {
|
||||
return useMemo(
|
||||
() => (selectedUnits.length >= 2 ? unitMatchService.buildBundle(selectedUnits) : null),
|
||||
[selectedUnits],
|
||||
)
|
||||
}
|
||||
|
||||
export function useBundleMatches(selectedUnits: PropertyUnit[], property: Property) {
|
||||
return useMemo(
|
||||
() =>
|
||||
selectedUnits.length >= 2
|
||||
? unitMatchService.getMatchesForBundle(selectedUnits, property)
|
||||
: [],
|
||||
[selectedUnits, property],
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user