feat(web): add Property Valuation UI with AVM integration
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>
This commit is contained in:
40
apps/web/lib/hooks/use-valuation.ts
Normal file
40
apps/web/lib/hooks/use-valuation.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user