Skip to content
Extraits de code Groupes Projets
Valider 521452e5 rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'fix/export-pagination-removal' into 'develop'

MYD-764/export products wuthout pagination

See merge request !384
parents 0c97ac5c 6c872de9
Branches
1 requête de fusion!384MYD-764/export products wuthout pagination
......@@ -168,17 +168,38 @@ export default function ProductListView() {
const handleExport = async () => {
try {
const dataToExport = products;
const arrayId = dataToExport.map((product) => product.id);
// Construct query parameters
const exportParams = {
priceMin: filters.priceMin,
priceMax: filters.priceMax,
sortBy: sortBy.join(','), // Join sortBy as a comma-separated string
direction: direction.join(','), // Join direction as a comma-separated string
isDraft: filters.isDraft,
isPublishLive: filters.isPublishLive,
isPublishWeb: filters.isPublishWeb,
isInStockWeb: filters.isInStockWeb,
isInStockLive: filters.isInStockLive,
keyword: filters.keyword,
};
// Make the API call using axiosInstance
const response = await axiosInstance.post(endpoints.product.export, arrayId, {
// Remove null or undefined values from the query parameters
const queryString = new URLSearchParams(
Object.entries(exportParams).reduce((acc, [key, value]) => {
if (value !== null && value !== undefined && value !== "") {
acc[key] = value.toString();
}
return acc;
}, {} as Record<string, string>)
).toString();
// Make the API call with query parameters
const response = await axiosInstance.get(`${endpoints.product.export}?${queryString}`, {
headers: {
"Content-Type": "application/json",
},
});
// Create a Blob and download the file
// Handle the response and initiate file download
const blob = new Blob([response.data], { type: "text/csv" });
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
......@@ -198,7 +219,6 @@ export default function ProductListView() {
const handleSearch = useCallback((searchTerm: string) => {
console.log(searchTerm);
handleFilters('keyword', searchTerm);
revalidate();
}, [handleFilters, revalidate]);
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter