chore: Refactor widget (#5621)
This commit is contained in:
parent
e310230f62
commit
a6960dc2d3
18 changed files with 31 additions and 55 deletions
|
@ -3,6 +3,5 @@ import { API } from 'widget/helpers/axios';
|
||||||
|
|
||||||
export const getAvailableAgents = async websiteToken => {
|
export const getAvailableAgents = async websiteToken => {
|
||||||
const urlData = endPoints.getAvailableAgents(websiteToken);
|
const urlData = endPoints.getAvailableAgents(websiteToken);
|
||||||
const result = await API.get(urlData.url, { params: urlData.params });
|
return API.get(urlData.url, { params: urlData.params });
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { API } from 'widget/helpers/axios';
|
||||||
|
|
||||||
const getCampaigns = async websiteToken => {
|
const getCampaigns = async websiteToken => {
|
||||||
const urlData = endPoints.getCampaigns(websiteToken);
|
const urlData = endPoints.getCampaigns(websiteToken);
|
||||||
const result = await API.get(urlData.url, { params: urlData.params });
|
return API.get(urlData.url, { params: urlData.params });
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggerCampaign = async ({
|
const triggerCampaign = async ({
|
||||||
|
|
|
@ -3,26 +3,22 @@ import { API } from 'widget/helpers/axios';
|
||||||
|
|
||||||
const createConversationAPI = async content => {
|
const createConversationAPI = async content => {
|
||||||
const urlData = endPoints.createConversation(content);
|
const urlData = endPoints.createConversation(content);
|
||||||
const result = await API.post(urlData.url, urlData.params);
|
return API.post(urlData.url, urlData.params);
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendMessageAPI = async content => {
|
const sendMessageAPI = async content => {
|
||||||
const urlData = endPoints.sendMessage(content);
|
const urlData = endPoints.sendMessage(content);
|
||||||
const result = await API.post(urlData.url, urlData.params);
|
return API.post(urlData.url, urlData.params);
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendAttachmentAPI = async attachment => {
|
const sendAttachmentAPI = async attachment => {
|
||||||
const urlData = endPoints.sendAttachment(attachment);
|
const urlData = endPoints.sendAttachment(attachment);
|
||||||
const result = await API.post(urlData.url, urlData.params);
|
return API.post(urlData.url, urlData.params);
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMessagesAPI = async ({ before }) => {
|
const getMessagesAPI = async ({ before }) => {
|
||||||
const urlData = endPoints.getConversation({ before });
|
const urlData = endPoints.getConversation({ before });
|
||||||
const result = await API.get(urlData.url, { params: urlData.params });
|
return API.get(urlData.url, { params: urlData.params });
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getConversationAPI = async () => {
|
const getConversationAPI = async () => {
|
||||||
|
|
|
@ -61,10 +61,7 @@ body {
|
||||||
|
|
||||||
.is-flat-design {
|
.is-flat-design {
|
||||||
.chat-bubble {
|
.chat-bubble {
|
||||||
border-bottom-left-radius: 0 !important;
|
border-radius: 0 !important;
|
||||||
border-bottom-right-radius: 0 !important;
|
|
||||||
border-top-left-radius: 0 !important;
|
|
||||||
border-top-right-radius: 0 !important;
|
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,8 +104,7 @@ export default {
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this.message.content) return false;
|
return this.message.content;
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
readableTime() {
|
readableTime() {
|
||||||
const { created_at: createdAt = '' } = this.message;
|
const { created_at: createdAt = '' } = this.message;
|
||||||
|
|
|
@ -54,9 +54,9 @@ export default {
|
||||||
},
|
},
|
||||||
async onFileUpload(file) {
|
async onFileUpload(file) {
|
||||||
if (this.globalConfig.directUploadsEnabled) {
|
if (this.globalConfig.directUploadsEnabled) {
|
||||||
this.onDirectFileUpload(file);
|
await this.onDirectFileUpload(file);
|
||||||
} else {
|
} else {
|
||||||
this.onIndirectFileUpload(file);
|
await this.onIndirectFileUpload(file);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onDirectFileUpload(file) {
|
async onDirectFileUpload(file) {
|
||||||
|
|
|
@ -7,7 +7,12 @@
|
||||||
class="flex items-start"
|
class="flex items-start"
|
||||||
:class="[avatarUrl ? 'justify-between' : 'justify-end']"
|
:class="[avatarUrl ? 'justify-between' : 'justify-end']"
|
||||||
>
|
>
|
||||||
<img v-if="avatarUrl" class="h-12 rounded-full" :src="avatarUrl" />
|
<img
|
||||||
|
v-if="avatarUrl"
|
||||||
|
class="h-12 rounded-full"
|
||||||
|
:src="avatarUrl"
|
||||||
|
alt="Avatar"
|
||||||
|
/>
|
||||||
<header-actions :show-popout-button="showPopoutButton" />
|
<header-actions :show-popout-button="showPopoutButton" />
|
||||||
</div>
|
</div>
|
||||||
<h2
|
<h2
|
||||||
|
|
|
@ -209,9 +209,7 @@ export default {
|
||||||
min-height: $space-large;
|
min-height: $space-large;
|
||||||
max-height: 2.4 * $space-mega;
|
max-height: 2.4 * $space-mega;
|
||||||
resize: none;
|
resize: none;
|
||||||
padding: 0;
|
padding: $space-smaller 0;
|
||||||
padding-top: $space-smaller;
|
|
||||||
padding-bottom: $space-smaller;
|
|
||||||
margin-top: $space-small;
|
margin-top: $space-small;
|
||||||
margin-bottom: $space-small;
|
margin-bottom: $space-small;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,7 @@ export default {
|
||||||
: decodeURI(this.fileName);
|
: decodeURI(this.fileName);
|
||||||
},
|
},
|
||||||
fileName() {
|
fileName() {
|
||||||
const filename = this.url.substring(this.url.lastIndexOf('/') + 1);
|
return this.url.substring(this.url.lastIndexOf('/') + 1);
|
||||||
return filename;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -118,13 +118,10 @@ export default {
|
||||||
const isUserEmailAvailable = !!this.currentUser.email;
|
const isUserEmailAvailable = !!this.currentUser.email;
|
||||||
const isUserPhoneNumberAvailable = !!this.currentUser.phone_number;
|
const isUserPhoneNumberAvailable = !!this.currentUser.phone_number;
|
||||||
return this.preChatFields.filter(field => {
|
return this.preChatFields.filter(field => {
|
||||||
if (
|
return !(
|
||||||
(isUserEmailAvailable && field.name === 'emailAddress') ||
|
(isUserEmailAvailable && field.name === 'emailAddress') ||
|
||||||
(isUserPhoneNumberAvailable && field.name === 'phoneNumber')
|
(isUserPhoneNumberAvailable && field.name === 'phoneNumber')
|
||||||
) {
|
);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
enabledPreChatFields() {
|
enabledPreChatFields() {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-xs leading-4 mt-1">
|
<div class="text-xs leading-4 mt-1">
|
||||||
{{ replyWaitMeessage }}
|
{{ replyWaitMessage }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<available-agents v-if="isOnline" :agents="availableAgents" />
|
<available-agents v-if="isOnline" :agents="availableAgents" />
|
||||||
|
@ -75,7 +75,7 @@ export default {
|
||||||
}
|
}
|
||||||
return anyAgentOnline;
|
return anyAgentOnline;
|
||||||
},
|
},
|
||||||
replyWaitMeessage() {
|
replyWaitMessage() {
|
||||||
const { workingHoursEnabled } = this.channelConfig;
|
const { workingHoursEnabled } = this.channelConfig;
|
||||||
|
|
||||||
if (this.isOnline) {
|
if (this.isOnline) {
|
||||||
|
|
|
@ -107,13 +107,12 @@ export default {
|
||||||
.clear-button {
|
.clear-button {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: $color-woot;
|
color: $color-woot;
|
||||||
padding: 0;
|
|
||||||
border: 0;
|
border: 0;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-bold;
|
||||||
font-size: $font-size-medium;
|
font-size: $font-size-medium;
|
||||||
transition: all 0.3s var(--ease-in-cubic);
|
transition: all 0.3s var(--ease-in-cubic);
|
||||||
margin-left: $space-smaller;
|
margin-left: $space-smaller;
|
||||||
padding-right: $space-one;
|
padding: 0 $space-one 0 0;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
transform: translateX($space-smaller);
|
transform: translateX($space-smaller);
|
||||||
|
|
|
@ -10,7 +10,7 @@ export const loadedEventConfig = () => {
|
||||||
|
|
||||||
export const getExtraSpaceToScroll = () => {
|
export const getExtraSpaceToScroll = () => {
|
||||||
// This function calculates the extra space needed for the view to
|
// This function calculates the extra space needed for the view to
|
||||||
// accomodate the height of close button + height of
|
// accommodate the height of close button + height of
|
||||||
// read messages button. So that scrollbar won't appear
|
// read messages button. So that scrollbar won't appear
|
||||||
const unreadMessageWrap = document.querySelector('.unread-messages');
|
const unreadMessageWrap = document.querySelector('.unread-messages');
|
||||||
const unreadCloseWrap = document.querySelector('.close-unread-wrap');
|
const unreadCloseWrap = document.querySelector('.close-unread-wrap');
|
||||||
|
|
|
@ -3,13 +3,6 @@ import { WOOT_PREFIX } from './constants';
|
||||||
export const isEmptyObject = obj =>
|
export const isEmptyObject = obj =>
|
||||||
Object.keys(obj).length === 0 && obj.constructor === Object;
|
Object.keys(obj).length === 0 && obj.constructor === Object;
|
||||||
|
|
||||||
export const arrayToHashById = array =>
|
|
||||||
array.reduce((map, obj) => {
|
|
||||||
const newMap = map;
|
|
||||||
newMap[obj.id] = obj;
|
|
||||||
return newMap;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
export const sendMessage = msg => {
|
export const sendMessage = msg => {
|
||||||
window.parent.postMessage(
|
window.parent.postMessage(
|
||||||
`chatwoot-widget:${JSON.stringify({ ...msg })}`,
|
`chatwoot-widget:${JSON.stringify({ ...msg })}`,
|
||||||
|
@ -22,9 +15,7 @@ export const IFrameHelper = {
|
||||||
sendMessage,
|
sendMessage,
|
||||||
isAValidEvent: e => {
|
isAValidEvent: e => {
|
||||||
const isDataAString = typeof e.data === 'string';
|
const isDataAString = typeof e.data === 'string';
|
||||||
const isAValidWootEvent =
|
return isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
|
||||||
isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
|
|
||||||
return isAValidWootEvent;
|
|
||||||
},
|
},
|
||||||
getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
|
getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,7 +32,7 @@ export const getters = {
|
||||||
},
|
},
|
||||||
getUnreadMessageCount: _state => {
|
getUnreadMessageCount: _state => {
|
||||||
const { userLastSeenAt } = _state.meta;
|
const { userLastSeenAt } = _state.meta;
|
||||||
const count = Object.values(_state.conversations).filter(chat => {
|
return Object.values(_state.conversations).filter(chat => {
|
||||||
const { created_at: createdAt, message_type: messageType } = chat;
|
const { created_at: createdAt, message_type: messageType } = chat;
|
||||||
const isOutGoing = messageType === MESSAGE_TYPE.OUTGOING;
|
const isOutGoing = messageType === MESSAGE_TYPE.OUTGOING;
|
||||||
const hasNotSeen = userLastSeenAt
|
const hasNotSeen = userLastSeenAt
|
||||||
|
@ -40,7 +40,6 @@ export const getters = {
|
||||||
: true;
|
: true;
|
||||||
return hasNotSeen && isOutGoing;
|
return hasNotSeen && isOutGoing;
|
||||||
}).length;
|
}).length;
|
||||||
return count;
|
|
||||||
},
|
},
|
||||||
getUnreadTextMessages: (_state, _getters) => {
|
getUnreadTextMessages: (_state, _getters) => {
|
||||||
const unreadCount = _getters.getUnreadMessageCount;
|
const unreadCount = _getters.getUnreadMessageCount;
|
||||||
|
@ -50,7 +49,6 @@ export const getters = {
|
||||||
return messageType === MESSAGE_TYPE.OUTGOING;
|
return messageType === MESSAGE_TYPE.OUTGOING;
|
||||||
});
|
});
|
||||||
const maxUnreadCount = Math.min(unreadCount, 3);
|
const maxUnreadCount = Math.min(unreadCount, 3);
|
||||||
const allUnreadMessages = unreadAgentMessages.splice(-maxUnreadCount);
|
return unreadAgentMessages.splice(-maxUnreadCount);
|
||||||
return allUnreadMessages;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@ const shouldShowAvatar = (message, nextMessage) => {
|
||||||
|
|
||||||
export const groupConversationBySender = conversationsForADate =>
|
export const groupConversationBySender = conversationsForADate =>
|
||||||
conversationsForADate.map((message, index) => {
|
conversationsForADate.map((message, index) => {
|
||||||
let showAvatar = false;
|
let showAvatar;
|
||||||
const isLastMessage = index === conversationsForADate.length - 1;
|
const isLastMessage = index === conversationsForADate.length - 1;
|
||||||
if (isASubmittedFormMessage(message)) {
|
if (isASubmittedFormMessage(message)) {
|
||||||
showAvatar = false;
|
showAvatar = false;
|
||||||
|
|
|
@ -88,8 +88,7 @@ export const mutations = {
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleAgentTypingStatus($state, { status }) {
|
toggleAgentTypingStatus($state, { status }) {
|
||||||
const isTyping = status === 'on';
|
$state.uiFlags.isAgentTyping = status === 'on';
|
||||||
$state.uiFlags.isAgentTyping = isTyping;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setMetaUserLastSeenAt($state, lastSeen) {
|
setMetaUserLastSeenAt($state, lastSeen) {
|
||||||
|
|
|
@ -9,14 +9,14 @@ export const actions = {
|
||||||
try {
|
try {
|
||||||
await conversationLabels.create(label);
|
await conversationLabels.create(label);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ingore error
|
// Ignore error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroy: async (_, label) => {
|
destroy: async (_, label) => {
|
||||||
try {
|
try {
|
||||||
await conversationLabels.destroy(label);
|
await conversationLabels.destroy(label);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ingore error
|
// Ignore error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue