[Enhancement] Remove frontend env file 🔥(#179)

This commit is contained in:
Pranav Raj S
2019-10-25 12:01:05 +05:30
committed by GitHub
parent f4358d9993
commit f869598cb4
7 changed files with 142 additions and 117 deletions

View File

@@ -1 +0,0 @@
fb_app_id=

View File

@@ -43,6 +43,5 @@ module.exports = {
}, },
globals: { globals: {
__WEBPACK_ENV__: true, __WEBPACK_ENV__: true,
__FB_APP_ID__: true,
}, },
}; };

View File

@@ -1,12 +1,20 @@
<template> <template>
<div class="wizard-body columns content-box small-9"> <div class="wizard-body columns content-box small-9">
<div class="login-init full-height" v-if="!hasLoginStarted"> <div v-if="!hasLoginStarted" class="login-init full-height">
<a href="#" @click="startLogin()"><img src="~dashboard/assets/images/channels/facebook_login.png" alt="Facebook-logo"/></a> <a href="#" @click="startLogin()">
<img
src="~dashboard/assets/images/channels/facebook_login.png"
alt="Facebook-logo"
/>
</a>
<p>{{ $t('INBOX_MGMT.ADD.FB.HELP') }}</p> <p>{{ $t('INBOX_MGMT.ADD.FB.HELP') }}</p>
</div> </div>
<div v-else> <div v-else>
<loading-state :message="emptyStateMessage" v-if="showLoader"></loading-state> <loading-state
<form class="row" v-on:submit.prevent="createChannel()" v-if="!showLoader"> v-if="showLoader"
:message="emptyStateMessage"
></loading-state>
<form v-if="!showLoader" class="row" @submit.prevent="createChannel()">
<div class="medium-12 columns"> <div class="medium-12 columns">
<page-header <page-header
:header-title="$t('INBOX_MGMT.ADD.DETAILS.TITLE')" :header-title="$t('INBOX_MGMT.ADD.DETAILS.TITLE')"
@@ -15,7 +23,8 @@
</div> </div>
<div class="medium-7 columns"> <div class="medium-7 columns">
<div class="medium-12 columns"> <div class="medium-12 columns">
<div class="input-wrap" :class="{ 'error': $v.selectedPage.$error }">Choose Page <div class="input-wrap" :class="{ error: $v.selectedPage.$error }">
Choose Page
<multiselect <multiselect
v-model.trim="selectedPage" v-model.trim="selectedPage"
:close-on-select="true" :close-on-select="true"
@@ -24,20 +33,30 @@
track-by="id" track-by="id"
label="name" label="name"
placeholder="Pick a value" placeholder="Pick a value"
selected-label='' selected-label=""
@select="setPageName" @select="setPageName"
/> />
<span class="message" v-if="$v.selectedPage.$error">Select a page from the list</span> <span v-if="$v.selectedPage.$error" class="message">
Select a page from the list
</span>
</div> </div>
</div> </div>
<div class="medium-12 columns"> <div class="medium-12 columns">
<label :class="{ 'error': $v.pageName.$error }">Inbox Name <label :class="{ error: $v.pageName.$error }">
<input type="text" v-model.trim="pageName" @input="$v.pageName.$touch" placeholder="Pick A Name Your Inbox"> Inbox Name
<span class="message" v-if="$v.pageName.$error">Add a name for your inbox</span> <input
v-model.trim="pageName"
type="text"
placeholder="Pick A Name Your Inbox"
@input="$v.pageName.$touch"
/>
<span v-if="$v.pageName.$error" class="message">
Add a name for your inbox
</span>
</label> </label>
</div> </div>
<div class="medium-12 columns text-right"> <div class="medium-12 columns text-right">
<input type="submit" value="Create Inbox" class="button"> <input type="submit" value="Create Inbox" class="button" />
</div> </div>
</div> </div>
</form> </form>
@@ -48,8 +67,6 @@
/* eslint no-console: 0 */ /* eslint no-console: 0 */
/* eslint-env browser */ /* eslint-env browser */
/* global FB */ /* global FB */
/* global bus */
/* global $v, __FB_ID__ */
import { required } from 'vuelidate/lib/validators'; import { required } from 'vuelidate/lib/validators';
import ChannelApi from '../../../../api/channels'; import ChannelApi from '../../../../api/channels';
import LoadingState from '../../../../components/widgets/LoadingState'; import LoadingState from '../../../../components/widgets/LoadingState';
@@ -57,7 +74,6 @@ import PageHeader from '../SettingsSubPageHeader';
import router from '../../../index'; import router from '../../../index';
export default { export default {
components: { components: {
LoadingState, LoadingState,
PageHeader, PageHeader,
@@ -78,7 +94,6 @@ export default {
}, },
validations: { validations: {
pageName: { pageName: {
required, required,
}, },
@@ -88,12 +103,6 @@ export default {
return this.selectedPage !== null && !!this.selectedPage.name; return this.selectedPage !== null && !!this.selectedPage.name;
}, },
}, },
},
created() {
this.initFB();
this.loadFBsdk();
}, },
computed: { computed: {
@@ -101,10 +110,15 @@ export default {
return !this.user_access_token || this.isCreating; return !this.user_access_token || this.isCreating;
}, },
getSelectablePages() { getSelectablePages() {
return this.pageList.filter(item => (!item.exists)); return this.pageList.filter(item => !item.exists);
}, },
}, },
created() {
this.initFB();
this.loadFBsdk();
},
mounted() { mounted() {
this.initFB(); this.initFB();
}, },
@@ -130,24 +144,22 @@ export default {
if (window.fbSDKLoaded === undefined) { if (window.fbSDKLoaded === undefined) {
window.fbAsyncInit = () => { window.fbAsyncInit = () => {
FB.init({ FB.init({
appId: __FB_ID__, appId: window.chatwootConfig.fbAppId,
xfbml: true, xfbml: true,
version: 'v2.8', version: 'v4.0',
status: true, status: true,
}); });
window.fbSDKLoaded = true; window.fbSDKLoaded = true;
FB.AppEvents.logPageView(); FB.AppEvents.logPageView();
// this.tryFBlogin();
}; };
} else {
// this.tryFBlogin();
} }
}, },
loadFBsdk() { loadFBsdk() {
((d, s, id) => { ((d, s, id) => {
let js; let js;
const fjs = js = d.getElementsByTagName(s)[0]; // eslint-disable-next-line
const fjs = (js = d.getElementsByTagName(s)[0]);
if (d.getElementById(id)) { if (d.getElementById(id)) {
return; return;
} }
@@ -159,25 +171,37 @@ export default {
}, },
tryFBlogin() { tryFBlogin() {
FB.login((response) => { FB.login(
response => {
if (response.status === 'connected') { if (response.status === 'connected') {
this.fetchPages(response.authResponse.accessToken); this.fetchPages(response.authResponse.accessToken);
} else if (response.status === 'not_authorized') { } else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app. // The person is logged into Facebook, but not your app.
this.emptyStateMessage = this.$t('INBOX_MGMT.DETAILS.ERROR_FB_AUTH'); this.emptyStateMessage = this.$t(
'INBOX_MGMT.DETAILS.ERROR_FB_AUTH'
);
} else { } else {
// The person is not logged into Facebook, so we're not sure if // The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not. // they are logged into this app or not.
this.emptyStateMessage = this.$t('INBOX_MGMT.DETAILS.ERROR_FB_AUTH'); this.emptyStateMessage = this.$t(
'INBOX_MGMT.DETAILS.ERROR_FB_AUTH'
);
} }
}, { scope: 'manage_pages,read_page_mailboxes,pages_messaging,pages_messaging_phone_number' }); },
{
scope:
'manage_pages,read_page_mailboxes,pages_messaging,pages_messaging_phone_number',
}
);
}, },
fetchPages(_token) { fetchPages(_token) {
ChannelApi.fetchFacebookPages(_token).then((response) => { ChannelApi.fetchFacebookPages(_token)
.then(response => {
this.pageList = response.data.data.page_details; this.pageList = response.data.data.page_details;
this.user_access_token = response.data.data.user_access_token; this.user_access_token = response.data.data.user_access_token;
}).catch(); })
.catch();
}, },
channelParams() { channelParams() {
@@ -195,14 +219,18 @@ export default {
if (!this.$v.$error) { if (!this.$v.$error) {
this.emptyStateMessage = this.$t('INBOX_MGMT.DETAILS.CREATING_CHANNEL'); this.emptyStateMessage = this.$t('INBOX_MGMT.DETAILS.CREATING_CHANNEL');
this.isCreating = true; this.isCreating = true;
this.$store.dispatch('addInboxItem', { this.$store
.dispatch('addInboxItem', {
channel: this.channel, channel: this.channel,
params: this.channelParams(), params: this.channelParams(),
}).then((response) => { })
console.log(response); .then(response => {
router.replace({ name: 'settings_inboxes_add_agents', params: { page: 'new', inbox_id: response.data.id } }); router.replace({
}).catch((error) => { name: 'settings_inboxes_add_agents',
console.log(error); params: { page: 'new', inbox_id: response.data.id },
});
})
.catch(() => {
this.isCreating = false; this.isCreating = false;
}); });
} }

View File

@@ -6,8 +6,12 @@
:header-title="inbox.label" :header-title="inbox.label"
/> />
<div class="code-wrapper"> <div class="code-wrapper">
<p class="title">{{ $t('INBOX_MGMT.SETTINGS_POPUP.MESSENGER_HEADING') }}</p> <p class="title">
<p class="sub-head">{{ $t('INBOX_MGMT.SETTINGS_POPUP.MESSENGER_SUB_HEAD') }}</p> {{ $t('INBOX_MGMT.SETTINGS_POPUP.MESSENGER_HEADING') }}
</p>
<p class="sub-head">
{{ $t('INBOX_MGMT.SETTINGS_POPUP.MESSENGER_SUB_HEAD') }}
</p>
<p class="code"> <p class="code">
<code> <code>
{{ messengerScript }} {{ messengerScript }}
@@ -15,8 +19,12 @@
</p> </p>
</div> </div>
<div class="agent-wrapper"> <div class="agent-wrapper">
<p class="title">{{ $t('INBOX_MGMT.SETTINGS_POPUP.INBOX_AGENTS') }}</p> <p class="title">
<p class="sub-head">{{ $t('INBOX_MGMT.SETTINGS_POPUP.INBOX_AGENTS_SUB_TEXT') }}</p> {{ $t('INBOX_MGMT.SETTINGS_POPUP.INBOX_AGENTS') }}
</p>
<p class="sub-head">
{{ $t('INBOX_MGMT.SETTINGS_POPUP.INBOX_AGENTS_SUB_TEXT') }}
</p>
<multiselect <multiselect
v-model="selectedAgents" v-model="selectedAgents"
:options="agentList" :options="agentList"
@@ -37,41 +45,29 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</woot-modal> </woot-modal>
</template> </template>
<script> <script>
/* global bus, __FB_ID__ */
/* eslint no-console: 0 */ /* eslint no-console: 0 */
/* eslint-disable no-useless-escape */ /* eslint-disable no-useless-escape */
/* global bus */
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import PageHeader from '../SettingsSubPageHeader';
export default { export default {
props: [ props: ['onClose', 'inbox', 'show'],
'onClose',
'inbox',
'show',
],
components: {
PageHeader,
},
data() { data() {
return { return {
selectedAgents: [], selectedAgents: [],
isUpdating: false, isUpdating: false,
messengerScript: `<script> messengerScript: `<script>
window.fbAsyncInit = function() { window.fbAsyncInit = function() {
FB.init({ FB.init({
appId: "${__FB_ID__}", appId: "${window.chatwootConfig.fbAppId}",
xfbml: true, xfbml: true,
version: "v2.6" version: "v4.0"
}); });
}; };
(function(d, s, id){ (function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0]; var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; } if (d.getElementById(id)) { return; }
@@ -82,7 +78,7 @@ export default {
<\/script> <\/script>
<div class="fb-messengermessageus" <div class="fb-messengermessageus"
messenger_app_id="${__FB_ID__}" messenger_app_id="${window.chatwootConfig.fbAppId}"
page_id="${this.inbox.pageId}" page_id="${this.inbox.pageId}"
color="blue" color="blue"
size="standard" > size="standard" >
@@ -95,39 +91,50 @@ export default {
}), }),
}, },
mounted() { mounted() {
this.$store.dispatch('fetchAgents') this.$store.dispatch('fetchAgents').then(() => {
.then(() => {
this.fetchAttachedAgents(); this.fetchAttachedAgents();
}); });
}, },
methods: { methods: {
fetchAttachedAgents() { fetchAttachedAgents() {
this.$store.dispatch('listInboxAgents', { this.$store
.dispatch('listInboxAgents', {
inboxId: this.inbox.channel_id, inboxId: this.inbox.channel_id,
}) })
.then((response) => { .then(response => {
const { payload } = response.data; const { payload } = response.data;
payload.forEach((el) => { payload.forEach(el => {
const [item] = this.agentList.filter(agent => agent.id === el.user_id); const [item] = this.agentList.filter(
agent => agent.id === el.user_id
);
if (item) this.selectedAgents.push(item); if (item) this.selectedAgents.push(item);
}); });
}) })
.catch((error) => { .catch(error => {
console.log(error); console.log(error);
}); });
}, },
updateAgents() { updateAgents() {
const agentList = this.selectedAgents.map(el => el.id); const agentList = this.selectedAgents.map(el => el.id);
this.isUpdating = true; this.isUpdating = true;
this.$store.dispatch('updateInboxAgents', { this.$store
.dispatch('updateInboxAgents', {
inboxId: this.inbox.channel_id, inboxId: this.inbox.channel_id,
agentList, agentList,
}).then(() => { })
.then(() => {
this.isUpdating = false; this.isUpdating = false;
bus.$emit('newToastMessage', this.$t('AGENT_MGMT.EDIT.API.SUCCESS_MESSAGE')); bus.$emit(
}).catch(() => { 'newToastMessage',
this.$t('AGENT_MGMT.EDIT.API.SUCCESS_MESSAGE')
);
})
.catch(() => {
this.isUpdating = false; this.isUpdating = false;
bus.$emit('newToastMessage', this.$t('AGENT_MGMT.EDIT.API.ERROR_MESSAGE')); bus.$emit(
'newToastMessage',
this.$t('AGENT_MGMT.EDIT.API.ERROR_MESSAGE')
);
}); });
}, },
}, },

View File

@@ -29,5 +29,10 @@
<div id="app"></div> <div id="app"></div>
<noscript id="noscript">This app works best with JavaScript enabled.</noscript> <noscript id="noscript">This app works best with JavaScript enabled.</noscript>
<%= yield %> <%= yield %>
<script>
window.chatwootConfig = {
fbAppId: <%= ENV['fb_app_id'] %>
}
</script>
</body> </body>
</html> </html>

View File

@@ -1,6 +1,5 @@
const { environment } = require('@rails/webpacker'); const { environment } = require('@rails/webpacker');
const { VueLoaderPlugin } = require('vue-loader'); const { VueLoaderPlugin } = require('vue-loader');
const webpack = require('webpack');
const resolve = require('./resolve'); const resolve = require('./resolve');
const vue = require('./loaders/vue'); const vue = require('./loaders/vue');
@@ -17,13 +16,4 @@ environment.loaders.append('audio', {
environment.config.merge({ resolve }); environment.config.merge({ resolve });
const { fb_app_id: fbAppID } = process.env;
environment.plugins.prepend(
'DefinePlugin',
new webpack.DefinePlugin({
__FB_ID__: `"${fbAppID}"`,
})
);
module.exports = environment; module.exports = environment;

3
configure vendored
View File

@@ -5,6 +5,3 @@
# ref docs for detailed instructions # ref docs for detailed instructions
cp shared/config/database.yml config/database.yml cp shared/config/database.yml config/database.yml
cp shared/config/application.yml config/application.yml cp shared/config/application.yml config/application.yml
# copy frontend env file
cp .env.sample .env