e36c5bc979
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>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
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],
|
|
)
|
|
}
|