|
|
|
@ -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,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; |
|
|
|
@ -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); |
|
|
|
@ -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]); |
|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -113,7 +112,7 @@ export const useQuickActions = ( |
|
|
|
|
try { |
|
|
|
|
await sendTranscript(token, rid, email, subject); |
|
|
|
|
closeModal(); |
|
|
|
|
} catch (error) { |
|
|
|
|
} catch (error: any) { |
|
|
|
|
handleError(error); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -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]); |
|
|
|
@ -168,7 +167,7 @@ export const useQuickActions = ( |
|
|
|
|
toastr.success(t('Transferred')); |
|
|
|
|
FlowRouter.go('/'); |
|
|
|
|
closeModal(); |
|
|
|
|
} catch (error) { |
|
|
|
|
} catch (error: any) { |
|
|
|
|
handleError(error); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -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} |
|
|
|
@ -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, |
|
|
|
|
); |
|
|
|
@ -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: |
|
|
|
|