Skip to content

Commit

Permalink
Merge pull request #2833 from glific/bug/errors_in_wa_messages
Browse files Browse the repository at this point in the history
Added error messages for WA groups
  • Loading branch information
mdshamoon authored Mar 28, 2024
2 parents 00bbd69 + b2ede77 commit 7ec2fbb
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/UI/Form/EmojiInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 9 additions & 1 deletion src/containers/Chat/ChatMessages/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ 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')) {
messageStatus = messageErrorStatus.message;
} else {
messageStatus = messageErrorStatus[0];
}

tooltipTitle = (
<>
{tooltipTitle}
<div className={styles.ErrorMessage}>{messageErrorStatus[0]}</div>
<div className={styles.ErrorMessage}>{messageStatus}</div>
</>
);
} else if (Object.keys(messageError).length !== 0) {
Expand Down
5 changes: 3 additions & 2 deletions src/containers/InteractiveMessage/InteractiveMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ const Template = ({
setIsActive(isActiveValue);

if (typeof bodyValue === 'string') {
setBody(bodyValue);
setBody(bodyValue || '');
setEditorState(null);
}

if (exampleValue) {
Expand Down Expand Up @@ -322,7 +323,7 @@ const Template = ({
) {
const content = translationsCopy[currentLanguage];
setLabel(content.label);
setBody(content.body);
setBody(content.body || '');
setEditorState(null);
}
setTranslations(translationsValue);
Expand Down Expand Up @@ -357,7 +358,8 @@ const Template = ({
setLabel(labelValue);

if (typeof bodyValue === 'string') {
setBody(bodyValue);
setBody(bodyValue || '');
setEditorState(null);
}

if (typeValue && typeValue !== 'TEXT') {
Expand Down
9 changes: 9 additions & 0 deletions src/containers/WaGroups/GroupMessageSubscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]);

Expand Down
13 changes: 13 additions & 0 deletions src/graphql/subscriptions/Groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
`;
8 changes: 6 additions & 2 deletions src/services/SubscriptionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.waGroup.id
: subscriptionData.data.updateMessageStatus.receiver.id;
break;
default:
break;
Expand Down

0 comments on commit 7ec2fbb

Please sign in to comment.