| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /* eslint-disable react/prop-types */
- import React from 'react';
- import {
- Button,
- Modal, ModalHeader, ModalBody, ModalFooter,
- } from 'reactstrap';
- import UserPicture from '../User/UserPicture';
- import Username from '../User/Username';
- export default class DeleteAttachmentModal extends React.Component {
- constructor(props) {
- super(props);
- this._onDeleteConfirm = this._onDeleteConfirm.bind(this);
- }
- _onDeleteConfirm() {
- this.props.onAttachmentDeleteClickedConfirm(this.props.attachmentToDelete);
- }
- iconNameByFormat(format) {
- if (format.match(/image\/.+/i)) {
- return 'icon-picture';
- }
- return 'icon-doc';
- }
- renderByFileFormat(attachment) {
- const content = (attachment.fileFormat.match(/image\/.+/i))
- ? <img src={attachment.filePathProxied} alt="deleting image" />
- : '';
- return (
- <div className="attachment-delete-image">
- <p>
- <i className={this.iconNameByFormat(attachment.fileFormat)}></i> {attachment.originalName}
- </p>
- <p>
- uploaded by <UserPicture user={attachment.creator} size="sm"></UserPicture> <Username user={attachment.creator}></Username>
- </p>
- {content}
- </div>
- );
- }
- render() {
- const attachment = this.props.attachmentToDelete;
- if (attachment === null) {
- return null;
- }
- const props = Object.assign({}, this.props);
- delete props.onAttachmentDeleteClickedConfirm;
- delete props.attachmentToDelete;
- delete props.inUse;
- delete props.deleting;
- delete props.deleteError;
- let deletingIndicator = '';
- if (this.props.deleting) {
- deletingIndicator = <div className="speeding-wheel-sm"></div>;
- }
- if (this.props.deleteError) {
- deletingIndicator = <span>{this.props.deleteError}</span>;
- }
- const renderAttachment = this.renderByFileFormat(attachment);
- return (
- <Modal {...props} className="attachment-delete-modal" bsSize="large" aria-labelledby="contained-modal-title-lg">
- <ModalHeader tag="h4" toggle={this.props.toggle}>
- <span id="contained-modal-title-lg">Delete attachment?</span>
- </ModalHeader>
- <ModalBody>
- {renderAttachment}
- </ModalBody>
- <ModalFooter>
- <div className="mr-3 d-inline-block">
- {deletingIndicator}
- </div>
- <Button
- color="danger"
- onClick={this._onDeleteConfirm}
- disabled={this.props.deleting}
- >Delete!
- </Button>
- </ModalFooter>
- </Modal>
- );
- }
- }
|