feat(web): add khu-cong-nghiep, chuyen-nhuong, and reports pages
Add three new frontend page sections: - Industrial parks (khu-cong-nghiep): listing, detail, filter bar - Transfer listings (chuyen-nhuong): search, category tabs, detail - AI reports dashboard: list, create, viewer with TOC Includes components, API clients, hooks, server helpers, i18n keys, navigation links in public and dashboard layouts, and lint fixes. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
32
apps/web/lib/hooks/use-chuyen-nhuong.ts
Normal file
32
apps/web/lib/hooks/use-chuyen-nhuong.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { transferApi, type SearchTransferListingsParams } from '@/lib/chuyen-nhuong-api';
|
||||
|
||||
export const transferKeys = {
|
||||
all: ['transfer'] as const,
|
||||
search: (params: SearchTransferListingsParams) => ['transfer', 'search', params] as const,
|
||||
detail: (id: string) => ['transfer', 'detail', id] as const,
|
||||
stats: () => ['transfer', 'stats'] as const,
|
||||
};
|
||||
|
||||
export function useTransferListingsSearch(params: SearchTransferListingsParams = {}) {
|
||||
return useQuery({
|
||||
queryKey: transferKeys.search(params),
|
||||
queryFn: () => transferApi.search(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTransferListingDetail(id: string) {
|
||||
return useQuery({
|
||||
queryKey: transferKeys.detail(id),
|
||||
queryFn: () => transferApi.getById(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTransferStats() {
|
||||
return useQuery({
|
||||
queryKey: transferKeys.stats(),
|
||||
queryFn: () => transferApi.getStats(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
53
apps/web/lib/hooks/use-khu-cong-nghiep.ts
Normal file
53
apps/web/lib/hooks/use-khu-cong-nghiep.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
industrialApi,
|
||||
type SearchIndustrialParksParams,
|
||||
} from '@/lib/khu-cong-nghiep-api';
|
||||
|
||||
export const industrialKeys = {
|
||||
all: ['industrial'] as const,
|
||||
search: (params: SearchIndustrialParksParams) => ['industrial', 'search', params] as const,
|
||||
detail: (slug: string) => ['industrial', 'detail', slug] as const,
|
||||
stats: () => ['industrial', 'stats'] as const,
|
||||
market: () => ['industrial', 'market'] as const,
|
||||
compare: (ids: string[]) => ['industrial', 'compare', ids] as const,
|
||||
};
|
||||
|
||||
export function useIndustrialParksSearch(params: SearchIndustrialParksParams = {}) {
|
||||
return useQuery({
|
||||
queryKey: industrialKeys.search(params),
|
||||
queryFn: () => industrialApi.search(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useIndustrialParkDetail(slug: string) {
|
||||
return useQuery({
|
||||
queryKey: industrialKeys.detail(slug),
|
||||
queryFn: () => industrialApi.getBySlug(slug),
|
||||
enabled: !!slug,
|
||||
});
|
||||
}
|
||||
|
||||
export function useIndustrialStats() {
|
||||
return useQuery({
|
||||
queryKey: industrialKeys.stats(),
|
||||
queryFn: () => industrialApi.getStats(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useIndustrialMarket() {
|
||||
return useQuery({
|
||||
queryKey: industrialKeys.market(),
|
||||
queryFn: () => industrialApi.getMarket(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useIndustrialCompare(ids: string[]) {
|
||||
return useQuery({
|
||||
queryKey: industrialKeys.compare(ids),
|
||||
queryFn: () => industrialApi.compare(ids),
|
||||
enabled: ids.length >= 2,
|
||||
});
|
||||
}
|
||||
68
apps/web/lib/hooks/use-reports.ts
Normal file
68
apps/web/lib/hooks/use-reports.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
'use client';
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
listReports,
|
||||
getReport,
|
||||
getReportStatus,
|
||||
generateReport,
|
||||
deleteReport,
|
||||
type ReportType,
|
||||
} from '../reports-api';
|
||||
|
||||
export const reportKeys = {
|
||||
all: ['reports'] as const,
|
||||
list: (params?: { type?: ReportType; limit?: number; offset?: number }) =>
|
||||
['reports', 'list', params] as const,
|
||||
detail: (id: string) => ['reports', 'detail', id] as const,
|
||||
status: (id: string) => ['reports', 'status', id] as const,
|
||||
};
|
||||
|
||||
export function useReportsList(params?: {
|
||||
type?: ReportType;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}) {
|
||||
return useQuery({
|
||||
queryKey: reportKeys.list(params),
|
||||
queryFn: () => listReports(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useReport(id: string | null) {
|
||||
return useQuery({
|
||||
queryKey: reportKeys.detail(id!),
|
||||
queryFn: () => getReport(id!),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
export function useReportStatus(id: string | null, shouldPoll = false) {
|
||||
return useQuery({
|
||||
queryKey: reportKeys.status(id!),
|
||||
queryFn: () => getReportStatus(id!),
|
||||
enabled: !!id,
|
||||
refetchInterval: shouldPoll ? 3000 : false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useGenerateReport() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: { type: ReportType; title: string; params: Record<string, unknown> }) =>
|
||||
generateReport(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: reportKeys.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteReport() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => deleteReport(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: reportKeys.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user