Merge branches 'main' and 'dev-sabda-v2' of https://gitlab.com/hanifsalafi/mediahub_redesign
This commit is contained in:
commit
745c0b72f2
|
|
@ -26,6 +26,7 @@ import { deleteBlog } from "@/service/blog/blog";
|
||||||
import { error, loading, close } from "@/lib/swal";
|
import { error, loading, close } from "@/lib/swal";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { downloadReport } from "@/service/report/report";
|
||||||
|
|
||||||
const useTableColumns = ({
|
const useTableColumns = ({
|
||||||
handlePreview,
|
handlePreview,
|
||||||
|
|
@ -127,14 +128,9 @@ const useTableColumns = ({
|
||||||
const handleDownload = async (id: string) => {
|
const handleDownload = async (id: string) => {
|
||||||
try {
|
try {
|
||||||
loading();
|
loading();
|
||||||
const response = await axios.get(
|
|
||||||
`https://netidhub.com/api/media/report/download?id=${id}`,
|
|
||||||
{
|
|
||||||
responseType: "blob",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const url = window.URL.createObjectURL(new Blob([response.data]));
|
const response = await downloadReport(id);
|
||||||
|
const url = window.URL.createObjectURL(new Blob([response?.data]));
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.setAttribute("download", `report-${id}.pdf`);
|
link.setAttribute("download", `report-${id}.pdf`);
|
||||||
|
|
@ -152,6 +148,34 @@ const useTableColumns = ({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleDownload = async (id: string) => {
|
||||||
|
// try {
|
||||||
|
// loading();
|
||||||
|
// const response = await axios.get(
|
||||||
|
// `https://netidhub.com/api/media/report/download?id=${id}`,
|
||||||
|
// {
|
||||||
|
// responseType: "blob",
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
|
// const link = document.createElement("a");
|
||||||
|
// link.href = url;
|
||||||
|
// link.setAttribute("download", `report-${id}.pdf`);
|
||||||
|
// document.body.appendChild(link);
|
||||||
|
// link.click();
|
||||||
|
// link.remove();
|
||||||
|
// close();
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Download failed", error);
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Gagal",
|
||||||
|
// text: "Terjadi kesalahan saat mengunduh file.",
|
||||||
|
// icon: "error",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,9 @@ export async function getUserReports(id: any) {
|
||||||
export async function saveUserReportsAction(id: any, action: any) {
|
export async function saveUserReportsAction(id: any, action: any) {
|
||||||
const url = `users/reports/action?id=${id}&action=${action}`;
|
const url = `users/reports/action?id=${id}&action=${action}`;
|
||||||
return httpPostInterceptor(url);
|
return httpPostInterceptor(url);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export async function downloadReport(id: any) {
|
||||||
|
const url = `/media/report/download?id=${id}`;
|
||||||
|
return httpGetInterceptor(url);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue