import type { JSX } from 'react'; import type { IAttachmentHasId } from '@growi/core'; import { format } from 'date-fns/format'; import { UserPicture } from './UserPicture'; type AttachmentProps = { attachment: IAttachmentHasId; inUse: boolean; onAttachmentDeleteClicked?: (attachment: IAttachmentHasId) => void; isUserLoggedIn?: boolean; }; export const Attachment = (props: AttachmentProps): JSX.Element => { const { attachment, inUse, isUserLoggedIn, onAttachmentDeleteClicked } = props; const _onAttachmentDeleteClicked = () => { if (onAttachmentDeleteClicked != null) { onAttachmentDeleteClicked(attachment); } }; const formatIcon = attachment.fileFormat.match(/image\/.+/i) ? 'image' : 'description'; const btnDownload = isUserLoggedIn ? ( cloud_download ) : ( '' ); const btnTrash = isUserLoggedIn ? ( ) : ( '' ); const fileType = ( {attachment.fileFormat} ); const fileInUse = inUse ? ( In Use ) : ( '' ); // Should UserDate be used like PageRevisionTable ? const formatType = 'yyyy/MM/dd HH:mm:ss'; const createdAt = format(new Date(attachment.createdAt), formatType); return (