- 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/eslint-plugin": "^4.26.1",
|
||||||
"@typescript-eslint/parser": "^4.26.1",
|
"@typescript-eslint/parser": "^4.26.1",
|
||||||
"antd": "^4.16.2",
|
"antd": "^4.16.2",
|
||||||
|
"axios": "^1.2.2",
|
||||||
"babel-eslint": "^10.1.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"babel-jest": "^27.0.2",
|
"babel-jest": "^27.0.2",
|
||||||
"babel-loader": "8.2.2",
|
"babel-loader": "8.2.2",
|
||||||
|
@ -67,6 +68,7 @@
|
||||||
"react-app-polyfill": "^2.0.0",
|
"react-app-polyfill": "^2.0.0",
|
||||||
"react-dev-utils": "^11.0.4",
|
"react-dev-utils": "^11.0.4",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
|
"react-file-download": "^0.3.5",
|
||||||
"react-refresh": "^0.8.3",
|
"react-refresh": "^0.8.3",
|
||||||
"react-responsive": "^9.0.0-beta.5",
|
"react-responsive": "^9.0.0-beta.5",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
|
|
|
@ -166,23 +166,24 @@ export const DetailUser = observer(() => {
|
||||||
|
|
||||||
const handleSubmitExport = async () => {
|
const handleSubmitExport = async () => {
|
||||||
const date = formExport.getFieldsValue();
|
const date = formExport.getFieldsValue();
|
||||||
const data ={
|
const dataDate ={
|
||||||
dateStart: moment(date.tanggal_export).format("YYYY-MM-DD")
|
dateStart: moment(date.tanggal_export).format("YYYY-MM-DD")
|
||||||
}
|
}
|
||||||
modalLoader.setLoading(true);
|
modalLoader.setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await store.transaction.exportTransaction(store.membership.dataDetail.id, data)
|
const response = await store.transaction.exportTransaction(store.membership.dataDetail.id, dataDate)
|
||||||
FileSaver.saveAs(response, `Helo.xlsx`)
|
console.log('responseiniyak', response);
|
||||||
response.statusCode == 201 || response.statusCode == 200
|
message.success("Success export");
|
||||||
? message.success(response?.body?.message || `Success Export`)
|
setModalExport(false);
|
||||||
: message.error(response?.body?.message || `Failed Export`);
|
modalLoader.setLoading(false);
|
||||||
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e, "apa errornya");
|
console.error(e, "apa errornya");
|
||||||
message.error(e.response?.body?.message || "Fail Approve");
|
message.error(e.response?.body?.message || "Failed to export");
|
||||||
setModalExport(false)
|
setModalExport(false);
|
||||||
modalLoader.setLoading(false);
|
modalLoader.setLoading(false);
|
||||||
}
|
}
|
||||||
setModalExport(false)
|
setModalExport(false);
|
||||||
modalLoader.setLoading(false);
|
modalLoader.setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1141,7 +1142,9 @@ export const DetailUser = observer(() => {
|
||||||
visible={modalExport}
|
visible={modalExport}
|
||||||
title={"Export"}
|
title={"Export"}
|
||||||
onOk={handleSubmitExport}
|
onOk={handleSubmitExport}
|
||||||
// onCancel={setModalExport(false)}
|
onCancel={() => {
|
||||||
|
setModalExport(false);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { makeAutoObservable } from "mobx";
|
import { makeAutoObservable } from "mobx";
|
||||||
import { http } from "../utils/http";
|
import { http } from "../utils/http";
|
||||||
import { binaryStringToArrayBuffer, arrayBufferToBlob } from 'blob-util'
|
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 {
|
export class Transaction {
|
||||||
page = 0;
|
page = 0;
|
||||||
|
@ -269,20 +273,24 @@ export class Transaction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async exportTransaction(id,data) {
|
async exportTransaction(id,dateStart) {
|
||||||
try {
|
try {
|
||||||
const response = await http
|
axios({
|
||||||
.post(`/excel/history-user/export/${id}`)
|
url: appConfig.apiUrl + `/excel/history-user/export/${id}`,
|
||||||
.send(data)
|
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) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user