Build the valuation page at /dashboard/valuation with form input, AI-powered price estimation results, comparable properties display, and valuation history. Add "Dinh gia AI" button to listing detail sidebar for quick per-listing estimates. Co-Authored-By: Paperclip <noreply@paperclip.ing>
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { valuationApi, type ValuationRequest } 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,
|
|
};
|
|
|
|
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 useValuationHistory(page = 1) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.history(page),
|
|
queryFn: () => valuationApi.getHistory(page),
|
|
});
|
|
}
|
|
|
|
export function useValuationDetail(id: string) {
|
|
return useQuery({
|
|
queryKey: valuationKeys.detail(id),
|
|
queryFn: () => valuationApi.getById(id),
|
|
enabled: !!id,
|
|
});
|
|
}
|