Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b605362f09 | ||
|
|
c697964110 | ||
|
|
53216766b8 | ||
|
|
a0153daca4 | ||
|
|
eb9adb4810 |
@@ -8,7 +8,7 @@ import availabilityMixin from 'widget/mixins/availability';
|
|||||||
import { getLocale } from './helpers/urlParamsHelper';
|
import { getLocale } from './helpers/urlParamsHelper';
|
||||||
import { isEmptyObject } from 'widget/helpers/utils';
|
import { isEmptyObject } from 'widget/helpers/utils';
|
||||||
import Spinner from 'shared/components/Spinner.vue';
|
import Spinner from 'shared/components/Spinner.vue';
|
||||||
import routerMixin from './mixins/routerMixin';
|
import { useReplaceRoute } from 'widget/composables/useReplaceRoute';
|
||||||
import {
|
import {
|
||||||
getExtraSpaceToScroll,
|
getExtraSpaceToScroll,
|
||||||
loadedEventConfig,
|
loadedEventConfig,
|
||||||
@@ -27,7 +27,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
Spinner,
|
Spinner,
|
||||||
},
|
},
|
||||||
mixins: [availabilityMixin, configMixin, routerMixin, darkModeMixin],
|
mixins: [availabilityMixin, configMixin, darkModeMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isMobile: false,
|
isMobile: false,
|
||||||
@@ -141,15 +141,15 @@ export default {
|
|||||||
this.setUnreadView();
|
this.setUnreadView();
|
||||||
});
|
});
|
||||||
emitter.on(ON_UNREAD_MESSAGE_CLICK, () => {
|
emitter.on(ON_UNREAD_MESSAGE_CLICK, () => {
|
||||||
this.replaceRoute('messages').then(() => this.unsetUnreadView());
|
useReplaceRoute('messages').then(() => this.unsetUnreadView());
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
registerCampaignEvents() {
|
registerCampaignEvents() {
|
||||||
emitter.on(ON_CAMPAIGN_MESSAGE_CLICK, () => {
|
emitter.on(ON_CAMPAIGN_MESSAGE_CLICK, () => {
|
||||||
if (this.shouldShowPreChatForm) {
|
if (this.shouldShowPreChatForm) {
|
||||||
this.replaceRoute('prechat-form');
|
useReplaceRoute('prechat-form');
|
||||||
} else {
|
} else {
|
||||||
this.replaceRoute('messages');
|
useReplaceRoute('messages');
|
||||||
emitter.emit('execute-campaign', {
|
emitter.emit('execute-campaign', {
|
||||||
campaignId: this.activeCampaign.id,
|
campaignId: this.activeCampaign.id,
|
||||||
});
|
});
|
||||||
@@ -160,7 +160,7 @@ export default {
|
|||||||
const { customAttributes, campaignId } = campaignDetails;
|
const { customAttributes, campaignId } = campaignDetails;
|
||||||
const { websiteToken } = window.chatwootWebChannel;
|
const { websiteToken } = window.chatwootWebChannel;
|
||||||
this.executeCampaign({ campaignId, websiteToken, customAttributes });
|
this.executeCampaign({ campaignId, websiteToken, customAttributes });
|
||||||
this.replaceRoute('messages');
|
useReplaceRoute('messages');
|
||||||
});
|
});
|
||||||
emitter.on('snooze-campaigns', () => {
|
emitter.on('snooze-campaigns', () => {
|
||||||
const expireBy = addHours(new Date(), 1);
|
const expireBy = addHours(new Date(), 1);
|
||||||
@@ -176,7 +176,7 @@ export default {
|
|||||||
!messageCount &&
|
!messageCount &&
|
||||||
!shouldSnoozeCampaign;
|
!shouldSnoozeCampaign;
|
||||||
if (this.isIFrame && isCampaignReadyToExecute) {
|
if (this.isIFrame && isCampaignReadyToExecute) {
|
||||||
this.replaceRoute('campaigns').then(() => {
|
useReplaceRoute('campaigns').then(() => {
|
||||||
this.setIframeHeight(true);
|
this.setIframeHeight(true);
|
||||||
IFrameHelper.sendMessage({ event: 'setUnreadMode' });
|
IFrameHelper.sendMessage({ event: 'setUnreadMode' });
|
||||||
});
|
});
|
||||||
@@ -191,7 +191,7 @@ export default {
|
|||||||
unreadMessageCount > 0 &&
|
unreadMessageCount > 0 &&
|
||||||
!this.isWidgetOpen
|
!this.isWidgetOpen
|
||||||
) {
|
) {
|
||||||
this.replaceRoute('unread-messages').then(() => {
|
useReplaceRoute('unread-messages').then(() => {
|
||||||
this.setIframeHeight(true);
|
this.setIframeHeight(true);
|
||||||
IFrameHelper.sendMessage({ event: 'setUnreadMode' });
|
IFrameHelper.sendMessage({ event: 'setUnreadMode' });
|
||||||
});
|
});
|
||||||
@@ -298,12 +298,12 @@ export default {
|
|||||||
['unread-messages', 'campaigns'].includes(this.$route.name);
|
['unread-messages', 'campaigns'].includes(this.$route.name);
|
||||||
|
|
||||||
if (shouldShowMessageView) {
|
if (shouldShowMessageView) {
|
||||||
this.replaceRoute('messages');
|
useReplaceRoute('messages');
|
||||||
}
|
}
|
||||||
if (shouldShowHomeView) {
|
if (shouldShowHomeView) {
|
||||||
this.$store.dispatch('conversation/setUserLastSeen');
|
this.$store.dispatch('conversation/setUserLastSeen');
|
||||||
this.unsetUnreadView();
|
this.unsetUnreadView();
|
||||||
this.replaceRoute('home');
|
useReplaceRoute('home');
|
||||||
}
|
}
|
||||||
if (!message.isOpen) {
|
if (!message.isOpen) {
|
||||||
this.resetCampaign();
|
this.resetCampaign();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import FooterReplyTo from 'widget/components/FooterReplyTo.vue';
|
|||||||
import ChatInputWrap from 'widget/components/ChatInputWrap.vue';
|
import ChatInputWrap from 'widget/components/ChatInputWrap.vue';
|
||||||
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
import { sendEmailTranscript } from 'widget/api/conversation';
|
import { sendEmailTranscript } from 'widget/api/conversation';
|
||||||
import routerMixin from 'widget/mixins/routerMixin';
|
import { useReplaceRoute } from 'widget/composables/useReplaceRoute';
|
||||||
import { IFrameHelper } from '../helpers/utils';
|
import { IFrameHelper } from '../helpers/utils';
|
||||||
import { CHATWOOT_ON_START_CONVERSATION } from '../constants/sdkEvents';
|
import { CHATWOOT_ON_START_CONVERSATION } from '../constants/sdkEvents';
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@ export default {
|
|||||||
CustomButton,
|
CustomButton,
|
||||||
FooterReplyTo,
|
FooterReplyTo,
|
||||||
},
|
},
|
||||||
mixins: [routerMixin],
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
inReplyTo: null,
|
inReplyTo: null,
|
||||||
@@ -85,7 +84,7 @@ export default {
|
|||||||
startNewConversation() {
|
startNewConversation() {
|
||||||
this.clearConversations();
|
this.clearConversations();
|
||||||
this.clearConversationAttributes();
|
this.clearConversationAttributes();
|
||||||
this.replaceRoute('prechat-form');
|
useReplaceRoute('prechat-form');
|
||||||
IFrameHelper.sendMessage({
|
IFrameHelper.sendMessage({
|
||||||
event: 'onEvent',
|
event: 'onEvent',
|
||||||
eventIdentifier: CHATWOOT_ON_START_CONVERSATION,
|
eventIdentifier: CHATWOOT_ON_START_CONVERSATION,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import availabilityMixin from 'widget/mixins/availability';
|
|||||||
import nextAvailabilityTime from 'widget/mixins/nextAvailabilityTime';
|
import nextAvailabilityTime from 'widget/mixins/nextAvailabilityTime';
|
||||||
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
|
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
|
||||||
import HeaderActions from './HeaderActions.vue';
|
import HeaderActions from './HeaderActions.vue';
|
||||||
import routerMixin from 'widget/mixins/routerMixin';
|
import { useReplaceRoute } from 'widget/composables/useReplaceRoute';
|
||||||
import darkMixin from 'widget/mixins/darkModeMixin.js';
|
import darkMixin from 'widget/mixins/darkModeMixin.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -12,7 +12,7 @@ export default {
|
|||||||
FluentIcon,
|
FluentIcon,
|
||||||
HeaderActions,
|
HeaderActions,
|
||||||
},
|
},
|
||||||
mixins: [nextAvailabilityTime, availabilityMixin, routerMixin, darkMixin],
|
mixins: [nextAvailabilityTime, availabilityMixin, darkMixin],
|
||||||
props: {
|
props: {
|
||||||
avatarUrl: {
|
avatarUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -48,7 +48,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onBackButtonClick() {
|
onBackButtonClick() {
|
||||||
this.replaceRoute('home');
|
useReplaceRoute('home');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { getContrastingTextColor } from '@chatwoot/utils';
|
|||||||
import { isEmptyObject } from 'widget/helpers/utils';
|
import { isEmptyObject } from 'widget/helpers/utils';
|
||||||
import { getRegexp } from 'shared/helpers/Validators';
|
import { getRegexp } from 'shared/helpers/Validators';
|
||||||
import messageFormatterMixin from 'shared/mixins/messageFormatterMixin';
|
import messageFormatterMixin from 'shared/mixins/messageFormatterMixin';
|
||||||
import routerMixin from 'widget/mixins/routerMixin';
|
|
||||||
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
||||||
import configMixin from 'widget/mixins/configMixin';
|
import configMixin from 'widget/mixins/configMixin';
|
||||||
|
|
||||||
@@ -15,7 +14,7 @@ export default {
|
|||||||
CustomButton,
|
CustomButton,
|
||||||
Spinner,
|
Spinner,
|
||||||
},
|
},
|
||||||
mixins: [routerMixin, darkModeMixin, messageFormatterMixin, configMixin],
|
mixins: [darkModeMixin, messageFormatterMixin, configMixin],
|
||||||
props: {
|
props: {
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { useRouter, useRoute } from 'dashboard/composables/route';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable for replacing the current route with a new one if it's different.
|
||||||
|
* @param {string} name - The name of the route to replace with.
|
||||||
|
* @param {Object} params - The params to pass to the new route.
|
||||||
|
* @returns {Promise|undefined} A promise that resolves when the navigation is complete, or undefined if no navigation occurs.
|
||||||
|
*/
|
||||||
|
export const useReplaceRoute = async (name, params = {}) => {
|
||||||
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (route.name !== name) {
|
||||||
|
router.replace({ name, params }).then(resolve).catch(reject);
|
||||||
|
}
|
||||||
|
resolve(undefined);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useReplaceRoute;
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
export default {
|
|
||||||
methods: {
|
|
||||||
async replaceRoute(name, params = {}) {
|
|
||||||
if (this.$route.name !== name) {
|
|
||||||
return this.$router.replace({ name, params });
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
import { useReplaceRoute } from 'widget/composables/useReplaceRoute';
|
||||||
|
|
||||||
|
const mockReplace = vi.fn();
|
||||||
|
const mockRoute = { name: 'initialRoute' };
|
||||||
|
|
||||||
|
vi.mock('dashboard/composables/route', () => ({
|
||||||
|
useRouter: () => ({
|
||||||
|
replace: mockReplace,
|
||||||
|
}),
|
||||||
|
useRoute: () => mockRoute,
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('useReplaceRoute', () => {
|
||||||
|
let replaceRoute;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
mockRoute.name = 'initialRoute';
|
||||||
|
replaceRoute = useReplaceRoute();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should replace route when current route is different', async () => {
|
||||||
|
mockReplace.mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await replaceRoute('newRoute', { id: 1 });
|
||||||
|
|
||||||
|
expect(mockReplace).toHaveBeenCalledWith({
|
||||||
|
name: 'newRoute',
|
||||||
|
params: { id: 1 },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not replace route when current route is the same', async () => {
|
||||||
|
mockRoute.name = 'sameRoute';
|
||||||
|
|
||||||
|
const result = await replaceRoute('sameRoute');
|
||||||
|
|
||||||
|
expect(mockReplace).not.toHaveBeenCalled();
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle router replace rejection', async () => {
|
||||||
|
const error = new Error('Navigation aborted');
|
||||||
|
mockReplace.mockRejectedValue(error);
|
||||||
|
|
||||||
|
await expect(replaceRoute('newRoute')).rejects.toThrow(
|
||||||
|
'Navigation aborted'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
import { useReplaceRoute } from '../../composables/useReplaceRoute';
|
||||||
|
|
||||||
|
const mockRouter = {
|
||||||
|
currentRoute: { name: 'initialRoute' },
|
||||||
|
replace: vi.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
vi.mock('../../composables/useReplaceRoute', () => ({
|
||||||
|
useReplaceRoute: () => ({
|
||||||
|
replaceRoute: async (name, params = {}) => {
|
||||||
|
if (mockRouter.currentRoute.name !== name) {
|
||||||
|
return mockRouter.replace({ name, params });
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('useReplaceRoute', () => {
|
||||||
|
let routerHelper;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.resetAllMocks();
|
||||||
|
mockRouter.currentRoute = { name: 'initialRoute' };
|
||||||
|
routerHelper = useReplaceRoute();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('replaceRoute', () => {
|
||||||
|
it('should replace route when current route is different', async () => {
|
||||||
|
mockRouter.replace.mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await routerHelper.replaceRoute('newRoute', { id: 1 });
|
||||||
|
|
||||||
|
expect(mockRouter.replace).toHaveBeenCalledWith({
|
||||||
|
name: 'newRoute',
|
||||||
|
params: { id: 1 },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not replace route when current route is the same', async () => {
|
||||||
|
mockRouter.currentRoute.name = 'sameRoute';
|
||||||
|
|
||||||
|
const result = await routerHelper.replaceRoute('sameRoute');
|
||||||
|
|
||||||
|
expect(mockRouter.replace).not.toHaveBeenCalled();
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle router replace rejection', async () => {
|
||||||
|
const error = new Error('Navigation aborted');
|
||||||
|
mockRouter.replace.mockRejectedValue(error);
|
||||||
|
|
||||||
|
await expect(routerHelper.replaceRoute('newRoute')).rejects.toThrow(
|
||||||
|
'Navigation aborted'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -5,7 +5,7 @@ import ArticleCardSkeletonLoader from 'widget/components/ArticleCardSkeletonLoad
|
|||||||
|
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
||||||
import routerMixin from 'widget/mixins/routerMixin';
|
import { useReplaceRoute } from 'widget/composables/useReplaceRoute';
|
||||||
import configMixin from 'widget/mixins/configMixin';
|
import configMixin from 'widget/mixins/configMixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -15,7 +15,7 @@ export default {
|
|||||||
TeamAvailability,
|
TeamAvailability,
|
||||||
ArticleCardSkeletonLoader,
|
ArticleCardSkeletonLoader,
|
||||||
},
|
},
|
||||||
mixins: [configMixin, routerMixin, darkModeMixin],
|
mixins: [configMixin, darkModeMixin],
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
availableAgents: 'agent/availableAgents',
|
availableAgents: 'agent/availableAgents',
|
||||||
@@ -63,9 +63,9 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
startConversation() {
|
startConversation() {
|
||||||
if (this.preChatFormEnabled && !this.conversationSize) {
|
if (this.preChatFormEnabled && !this.conversationSize) {
|
||||||
return this.replaceRoute('prechat-form');
|
return useReplaceRoute('prechat-form');
|
||||||
}
|
}
|
||||||
return this.replaceRoute('messages');
|
return useReplaceRoute('messages');
|
||||||
},
|
},
|
||||||
openArticleInArticleViewer(link) {
|
openArticleInArticleViewer(link) {
|
||||||
let linkToOpen = `${link}?show_plain_layout=true`;
|
let linkToOpen = `${link}?show_plain_layout=true`;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import PreChatForm from '../components/PreChat/Form.vue';
|
import PreChatForm from '../components/PreChat/Form.vue';
|
||||||
import configMixin from '../mixins/configMixin';
|
import configMixin from '../mixins/configMixin';
|
||||||
import routerMixin from '../mixins/routerMixin';
|
import { useReplaceRoute } from 'widget/composables/useReplaceRoute';
|
||||||
import { isEmptyObject } from 'widget/helpers/utils';
|
import { isEmptyObject } from 'widget/helpers/utils';
|
||||||
import { ON_CONVERSATION_CREATED } from '../constants/widgetBusEvents';
|
import { ON_CONVERSATION_CREATED } from '../constants/widgetBusEvents';
|
||||||
|
|
||||||
@@ -9,11 +9,11 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
PreChatForm,
|
PreChatForm,
|
||||||
},
|
},
|
||||||
mixins: [configMixin, routerMixin],
|
mixins: [configMixin],
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$emitter.on(ON_CONVERSATION_CREATED, () => {
|
this.$emitter.on(ON_CONVERSATION_CREATED, () => {
|
||||||
// Redirect to messages page after conversation is created
|
// Redirect to messages page after conversation is created
|
||||||
this.replaceRoute('messages');
|
useReplaceRoute('messages');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
Reference in New Issue
Block a user