Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release/v3.2.4' into release/v…
Browse files Browse the repository at this point in the history
…3.2.4
  • Loading branch information
ptchayap committed Mar 11, 2024
2 parents ff73007 + 57a7daa commit 0b3c4f2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,7 @@
"editChatMembersModal.confirm.title": "Leave without finishing?",
"editChatMembersModal.confirm.content": "Your progress won’t be saved. Are you sure to leave this page now?",
"editChatMembersModal.confirm.cancelText": "Continue editing",
"editChatMembersModal.confirm.okText": "Leave"
"editChatMembersModal.confirm.okText": "Leave",

"notification.error.blockedWord": "Amity SDK (400308): Text contain blocked word"
}
40 changes: 25 additions & 15 deletions src/social/components/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import useSDK from '~/core/hooks/useSDK';
import useUser from '~/core/hooks/useUser';
import useFile from '~/core/hooks/useFile';
import { CommentRepository } from '@amityco/ts-sdk';
import useCommunity from '~/social/hooks/useCommunity';
import { useCustomComponent } from '~/core/providers/CustomComponentsProvider';
import useCommentFlaggedByMe from '~/social/hooks/useCommentFlaggedByMe';
import useCommentPermission from '~/social/hooks/useCommentPermission';
import useCommentSubscription from '~/social/hooks/useCommentSubscription';
import { ERROR_RESPONSE } from '~/social/constants';

const REPLIES_PER_PAGE = 5;

Expand Down Expand Up @@ -138,18 +138,30 @@ const Comment = ({ commentId, readonly }: CommentProps) => {
) => {
if (!comment?.referenceType || !comment?.referenceId) return;

const { referenceType, referenceId } = comment;

await CommentRepository.createComment({
referenceType,
referenceId,
data: {
text: replyCommentText,
},
parentId: commentId,
metadata,
mentionees,
});
try {
const { referenceType, referenceId } = comment;

await CommentRepository.createComment({
referenceType,
referenceId,
data: {
text: replyCommentText,
},
parentId: commentId,
metadata,
mentionees,
});
setIsReplying(false);
setExpanded(true);
} catch (error: unknown) {
if (error instanceof Error) {
if (error.message === ERROR_RESPONSE.CONTAIN_BLOCKED_WORD) {
notification.error({
content: <FormattedMessage id="notification.error.blockedWord" />,
});
}
}
}
};

const handleEditComment = async (text: string, mentionees: Mentionees, metadata: Metadata) =>
Expand Down Expand Up @@ -288,8 +300,6 @@ const Comment = ({ commentId, readonly }: CommentProps) => {
userToReply={commentAuthor?.displayName}
onSubmit={(replyText, mentionees, metadata) => {
handleReplyToComment(replyText, mentionees, metadata);
setIsReplying(false);
setExpanded(true);
}}
/>
)}
Expand Down
3 changes: 1 addition & 2 deletions src/social/components/CommentComposeBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CommentComposeBar = ({
const { currentUserId } = useSDK();
const user = useUser(currentUserId);
const avatarFileUrl = useImage({ fileId: user?.avatarFileId, imageSize: 'small' });
const { text, markup, mentions, mentionees, metadata, onChange, clearAll, queryMentionees } =
const { text, markup, mentions, mentionees, metadata, onChange, queryMentionees } =
useSocialMention({
targetId: post?.targetId,
targetType: post?.targetType,
Expand Down Expand Up @@ -76,7 +76,6 @@ const CommentComposeBar = ({
}

onSubmit?.(text, mentionees, metadata);
clearAll?.();
};

const isEmpty = text === '';
Expand Down
40 changes: 29 additions & 11 deletions src/social/components/EngagementBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { Mentionees, Metadata } from '~/helpers/utils';
import { useCustomComponent } from '~/core/providers/CustomComponentsProvider';
import useReactionSubscription from '~/social/hooks/useReactionSubscription';
import usePostSubscription from '~/social/hooks/usePostSubscription';
import { notification } from '~/core/components/Notification';
import { FormattedMessage } from 'react-intl';
import useSocialMention from '~/social/hooks/useSocialMention';
import { ERROR_RESPONSE } from '~/social/constants';

interface EngagementBarProps {
postId: string;
Expand All @@ -20,6 +24,10 @@ const EngagementBar = ({ postId, readonly = false }: EngagementBarProps) => {
const hideComposeBar = () => setComposeBarDisplayed(false);

const post = usePost(postId);
const { clearAll } = useSocialMention({
targetType: post?.targetType,
targetId: post?.targetId,
});

usePostSubscription({
postId,
Expand All @@ -39,17 +47,27 @@ const EngagementBar = ({ postId, readonly = false }: EngagementBarProps) => {
mentionees: Mentionees,
metadata: Metadata,
) => {
await CommentRepository.createComment({
referenceType: 'post',
referenceId: postId,
data: {
text: commentText,
},
mentionees,
metadata,
});

hideComposeBar();
try {
await CommentRepository.createComment({
referenceType: 'post',
referenceId: postId,
data: {
text: commentText,
},
mentionees,
metadata,
});
clearAll?.();
hideComposeBar();
} catch (error: unknown) {
if (error instanceof Error) {
if (error.message === ERROR_RESPONSE.CONTAIN_BLOCKED_WORD) {
notification.error({
content: <FormattedMessage id="notification.error.blockedWord" />,
});
}
}
}
};

return (
Expand Down
9 changes: 9 additions & 0 deletions src/social/components/post/Creator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { MAXIMUM_POST_CHARACTERS, MAXIMUM_POST_MENTIONEES } from './constants';
import useSDK from '~/core/hooks/useSDK';
import useSocialMention from '~/social/hooks/useSocialMention';
import useCommunityModeratorsCollection from '~/social/hooks/collections/useCommunityModeratorsCollection';
import { ERROR_RESPONSE } from '~/social/constants';

const useTargetData = ({
targetId,
Expand Down Expand Up @@ -227,6 +228,14 @@ const PostCreatorBar = ({
});
}
}
} catch (error: unknown) {
if (error instanceof Error) {
if (error.message === ERROR_RESPONSE.CONTAIN_BLOCKED_WORD) {
notification.error({
content: <FormattedMessage id="notification.error.blockedWord" />,
});
}
}
} finally {
setIsCreating(false);
}
Expand Down
20 changes: 16 additions & 4 deletions src/social/components/post/PollComposer/PollModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState } from 'react';
import { useIntl } from 'react-intl';
import { FormattedMessage, useIntl } from 'react-intl';
import { PollRepository } from '@amityco/ts-sdk';

import Modal from '~/core/components/Modal';
import { confirm } from '~/core/components/Confirm';
import PollComposer from '~/social/components/post/PollComposer';
import { notification } from '~/core/components/Notification';
import { ERROR_RESPONSE } from '~/social/constants';

interface PollModalProps {
targetId?: string | null;
Expand All @@ -27,9 +29,19 @@ const PollModal = ({ targetId, targetType, onClose, onCreatePoll }: PollModalPro
mentionees: Amity.UserMention[],
metadata: Record<string, unknown>,
) => {
const createdPoll = await PollRepository.createPoll(data);
await onCreatePoll(createdPoll.data.pollId, data.question, mentionees, metadata);
onClose();
try {
const createdPoll = await PollRepository.createPoll(data);
await onCreatePoll(createdPoll.data.pollId, data.question, mentionees, metadata);
onClose();
} catch (error: unknown) {
if (error instanceof Error) {
if (error.message === ERROR_RESPONSE.CONTAIN_BLOCKED_WORD) {
notification.error({
content: <FormattedMessage id="notification.error.blockedWord" />,
});
}
}
}
};

const closeConfirm = () =>
Expand Down
4 changes: 4 additions & 0 deletions src/social/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ export const VideoQuality = Object.freeze({
});

export const MP4MimeType = 'video/mp4';

export const ERROR_RESPONSE = Object.freeze({
CONTAIN_BLOCKED_WORD: 'Amity SDK (400308): Text contain blocked word',
});

0 comments on commit 0b3c4f2

Please sign in to comment.