Browse Source

add loader

pull/1/head
wahyuun 1 year ago
parent
commit
cd29f3de52
  1. 687
      src/views/SimproV2/CreatedProyek/DialogDocument.js

687
src/views/SimproV2/CreatedProyek/DialogDocument.js

@ -1,341 +1,346 @@
import React, { useEffect, useState, useMemo } from 'react' import React, { useEffect, useState, useMemo } from 'react'
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { Button } from 'reactstrap'; import { Button } from 'reactstrap';
import { Table, Tooltip, Popover } from 'antd'; import { Table, Tooltip, Popover, Spin } from 'antd';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import moment from 'moment'; import moment from 'moment';
import SweetAlert from 'react-bootstrap-sweetalert'; import SweetAlert from 'react-bootstrap-sweetalert';
import { DOCUMENT_DOWNLOAD, DOCUMENT_GET, BASE_SIMPRO_LUMEN_FILE, REQUEST_MATERIAL_EDIT, DOCUMENT_DELETE, DOCUMENT_SEARCH, FOLDER_DOCUMENT_PROYEK_GET_TREE, FOLDER_DOCUMENT_PROYEK_DELETE } from '../../../const/ApiConst'; import { DOCUMENT_DOWNLOAD, DOCUMENT_GET, BASE_SIMPRO_LUMEN_FILE, REQUEST_MATERIAL_EDIT, DOCUMENT_DELETE, DOCUMENT_SEARCH, FOLDER_DOCUMENT_PROYEK_GET_TREE, FOLDER_DOCUMENT_PROYEK_DELETE } from '../../../const/ApiConst';
import axios from "../../../const/interceptorApi" import axios from "../../../const/interceptorApi"
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import DialogRequest from './FormDocument'; import DialogRequest from './FormDocument';
import DialogRequestFolder from './FormFolderDocument'; import DialogRequestFolder from './FormFolderDocument';
const DialogDocument = ({ openDialog, closeDialog, toggleDialog, idTask, proyekName }) => { const DialogDocument = ({ openDialog, closeDialog, toggleDialog, idTask, proyekName }) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
const HEADER = { const HEADER = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const config = { const config = {
headers: headers:
{ {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
"Content-type": `application/json` "Content-type": `application/json`
} }
}; };
const [dataDocument, setDataDocument] = useState([]) const [dataDocument, setDataDocument] = useState([])
const [openDialogReq, setOpenDialogReq] = useState(false) const [openDialogReq, setOpenDialogReq] = useState(false)
const [openDialogNewFolder, setOpenDialogNewFolder] = useState(false) const [openDialogNewFolder, setOpenDialogNewFolder] = useState(false)
const [alertDelete, setAlertDelete] = useState(false) const [alertDelete, setAlertDelete] = useState(false)
const [alertDeleteFolder, setAlertDeleteFolder] = useState(false) const [alertDeleteFolder, setAlertDeleteFolder] = useState(false)
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
const [dataEdit, setDataEdit] = useState(null) const [dataEdit, setDataEdit] = useState(null)
const [parentIdNewFolder, setParentIdNewFolder] = useState(0) const [parentIdNewFolder, setParentIdNewFolder] = useState(0)
const [loading, setLoading] = useState(true);
useEffect(() => {
if (idTask > 0) { useEffect(() => {
getDataDocument(); if (idTask > 0) {
} getDataDocument();
}, [idTask, openDialog]) }
}, [idTask, openDialog])
useEffect(() => {
if (!openDialog) { useEffect(() => {
setDataDocument([]); if (!openDialog) {
} else { setDataDocument([]);
} else {
}
}, [openDialog]) }
}, [openDialog])
const getDataDocument = async () => {
const url = FOLDER_DOCUMENT_PROYEK_GET_TREE(idTask) const getDataDocument = async () => {
const result = await axios const url = FOLDER_DOCUMENT_PROYEK_GET_TREE(idTask)
.get(url, config) const result = await axios
.then(res => res) .get(url, config)
.catch((error) => error.response); .then(res => res)
if (result && result.data && result.data.code == 200) { .catch((error) => error.response);
setDataDocument(result.data.data); if (result && result.data && result.data.code == 200) {
} else { setDataDocument(result.data.data);
NotificationManager.error('Gagal mengambil data, Silahkan coba lagi!!', 'Failed'); setLoading(false);
} } else {
} setLoading(false);
NotificationManager.error('Gagal mengambil data, Silahkan coba lagi!!', 'Failed');
const handleCancel = () => { }
setDataDocument([]); }
closeDialog('cancel', 'none')
} const handleCancel = () => {
setDataDocument([]);
const handleDelete = (id) => { closeDialog('cancel', 'none')
setIdDelete(id) }
setAlertDelete(true)
} const handleDelete = (id) => {
setIdDelete(id)
const handleDeleteFolder = (id) => { setAlertDelete(true)
setIdDelete(id) }
setAlertDeleteFolder(true)
} const handleDeleteFolder = (id) => {
setIdDelete(id)
const handleDownload = (id, file) => { setAlertDeleteFolder(true)
fetch(DOCUMENT_DOWNLOAD(id), { }
headers: new Headers({
'Content-Type': 'application/json', const handleDownload = (id, file) => {
'Authorization': `Bearer ${token}` fetch(DOCUMENT_DOWNLOAD(id), {
}) headers: new Headers({
}) 'Content-Type': 'application/json',
.then(response => { 'Authorization': `Bearer ${token}`
response.blob().then(blob => { })
const url = window.URL.createObjectURL(new Blob([blob])); })
let a = document.createElement('a'); .then(response => {
a.href = url; response.blob().then(blob => {
a.download = file; const url = window.URL.createObjectURL(new Blob([blob]));
a.click(); let a = document.createElement('a');
a.remove(); a.href = url;
}); a.download = file;
//window.location.href = response.url; a.click();
}); a.remove();
// const urlDownload = DOCUMENT_DOWNLOAD(id); });
// window.open(urlDownload); //window.location.href = response.url;
} });
// const urlDownload = DOCUMENT_DOWNLOAD(id);
const handleShow = (file) => { // window.open(urlDownload);
const urlShow = `${BASE_SIMPRO_LUMEN_FILE}/${file}` }
window.open(urlShow);
} const handleShow = (file) => {
const urlShow = `${BASE_SIMPRO_LUMEN_FILE}/${file}`
const handleNewFolderParent = (folderId) => { window.open(urlShow);
setParentIdNewFolder(folderId) }
setOpenDialogNewFolder(true)
} const handleNewFolderParent = (folderId) => {
setParentIdNewFolder(folderId)
const handleNewFolderWOParent = () => { setOpenDialogNewFolder(true)
setParentIdNewFolder(0) }
setOpenDialogNewFolder(true)
} const handleNewFolderWOParent = () => {
setParentIdNewFolder(0)
const handleNewFileParent = (folderId) => { setOpenDialogNewFolder(true)
setParentIdNewFolder(folderId) }
openDialogRequest()
} const handleNewFileParent = (folderId) => {
setParentIdNewFolder(folderId)
const handleNewFileWOParent = () => { openDialogRequest()
setParentIdNewFolder(0) }
openDialogRequest()
} const handleNewFileWOParent = () => {
setParentIdNewFolder(0)
const renderShowDokumen = (file) => { openDialogRequest()
let arrayFile = file.split(".") }
let length = arrayFile.length
length = length - 1 const renderShowDokumen = (file) => {
const fileExt = arrayFile[length]; let arrayFile = file.split(".")
if (fileExt == "pdf" || fileExt == "png" || fileExt == "jpg" || fileExt == "jpeg" || fileExt == "gif") { let length = arrayFile.length
return ( length = length - 1
<Tooltip title="View Document"> const fileExt = arrayFile[length];
<Button size={"sm"} color='info' style={{ color: "#FFFFFF" }} onClick={() => handleShow(file)}><i className="fa fa-eye"></i></Button> if (fileExt == "pdf" || fileExt == "png" || fileExt == "jpg" || fileExt == "jpeg" || fileExt == "gif") {
</Tooltip> return (
) <Tooltip title="View Document">
} <Button size={"sm"} color='info' style={{ color: "#FFFFFF" }} onClick={() => handleShow(file)}><i className="fa fa-eye"></i></Button>
} </Tooltip>
const RenderTable = useMemo(() => { )
const columns = [ }
{ }
title: 'Action', const RenderTable = useMemo(() => {
dataIndex: '', const columns = [
key: 'id', {
className: "nowrap", title: 'Action',
render: (text, record) => dataIndex: '',
<> key: 'id',
{!record.isDir && <Tooltip title="Delete Document"> className: "nowrap",
<Button size={"sm"} color='danger' onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button> render: (text, record) =>
</Tooltip>}{" "} <>
{record.isDir && <Tooltip title="Delete Folder"> {!record.isDir && <Tooltip title="Delete Document">
<Button size={"sm"} color='danger' onClick={() => handleDeleteFolder(text.id)}><i className="fa fa-trash"></i></Button> <Button size={"sm"} color='danger' onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button>
</Tooltip>}{" "} </Tooltip>}{" "}
{!record.isDir && <Tooltip title="Download Document"> {record.isDir && <Tooltip title="Delete Folder">
<Button size={"sm"} color='primary' onClick={() => handleDownload(text.id, text.file)}><i className="fa fa-download"></i></Button> <Button size={"sm"} color='danger' onClick={() => handleDeleteFolder(text.id)}><i className="fa fa-trash"></i></Button>
</Tooltip>}{" "} </Tooltip>}{" "}
{record.isDir && <Tooltip title="New Folder"> {!record.isDir && <Tooltip title="Download Document">
<Button size="sm" color="success" onClick={() => handleNewFolderParent(record.id)}><i className="fa fa-folder"></i></Button> <Button size={"sm"} color='primary' onClick={() => handleDownload(text.id, text.file)}><i className="fa fa-download"></i></Button>
</Tooltip>}{" "} </Tooltip>}{" "}
{record.isDir && <Tooltip title="New File"> {record.isDir && <Tooltip title="New Folder">
<Button size="sm" color="primary" onClick={() => handleNewFileParent(record.id)}><i className="fa fa-file"></i></Button> <Button size="sm" color="success" onClick={() => handleNewFolderParent(record.id)}><i className="fa fa-folder"></i></Button>
</Tooltip>}{" "} </Tooltip>}{" "}
{text.file ? renderShowDokumen(text.file) : ""} {record.isDir && <Tooltip title="New File">
</> <Button size="sm" color="primary" onClick={() => handleNewFileParent(record.id)}><i className="fa fa-file"></i></Button>
, </Tooltip>}{" "}
}, {text.file ? renderShowDokumen(text.file) : ""}
{ title: 'Document Name', dataIndex: 'name_folder', key: 'name_folder', render: (text, record) => record.isDir ? record.name_folder : record.file }, </>
{ title: 'Type', dataIndex: 'isDir', key: 'isDir', render: (text, record) => record.isDir ? 'Folder' : 'File' }, ,
{ title: 'Upload Date', dataIndex: 'created_at', key: 'created_at', render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) } },
]; { title: 'Document Name', dataIndex: 'name_folder', key: 'name_folder', render: (text, record) => record.isDir ? record.name_folder : record.file },
{ title: 'Type', dataIndex: 'isDir', key: 'isDir', render: (text, record) => record.isDir ? 'Folder' : 'File' },
return ( { title: 'Upload Date', dataIndex: 'created_at', key: 'created_at', render: (text, record) => (<div style={{ whiteSpace: "nowrap" }}>{text ? moment(text).format("D-M-YYYY") : "-"}</div>) }
<Table ];
size="small"
columns={columns} return (
rowKey={"id"} <Table
dataSource={dataDocument} size="small"
pagination={{ position: ["bottomLeft"] }} columns={columns}
/> rowKey={"id"}
) dataSource={dataDocument}
}, [dataDocument]) pagination={{ position: ["bottomLeft"] }}
/>
const closeDialogReq = (type) => { )
if (type == "upload") { }, [dataDocument])
getDataDocument();
} const closeDialogReq = (type) => {
setOpenDialogReq(false); if (type == "upload") {
} getDataDocument();
}
const toggleDialogReq = () => { setOpenDialogReq(false);
setOpenDialogReq(!openDialogReq) }
}
const toggleDialogReq = () => {
const openDialogRequest = () => { setOpenDialogReq(!openDialogReq)
setOpenDialogReq(true) }
}
const openDialogRequest = () => {
const cancelDelete = () => { setOpenDialogReq(true)
setAlertDelete(false) }
setIdDelete(0)
} const cancelDelete = () => {
setAlertDelete(false)
const cancelDeleteFolder = () => { setIdDelete(0)
setAlertDeleteFolder(false) }
setIdDelete(0)
} const cancelDeleteFolder = () => {
setAlertDeleteFolder(false)
const onConfirmDelete = async () => { setIdDelete(0)
let urlDel = DOCUMENT_DELETE(idDelete) }
const result = await axios.delete(urlDel, HEADER)
.then(res => res) const onConfirmDelete = async () => {
.catch((error) => error.response); let urlDel = DOCUMENT_DELETE(idDelete)
const result = await axios.delete(urlDel, HEADER)
if (result && result.data && result.data.code === 200) { .then(res => res)
getDataDocument() .catch((error) => error.response);
setIdDelete(0)
setAlertDelete(false) if (result && result.data && result.data.code === 200) {
NotificationManager.success(`Dokumen project berhasil dihapus`, 'Success!!'); getDataDocument()
} else { setIdDelete(0)
setIdDelete(0) setAlertDelete(false)
setAlertDelete(false) NotificationManager.success(`Dokumen project berhasil dihapus`, 'Success!!');
NotificationManager.error(`Dokumen project gagal dihapus`, 'Failed!!'); } else {
} setIdDelete(0)
} setAlertDelete(false)
NotificationManager.error(`Dokumen project gagal dihapus`, 'Failed!!');
const onConfirmDeleteFolder = async () => { }
let urlDel = FOLDER_DOCUMENT_PROYEK_DELETE(idDelete) }
const result = await axios.delete(urlDel, HEADER)
.then(res => res) const onConfirmDeleteFolder = async () => {
.catch((error) => error.response); let urlDel = FOLDER_DOCUMENT_PROYEK_DELETE(idDelete)
const result = await axios.delete(urlDel, HEADER)
if (result && result.data && result.data.code === 200) { .then(res => res)
getDataDocument() .catch((error) => error.response);
setIdDelete(0)
setAlertDeleteFolder(false) if (result && result.data && result.data.code === 200) {
NotificationManager.success(`Folder berhasil dihapus`, 'Success!!'); getDataDocument()
} else { setIdDelete(0)
setIdDelete(0) setAlertDeleteFolder(false)
setAlertDeleteFolder(false) NotificationManager.success(`Folder berhasil dihapus`, 'Success!!');
NotificationManager.error(`Folder gagal dihapus`, 'Failed!!'); } else {
} setIdDelete(0)
} setAlertDeleteFolder(false)
NotificationManager.error(`Folder gagal dihapus`, 'Failed!!');
const closeDialogNewFolder = (type) => { }
if (type == "upload") { }
getDataDocument();
} const closeDialogNewFolder = (type) => {
setOpenDialogNewFolder(false); if (type == "upload") {
setParentIdNewFolder(0); getDataDocument();
} }
setOpenDialogNewFolder(false);
const toggleDialogNewFolder = () => { setParentIdNewFolder(0);
setOpenDialogNewFolder(!openDialogNewFolder) }
}
const toggleDialogNewFolder = () => {
return ( setOpenDialogNewFolder(!openDialogNewFolder)
<> }
<Modal size="xl" isOpen={openDialog} toggle={toggleDialog}>
<ModalHeader className="capitalize withBtn" toggle={closeDialog} style={{ width: "100%" }}> return (
<div>Project Documents - {proyekName} </div> <>
{/* <Button onClick={openDialogRequest} size='sm' color="primary"><i className='fa fa-plus'></i></Button> */} <Modal size="xl" isOpen={openDialog} toggle={toggleDialog}>
{/* <Popover placement="bottom" title="Add" content={popupAddDoc()} trigger="click"> <ModalHeader className="capitalize withBtn" toggle={closeDialog} style={{ width: "100%" }}>
<Button size='sm' color="primary"><i className='fa fa-plus'></i></Button> <div>Project Documents - {proyekName} </div>
</Popover> */} {/* <Button onClick={openDialogRequest} size='sm' color="primary"><i className='fa fa-plus'></i></Button> */}
<div> {/* <Popover placement="bottom" title="Add" content={popupAddDoc()} trigger="click">
<Tooltip title="New Folder"> <Button size='sm' color="primary"><i className='fa fa-plus'></i></Button>
<Button size="sm" color="success" onClick={handleNewFolderWOParent}><i className="fa fa-folder"></i></Button> </Popover> */}
</Tooltip> <div>
<span style={{ marginLeft: 5, marginRight: 5 }}></span> <Tooltip title="New Folder">
<Tooltip title="New File"> <Button size="sm" color="success" onClick={handleNewFolderWOParent}><i className="fa fa-folder"></i></Button>
<Button size="sm" color="primary" onClick={handleNewFileWOParent}><i className="fa fa-file"></i></Button> </Tooltip>
</Tooltip> <span style={{ marginLeft: 5, marginRight: 5 }}></span>
</div> <Tooltip title="New File">
{/* <Button onClick={openDialogRequest} size='sm' color="primary"><i className='fa fa-folder'></i></Button> */} <Button size="sm" color="primary" onClick={handleNewFileWOParent}><i className="fa fa-file"></i></Button>
</ModalHeader> </Tooltip>
<ModalBody> </div>
<div style={{ width: '100%', overflow: "auto" }}> {/* <Button onClick={openDialogRequest} size='sm' color="primary"><i className='fa fa-folder'></i></Button> */}
{RenderTable} </ModalHeader>
</div> <ModalBody>
</ModalBody> <Spin tip="Loading..." spinning={loading}>
{/* <ModalFooter> <div style={{ width: '100%', overflow: "auto" }}>
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> {RenderTable}
</ModalFooter> */} </div>
</Modal> </Spin>
<NotificationContainer /> </ModalBody>
<SweetAlert {/* <ModalFooter>
show={alertDelete} <Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button>
warning </ModalFooter> */}
showCancel </Modal>
confirmBtnText="Delete" <NotificationContainer />
confirmBtnBsStyle="danger" <SweetAlert
title={`Are you sure?`} show={alertDelete}
onConfirm={onConfirmDelete} warning
onCancel={() => cancelDelete()} showCancel
focusCancelBtn confirmBtnText="Delete"
> confirmBtnBsStyle="danger"
Delete this data title={`Are you sure?`}
</SweetAlert> onConfirm={onConfirmDelete}
onCancel={() => cancelDelete()}
<SweetAlert focusCancelBtn
show={alertDeleteFolder} >
warning Delete this data
showCancel </SweetAlert>
confirmBtnText="Delete"
confirmBtnBsStyle="danger" <SweetAlert
title={`Are you sure?`} show={alertDeleteFolder}
onConfirm={onConfirmDeleteFolder} warning
onCancel={() => cancelDeleteFolder()} showCancel
focusCancelBtn confirmBtnText="Delete"
> confirmBtnBsStyle="danger"
Delete this folder title={`Are you sure?`}
</SweetAlert> onConfirm={onConfirmDeleteFolder}
onCancel={() => cancelDeleteFolder()}
<DialogRequest focusCancelBtn
openDialog={openDialogReq} >
closeDialog={closeDialogReq} Delete this folder
toggleDialog={toggleDialogReq} </SweetAlert>
idTask={idTask}
parentIdNewFolder={parentIdNewFolder} <DialogRequest
dataEdit={dataEdit} openDialog={openDialogReq}
/> closeDialog={closeDialogReq}
toggleDialog={toggleDialogReq}
<DialogRequestFolder idTask={idTask}
openDialog={openDialogNewFolder} parentIdNewFolder={parentIdNewFolder}
closeDialog={closeDialogNewFolder} dataEdit={dataEdit}
toggleDialog={toggleDialogNewFolder} />
idTask={idTask}
parentIdNewFolder={parentIdNewFolder} <DialogRequestFolder
dataEdit={dataEdit} openDialog={openDialogNewFolder}
/> closeDialog={closeDialogNewFolder}
</> toggleDialog={toggleDialogNewFolder}
) idTask={idTask}
parentIdNewFolder={parentIdNewFolder}
} dataEdit={dataEdit}
/>
export default DialogDocument; </>
)
}
export default DialogDocument;

Loading…
Cancel
Save