Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Omnichannel transcript button without user's email #23150

Merged
merged 13 commits into from
Sep 22, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,13 +34,13 @@ 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),
);

const [onHoldModalActive, setOnHoldModalActive] = useState(false);
const [email, setEmail] = useState('');

const visitorRoomId = room.v._id;
const rid = room._id;
Expand All @@ -52,18 +53,16 @@ export const useQuickActions = (
if (!visitorRoomId) {
return;
}

const {
visitor: { visitorEmails },
} = await getVisitorInfo({ visitorId: visitorRoomId });

if (visitorEmails?.length && visitorEmails[0].address) {
setEmail(visitorEmails[0].address);
return visitorEmails[0].address;
}
});

useEffect(() => {
getVisitorEmail();
}, [visitorRoomId, getVisitorEmail]);

useEffect(() => {
if (onHoldModalActive && roomLastMessage?.token) {
setModal(null);
Expand All @@ -85,7 +84,7 @@ export const useQuickActions = (
closeModal();
Session.set('openedRoom', null);
FlowRouter.go('/home');
} catch (error) {
} catch (error: any) {
handleError(error);
}
}, [closeModal, methodReturn, rid]);
Expand All @@ -99,7 +98,7 @@ export const useQuickActions = (
closeModal();
RoomManager.close(`l${rid}`);
toastr.success(t('Livechat_transcript_has_been_requested'));
} catch (error) {
} catch (error: any) {
handleError(error);
}
},
Expand All @@ -113,7 +112,7 @@ export const useQuickActions = (
try {
await sendTranscript(token, rid, email, subject);
closeModal();
} catch (error) {
} catch (error: any) {
handleError(error);
}
},
Expand All @@ -127,7 +126,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]);
Expand Down Expand Up @@ -168,7 +167,7 @@ export const useQuickActions = (
toastr.success(t('Transferred'));
FlowRouter.go('/');
closeModal();
} catch (error) {
} catch (error: any) {
handleError(error);
}
},
Expand All @@ -183,7 +182,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);
}
},
Expand All @@ -197,21 +196,28 @@ 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]);

const openModal = useMutableCallback((id: string) => {
const openModal = useMutableCallback(async (id: string) => {
switch (id) {
case QuickActionsEnum.MoveQueue:
setModal(<ReturnChatQueueModal onMoveChat={handleMoveChat} onCancel={closeModal} />);
break;
case QuickActionsEnum.Transcript:
const visitorEmail = await getVisitorEmail();

if (!visitorEmail) {
dispatchToastMessage({ type: 'error', message: t('Customer_without_registered_email') });
break;
}

setModal(
<TranscriptModal
room={room}
email={email}
email={visitorEmail}
onRequest={handleRequestTranscript}
onSend={handleSendTranscript}
onDiscard={handleDiscardTranscript}
Expand Down Expand Up @@ -258,17 +264,11 @@ export const useQuickActions = (
room?.open &&
(room.u?._id === uid || hasManagerRole) &&
room?.lastMessage?.t !== 'livechat-close';

const canMoveQueue = !!omnichannelRouteConfig?.returnQueue && room?.u !== undefined;
const canForwardGuest = usePermission('transfer-livechat-guest');

const canSendTranscript = usePermission('send-omnichannel-chat-transcript');

const canCloseOthersRoom = usePermission('close-others-livechat-room');

const canCloseRoom = usePermission('close-livechat-room');

const canMoveQueue = !!omnichannelRouteConfig?.returnQueue && room?.u !== undefined;

const canCloseOthersRoom = usePermission('close-others-livechat-room');
const canPlaceChatOnHold = Boolean(
!room.onHold && room.u && !(room as any).lastMessage?.token && manualOnHoldAllowed,
);
Expand All @@ -280,7 +280,7 @@ export const useQuickActions = (
case QuickActionsEnum.ChatForward:
return !!roomOpen && canForwardGuest;
case QuickActionsEnum.Transcript:
return !!email && canSendTranscript;
return canSendTranscript;
case QuickActionsEnum.CloseChat:
return !!roomOpen && (canCloseRoom || canCloseOthersRoom);
case QuickActionsEnum.OnHoldChat:
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@
"Custom_User_Status_Has_Been_Deleted": "Custom User Status Has Been Deleted",
"Custom_User_Status_Info": "Custom User Status Info",
"Custom_User_Status_Updated_Successfully": "Custom User Status Updated Successfully",
"Customer_without_registered_email": "The customer does not have a registered email address",
"Customize": "Customize",
"CustomSoundsFilesystem": "Custom Sounds Filesystem",
"Daily_Active_Users": "Daily Active Users",
Expand Down