Files
old-new-wiaas/frontend/src/containers/orders/components/OrderDocumentsGroup.jsx

63 lines
2.1 KiB
React
Raw Normal View History

2018-06-14 16:49:28 +02:00
import React, {Component} from 'react';
import WiaasBox from '../../../mainComponents/box/WiaasBox.jsx';
import {API_SERVER} from '../../../config';
import FileDownloader from '../../../helpers/FileDownloader';
const fileHandler = new FileDownloader();
const iconTypes = {
doc: 'file-word-o',
docx: 'file-word-o',
odt: 'file-word-o',
ods: 'file-excel-o',
pdf: 'file-pdf-o',
png: 'file-image-o',
jpg: 'file-image-o',
xls: 'file-excel-o',
xlsx: 'file-excel-o',
ppt: 'file-powerpoint-o',
pptx: 'file-powerpoint-o'
2018-10-03 16:46:41 +02:00
};
2018-06-14 16:49:28 +02:00
class OrderDocumentsGroup extends Component {
constructor(props) {
super(props);
this.state = {};
}
getDocumentIcon(documentType) {
return iconTypes[documentType] || 'file';
}
2018-10-03 16:46:41 +02:00
downloadDocument(orderId, itemId, document){
const fileUrl = `${API_SERVER}/wp-json/wiaas/documents/order/${orderId}/${document.type}?item_id=${itemId}&document_key=${document.key}`;
fileHandler.download(fileUrl, document.name);
2018-06-14 16:49:28 +02:00
}
render() {
2018-10-03 16:46:41 +02:00
const {documentsGroup, orderId} = this.props;
2018-06-14 16:49:28 +02:00
return (
<div>
{
2018-08-15 22:21:29 +02:00
documentsGroup.documents &&
2018-06-14 16:49:28 +02:00
documentsGroup.documents.length > 0 &&
2018-10-03 16:46:41 +02:00
<WiaasBox mainTitle={documentsGroup.name}>
2018-06-14 16:49:28 +02:00
{
2018-10-03 16:46:41 +02:00
documentsGroup.documents.map(document => <a id={'document-' + document.key} key={'order-document-' + document.key}>
<div onClick={() => {this.downloadDocument(orderId, documentsGroup.orderItemId, document)}} className="document-link-big">
2018-06-14 16:49:28 +02:00
<i className={'fa fa-4x fa-' + this.getDocumentIcon(document.extension)} aria-hidden="true"></i>
<div>
2018-10-03 16:46:41 +02:00
{document.name}
2018-06-14 16:49:28 +02:00
</div>
</div></a>)
}
</WiaasBox>
}
</div>)
}
}
export default OrderDocumentsGroup;