2019-09-12 15:51:45 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
|
|
import IPost from '../../interfaces/IPost';
|
|
|
|
|
import IPostStatus from '../../interfaces/IPostStatus';
|
|
|
|
|
|
|
|
|
|
import PostStatusSelect from './PostStatusSelect';
|
2019-09-12 18:03:19 +02:00
|
|
|
import PostStatusLabel from '../shared/PostStatusLabel';
|
2019-09-17 11:33:18 +02:00
|
|
|
import Comments from '../../containers/Comments';
|
2019-09-12 15:51:45 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
postId: number;
|
|
|
|
|
post: IPost;
|
|
|
|
|
postStatuses: Array<IPostStatus>;
|
|
|
|
|
isLoggedIn: boolean;
|
|
|
|
|
isPowerUser: boolean;
|
|
|
|
|
authenticityToken: string;
|
|
|
|
|
|
|
|
|
|
requestPost(postId: number): void;
|
|
|
|
|
changePostStatus(
|
|
|
|
|
postId: number,
|
|
|
|
|
newPostStatusId: number,
|
|
|
|
|
authenticityToken: string,
|
|
|
|
|
): void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PostP extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.requestPost(this.props.postId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
post,
|
|
|
|
|
postStatuses,
|
|
|
|
|
|
|
|
|
|
isPowerUser,
|
|
|
|
|
authenticityToken,
|
|
|
|
|
|
|
|
|
|
changePostStatus,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2019-09-12 18:03:19 +02:00
|
|
|
<h2>{post.title}</h2>
|
2019-09-12 15:51:45 +02:00
|
|
|
{
|
2019-09-12 18:03:19 +02:00
|
|
|
isPowerUser && post ?
|
2019-09-12 15:51:45 +02:00
|
|
|
<PostStatusSelect
|
|
|
|
|
postStatuses={postStatuses}
|
|
|
|
|
selectedPostStatusId={post.postStatusId}
|
|
|
|
|
handleChange={
|
|
|
|
|
newPostStatusId => changePostStatus(post.id, newPostStatusId, authenticityToken)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
:
|
2019-09-12 18:03:19 +02:00
|
|
|
<PostStatusLabel
|
|
|
|
|
{...postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
|
|
|
|
|
/>
|
2019-09-12 15:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<p>{post.description}</p>
|
2019-09-17 11:33:18 +02:00
|
|
|
|
|
|
|
|
<Comments postId={this.props.postId} />
|
2019-09-12 15:51:45 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default PostP;
|