Files
astuto/app/javascript/components/Comments/CommentFooter.tsx

81 lines
2.0 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import I18n from 'i18n-js';
import Separator from '../common/Separator';
import { MutedText } from '../common/CustomTexts';
import friendlyDate from '../../helpers/datetime';
import { ReplyFormState } from '../../reducers/replyFormReducer';
2022-08-22 10:38:03 +02:00
import ActionLink from '../common/ActionLink';
import { CancelIcon, DeleteIcon, EditIcon, ReplyIcon } from '../common/Icons';
interface Props {
id: number;
createdAt: string;
updatedAt: string;
replyForm: ReplyFormState;
isPowerUser: boolean;
currentUserEmail: string;
commentAuthorEmail: string;
handleDeleteComment(id: number): void;
handleToggleCommentReply(): void;
toggleEditMode(): void;
}
const CommentFooter = ({
id,
createdAt,
updatedAt,
replyForm,
isPowerUser,
currentUserEmail,
commentAuthorEmail,
handleDeleteComment,
handleToggleCommentReply,
toggleEditMode,
}: Props) => (
<div className="commentFooter">
2022-08-22 10:38:03 +02:00
<ActionLink
onClick={handleToggleCommentReply}
icon={replyForm.isOpen ? <CancelIcon /> : <ReplyIcon />}
2023-03-19 19:57:53 +01:00
customClass={replyForm.isOpen ? 'cancelAction' : 'replyAction'}
2022-08-22 10:38:03 +02:00
>
{
replyForm.isOpen ?
I18n.t('common.buttons.cancel')
:
I18n.t('post.comments.reply_button')
}
2022-08-22 10:38:03 +02:00
</ActionLink>
{
isPowerUser || currentUserEmail === commentAuthorEmail ?
<>
2022-08-22 10:38:03 +02:00
<ActionLink onClick={toggleEditMode} icon={<EditIcon />}>
{I18n.t('common.buttons.edit')}
2022-08-22 10:38:03 +02:00
</ActionLink>
2022-08-22 10:38:03 +02:00
<ActionLink
onClick={() => confirm(I18n.t('common.confirmation')) && handleDeleteComment(id)}
2022-08-22 10:38:03 +02:00
icon={<DeleteIcon />}
>
{I18n.t('common.buttons.delete')}
</ActionLink>
</>
:
null
}
2022-08-22 10:38:03 +02:00
<MutedText>{friendlyDate(createdAt)}</MutedText>
{
2022-08-22 10:38:03 +02:00
createdAt !== updatedAt &&
<>
<Separator />
<MutedText>{ I18n.t('common.edited').toLowerCase() }</MutedText>
</>
}
</div>
);
export default CommentFooter;