mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
chore: enable close button in react-native widget (#1910)
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { mapGetters, mapActions } from 'vuex';
|
import { mapGetters, mapActions } from 'vuex';
|
||||||
import { setHeader } from 'widget/helpers/axios';
|
import { setHeader } from 'widget/helpers/axios';
|
||||||
import { IFrameHelper } from 'widget/helpers/utils';
|
import { IFrameHelper, RNHelper } from 'widget/helpers/utils';
|
||||||
|
|
||||||
import Router from './views/Router';
|
import Router from './views/Router';
|
||||||
import { getLocale } from './helpers/urlParamsHelper';
|
import { getLocale } from './helpers/urlParamsHelper';
|
||||||
@@ -45,6 +45,9 @@ export default {
|
|||||||
isIFrame() {
|
isIFrame() {
|
||||||
return IFrameHelper.isIFrame();
|
return IFrameHelper.isIFrame();
|
||||||
},
|
},
|
||||||
|
isRNWebView() {
|
||||||
|
return RNHelper.isRNWebView();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const { websiteToken, locale } = window.chatwootWebChannel;
|
const { websiteToken, locale } = window.chatwootWebChannel;
|
||||||
@@ -59,15 +62,9 @@ export default {
|
|||||||
this.fetchAvailableAgents(websiteToken);
|
this.fetchAvailableAgents(websiteToken);
|
||||||
this.setLocale(getLocale(window.location.search));
|
this.setLocale(getLocale(window.location.search));
|
||||||
}
|
}
|
||||||
// Pass cookie to react native widget
|
if (this.isRNWebView) {
|
||||||
if (window.ReactNativeWebView) {
|
|
||||||
this.registerListeners();
|
this.registerListeners();
|
||||||
window.ReactNativeWebView.postMessage(
|
this.sendRNWebViewLoadedEvent();
|
||||||
JSON.stringify({
|
|
||||||
type: 'auth-token',
|
|
||||||
value: window.authToken,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
this.$store.dispatch('conversationAttributes/get');
|
this.$store.dispatch('conversationAttributes/get');
|
||||||
this.setWidgetColor(window.chatwootWebChannel);
|
this.setWidgetColor(window.chatwootWebChannel);
|
||||||
@@ -196,6 +193,15 @@ export default {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
sendRNWebViewLoadedEvent() {
|
||||||
|
RNHelper.sendMessage({
|
||||||
|
event: 'loaded',
|
||||||
|
config: {
|
||||||
|
authToken: window.authToken,
|
||||||
|
channelConfig: window.chatwootWebChannel,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="isIframe" class="actions flex items-center">
|
<div v-if="showHeaderActions" class="actions flex items-center">
|
||||||
<button
|
<button
|
||||||
v-if="showPopoutButton"
|
v-if="showPopoutButton"
|
||||||
class="button transparent compact new-window--button"
|
class="button transparent compact new-window--button"
|
||||||
@@ -7,13 +7,18 @@
|
|||||||
>
|
>
|
||||||
<span class="ion-android-open"></span>
|
<span class="ion-android-open"></span>
|
||||||
</button>
|
</button>
|
||||||
<button class="button transparent compact close-button">
|
<button
|
||||||
|
class="button transparent compact close-button"
|
||||||
|
:class="{
|
||||||
|
'rn-close-button': isRNWebView,
|
||||||
|
}"
|
||||||
|
>
|
||||||
<span class="ion-android-close" @click="closeWindow"></span>
|
<span class="ion-android-close" @click="closeWindow"></span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { IFrameHelper } from 'widget/helpers/utils';
|
import { IFrameHelper, RNHelper } from 'widget/helpers/utils';
|
||||||
import { buildPopoutURL } from '../helpers/urlParamsHelper';
|
import { buildPopoutURL } from '../helpers/urlParamsHelper';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -28,6 +33,12 @@ export default {
|
|||||||
isIframe() {
|
isIframe() {
|
||||||
return IFrameHelper.isIFrame();
|
return IFrameHelper.isIFrame();
|
||||||
},
|
},
|
||||||
|
isRNWebView() {
|
||||||
|
return RNHelper.isRNWebView();
|
||||||
|
},
|
||||||
|
showHeaderActions() {
|
||||||
|
return this.isIframe || this.isRNWebView;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
popoutWindow() {
|
popoutWindow() {
|
||||||
@@ -56,6 +67,8 @@ export default {
|
|||||||
IFrameHelper.sendMessage({
|
IFrameHelper.sendMessage({
|
||||||
event: 'toggleBubble',
|
event: 'toggleBubble',
|
||||||
});
|
});
|
||||||
|
} else if (RNHelper.isRNWebView) {
|
||||||
|
RNHelper.sendMessage({ type: 'close-widget' });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -81,5 +94,8 @@ export default {
|
|||||||
.close-button {
|
.close-button {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.rn-close-button {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -26,3 +26,11 @@ export const IFrameHelper = {
|
|||||||
},
|
},
|
||||||
getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
|
getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
|
||||||
};
|
};
|
||||||
|
export const RNHelper = {
|
||||||
|
isRNWebView: () => window.ReactNativeWebView,
|
||||||
|
sendMessage: msg => {
|
||||||
|
window.ReactNativeWebView.postMessage(
|
||||||
|
`chatwoot-widget:${JSON.stringify({ ...msg })}`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user