From 4ff549008a7fd47ac78d32ca5cc961e4beee3409 Mon Sep 17 00:00:00 2001 From: akanshaaaa19 Date: Thu, 28 Mar 2024 15:46:37 +0530 Subject: [PATCH 1/5] added error messages in wa groups --- src/components/UI/Form/EmojiInput/Editor.tsx | 2 +- .../ChatMessages/ChatMessage/ChatMessage.tsx | 23 ++++++++++++++----- .../WaGroups/GroupMessageSubscription.tsx | 9 ++++++++ src/graphql/subscriptions/Groups.ts | 13 +++++++++++ src/services/SubscriptionService.ts | 8 +++++-- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/components/UI/Form/EmojiInput/Editor.tsx b/src/components/UI/Form/EmojiInput/Editor.tsx index 1047dfcf2..82985ca33 100644 --- a/src/components/UI/Form/EmojiInput/Editor.tsx +++ b/src/components/UI/Form/EmojiInput/Editor.tsx @@ -48,7 +48,7 @@ export const Editor = ({ const [editor] = useLexicalComposerContext(); useEffect(() => { - if (field.value && !editorState && isEditing) { + if (!editorState && isEditing) { setInitialState(editor, field.value); } }, [field.value]); diff --git a/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx b/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx index 98f2e3e4a..cfeb35401 100644 --- a/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx +++ b/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx @@ -129,12 +129,23 @@ export const ChatMessage = ({ ); } else if (Object.prototype.hasOwnProperty.call(messageError, 'message')) { messageErrorStatus = parseTextMethod(messageError.message); - tooltipTitle = ( - <> - {tooltipTitle} -
{messageErrorStatus[0]}
- - ); + + if (Object.prototype.hasOwnProperty.call(messageErrorStatus, 'message')) { + const messageStatus = messageErrorStatus.message; + tooltipTitle = ( + <> + {tooltipTitle} +
{messageStatus}
+ + ); + } else { + tooltipTitle = ( + <> + {tooltipTitle} +
{messageErrorStatus[0]}
+ + ); + } } else if (Object.keys(messageError).length !== 0) { messageErrorStatus = true; tooltipTitle = ( diff --git a/src/containers/WaGroups/GroupMessageSubscription.tsx b/src/containers/WaGroups/GroupMessageSubscription.tsx index eeff6a6e2..72f8ecf71 100644 --- a/src/containers/WaGroups/GroupMessageSubscription.tsx +++ b/src/containers/WaGroups/GroupMessageSubscription.tsx @@ -12,6 +12,7 @@ import { randomIntFromInterval, addLogs } from 'common/utils'; import { GROUP_SEARCH_QUERY } from 'graphql/queries/WaGroups'; import { SENT_MESSAGE_WA_GROUP_COLLECTION, + UPDATE_WA_MESSAGE_STATUS, WA_MESSAGE_RECEIVED_SUBSCRIPTION, WA_MESSAGE_SENT_SUBSCRIPTION, } from 'graphql/subscriptions/Groups'; @@ -219,6 +220,14 @@ export const GroupMessageSubscription = ({ setDataLoaded }: GroupMessageProps) = updateQuery: (prev, { subscriptionData }) => updateConversations(prev, subscriptionData, 'SENT'), }); + + subscribeToMore({ + document: UPDATE_WA_MESSAGE_STATUS, + variables: subscriptionVariables, + onError: (error) => console.log(error), + updateQuery: (prev, { subscriptionData }) => + updateConversations(prev, subscriptionData, 'STATUS'), + }); } }, [subscribeToMore]); diff --git a/src/graphql/subscriptions/Groups.ts b/src/graphql/subscriptions/Groups.ts index 5f7f7c6db..9ced03d8d 100644 --- a/src/graphql/subscriptions/Groups.ts +++ b/src/graphql/subscriptions/Groups.ts @@ -118,3 +118,16 @@ export const SENT_MESSAGE_WA_GROUP_COLLECTION = gql` } } `; + +export const UPDATE_WA_MESSAGE_STATUS = gql` + subscription UpdateWaMessageStatus($organizationId: ID!) { + updateWaMessageStatus(organizationId: $organizationId) { + id + messageNumber + errors + waGroup { + id + } + } + } +`; diff --git a/src/services/SubscriptionService.ts b/src/services/SubscriptionService.ts index 326ad0052..55a55710e 100644 --- a/src/services/SubscriptionService.ts +++ b/src/services/SubscriptionService.ts @@ -78,8 +78,12 @@ export const getSubscriptionDetails = (action: string, subscriptionData: any, gr break; case 'STATUS': // set the receiver contact id - messageStatusData = subscriptionData.data.updateMessageStatus; - entityId = subscriptionData.data.updateMessageStatus.receiver.id; + messageStatusData = groups + ? subscriptionData.data.updateWaMessageStatus + : subscriptionData.data.updateMessageStatus; + entityId = groups + ? subscriptionData.data.updateWaMessageStatus + : subscriptionData.data.updateMessageStatus.waGroup.id; break; default: break; From 64b4b7b2d9019d22ef92c1493a186143ab219da5 Mon Sep 17 00:00:00 2001 From: akanshaaaa19 Date: Thu, 28 Mar 2024 15:52:32 +0530 Subject: [PATCH 2/5] added error messages in wa groups --- src/components/UI/Form/EmojiInput/Editor.tsx | 2 +- src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/UI/Form/EmojiInput/Editor.tsx b/src/components/UI/Form/EmojiInput/Editor.tsx index 82985ca33..1047dfcf2 100644 --- a/src/components/UI/Form/EmojiInput/Editor.tsx +++ b/src/components/UI/Form/EmojiInput/Editor.tsx @@ -48,7 +48,7 @@ export const Editor = ({ const [editor] = useLexicalComposerContext(); useEffect(() => { - if (!editorState && isEditing) { + if (field.value && !editorState && isEditing) { setInitialState(editor, field.value); } }, [field.value]); diff --git a/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx b/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx index cfeb35401..42befd2a5 100644 --- a/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx +++ b/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx @@ -129,7 +129,6 @@ export const ChatMessage = ({ ); } else if (Object.prototype.hasOwnProperty.call(messageError, 'message')) { messageErrorStatus = parseTextMethod(messageError.message); - if (Object.prototype.hasOwnProperty.call(messageErrorStatus, 'message')) { const messageStatus = messageErrorStatus.message; tooltipTitle = ( From c0a80b2073d026f00a013b62603629873b06a936 Mon Sep 17 00:00:00 2001 From: akanshaaaa19 Date: Thu, 28 Mar 2024 15:59:34 +0530 Subject: [PATCH 3/5] added error messages in wa groups --- src/services/SubscriptionService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/SubscriptionService.ts b/src/services/SubscriptionService.ts index 55a55710e..f638148c3 100644 --- a/src/services/SubscriptionService.ts +++ b/src/services/SubscriptionService.ts @@ -82,8 +82,8 @@ export const getSubscriptionDetails = (action: string, subscriptionData: any, gr ? subscriptionData.data.updateWaMessageStatus : subscriptionData.data.updateMessageStatus; entityId = groups - ? subscriptionData.data.updateWaMessageStatus - : subscriptionData.data.updateMessageStatus.waGroup.id; + ? subscriptionData.data.updateWaMessageStatus.waGroup.id + : subscriptionData.data.updateMessageStatus.receiver.id; break; default: break; From e2daeddb4ea491e2ef9e4243116384b35595a5f7 Mon Sep 17 00:00:00 2001 From: akanshaaaa19 Date: Thu, 28 Mar 2024 17:01:07 +0530 Subject: [PATCH 4/5] fix for interactivve message --- src/components/UI/Form/EmojiInput/Editor.tsx | 2 +- src/containers/InteractiveMessage/InteractiveMessage.tsx | 5 +++-- src/containers/Template/Form/Template.tsx | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/UI/Form/EmojiInput/Editor.tsx b/src/components/UI/Form/EmojiInput/Editor.tsx index 1047dfcf2..a2f20dbcd 100644 --- a/src/components/UI/Form/EmojiInput/Editor.tsx +++ b/src/components/UI/Form/EmojiInput/Editor.tsx @@ -48,7 +48,7 @@ export const Editor = ({ const [editor] = useLexicalComposerContext(); useEffect(() => { - if (field.value && !editorState && isEditing) { + if ((field.value || field.value === '') && !editorState && isEditing) { setInitialState(editor, field.value); } }, [field.value]); diff --git a/src/containers/InteractiveMessage/InteractiveMessage.tsx b/src/containers/InteractiveMessage/InteractiveMessage.tsx index 4615ea188..b992f876a 100644 --- a/src/containers/InteractiveMessage/InteractiveMessage.tsx +++ b/src/containers/InteractiveMessage/InteractiveMessage.tsx @@ -166,7 +166,7 @@ export const InteractiveMessage = () => { setTitle(data.title); setFooter(data.footer || ''); - setBody(data.body); + setBody(data.body || ''); setEditorState(null); setTemplateType(typeValue); setTemplateTypeField(templateTypeOptions.find((option) => option.id === typeValue)); @@ -236,7 +236,8 @@ export const InteractiveMessage = () => { setTitle(titleText); setFooter(data.footer || ''); - setBody(data.body); + setBody(data.body || ''); + setEditorState(null); setTemplateType(typeValue); setTemplateTypeField(templateTypeOptions.find((option) => option.id === typeValue)); setTimeout(() => setTemplateButtons(data.templateButtons), 100); diff --git a/src/containers/Template/Form/Template.tsx b/src/containers/Template/Form/Template.tsx index aae4b2bc7..89400c36c 100644 --- a/src/containers/Template/Form/Template.tsx +++ b/src/containers/Template/Form/Template.tsx @@ -282,7 +282,8 @@ const Template = ({ setIsActive(isActiveValue); if (typeof bodyValue === 'string') { - setBody(bodyValue); + setBody(bodyValue || ''); + setEditorState(null); } if (exampleValue) { @@ -322,7 +323,7 @@ const Template = ({ ) { const content = translationsCopy[currentLanguage]; setLabel(content.label); - setBody(content.body); + setBody(content.body || ''); setEditorState(null); } setTranslations(translationsValue); @@ -357,7 +358,8 @@ const Template = ({ setLabel(labelValue); if (typeof bodyValue === 'string') { - setBody(bodyValue); + setBody(bodyValue || ''); + setEditorState(null); } if (typeValue && typeValue !== 'TEXT') { From b2ede77805e31c4126a035c0005834453cd411f6 Mon Sep 17 00:00:00 2001 From: akanshaaaa19 Date: Thu, 28 Mar 2024 18:19:22 +0530 Subject: [PATCH 5/5] refactor --- .../ChatMessages/ChatMessage/ChatMessage.tsx | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx b/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx index 42befd2a5..df143aff1 100644 --- a/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx +++ b/src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx @@ -129,22 +129,20 @@ export const ChatMessage = ({ ); } else if (Object.prototype.hasOwnProperty.call(messageError, 'message')) { messageErrorStatus = parseTextMethod(messageError.message); + let messageStatus: any; + if (Object.prototype.hasOwnProperty.call(messageErrorStatus, 'message')) { - const messageStatus = messageErrorStatus.message; - tooltipTitle = ( - <> - {tooltipTitle} -
{messageStatus}
- - ); + messageStatus = messageErrorStatus.message; } else { - tooltipTitle = ( - <> - {tooltipTitle} -
{messageErrorStatus[0]}
- - ); + messageStatus = messageErrorStatus[0]; } + + tooltipTitle = ( + <> + {tooltipTitle} +
{messageStatus}
+ + ); } else if (Object.keys(messageError).length !== 0) { messageErrorStatus = true; tooltipTitle = (