refactor(tender-details): enhance translation and summary features
- Integrated language selection and translation functionality in TenderDetails, allowing users to choose display language and translate tender metadata. - Added AI summary section to display overall summary of the tender. - Updated API service to support translation requests and handle responses effectively. - Improved pagination handling in AdminsTable for better user experience. - Refactored various components to ensure consistent data flow and state management.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { API_ENDPOINTS, tendersService } from "@/lib/api";
|
||||
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
export const useTendersQuery = (params?: Record<string, any>) => {
|
||||
const queryKey = useMemo(
|
||||
@@ -14,10 +15,36 @@ export const useTendersQuery = (params?: Record<string, any>) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useTenderDetailQuery = (id: string) => {
|
||||
const queryKey = useMemo(() => [API_ENDPOINTS.TENDERS.DETAILS(id)], [id]);
|
||||
export const useTenderDetailQuery = (id: string, params?: Record<string, any>) => {
|
||||
const queryKey = useMemo(
|
||||
() => [API_ENDPOINTS.TENDERS.DETAILS(id), params],
|
||||
[id, params],
|
||||
);
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: () => tendersService.tenderDetails(id),
|
||||
queryFn: () => tendersService.tenderDetails(id, params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useTranslateTenderMutation = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: [API_ENDPOINTS.TENDERS.AI_TRANSLATE("translate")],
|
||||
mutationFn: tendersService.translateTender,
|
||||
onSuccess: (_, variables) => {
|
||||
toast.success(`Translation for "${variables.language}" is ready`);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [API_ENDPOINTS.TENDERS.READ_ALL],
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [API_ENDPOINTS.TENDERS.DETAILS(variables.id)],
|
||||
});
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(
|
||||
"Translation temporarily unavailable. Showing original content.",
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user