Commit 2c2ab1c8 authored by henrik.prangel's avatar henrik.prangel
Browse files

Jut-89 Add button for ending a conversation to the customer support personnel

parent 14beffbd
......@@ -107,6 +107,10 @@ public class ConversationResource {
} else {
chatDTO = chatService.getChatByMessage(userMessage);
}
if (chatDTO.getEnded() != null) {
return ResponseEntity
.badRequest().build();
}
chatDTO.setLastUserReferer(referer);
MessageDTO savedUserMessage = messageService.save(userMessage);
chatService.updateChatWithMessageInformation(chatDTO, savedUserMessage);
......
......@@ -27,7 +27,7 @@ public class DisconnectHandler implements ApplicationListener<SessionDisconnectE
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
Chat chat = chatRepository.findBySessionId(event.getSessionId());
if (chat == null) return;
if (chat == null || chat.getEnded() != null) return;
log.debug("Got disconnect event for chat with id {}", chat.getId());
chat.setEnded(Instant.now());
chatRepository.save(chat);
......
......@@ -12,7 +12,7 @@ import { ACTION_TYPES as AUTH_ACTIONS } from 'app/shared/reducers/authentication
import { SUCCESS, FAILURE } from 'app/shared/reducers/action-type.util';
import {
BOT_NAMES,
BOT_NAMES, CHAT_ENDED,
CHAT_REQUIRES_CUSTOMER_SERVICE,
REMOVE_CHAT,
USER_HAS_LEFT
......@@ -145,6 +145,12 @@ export default store => next => action => {
return;
}
if (activity.text === USER_HAS_LEFT || activity.text === CHAT_ENDED) {
store.dispatch({ type: CHAT_ACTIONS.END_CHAT, payload: activity });
store.dispatch({ type: CHAT_ACTIONS.UPDATE_ACTIVE_CHAT, payload: activity });
return
}
if (activity.text === CHAT_REQUIRES_CUSTOMER_SERVICE) {
store.dispatch({ type: CHAT_ACTIONS.UPDATE_NEEDS_CUSTOMER_SERVICE, payload: activity });
return;
......@@ -154,10 +160,6 @@ export default store => next => action => {
store.dispatch({ type: CHAT_ACTIONS.UPDATE_ACTIVE_CHAT, payload: activity });
}
if (activity.text === USER_HAS_LEFT) {
store.dispatch({ type: CHAT_ACTIONS.END_CHAT, payload: activity });
store.dispatch({ type: CHAT_ACTIONS.UPDATE_ACTIVE_CHAT, payload: activity });
}
if (activity.chatId && activity.chatId === (activeChat && activeChat.id)) {
store.dispatch({ type: MESSAGE_ACTIONS.ADD_NEW_MESSAGE, payload: activity });
......
......@@ -7,7 +7,7 @@ import { broadcastMessageToUserGroup, sendMessageToUser } from "app/modules/cust
import { setActiveChat, updateChat, startConversation } from "app/modules/customer-service/chats/customer-service-chat.reducer";
import { VISIBILITY_STATES } from "app/modules/customer-service/chats/customer-service-chat.reducer";
import { INSTITUTION_NAMES } from "app/modules/training-interface/training-interface.reducer";
import { BOT_NAMES, CHAT_INSTITUTION_CHANGED, REMOVE_CHAT } from "app/shared/util/customer-service.constants";
import { BOT_NAMES, CHAT_INSTITUTION_CHANGED, REMOVE_CHAT, CHAT_ENDED } from "app/shared/util/customer-service.constants";
import { AUTHORITIES } from "app/config/constants";
export type IAdditionalContentProp = StateProps
......@@ -35,13 +35,11 @@ export const AdditionalContent = (props: IAdditionalContentProp) => {
dispatch(setActiveChat(null))
dispatch(broadcastMessageToUserGroup({
text: REMOVE_CHAT,
sender: activeChat.committedBot,
chatId: activeChat.id,
sessionId: activeChat.sessionId,
}, activeChat.committedBot))
dispatch(sendMessageToUser({
text: CHAT_INSTITUTION_CHANGED,
sender: updatedChat.committedBot,
chatId: updatedChat.id,
sessionId: updatedChat.sessionId,
}))
......@@ -64,6 +62,18 @@ export const AdditionalContent = (props: IAdditionalContentProp) => {
);
};
const endConversation = () => {
const updatedChat = {...activeChat}
updatedChat.ended = new Date().toISOString();
dispatch(updateChat(updatedChat, () => {
dispatch(broadcastMessageToUserGroup({
text: CHAT_ENDED,
chatId: activeChat.id,
sessionId: activeChat.sessionId,
}, activeChat.committedBot))
}));
}
return (
<div className="room additional-content">
{activeChat && activeChat.id &&
......@@ -107,9 +117,8 @@ export const AdditionalContent = (props: IAdditionalContentProp) => {
<Translate contentKey="customerService.messages.takeOver">Take over conversation</Translate>
)}
</Button>
<Button className="room-button">
<Button className="room-button" onClick={endConversation}>
<Translate contentKey="customerService.additionalContent.end">End conversation</Translate>
(PH)
</Button>
<UncontrolledDropdown className="additional-content-dropdown">
<DropdownToggle nav caret className="d-flex align-items-center">
......
......@@ -11,7 +11,6 @@
position: relative;
background: var(--chat-sidemenu-bg-color);
height: 100%;
user-select: none;
border-top-left-radius: var(--chat-container-border-radius);
border-bottom-left-radius: var(--chat-container-border-radius);
border-right: var(--chat-border-style);
......
......@@ -2,6 +2,7 @@ export const USER_HAS_LEFT = 'USER_HAS_LEFT';
export const CHAT_INSTITUTION_CHANGED = 'CHAT_INSTITUTION_CHANGED';
export const CHAT_REQUIRES_CUSTOMER_SERVICE = 'CHAT_REQUIRES_CUSTOMER_SERVICE';
export const REMOVE_CHAT = 'REMOVE_CHAT';
export const CHAT_ENDED = 'CHAT_ENDED';
export const BOT_NAMES = {
PPA: 'bot_ppa',
RIA: 'bot_ria'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment