import React from 'react'; import { UserPicture } from '@growi/ui/dist/components'; import { format } from 'date-fns'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import { ICommentHasId } from '../../interfaces/comment'; import { Username } from '../User/Username'; import styles from './DeleteCommentModal.module.scss'; export type DeleteCommentModalProps = { isShown: boolean, comment: ICommentHasId | null, errorMessage: string, cancelToDelete: () => void, confirmToDelete: () => void, } export const DeleteCommentModal = (props: DeleteCommentModalProps): JSX.Element => { const { isShown, comment, errorMessage, cancelToDelete, confirmToDelete, } = props; const headerContent = () => { if (comment == null || isShown === false) { return <>; } return ( Delete comment? ); }; const bodyContent = () => { if (comment == null || isShown === false) { return <>; } // the threshold for omitting body const OMIT_BODY_THRES = 400; const commentDate = format(new Date(comment.createdAt), 'yyyy/MM/dd HH:mm'); let commentBody = comment.comment; if (commentBody.length > OMIT_BODY_THRES) { // omit commentBody = `${commentBody.substr(0, OMIT_BODY_THRES)}...`; } const commentBodyElement = {commentBody}; return ( <> wrote on {commentDate}:

{commentBodyElement}

); }; const footerContent = () => { if (comment == null || isShown === false) { return <>; } return ( <> {errorMessage}  ); }; return ( {headerContent()} {bodyContent()} {footerContent()} ); };