Add Download LOG

This commit is contained in:
R
2023-02-01 19:15:31 +07:00
parent 8d5f4bb0bd
commit f0c787fede
28 changed files with 470 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import AddIcon from '@mui/icons-material/Add';
import UploadIcon from '@mui/icons-material/Upload';
import CancelIcon from '@mui/icons-material/Cancel';
import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
// hooks
import React, { ChangeEvent, Component, useEffect, useRef, useState } from 'react';
import useSettings from '../../../hooks/useSettings';
@@ -327,6 +328,7 @@ export default function CorporatePlanList() {
function Row(props: { row: ReturnType<typeof createData> }) {
const { row } = props;
const [open, setOpen] = React.useState(false);
const [loadingLog, setLoadingLog] = React.useState(false);
const handleActivate = (model: any, status: string) => {
axios
.put(`/members/${row.id}/activation`, {
@@ -353,6 +355,23 @@ export default function CorporatePlanList() {
);
});
};
const handleDownloadLog = (row: ReturnType<typeof createData>) => {
setLoadingLog(true);
axios.get(`generate-log/${row.id}`)
.then((response) => {
const link = document.createElement('a');
link.href = response.data.data.file_url;
link.setAttribute('download', response.data.data.file_name);
document.body.appendChild(link);
link.click();
setLoadingLog(false);
})
.catch((response) => {
enqueueSnackbar(response.message, {variant: 'error'})
setLoadingLog(false);
})
}
return (
<React.Fragment>
<TableRow sx={{ '& > *': { borderBottom: 'unset' } }}>
@@ -516,6 +535,19 @@ export default function CorporatePlanList() {
</Grid>
</Grid>
<Grid>
<LoadingButton
id="upload-button"
variant="outlined"
startIcon={<InsertDriveFileIcon />}
// sx={{ p: 1.8 }}
onClick={() => {handleDownloadLog(row)}}
loading={loadingLog}
>
Download LOG
</LoadingButton>
</Grid>
{/* <Typography sx={{ fontWeight: '600', mb: 1, mt: 2 }}>Sub Corporate</Typography>
<Grid container>
<Grid item xs={12}>