import React from 'react'; import PropTypes from 'prop-types'; import Flex from '../common/Flex'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { UncontrolledTooltip } from 'reactstrap'; import truncate from 'lodash/truncate'; import join from 'lodash/join'; const getIcon = type => { const icon = ['far']; if (type.includes('image')) { icon.push('file-image'); } if (type.includes('video')) { icon.push('file-video'); } if (type.includes('audio')) { icon.push('file-audio'); } if (type.includes('zip')) { icon.push('file-archive'); } if (type.includes('pdf')) { icon.push('file-pdf'); } if (type.includes('html') || type.includes('css') || type.includes('json') || type.includes('javascript')) { icon.push('file-code'); } if (icon.length === 1) { icon.push('file'); } return icon; }; const getName = name => { const nameStrings = name.split('.'); const extension = nameStrings.pop(); return `${truncate(join(nameStrings), { length: 24, omission: '[...]' })}.${extension}`; }; const ComposeAttachment = ({ id, name, size, handleDetachAttachment, type }) => ( {getName(name)} ({(size / 1024).toFixed(2)}kb) handleDetachAttachment(id)} > Detach ); ComposeAttachment.propTypes = { id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, name: PropTypes.string.isRequired, size: PropTypes.number.isRequired, handleDetachAttachment: PropTypes.func.isRequired, type: PropTypes.string.isRequired }; ComposeAttachment.defaultProps = { value: `ComposeAttachment` }; export default ComposeAttachment;