/* eslint-disable react/prop-types */ import React, { useCallback } from 'react'; import { HasObjectId, IAttachment } from '@growi/core'; import { UserPicture } from '@growi/ui'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import Username from '../User/Username'; function iconNameByFormat(format: string): string { if (format.match(/image\/.+/i)) { return 'icon-picture'; } return 'icon-doc'; } type Props = { isOpen: boolean, toggle: () => void, attachmentToDelete: IAttachment & HasObjectId | null, deleting: boolean, deleteError: string, onAttachmentDeleteClickedConfirm?: (attachment: IAttachment & HasObjectId) => Promise, } export const DeleteAttachmentModal = (props: Props): JSX.Element => { const { isOpen, toggle, attachmentToDelete, deleting, deleteError, onAttachmentDeleteClickedConfirm, } = props; const onDeleteConfirm = useCallback(() => { if (attachmentToDelete == null || onAttachmentDeleteClickedConfirm == null) { return; } onAttachmentDeleteClickedConfirm(attachmentToDelete); }, [attachmentToDelete, onAttachmentDeleteClickedConfirm]); const renderByFileFormat = useCallback((attachment) => { const content = (attachment.fileFormat.match(/image\/.+/i)) // eslint-disable-next-line @next/next/no-img-element ? deleting image : ''; return (

{attachment.originalName}

uploaded by

{content}
); }, []); let deletingIndicator = <>; if (deleting) { deletingIndicator =
; } if (deleteError) { deletingIndicator = {deleteError}; } return ( Delete attachment? {renderByFileFormat(attachmentToDelete)}
{deletingIndicator}
); };