Add batch valuation (POST /analytics/valuation/batch, max 50 properties), valuation comparison (POST /analytics/valuation/compare, 2-5 properties), and history endpoint (GET /analytics/valuation/history/:propertyId) with confidence explanation helper. Frontend: enhanced valuation form with project autocomplete and deep analysis toggle, results with confidence badges and price range visualization, comparables table, history chart, market context card, and PDF export. Co-Authored-By: Paperclip <noreply@paperclip.ing>
86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import {
|
|
valuationApi,
|
|
type ValuationRequest,
|
|
type BatchValuationRequest,
|
|
} from '@/lib/valuation-api';
|
|
|
|
export const valuationKeys = {
|
|
all: ['valuation'] as const,
|
|
history: (page: number) => ['valuation', 'history', page] as const,
|
|
detail: (id: string) => ['valuation', 'detail', id] as const,
|
|
propertyHistory: (propertyId: string) =>
|
|
['valuation', 'property-history', propertyId] as const,
|
|
compare: (ids: string[]) => ['valuation', 'compare', ...ids] as const,
|
|
projectSearch: (query: string) =>
|
|
['valuation', 'project-search', query] as const,
|
|
};
|
|
|
|
export function useValuationPredict() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (data: ValuationRequest) => valuationApi.predict(data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: valuationKeys.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useValuationPredictForListing() {
|
|
return useMutation({
|
|
mutationFn: (listingId: string) => valuationApi.predictForListing(listingId),
|
|
});
|
|
}
|
|
|
|
export function useValuationBatch() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (data: BatchValuationRequest) => valuationApi.batchPredict(data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: valuationKeys.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useValuationCompare(propertyIds: string[]) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.compare(propertyIds),
|
|
queryFn: () => valuationApi.compare({ propertyIds }),
|
|
enabled: propertyIds.length >= 2,
|
|
});
|
|
}
|
|
|
|
export function useValuationHistory(page = 1) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.history(page),
|
|
queryFn: () => valuationApi.getHistory(page),
|
|
});
|
|
}
|
|
|
|
export function useValuationPropertyHistory(propertyId: string) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.propertyHistory(propertyId),
|
|
queryFn: () => valuationApi.getPropertyHistory(propertyId),
|
|
enabled: !!propertyId,
|
|
});
|
|
}
|
|
|
|
export function useValuationDetail(id: string) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.detail(id),
|
|
queryFn: () => valuationApi.getById(id),
|
|
enabled: !!id,
|
|
});
|
|
}
|
|
|
|
export function useProjectSearch(query: string) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.projectSearch(query),
|
|
queryFn: () => valuationApi.searchProjects(query),
|
|
enabled: query.length >= 2,
|
|
staleTime: 30_000,
|
|
});
|
|
}
|