Skip to content

Commit

Permalink
new Post inside existing Discussion async-labs#18
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Apr 26, 2019
1 parent dba1d81 commit c5f1522
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 0 additions & 2 deletions app/components/discussions/CreateDiscussionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ class CreateDiscussionForm extends React.Component<Props, State> {
notificationType,
});

// await discussion.addPost(content);

const post = await discussion.addPost(content);

if (discussion.notificationType === 'email') {
Expand Down
21 changes: 19 additions & 2 deletions app/components/posts/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { Discussion, Post, Store, User } from '../../lib/store';

import PostEditor from './PostEditor';

const dev = process.env.NODE_ENV !== 'production';
const { PRODUCTION_URL_APP } = process.env;
const URL_APP = dev ? 'http://localhost:3000' : PRODUCTION_URL_APP;

const styles = {
paper: {
width: '100%', // TODO: should 100% when isMobile is true
Expand Down Expand Up @@ -181,9 +185,22 @@ class PostForm extends React.Component<MyProps, MyState> {
this.setState({ disabled: true });

try {
await discussion.addPost(content);
const newPost = await discussion.addPost(content);

if (discussion.notificationType === 'email') {
const userIdsForLambda = discussion.memberIds.filter(m => m !== discussion.createdUserId);
console.log(discussion.notificationType, userIdsForLambda);
await discussion.sendDataToLambdaApiMethod({
discussionName: discussion.name,
discussionLink: `${URL_APP}/team/${discussion.team.slug}/discussions/${discussion.slug}`,
postContent: newPost.content,
authorName: newPost.user.displayName,
userIds: userIdsForLambda,
});
}
this.setState({ content: '' });
notify('You successfully published Post.');
notify('You successfully published new Post.');

} catch (error) {
console.log(error);
notify(error);
Expand Down

0 comments on commit c5f1522

Please sign in to comment.