diff --git a/.codeclimate.yml b/.codeclimate.yml index d0cde2858..f12f590a2 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -11,7 +11,9 @@ plugins: enabled: true brakeman: enabled: true - +checks: + similar-code: + enabled: false exclude_patterns: - "spec/" - "**/specs/" diff --git a/app/controllers/api/v1/widget/inboxes_controller.rb b/app/controllers/api/v1/widget/inboxes_controller.rb index a16f5bfed..ce739fef0 100644 --- a/app/controllers/api/v1/widget/inboxes_controller.rb +++ b/app/controllers/api/v1/widget/inboxes_controller.rb @@ -1,17 +1,25 @@ class Api::V1::Widget::InboxesController < Api::BaseController before_action :authorize_request + before_action :set_web_widget_channel, only: [:update] + before_action :set_inbox, only: [:update] def create ActiveRecord::Base.transaction do channel = web_widgets.create!( - website_name: permitted_params[:website_name], - website_url: permitted_params[:website_url], - widget_color: permitted_params[:widget_color] + website_name: permitted_params[:website][:website_name], + website_url: permitted_params[:website][:website_url], + widget_color: permitted_params[:website][:widget_color] ) - @inbox = inboxes.create!(name: permitted_params[:website_name], channel: channel) + @inbox = inboxes.create!(name: permitted_params[:website][:website_name], channel: channel) end end + def update + @channel.update!( + widget_color: permitted_params[:website][:widget_color] + ) + end + private def authorize_request @@ -26,7 +34,15 @@ class Api::V1::Widget::InboxesController < Api::BaseController current_account.web_widgets end + def set_web_widget_channel + @channel = web_widgets.find_by(id: permitted_params[:id]) + end + + def set_inbox + @inbox = @channel.inbox + end + def permitted_params - params.fetch(:website).permit(:website_name, :website_url, :widget_color) + params.permit(:id, website: [:website_name, :website_url, :widget_color]) end end diff --git a/app/javascript/dashboard/api/ApiClient.js b/app/javascript/dashboard/api/ApiClient.js index 0bbd13d9c..a3b87dae1 100644 --- a/app/javascript/dashboard/api/ApiClient.js +++ b/app/javascript/dashboard/api/ApiClient.js @@ -4,7 +4,8 @@ const API_VERSION = `/api/v1`; class ApiClient { constructor(url) { - this.url = `${API_VERSION}/${url}`; + this.apiVersion = API_VERSION; + this.url = `${this.apiVersion}/${url}`; } get() { diff --git a/app/javascript/dashboard/api/account.js b/app/javascript/dashboard/api/account.js deleted file mode 100644 index 114cb69ec..000000000 --- a/app/javascript/dashboard/api/account.js +++ /dev/null @@ -1,32 +0,0 @@ -/* global axios */ -import endPoints from './endPoints'; - -export default { - getLabels() { - const urlData = endPoints('fetchLabels'); - return axios.get(urlData.url); - }, - - getInboxes() { - const urlData = endPoints('fetchInboxes'); - return axios.get(urlData.url); - }, - - deleteInbox(id) { - const urlData = endPoints('inbox').delete(id); - return axios.delete(urlData.url); - }, - - listInboxAgents(id) { - const urlData = endPoints('inbox').agents.get(id); - return axios.get(urlData.url); - }, - - updateInboxAgents(inboxId, agentList) { - const urlData = endPoints('inbox').agents.post(); - return axios.post(urlData.url, { - user_ids: agentList, - inbox_id: inboxId, - }); - }, -}; diff --git a/app/javascript/dashboard/api/channel/fbChannel.js b/app/javascript/dashboard/api/channel/fbChannel.js index 215900130..f9781097c 100644 --- a/app/javascript/dashboard/api/channel/fbChannel.js +++ b/app/javascript/dashboard/api/channel/fbChannel.js @@ -19,6 +19,13 @@ class FBChannel extends ApiClient { contact_id: contactId, }); } + + create(params) { + return axios.post( + `${this.apiVersion}/callbacks/register_facebook_page`, + params + ); + } } export default new FBChannel(); diff --git a/app/javascript/dashboard/api/channels.js b/app/javascript/dashboard/api/channels.js index 8a8ac3918..f7db9afbc 100644 --- a/app/javascript/dashboard/api/channels.js +++ b/app/javascript/dashboard/api/channels.js @@ -5,19 +5,6 @@ import endPoints from './endPoints'; export default { - // Get Inbox related to the account - createChannel(channel, channelParams) { - const urlData = endPoints('createChannel')(channel, channelParams); - return axios.post(urlData.url, urlData.params); - }, - - addAgentsToChannel(inboxId, agentsId) { - const urlData = endPoints('addAgentsToChannel'); - urlData.params.inbox_id = inboxId; - urlData.params.user_ids = agentsId; - return axios.post(urlData.url, urlData.params); - }, - fetchFacebookPages(token) { const urlData = endPoints('fetchFacebookPages'); urlData.params.omniauth_token = token; diff --git a/app/javascript/dashboard/api/endPoints.js b/app/javascript/dashboard/api/endPoints.js index 062cbec1f..2898362cc 100644 --- a/app/javascript/dashboard/api/endPoints.js +++ b/app/javascript/dashboard/api/endPoints.js @@ -24,26 +24,6 @@ const endPoints = { params: { inbox_id: null }, }, - fetchLabels: { - url: 'api/v1/labels.json', - }, - - fetchInboxes: { - url: 'api/v1/inboxes.json', - }, - - createChannel(channel, channelParams) { - return { - url: `api/v1/callbacks/register_${channel}_page.json`, - params: channelParams, - }; - }, - - addAgentsToChannel: { - url: 'api/v1/inbox_members.json', - params: { user_ids: [], inbox_id: null }, - }, - fetchFacebookPages: { url: 'api/v1/callbacks/get_facebook_pages.json', params: { omniauth_token: '' }, @@ -69,26 +49,6 @@ const endPoints = { }; }, }, - - inbox: { - delete(id) { - return { - url: `/api/v1/inboxes/${id}`, - }; - }, - agents: { - get(id) { - return { - url: `/api/v1/inbox_members/${id}.json`, - }; - }, - post() { - return { - url: '/api/v1/inbox_members.json', - }; - }, - }, - }, }; export default page => { diff --git a/app/javascript/dashboard/api/inboxMembers.js b/app/javascript/dashboard/api/inboxMembers.js new file mode 100644 index 000000000..2d7001562 --- /dev/null +++ b/app/javascript/dashboard/api/inboxMembers.js @@ -0,0 +1,17 @@ +/* global axios */ +import ApiClient from './ApiClient'; + +class InboxMembers extends ApiClient { + constructor() { + super('inbox_members'); + } + + create({ inboxId, agentList }) { + return axios.post(this.url, { + inbox_id: inboxId, + user_ids: agentList, + }); + } +} + +export default new InboxMembers(); diff --git a/app/javascript/dashboard/api/inboxes.js b/app/javascript/dashboard/api/inboxes.js new file mode 100644 index 000000000..fb3e63dfd --- /dev/null +++ b/app/javascript/dashboard/api/inboxes.js @@ -0,0 +1,9 @@ +import ApiClient from './ApiClient'; + +class Inboxes extends ApiClient { + constructor() { + super('inboxes'); + } +} + +export default new Inboxes(); diff --git a/app/javascript/dashboard/api/specs/inboxes.spec.js b/app/javascript/dashboard/api/specs/inboxes.spec.js new file mode 100644 index 000000000..d1a1d2683 --- /dev/null +++ b/app/javascript/dashboard/api/specs/inboxes.spec.js @@ -0,0 +1,13 @@ +import inboxes from '../inboxes'; +import ApiClient from '../ApiClient'; + +describe('#AgentAPI', () => { + it('creates correct instance', () => { + expect(inboxes).toBeInstanceOf(ApiClient); + expect(inboxes).toHaveProperty('get'); + expect(inboxes).toHaveProperty('show'); + expect(inboxes).toHaveProperty('create'); + expect(inboxes).toHaveProperty('update'); + expect(inboxes).toHaveProperty('delete'); + }); +}); diff --git a/app/javascript/dashboard/assets/scss/views/settings/inbox.scss b/app/javascript/dashboard/assets/scss/views/settings/inbox.scss index 479dbbd8f..b6865213e 100644 --- a/app/javascript/dashboard/assets/scss/views/settings/inbox.scss +++ b/app/javascript/dashboard/assets/scss/views/settings/inbox.scss @@ -1,3 +1,10 @@ +.settings { + overflow: auto; + + .page-top-bar { + @include padding($space-normal $space-two $zero); + } +} // Conversation header - Light BG .settings-header { @include padding($space-small $space-normal); @@ -196,51 +203,23 @@ } } -.settings-modal { - height: 80%; - max-width: 1040px; - width: 100%; +.settings--content { + @include margin($space-small $space-medium); - .delete-wrapper { - position: absolute; - bottom: 0; - width: 100%; - @include flex; - flex-direction: row; - justify-content: space-between; - @include padding($space-normal $space-large); - - a { - margin-left: $space-normal; - } + .title { + font-weight: $font-weight-medium; } - .settings--content { - @include margin($space-medium); + .code { + max-height: $space-mega; + overflow: scroll; + white-space: nowrap; + @include padding($space-one); + background: $color-background; - .title { - font-weight: $font-weight-medium; - } - - .code { - max-height: $space-mega; - overflow: scroll; - white-space: nowrap; - @include padding($space-one); - background: $color-background; - - code { - background: transparent; - border: 0; - } - } - } - - .agent-wrapper { - @include margin($space-medium); - - .title { - font-weight: $font-weight-medium; + code { + background: transparent; + border: 0; } } } diff --git a/app/javascript/dashboard/assets/scss/widgets/_modal.scss b/app/javascript/dashboard/assets/scss/widgets/_modal.scss index 04c92e836..5a2cc7b3d 100644 --- a/app/javascript/dashboard/assets/scss/widgets/_modal.scss +++ b/app/javascript/dashboard/assets/scss/widgets/_modal.scss @@ -27,6 +27,15 @@ } } + +.page-top-bar { + @include padding($zero $space-two); + + img { + max-height: 6rem; + } +} + .modal-container { background-color: $color-white; border-radius: $space-small; @@ -35,13 +44,6 @@ position: relative; width: 60rem; - .page-top-bar { - @include padding($zero $space-two); - - img { - max-height: 6rem; - } - } .content-box { @include padding($zero); diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index ac3afe4dd..6f69857f7 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -3,7 +3,7 @@
-
+