@@ -100,7 +100,6 @@ import {
100
100
} from " vue" ;
101
101
import { useRouter , useRoute , RouteLocationRaw , RouteLocation } from " vue-router" ;
102
102
import { useChatWoot } from " @productdevbook/chatwoot/vue" ;
103
- import { useEventListener } from " @vueuse/core" ;
104
103
import { useStore } from " @/store" ;
105
104
import handleError from " @/utils/handleError" ;
106
105
import UserIcon from " ../User/UserIcon.vue" ;
@@ -126,13 +125,15 @@ defineOptions({
126
125
inheritAttrs: false ,
127
126
});
128
127
128
+ const { setUser, setConversationCustomAttributes, toggle, reset } = useChatWoot ();
129
129
const store = useStore ();
130
130
const router = useRouter ();
131
131
const route = useRoute ();
132
132
const snackbar = useSnackbar ();
133
133
const getStatusDarkMode = computed (
134
134
() => store .getters [" layout/getStatusDarkMode" ],
135
135
);
136
+ const isChatCreated = computed (() => store .getters [" support/getCreatedStatus" ]);
136
137
const tenant = computed (() => store .getters [" auth/tenant" ]);
137
138
const userEmail = computed (() => store .getters [" auth/email" ]);
138
139
const userId = computed (() => store .getters [" auth/id" ]);
@@ -161,6 +162,11 @@ const logout = async () => {
161
162
await store .dispatch (" auth/logout" );
162
163
await store .dispatch (" stats/clear" );
163
164
await store .dispatch (" namespaces/clearNamespaceList" );
165
+ if (isChatCreated .value ) {
166
+ toggle (" close" );
167
+ reset ();
168
+ store .commit (" support/setCreatedStatus" , false );
169
+ }
164
170
await router .push ({ name: " Login" });
165
171
} catch (error : unknown ) {
166
172
handleError (error );
@@ -174,8 +180,6 @@ const toggleDarkMode = () => {
174
180
175
181
const openChatwoot = async (): Promise <void > => {
176
182
try {
177
- const { setUser, setConversationCustomAttributes, toggle } = useChatWoot ();
178
-
179
183
await store .dispatch (" support/get" , tenant .value );
180
184
181
185
setUser (userId .value , {
@@ -184,13 +188,22 @@ const openChatwoot = async (): Promise<void> => {
184
188
identifier_hash: identifier .value ,
185
189
});
186
190
187
- useEventListener (window , " chatwoot:on-message" , () => {
188
- setConversationCustomAttributes ({
189
- namespace: store .getters [" namespaces/get" ].name ,
190
- tenant: tenant .value ,
191
- domain: window .location .hostname ,
192
- });
193
- });
191
+ window .addEventListener (
192
+ " chatwoot:on-message" ,
193
+ () => {
194
+ setConversationCustomAttributes ({
195
+ namespace: store .getters [" namespaces/get" ].name ,
196
+ tenant: tenant .value ,
197
+ domain: window .location .hostname ,
198
+ });
199
+ },
200
+ { once: true },
201
+ );
202
+
203
+ const holder = document .querySelector (" .woot-widget-holder" );
204
+ if (holder ) {
205
+ window .dispatchEvent (new CustomEvent (" chatwoot:ready" ));
206
+ }
194
207
195
208
store .commit (" support/setCreatedStatus" , true );
196
209
toggle (" open" );
0 commit comments