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:
@@ -43,6 +43,8 @@ export const API_ENDPOINTS = {
|
||||
UPDATE: (id: string) => `tenders/${id}`,
|
||||
DELETE: (id: string) => `tenders/${id}`,
|
||||
DETAILS: (id: string) => `tenders/${id}`,
|
||||
AI_TRANSLATE: (id: string) => `tenders/${id}/ai-translate`,
|
||||
AI_SUMMARY: (id: string) => `tenders/${id}/ai-summary`,
|
||||
},
|
||||
CUSTOMERS: {
|
||||
READ_ALL: "customers",
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import api from "../axios";
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import { ApiResponse } from "../types";
|
||||
import { TTenderDetails, TTenderResponse } from "../types/Tenders";
|
||||
import {
|
||||
TTenderDetails,
|
||||
TTenderResponse,
|
||||
TTenderTranslationResponse,
|
||||
} from "../types/Tenders";
|
||||
|
||||
export const tendersService = {
|
||||
tendersList: async (
|
||||
@@ -14,9 +18,12 @@ export const tendersService = {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
tenderDetails: async (id: string): Promise<ApiResponse<TTenderDetails>> => {
|
||||
tenderDetails: async (
|
||||
id: string,
|
||||
params?: Record<string, any>,
|
||||
): Promise<ApiResponse<TTenderDetails>> => {
|
||||
try {
|
||||
return (await api.get(API_ENDPOINTS.TENDERS.DETAILS(id))).data;
|
||||
return (await api.get(API_ENDPOINTS.TENDERS.DETAILS(id), { params })).data;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"ERROR caught in Tender Service => tender details: ",
|
||||
@@ -25,4 +32,22 @@ export const tendersService = {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
translateTender: async ({
|
||||
id,
|
||||
language,
|
||||
}: {
|
||||
id: string;
|
||||
language: string;
|
||||
}): Promise<ApiResponse<TTenderTranslationResponse>> => {
|
||||
try {
|
||||
return (
|
||||
await api.post(API_ENDPOINTS.TENDERS.AI_TRANSLATE(id), {
|
||||
language,
|
||||
})
|
||||
).data;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Tender Service => translate tender: ", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,9 +23,21 @@ export const TenderSchema = z.object({
|
||||
created_at: z.number().optional(),
|
||||
tender_id: z.string(),
|
||||
title: z.string(),
|
||||
language: z.string().optional(),
|
||||
overall_summary: z.string().optional(),
|
||||
});
|
||||
|
||||
export const TenderTranslationResponseSchema = z.object({
|
||||
notice_id: z.string(),
|
||||
language: z.string(),
|
||||
translated_title: z.string(),
|
||||
translated_description: z.string(),
|
||||
});
|
||||
export const TendersResponse = z.object({
|
||||
tenders: z.array(TenderSchema).or(z.null()),
|
||||
});
|
||||
export type TTenderResponse = z.infer<typeof TendersResponse>;
|
||||
export type TTenderDetails = z.infer<typeof TenderSchema>;
|
||||
export type TTenderTranslationResponse = z.infer<
|
||||
typeof TenderTranslationResponseSchema
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user