Commit f97d5d21 authored by Riri Novita's avatar Riri Novita

chcm

parent e288c640
...@@ -494,6 +494,9 @@ const create = (type = "") => { ...@@ -494,6 +494,9 @@ const create = (type = "") => {
const uploadCarfmDocument = (body) => api.post('document/upload_cafrm_document', body) const uploadCarfmDocument = (body) => api.post('document/upload_cafrm_document', body)
const getChcmDocumentBySubmenu = (body) => api.post('document/get_chcm_document_by_submenu', body); const getChcmDocumentBySubmenu = (body) => api.post('document/get_chcm_document_by_submenu', body);
const uploadChcmDocument = (body) => api.post('document/upload_chcm_document', body) const uploadChcmDocument = (body) => api.post('document/upload_chcm_document', body)
const deleteReportChcm = (id) => api.post(`document/delete_chcm_document/${id}`)
const getDetailReportChcm = (id) => api.get(`document/get_chcm_document_by_id/${id}`)
const updateReportChcm = (body) => api.post('document/update_chcm_document', body)
// Monitoring // Monitoring
...@@ -677,6 +680,9 @@ const create = (type = "") => { ...@@ -677,6 +680,9 @@ const create = (type = "") => {
uploadCarfmDocument, uploadCarfmDocument,
getChcmDocumentBySubmenu, getChcmDocumentBySubmenu,
uploadChcmDocument, uploadChcmDocument,
deleteReportChcm,
getDetailReportChcm,
updateReportChcm,
updateDocument, updateDocument,
downloadDocument, downloadDocument,
getPerusahaanUserActive, getPerusahaanUserActive,
......
...@@ -101,6 +101,8 @@ export default class ChcmDocument extends Component { ...@@ -101,6 +101,8 @@ export default class ChcmDocument extends Component {
menu: subMenu menu: subMenu
} }
api.create().getPermission(payload).then(response => { api.create().getPermission(payload).then(response => {
console.log(response);
if (response.data) { if (response.data) {
console.log(`status get permission ${response.data.status}`); console.log(`status get permission ${response.data.status}`);
if (response.data.status === "success") { if (response.data.status === "success") {
...@@ -108,6 +110,8 @@ export default class ChcmDocument extends Component { ...@@ -108,6 +110,8 @@ export default class ChcmDocument extends Component {
btncreate: response.data.data.create, btncreate: response.data.data.create,
btnview: response.data.data.view, btnview: response.data.data.view,
btndownload: response.data.data.download, btndownload: response.data.data.download,
btnedit: response.data.data.edit,
btndelete: response.data.data.delete,
load: true, load: true,
}) })
console.log("btn create " + this.state.btncreate); console.log("btn create " + this.state.btncreate);
...@@ -190,7 +194,6 @@ export default class ChcmDocument extends Component { ...@@ -190,7 +194,6 @@ export default class ChcmDocument extends Component {
if (response.data) { if (response.data) {
if (response.ok) { if (response.ok) {
if (response.data.message === "Data was Saved Successfully") { if (response.data.message === "Data was Saved Successfully") {
console.log("tes123");
this.setState({ visibleCreate: false, visibleTrue: true, loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success'}, () => { this.setState({ visibleCreate: false, visibleTrue: true, loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success'}, () => {
// window.location.reload(); // window.location.reload();
...@@ -295,6 +298,10 @@ export default class ChcmDocument extends Component { ...@@ -295,6 +298,10 @@ export default class ChcmDocument extends Component {
name={this.state.name} name={this.state.name}
submenu_id={this.state.submenu_id} submenu_id={this.state.submenu_id}
btndownload = {this.state.btndownload} btndownload = {this.state.btndownload}
btnedit = {this.state.btnedit}
btndelete = {this.state.btndelete}
menuName={this.state.menu_title}
submenu_id={this.state.submenu_id}
/>)} />)}
</div> </div>
......
import React, { Component } from 'react'
import Images from '../../assets/Images'
import { TextField, withStyles, Snackbar, Typography } from '@material-ui/core'
import MuiAlert from '@material-ui/lab/Alert';
import api from '../../api'
import Autocomplete from '@material-ui/lab/Autocomplete'
import Constant from '../../library/Constant'
import { format } from 'date-fns';
import UploadFile from "../../library/Upload";
import { ExcelRenderer } from 'react-excel-renderer';
import * as R from 'ramda'
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class EditDocumentChcm extends Component {
constructor(props) {
super(props)
this.state = {
perusahaan: null,
perusahaanData: null,
getPerusahaan: null,
errorPerusahaan: false,
msgErrorPerusahaan: '',
document: null,
documentData: null,
getDocument: null,
errorDocument: false,
msgErrorDocument: '',
listPeriode: null,
periode: null,
listMonth: null,
monthId: null,
description: '',
errorDesc: false,
msgErrorDesc: '',
errorMonth: false,
msgErrorMonth: '',
errorPeriode: false,
msgErrorPeriode: '',
file: null,
alert: false,
tipeAlert: '',
messageAlert: '',
fileType: '',
konfirmasi: false,
docId: '',
document_name: "",
document_size: 0,
loadUpload: false,
sizeUpload: "1",
name: '',
disabledPeriode: false
}
}
componentDidMount() {
console.log(this.props);
this.getFileSize()
if (this.props.type === 'edit') {
this.getDetailDoc()
}
}
getFileSize() {
let body = {
group: 'MAX_FILE_SIZE',
company_id: 0,
type: 'MAX_FILE_SIZE'
}
api.create().getAllSettingByType(body).then(response => {
// console.log(response);
if (response.data) {
if (response.data.status === "success") {
this.setState({
sizeUpload: response.data.data[0] ? response.data.data[0].value === undefined ? "1" : response.data.data[0].value : "1"
})
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
}
})
}
getDetailDoc() {
api.create().getDetailReportChcm(this.props.idoc).then(response => {
console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
let data = response.data.data
this.setState({
companyId: data.company_id,
companyName: data.company_name,
period: data.document_periode,
getMonthName: data.document_month,
description: data.description,
filePath: data.document_filepath,
file: data.document_filepath,
document_name: data.document_name,
document_size: data.document_size,
fileType: data.document_type,
created: data.created,
updated: data.updated === null ? "" : data.updated,
loadUpload: true,
name: data.values,
disabledPeriode: data.values === 'Manual Book TIA 4.0' ? true : false
}, () => {
this.getDataCompany()
// this.getDataDocument()
this.getPeriode()
this.getMonth()
})
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
getDataCompany() {
api.create().getPerusahaanUserActive().then((response) => {
if (response.data) {
if (response.data.status == 'success') {
let data = response.data.data
let typeData = data.map((item) => {
return {
company_id: item.company_id,
company_name: item.company_name
}
})
let typeProps = {
options: typeData,
getOptionLabel: (option) => option.company_name,
};
let index = typeData.findIndex((val) => val.company_id == this.state.companyId)
this.setState({ perusahaan: typeProps, perusahaanData: response.data.data, getPerusahaan: index === -1 ? typeData[0] : typeData[index] })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
// getDataDocument() {
// // let payload = {
// // "setting_group_id": 7,
// // "setting_type_id": 167,
// // "company_id": 0
// // }
// api.create().getDocumentCategory().then(response => {
// // console.log(response);
// if (response.data) {
// if (response.data.status == 'success') {
// let data = response.data.data
// let typeData = data.map((item) => {
// return {
// document_category_id: item.setting_id,
// document_category_name: item.value
// }
// })
// let typeProps = {
// options: typeData,
// getOptionLabel: (option) => option.document_category_name,
// };
// let index = typeData.findIndex((val) => val.document_category_id == this.state.categoryId)
// this.setState({ document: typeProps, documentData: response.data.data, getDocument: index === -1 ? typeData[0] : typeData[index] })
// } else {
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
// if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
// setTimeout(() => {
// localStorage.removeItem(Constant.TOKEN)
// window.location.reload();
// }, 1000);
// }
// })
// }
// } else {
// this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
// }
// })
// }
getPeriode() {
api.create().getPeriodeTransaction().then(response => {
let dateNow = new Date
let year = format(dateNow, 'yyyy')
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
let periodeData = data.map((item) => {
return {
periode: item,
}
})
let defaultProps = {
options: periodeData,
getOptionLabel: (option) => option.periode,
};
let index = data.sort((a, b) => a - b).findIndex((val) => val == this.state.period)
this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] })
}
}
})
}
getMonth() {
api.create().getMonthTransaction().then(response => {
let dateNow = new Date
// let bulan = format(dateNow, 'MMMM')
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
let monthData = data.map((item) => {
return {
month_name: item.month_name,
month_id: item.month_id
}
})
let index = monthData.findIndex((val) => val.month_name == this.state.getMonthName)
let defaultProps = {
options: monthData,
getOptionLabel: (option) => option.month_name,
};
// let index = data.sort((a, b) => a - b).findIndex((val) => val.month_name == this.state.getMonth)
this.setState({ listMonth: defaultProps, monthId: index == -1 ? monthData[0] : monthData[index] })
}
}
})
}
clearMessage() {
this.setState({
errorPerusahaan: false,
msgErrorPerusahaan: '',
errorDocument: false,
msgErrorDocument: '',
errorMonth: false,
msgErrorMonth: '',
errorPeriode: false,
msgErrorPeriode: '',
})
}
fileHandler = (event) => {
let fileObj = event
let length = event.name.split(".").length
let fileType = event.name.split(".")[length - 1]
if (fileType === 'zip' || 'rar') {
this.setState({ file: event, fileType: String(fileType) })
} else {
ExcelRenderer(fileObj, (err, resp) => {
// console.log(fileType)
if (err) {
// console.log(err);
}
else {
this.setState({ file: event, fileType: String(fileType) })
}
})
}
}
validasi() {
if (R.isNil(this.state.periode)) {
this.setState({ errorPeriode: true, msgErrorPeriode: 'Period Cannot be Empty' })
} else if (R.isNil(this.state.monthId)) {
this.setState({ errorMonth: true, msgErrorMonth: 'Month Cannot be Empty' })
} else if (R.isNil(this.state.getPerusahaan)) {
this.setState({ errorPerusahaan: true, msgErrorPerusahaan: 'Company Cannot be Empty' })
} else {
const formData = new FormData();
if (this.state.file == this.state.filePath) {
formData.append("updated", 0);
formData.append("file", null);
} else {
formData.append("updated", 1);
formData.append("file", this.state.file);
}
formData.append("documentId", this.props.idoc);
formData.append("companyId", this.state.getPerusahaan.company_id);
formData.append("submenuId", this.props.submenu_id);
formData.append("description", this.state.description);
formData.append("extension", this.state.fileType);
formData.append("documentPeriode", this.state.periode.periode);
formData.append("documentMonth", this.state.monthId.month_id);
this.setState({ formData }, () => {
this.props.updateDocument(this.state.formData)
})
}
}
deleteFile(e) {
this.setState({ file: null })
}
closeAlert() {
this.setState({ alert: false })
}
render() {
return (
<div>
<div className="test app-popup-show">
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
<div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
<div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
<div className="popup-title">
<span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Edit</span>
</div>
</div>
<div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
<button
type="button"
className="btn btn-circle btn-white"
onClick={() => this.props.onClickClose()}
>
<img src={Images.close} />
</button>
</div>
</div>
<div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20, paddingTop: 20 }}>
<div className="column-1">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
{...this.state.perusahaan}
debug
// clearOnEscape
id="tipe"
onChange={(event, newInputValue) => this.setState({ getPerusahaan: newInputValue }, () => this.clearMessage())}
renderInput={(params) =>
<TextField {...params}
error={this.state.errorPerusahaan}
helperText={this.state.msgErrorPerusahaan}
InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
label="Company Name" />}
value={this.state.getPerusahaan}
/>
</div>
</div>
<div className="column-2">
<div style={{ padding: 10, borderRadius: 5, marginTop: "1.2em" }}>
<TextField
value={this.props.menuName}
InputProps={{ style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
placeholder="Category"
disabled
size="medium"
fullWidth={true}
/>
</div>
</div>
<div className="column-1">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
{...this.state.listMonth}
// debug
clearOnEscape
id="month"
onChange={(event, newInputValue) => this.setState({ monthId: newInputValue }, () => this.clearMessage())}
style={{ width: 250 }}
renderInput={(params) =>
<TextField {...params} label="Period Month" margin="normal" style={{ marginTop: 7 }}
InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
error={this.state.errorMonth}
helperText={this.state.msgErrorMonth}
/>}
value={this.state.monthId}
/>
</div>
</div>
<div className="column-2">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
{...this.state.listPeriode}
// debug
clearOnEscape
id="periode"
onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => this.clearMessage())}
style={{ width: 250 }}
renderInput={(params) =>
<TextField {...params} label="Period Year" margin="normal" style={{ marginTop: 7 }}
InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
error={this.state.errorPeriode}
helperText={this.state.msgErrorPeriode}
/>}
value={this.state.periode}
/>
</div>
</div>
</div>
<div style={{ paddingLeft: 30, paddingRight: 30, paddingTop: 10 }}>
{this.state.loadUpload && (
<UploadFile
type={this.state.uploadStatus}
percentage={this.state.percentage}
result={this.state.result}
acceptedFiles={["xls", "xlsx", "pdf", "PDF", "docx", "doc", "pptx", "ppt", "ods", "odf"]}
intent={"management"}
onHandle={(dt) => {
this.fileHandler(dt)
this.setState({ uploadStatus: 'idle', percentage: '0' })
}}
onDelete={(e) => {
this.deleteFile(e)
}}
onUpload={() => alert('sukses')}
value={this.state.file}
docSize={this.state.document_size}
docName={this.state.document_name}
sizeUpload={Number(this.state.sizeUpload)}
/>
)}
</div>
<div className="margin-top-10px" style={{ paddingLeft: 30, paddingRight: 30, borderRadius: 5, paddingBottom: 20 }}>
<TextField
style={{ width: '100%' }}
id="description"
label="Description"
value={this.state.description}
inputProps={{
min: 0,
style: {
fontSize: 11
}
}}
InputLabelProps={{
style: {
fontSize: 11,
color: '#7e8085'
}
}}
name="Description"
onChange={(e) => {
this.setState({
description: e.target.value
})
this.clearMessage()
}}
error={this.state.errorDesc}
helperText={this.state.msgErrorDesc}
>
</TextField>
</div>
<div className="margin-top-10px" style={{ paddingLeft: 30, paddingRight: 30, borderRadius: 5, paddingBottom: 20 }}>
<div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '12%' }}>Created By</Typography>
<Typography style={{ fontSize: 11 }}>: {this.state.created}</Typography>
</div>
<div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '12%' }}>Updated By</Typography>
<Typography style={{ fontSize: 11 }}>: {this.state.updated == - null ? "" : this.state.updated}</Typography>
</div>
</div>
<div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1" style={{ alignSelf: 'center' }}>
<button
type="button"
onClick={() => this.props.onClickClose()}
>
<div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
</div>
</button>
</div>
<div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<button
type="button"
onClick={() =>
this.setState({ loading: true }, () => {
setTimeout(() => {
this.validasi()
}, 100);
})
}
>
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#fff', fontSize: 11 }}>Save</span>
</div>
</button>
</div>
</div>
</div>
<Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
<Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
</Alert>
</Snackbar>
</div>
</div>
)
}
}
import React, { Component } from 'react';
import Images from '../../assets/Images';
import { Typography } from '@material-ui/core';
import api from "../../api";
import Constant from '../../library/Constant';
export default class PopUpDelete extends Component {
constructor(props) {
super(props)
this.state = {
id: '',
getApprovedBy: null,
getTypes: null,
}
}
componentDidMount() {
console.log(this.props);
if (this.props.type === 'delete') {
// console.log(this.props.idoc)
// console.log(this.props.data)
}
}
onClickDelete() {
if (this.props.type == 'delete') {
let payload = this.props.idoc
this.props.deleteDoc(payload)
}
}
render() {
return (
<div className="test app-popup-show">
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
<div style={{ display: 'flex', justifyContent: 'center', paddingTop: 20 }}>
<img src={Images.failed} />
</div>
<div style={{ display: 'grid', justifyContent: 'center', marginTop: 20, paddingBottom: 20 }}>
<span style={{ textAlign: 'center', fontSize: 14, fontWeight: 'bold', fontFamily: 'Nunito Sans, sans-serif' }}>
Delete {this.props.data[1]} ?
</span>
</div>
<div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1" style={{ alignSelf: 'center' }}>
<button
type="button"
onClick={() => this.props.onClickClose()}
>
<div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
</div>
</button>
</div>
<div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<button
type="button"
onClick={() =>
this.setState({ loading: true }, () => {
setTimeout(() => {
this.onClickDelete()
}, 100);
})
}
>
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#fff', fontSize: 11 }}>Delete</span>
</div>
</button>
</div>
</div>
</div>
</div>
);
}
}
import React, {Component} from 'react'; import React, { Component } from 'react';
import api from "../../api"; import api from "../../api";
import Constant from "../../library/Constant"; import Constant from "../../library/Constant";
import Images from "../../assets/Images"; import Images from "../../assets/Images";
import ReactTooltip from "react-tooltip"; import ReactTooltip from "react-tooltip";
import PropagateLoader from "react-spinners/PropagateLoader"; import PropagateLoader from "react-spinners/PropagateLoader";
import {createMuiTheme, MuiThemeProvider, Snackbar} from "@material-ui/core"; import { createMuiTheme, MuiThemeProvider, Snackbar } from "@material-ui/core";
import MUIDataTable from "mui-datatables"; import MUIDataTable from "mui-datatables";
import {withStyles} from "@material-ui/core/styles"; import { withStyles } from "@material-ui/core/styles";
import MuiAlert from "@material-ui/lab/Alert"; import MuiAlert from "@material-ui/lab/Alert";
import EditDocumentChcm from './EditDocumentChcm';
import PopUpDelete from "./PopUpDelete";
var ct = require("../../library/CustomTable"); var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable()); const getMuiTheme = () => createMuiTheme(ct.customTable());
...@@ -26,7 +28,8 @@ export default class TableChcmDocument extends Component { ...@@ -26,7 +28,8 @@ export default class TableChcmDocument extends Component {
visibleCreate: false, visibleCreate: false,
refresh: '', refresh: '',
alert: false, alert: false,
visibleEdit: false,
popupDel: false,
} }
} }
...@@ -36,7 +39,7 @@ export default class TableChcmDocument extends Component { ...@@ -36,7 +39,7 @@ export default class TableChcmDocument extends Component {
componentWillReceiveProps(props) { componentWillReceiveProps(props) {
// console.log(props); // console.log(props);
const {refresh} = this.props; const { refresh } = this.props;
if (props.refresh !== refresh) { if (props.refresh !== refresh) {
this.getData() this.getData()
} }
...@@ -57,21 +60,22 @@ export default class TableChcmDocument extends Component { ...@@ -57,21 +60,22 @@ export default class TableChcmDocument extends Component {
let dataTable = [] let dataTable = []
response.data.data.map((item, index) => { response.data.data.map((item, index) => {
let indexId = this.props.userCompActive.findIndex((val) => val == item.company_id) let indexId = this.props.userCompActive.findIndex((val) => val == item.company_id)
if (indexId !== -1) { if (indexId !== -1) {
dataTable.push( [ dataTable.push([
index, index,
item.document_name, item.document_name,
item.description, item.description,
item.company_name, item.company_name,
item.document_month, item.document_month,
item.document_periode, item.document_periode,
item.document_type, item.document_type,
String(Number(item.document_size) / 1000 + ' KB'), String(Number(item.document_size) / 1000 + ' KB'),
item.created_by, item.created_by,
item.created_at, item.created_at,
item.values item.values,
]) item.document_id,
} ])
}
}) })
let docPath = response.data.data.map((item) => { let docPath = response.data.data.map((item) => {
...@@ -109,22 +113,121 @@ export default class TableChcmDocument extends Component { ...@@ -109,22 +113,121 @@ export default class TableChcmDocument extends Component {
}) })
} }
openPopUp = async (index, val, type) =>{ openPopUp = async (index, val, type) => {
// console.log(index)
if (type === 'download') { if (type === "download") {
let res = await fetch( try {
`${process.env.REACT_APP_URL_MAIN_BE}/public/document/download_chcm_document?documentName=`+this.state.docPath[val]+"&&fileType="+index[6] let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/document/download_chcm_document?documentName=${this.state.docPath[val]}&&fileType=${index[6]}`;
)
res = await res.blob() console.log("Fetching URL:", url); // Debugging step
// console.log(res)
if (res.size > 0) { let response = await fetch(url);
let url = window.URL.createObjectURL(res);
let a = document.createElement('a'); if (!response.ok) {
a.href = url; throw new Error(`HTTP error! Status: ${response.status}`);
a.download = (String(index[3]).includes(":") ? String(index[3]).replace(":", " (") + ` )` : String(index[3])) +" - "+index[4]+" - "+index[5]+" - "+index[10]+"."+index[6]; }
a.click();
let blob = await response.blob();
if (blob.size > 0) {
let downloadUrl = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = downloadUrl;
a.download =
(String(index[3]).includes(":")
? String(index[3]).replace(":", " (") + ` )`
: String(index[3])) +
" - " +
index[4] +
" - " +
index[5] +
" - " +
index[10] +
"." +
index[6];
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
console.error("Downloaded file is empty.");
}
} catch (error) {
console.error("Download error:", error);
} }
} }
if (type === 'delete') {
this.setState({
id: this.state.docId[val],
rowData: index,
popupDel: true
})
}
if (type === 'edit') {
this.setState({
id: this.state.docId[val],
rowData: index,
visibleEdit: true
})
}
};
deleteDoc = (payload) => {
console.log(payload);
this.setState({ popupDel: false, loading: true })
api.create().deleteReportChcm(payload).then(response => {
console.log(response.data)
if (response.data) {
if (response.ok) {
if (response.data.status == 'success') {
this.getData()
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', loading: false })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
}
updateDocument(payload) {
console.log(payload);
this.setState({ visibleEdit: false, loading: true })
api.create().updateReportChcm(payload).then(response => {
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
this.getData()
this.setState({ konfirmasi: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success', visibleEdit: false, loading: false })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
} }
closeAlert() { closeAlert() {
...@@ -154,26 +257,58 @@ export default class TableChcmDocument extends Component { ...@@ -154,26 +257,58 @@ export default class TableChcmDocument extends Component {
<img src={Images.download} /> <img src={Images.download} />
</button> </button>
</a>} </a>}
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" /> {this.props.btnedit && <a data-tip={'Edit'} data-for="download">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
marginRight: 15
}}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'edit')}
>
<img src={Images.editCopy} />
</button>
</a>}
{this.props.btndelete && <a data-tip={'Delete'} data-for="download">
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
marginRight: 15
}}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'delete')}
>
<img src={Images.delete} />
</button>
</a>}
<ReactTooltip border={true} id="delete" place="bottom" type="light" effect="solid" />
</div > </div >
); );
} }
} }
}, },
{ {
name: "File Name", name: "File Name",
options: { options: {
display: false display: false
} }
}, },
"Description", "Company Name", "Period Month", "Period Year", "Description", "Company Name", "Period Month", "Period Year",
"Type", "File Size", "Created By", "Created Date", "Type", "File Size", "Created By", "Created Date",
{ {
name: "Category", name: "Category",
options: { options: {
display: false display: false
} }
}, },
{
name: "",
options: {
display: false
}
},
] ]
const loadingComponent = ( const loadingComponent = (
...@@ -207,7 +342,27 @@ export default class TableChcmDocument extends Component { ...@@ -207,7 +342,27 @@ export default class TableChcmDocument extends Component {
</MuiThemeProvider> </MuiThemeProvider>
</div> </div>
)} )}
{this.state.visibleEdit && (
<EditDocumentChcm
type={"edit"}
onClickClose={() => this.setState({ visibleEdit: false })}
data={this.state.rowData}
idoc={this.state.id}
updateDocument={this.updateDocument.bind(this)}
menuName={this.props.menuName}
submenu_id={this.props.submenu_id}
/>
)}
{this.state.popupDel && (
<PopUpDelete
type={"delete"}
onClickClose={() => this.setState({ popupDel: false })}
data={this.state.rowData}
idoc={this.state.id}
// getList={() => this.getData.bind(this)}
deleteDoc={this.deleteDoc.bind(this)}
/>
)}
</div> </div>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment