2019-09-18 13:40:00 +02:00
|
|
|
import * as React from 'react';
|
2022-06-05 11:40:43 +02:00
|
|
|
import I18n from 'i18n-js';
|
2019-10-02 15:26:32 +02:00
|
|
|
import Gravatar from 'react-gravatar';
|
2019-09-18 13:40:00 +02:00
|
|
|
|
2022-05-28 11:03:36 +02:00
|
|
|
import NewCommentUpdateSection from './NewCommentUpdateSection';
|
|
|
|
|
|
2019-09-18 13:40:00 +02:00
|
|
|
import Button from '../shared/Button';
|
2019-09-20 18:43:24 +02:00
|
|
|
import Spinner from '../shared/Spinner';
|
2019-09-26 18:22:18 +02:00
|
|
|
import { DangerText } from '../shared/CustomTexts';
|
2019-09-18 13:40:00 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
body: string;
|
|
|
|
|
parentId: number;
|
2022-05-28 11:03:36 +02:00
|
|
|
postUpdateFlagValue: boolean;
|
2019-09-20 18:43:24 +02:00
|
|
|
isSubmitting: boolean;
|
2019-09-26 18:22:18 +02:00
|
|
|
error: string;
|
2019-09-26 11:00:32 +02:00
|
|
|
handleChange(e: React.FormEvent): void;
|
2022-05-28 11:03:36 +02:00
|
|
|
handlePostUpdateFlag(): void;
|
|
|
|
|
handleSubmit(
|
|
|
|
|
body: string,
|
|
|
|
|
parentId: number,
|
|
|
|
|
isPostUpdate: boolean
|
|
|
|
|
): void;
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn: boolean;
|
2022-05-28 11:03:36 +02:00
|
|
|
isPowerUser: boolean;
|
2019-10-02 15:26:32 +02:00
|
|
|
userEmail: string;
|
2019-09-18 13:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NewComment = ({
|
|
|
|
|
body,
|
|
|
|
|
parentId,
|
2022-05-28 11:03:36 +02:00
|
|
|
postUpdateFlagValue,
|
2019-09-20 18:43:24 +02:00
|
|
|
isSubmitting,
|
2019-09-26 18:22:18 +02:00
|
|
|
error,
|
2019-09-18 13:40:00 +02:00
|
|
|
handleChange,
|
2022-05-28 11:03:36 +02:00
|
|
|
handlePostUpdateFlag,
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmit,
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn,
|
2022-05-28 11:03:36 +02:00
|
|
|
isPowerUser,
|
2019-10-02 15:26:32 +02:00
|
|
|
userEmail,
|
2019-09-18 13:40:00 +02:00
|
|
|
}: Props) => (
|
2019-09-26 18:22:18 +02:00
|
|
|
<React.Fragment>
|
|
|
|
|
<div className="newCommentForm">
|
|
|
|
|
{
|
|
|
|
|
isLoggedIn ?
|
|
|
|
|
<React.Fragment>
|
2022-05-28 11:03:36 +02:00
|
|
|
<div className="commentBodyForm">
|
|
|
|
|
<Gravatar email={userEmail} size={48} className="currentUserAvatar" />
|
|
|
|
|
<textarea
|
|
|
|
|
value={body}
|
|
|
|
|
onChange={handleChange}
|
2022-06-05 11:40:43 +02:00
|
|
|
placeholder={I18n.t('post.new_comment.body_placeholder')}
|
2022-05-28 11:03:36 +02:00
|
|
|
className="newCommentBody"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => handleSubmit(body, parentId, postUpdateFlagValue)}
|
|
|
|
|
className="submitCommentButton">
|
2022-06-05 11:40:43 +02:00
|
|
|
{ isSubmitting ? <Spinner color="light" /> : I18n.t('post.new_comment.submit_button') }
|
2022-05-28 11:03:36 +02:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{
|
|
|
|
|
isPowerUser && parentId == null ?
|
|
|
|
|
<NewCommentUpdateSection
|
|
|
|
|
postUpdateFlagValue={postUpdateFlagValue}
|
|
|
|
|
handlePostUpdateFlag={handlePostUpdateFlag}
|
|
|
|
|
/>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
2019-09-26 18:22:18 +02:00
|
|
|
</React.Fragment>
|
|
|
|
|
:
|
2022-06-05 11:40:43 +02:00
|
|
|
<a href="/users/sign_in" className="loginInfo">
|
|
|
|
|
{I18n.t('post.new_comment.not_logged_in')}
|
|
|
|
|
</a>
|
2019-09-26 18:22:18 +02:00
|
|
|
}
|
|
|
|
|
</div>
|
2022-06-05 11:40:43 +02:00
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
{ error ? <DangerText>{error}</DangerText> : null }
|
|
|
|
|
</React.Fragment>
|
2019-09-18 13:40:00 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default NewComment;
|