- fix export transaction history data in detail user
This commit is contained in:
parent
08196fdc1d
commit
aed004fc15
|
@ -16,6 +16,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "^4.26.1",
|
||||
"@typescript-eslint/parser": "^4.26.1",
|
||||
"antd": "^4.16.2",
|
||||
"axios": "^1.2.2",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-jest": "^27.0.2",
|
||||
"babel-loader": "8.2.2",
|
||||
|
@ -67,6 +68,7 @@
|
|||
"react-app-polyfill": "^2.0.0",
|
||||
"react-dev-utils": "^11.0.4",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-file-download": "^0.3.5",
|
||||
"react-refresh": "^0.8.3",
|
||||
"react-responsive": "^9.0.0-beta.5",
|
||||
"react-router-dom": "^5.2.0",
|
||||
|
|
|
@ -166,23 +166,24 @@ export const DetailUser = observer(() => {
|
|||
|
||||
const handleSubmitExport = async () => {
|
||||
const date = formExport.getFieldsValue();
|
||||
const data ={
|
||||
const dataDate ={
|
||||
dateStart: moment(date.tanggal_export).format("YYYY-MM-DD")
|
||||
}
|
||||
modalLoader.setLoading(true);
|
||||
try {
|
||||
const response = await store.transaction.exportTransaction(store.membership.dataDetail.id, data)
|
||||
FileSaver.saveAs(response, `Helo.xlsx`)
|
||||
response.statusCode == 201 || response.statusCode == 200
|
||||
? message.success(response?.body?.message || `Success Export`)
|
||||
: message.error(response?.body?.message || `Failed Export`);
|
||||
const response = await store.transaction.exportTransaction(store.membership.dataDetail.id, dataDate)
|
||||
console.log('responseiniyak', response);
|
||||
message.success("Success export");
|
||||
setModalExport(false);
|
||||
modalLoader.setLoading(false);
|
||||
return response;
|
||||
} catch (e) {
|
||||
console.error(e, "apa errornya");
|
||||
message.error(e.response?.body?.message || "Fail Approve");
|
||||
setModalExport(false)
|
||||
message.error(e.response?.body?.message || "Failed to export");
|
||||
setModalExport(false);
|
||||
modalLoader.setLoading(false);
|
||||
}
|
||||
setModalExport(false)
|
||||
setModalExport(false);
|
||||
modalLoader.setLoading(false);
|
||||
};
|
||||
|
||||
|
@ -1141,7 +1142,9 @@ export const DetailUser = observer(() => {
|
|||
visible={modalExport}
|
||||
title={"Export"}
|
||||
onOk={handleSubmitExport}
|
||||
// onCancel={setModalExport(false)}
|
||||
onCancel={() => {
|
||||
setModalExport(false);
|
||||
}}
|
||||
>
|
||||
<Row>
|
||||
<Col span={24}>
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { makeAutoObservable } from "mobx";
|
||||
import { http } from "../utils/http";
|
||||
import { binaryStringToArrayBuffer, arrayBufferToBlob } from 'blob-util'
|
||||
import axios from "axios";
|
||||
import {appConfig} from "../config/app";
|
||||
import fileDownload from "react-file-download";
|
||||
import {TokenUtil} from "../utils/token";
|
||||
|
||||
export class Transaction {
|
||||
page = 0;
|
||||
|
@ -269,20 +273,24 @@ export class Transaction {
|
|||
}
|
||||
}
|
||||
|
||||
async exportTransaction(id,data) {
|
||||
async exportTransaction(id,dateStart) {
|
||||
try {
|
||||
const response = await http
|
||||
.post(`/excel/history-user/export/${id}`)
|
||||
.send(data)
|
||||
axios({
|
||||
url: appConfig.apiUrl + `/excel/history-user/export/${id}`,
|
||||
headers: {"Authorization" : `Bearer ${TokenUtil.accessToken}`},
|
||||
method: 'POST',
|
||||
data: dateStart,
|
||||
responseType: 'blob'
|
||||
}).then((response) => {
|
||||
var fileDownload = require('react-file-download');
|
||||
fileDownload(response.data, `Mutasi Transaki IRS 2022-12-08.xlsx`);
|
||||
return fileDownload;
|
||||
}).catch(function (error) {
|
||||
return error.message;
|
||||
});
|
||||
|
||||
console.log(response, 'ress');
|
||||
const apa = binaryStringToArrayBuffer(response.text)
|
||||
const ini = arrayBufferToBlob(apa, 'text/xlsx')
|
||||
let file = new File([ini], 'text.xlsx', {type: "text/xlsx;charset=utf-8"})
|
||||
console.log(file, 'ini file');
|
||||
return file;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user