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:
Benjamin Sutter
2026-05-24 14:56:32 +02:00
parent f487435a94
commit e36c5bc979
33 changed files with 666 additions and 407 deletions
+41
View File
@@ -0,0 +1,41 @@
import { useQuery, useMutation } from '@tanstack/react-query'
import { inquiryReportService } from '../services/inquiryReportService'
import type { InquiryPreparationReportDraft } from '../domain/inquiryReport'
export function useInquiryReportByInquiry(inquiryId: string | null) {
return useQuery({
queryKey: ['inquiry-report', inquiryId],
queryFn: () => inquiryReportService.getByInquiry(inquiryId!),
enabled: !!inquiryId,
})
}
export function useCreateInquiryReport() {
return useMutation({
mutationFn: ({
inquiryId,
selectedPropertyIds,
}: {
inquiryId: string
selectedPropertyIds: string[]
}) => inquiryReportService.create(inquiryId, selectedPropertyIds),
})
}
export function useUpdateInquiryReport() {
return useMutation({
mutationFn: ({
draftId,
data,
}: {
draftId: string
data: Partial<InquiryPreparationReportDraft>
}) => inquiryReportService.update(draftId, data),
})
}
export function useFinalizeInquiryReport() {
return useMutation({
mutationFn: (draftId: string) => inquiryReportService.finalize(draftId),
})
}