From 3563466f581bc4cd11d54456a41304304e7c9186 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Wed, 8 Sep 2021 15:32:56 -0300 Subject: [PATCH 1/5] fix --- .../Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx index 9fdc0238287a..23dae33d365e 100644 --- a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx +++ b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx @@ -57,6 +57,8 @@ export const useQuickActions = ( } = await getVisitorInfo({ visitorId: visitorRoomId }); if (visitorEmails?.length && visitorEmails[0].address) { setEmail(visitorEmails[0].address); + } else { + setEmail(''); } }); From 1510d668183fe224322a5aa99ed01b01fbc81e25 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Fri, 17 Sep 2021 15:13:27 -0300 Subject: [PATCH 2/5] different approach --- .../QuickActions/hooks/useQuickActions.tsx | 35 ++++++++++--------- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx index 687765c3aa1f..93224703eea6 100644 --- a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx +++ b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx @@ -17,6 +17,7 @@ import { useSetModal } from '../../../../../../contexts/ModalContext'; import { useOmnichannelRouteConfig } from '../../../../../../contexts/OmnichannelContext'; import { useEndpoint, useMethod } from '../../../../../../contexts/ServerContext'; import { useSetting } from '../../../../../../contexts/SettingsContext'; +import { useToastMessageDispatch } from '../../../../../../contexts/ToastMessagesContext'; import { useTranslation } from '../../../../../../contexts/TranslationContext'; import { useUserId } from '../../../../../../contexts/UserContext'; import { handleError } from '../../../../../../lib/utils/handleError'; @@ -33,6 +34,7 @@ export const useQuickActions = ( const setModal = useSetModal(); const t = useTranslation(); + const dispatchToastMessage = useToastMessageDispatch(); const context = useQuickActionsContext(); const actions = (Array.from(context.actions.values()) as QuickActionsActionConfig[]).sort( (a, b) => (a.order || 0) - (b.order || 0), @@ -87,7 +89,7 @@ export const useQuickActions = ( closeModal(); Session.set('openedRoom', null); FlowRouter.go('/home'); - } catch (error) { + } catch (error: any) { handleError(error); } }, [closeModal, methodReturn, rid]); @@ -101,7 +103,7 @@ export const useQuickActions = ( closeModal(); RoomManager.close(`l${rid}`); toastr.success(t('Livechat_transcript_has_been_requested')); - } catch (error) { + } catch (error: any) { handleError(error); } }, @@ -115,7 +117,7 @@ export const useQuickActions = ( try { await sendTranscript(token, rid, email, subject); closeModal(); - } catch (error) { + } catch (error: any) { handleError(error); } }, @@ -129,7 +131,7 @@ export const useQuickActions = ( await discardTranscript(rid); toastr.success(t('Livechat_transcript_request_has_been_canceled')); closeModal(); - } catch (error) { + } catch (error: any) { handleError(error); } }, [closeModal, discardTranscript, rid, t]); @@ -170,7 +172,7 @@ export const useQuickActions = ( toastr.success(t('Transferred')); FlowRouter.go('/'); closeModal(); - } catch (error) { + } catch (error: any) { handleError(error); } }, @@ -185,7 +187,7 @@ export const useQuickActions = ( await closeChat(rid, comment, { clientAction: true, tags }); closeModal(); toastr.success(t('Chat_closed_successfully')); - } catch (error) { + } catch (error: any) { handleError(error); } }, @@ -199,7 +201,7 @@ export const useQuickActions = ( await onHoldChat({ roomId: rid }); closeModal(); toastr.success(t('Chat_On_Hold_Successfully')); - } catch (error) { + } catch (error: any) { handleError(error); } }, [onHoldChat, closeModal, rid, t]); @@ -210,6 +212,13 @@ export const useQuickActions = ( setModal(); break; case QuickActionsEnum.Transcript: + getVisitorEmail(); + + if (!email) { + dispatchToastMessage({ type: 'error', message: t('Customer_without_registered_email') }); + break; + } + setModal( Date: Fri, 17 Sep 2021 16:35:31 -0300 Subject: [PATCH 3/5] use async await --- .../Omnichannel/QuickActions/hooks/useQuickActions.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx index 93224703eea6..c22946763efc 100644 --- a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx +++ b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx @@ -62,11 +62,9 @@ export const useQuickActions = ( } else { setEmail(''); } - }); - useEffect(() => { - getVisitorEmail(); - }, [visitorRoomId, getVisitorEmail]); + return 0; + }); useEffect(() => { if (onHoldModalActive && roomLastMessage?.token) { @@ -206,13 +204,13 @@ export const useQuickActions = ( } }, [onHoldChat, closeModal, rid, t]); - const openModal = useMutableCallback((id: string) => { + const openModal = useMutableCallback(async (id: string) => { switch (id) { case QuickActionsEnum.MoveQueue: setModal(); break; case QuickActionsEnum.Transcript: - getVisitorEmail(); + await getVisitorEmail(); if (!email) { dispatchToastMessage({ type: 'error', message: t('Customer_without_registered_email') }); From 41a7ddc77e49d990d9601a14f1dac8d1efabe1b0 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Fri, 17 Sep 2021 16:35:59 -0300 Subject: [PATCH 4/5] useEndpoint --- .../contacts/contextualBar/ContactNewEdit.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/client/views/omnichannel/directory/contacts/contextualBar/ContactNewEdit.js b/client/views/omnichannel/directory/contacts/contextualBar/ContactNewEdit.js index 0ceb43c9d91f..fa6112506fc0 100644 --- a/client/views/omnichannel/directory/contacts/contextualBar/ContactNewEdit.js +++ b/client/views/omnichannel/directory/contacts/contextualBar/ContactNewEdit.js @@ -8,11 +8,11 @@ import { isEmail } from '../../../../../../app/utils/client'; import CustomFieldsForm from '../../../../../components/CustomFieldsForm'; import VerticalBar from '../../../../../components/VerticalBar'; import { createToken } from '../../../../../components/helpers'; +import { useEndpoint } from '../../../../../contexts/ServerContext'; import { useToastMessageDispatch } from '../../../../../contexts/ToastMessagesContext'; import { useTranslation } from '../../../../../contexts/TranslationContext'; import { AsyncStatePhase } from '../../../../../hooks/useAsyncState'; import { useComponentDidUpdate } from '../../../../../hooks/useComponentDidUpdate'; -import { useEndpointAction } from '../../../../../hooks/useEndpointAction'; import { useEndpointData } from '../../../../../hooks/useEndpointData'; import { useForm } from '../../../../../hooks/useForm'; import { formsSubscription } from '../../../additionalForms'; @@ -107,15 +107,9 @@ function ContactNewEdit({ id, data, close }) { [allCustomFields], ); - const saveContact = useEndpointAction('POST', 'omnichannel/contact'); - const emailAlreadyExistsAction = useEndpointAction( - 'GET', - `omnichannel/contact.search?email=${email}`, - ); - const phoneAlreadyExistsAction = useEndpointAction( - 'GET', - `omnichannel/contact.search?phone=${phone}`, - ); + const saveContact = useEndpoint('POST', 'omnichannel/contact'); + const emailAlreadyExistsAction = useEndpoint('GET', `omnichannel/contact.search?email=${email}`); + const phoneAlreadyExistsAction = useEndpoint('GET', `omnichannel/contact.search?phone=${phone}`); const checkEmailExists = useMutableCallback(async () => { if (!isEmail(email)) { From 7477a0e6cfd4022deb7f102c01d1ee7f9ece9369 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Fri, 17 Sep 2021 16:57:12 -0300 Subject: [PATCH 5/5] fix --- .../QuickActions/hooks/useQuickActions.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx index c22946763efc..77a3806ebde3 100644 --- a/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx +++ b/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx @@ -41,7 +41,6 @@ export const useQuickActions = ( ); const [onHoldModalActive, setOnHoldModalActive] = useState(false); - const [email, setEmail] = useState(''); const visitorRoomId = room.v._id; const rid = room._id; @@ -54,16 +53,14 @@ export const useQuickActions = ( if (!visitorRoomId) { return; } + const { visitor: { visitorEmails }, } = await getVisitorInfo({ visitorId: visitorRoomId }); + if (visitorEmails?.length && visitorEmails[0].address) { - setEmail(visitorEmails[0].address); - } else { - setEmail(''); + return visitorEmails[0].address; } - - return 0; }); useEffect(() => { @@ -210,9 +207,9 @@ export const useQuickActions = ( setModal(); break; case QuickActionsEnum.Transcript: - await getVisitorEmail(); + const visitorEmail = await getVisitorEmail(); - if (!email) { + if (!visitorEmail) { dispatchToastMessage({ type: 'error', message: t('Customer_without_registered_email') }); break; } @@ -220,7 +217,7 @@ export const useQuickActions = ( setModal(