import React from 'react';
import { isPopulated } from '@growi/core';
import { UserPicture } from '@growi/ui/dist/components';
import { format } from 'date-fns/format';
import { useTranslation } from 'next-i18next';
import {
Button, Modal, ModalHeader, ModalBody, ModalFooter,
} from 'reactstrap';
import { Username } from '../../../components/User/Username';
import type { ICommentHasId } from '../../../interfaces/comment';
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 { t } = useTranslation();
const headerContent = () => {
if (comment == null || isShown === false) {
return <>>;
}
return (
delete_forever
{t('page_comment.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');
const creator = isPopulated(comment.creator) ? comment.creator : undefined;
let commentBody = comment.comment;
if (commentBody.length > OMIT_BODY_THRES) { // omit
commentBody = `${commentBody.substr(0, OMIT_BODY_THRES)}...`;
}
const commentBodyElement = {commentBody};
return (
<>