Skip to content

Commit

Permalink
Fix: callback response viewpoint of search stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
versedpro committed Oct 25, 2020
1 parent faee132 commit fca2c9b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ buildreports
coverage

/storage
/vendor

# ignore packages
node_modules
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/accounts/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update
def search
render json: { error: 'Specify search string with parameter q' }, status: :unprocessable_entity if params[:q].blank? && return

@contacts = Current.account.contacts.where('name LIKE :search OR email LIKE :search', search: "%#{params[:q]}%")
@contacts = Current.account.contacts.where('name LIKE :search OR email LIKE :search OR phone_number LIKE :search', search: "%#{params[:q]}%")
end

private
Expand Down
14 changes: 14 additions & 0 deletions app/javascript/dashboard/api/contactsSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* global axios */
import ApiClient from './ApiClient';

class ContactSearchAPI extends ApiClient {
constructor() {
super('contacts', { accountScoped: true });
}

getContacts(keyWords) {
return axios.get(`${this.url}/search?q=${keyWords}`);
}
}

export default new ContactSearchAPI();
45 changes: 45 additions & 0 deletions app/javascript/dashboard/components/ChatList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
</h1>
<chat-filter @statusFilterChange="updateStatusType" />
</div>

<!-- <search-box
v-on:searchToList='generateChats'
/> -->
<div class="search">
<i class="icon ion-ios-search-strong" />
<input
class="input"
type="text"
:placeholder="$t('CHAT_LIST.SEARCH.CONTACT')"
v-model.trim="searchKey"
@keyup="search()"
>
</div>

<chat-type-tabs
:items="assigneeTabItems"
Expand Down Expand Up @@ -87,6 +101,8 @@ export default {
return {
activeAssigneeTab: wootConstants.ASSIGNEE_TYPE.ME,
activeStatus: wootConstants.STATUS_TYPE.OPEN,
contactsSearched: null,
searchKey: '',
};
},
computed: {
Expand All @@ -99,6 +115,7 @@ export default {
currentUserID: 'getCurrentUserID',
activeInbox: 'getSelectedInbox',
conversationStats: 'conversationStats/getStats',
currentContacts: 'contacts/getContacts',
}),
assigneeTabItems() {
return this.$t('CHAT_LIST.ASSIGNEE_TYPE_TABS').map(item => {
Expand Down Expand Up @@ -143,13 +160,21 @@ export default {
},
conversationList() {
let conversationList = [];
if (this.activeAssigneeTab === 'me') {
conversationList = this.mineChatsList.slice();
} else if (this.activeAssigneeTab === 'unassigned') {
conversationList = this.unAssignedChatsList.slice();
} else {
conversationList = this.allChatList.slice();
}
// Return filtered array with searched contacts
if (this.contactsSearched) {
const conversations = conversationList.filter(conversation =>
this.contactsSearched.some(contact => contact.id == conversation.meta.sender.id));
return conversations;
}
if (!this.label) {
return conversationList;
Expand Down Expand Up @@ -202,6 +227,26 @@ export default {
this.resetAndFetchData();
}
},
generateChats(contacts) {
this.contactsSearched = contacts;
},
search() {
if (this.searchKey.length < 1) this.contactsSearched = this.currentContacts;
else {
this.contactsSearched = this.currentContacts.filter(contact => {
if (contact.name) {
if (contact.name.includes(this.searchKey)) return contact;
}
if (contact.phone_number) {
if (contact.phone_number.includes(this.searchKey)) return contact;
}
if (contact.email) {
if (contact.email.includes(this.searchKey)) return contact;
}
});
}
},
},
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/dashboard/components/widgets/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
export default {
};
</script>
</script>
3 changes: 2 additions & 1 deletion app/javascript/dashboard/i18n/locale/en/chatlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"TAB_HEADING": "Conversations",
"SEARCH": {
"INPUT": "Search for People, Chats, Saved Replies .."
"INPUT": "Search for People, Chats, Saved Replies ..",
"CONTACT": "Search for contact name, email, phone..."
},
"STATUS_TABS": [
{
Expand Down
10 changes: 10 additions & 0 deletions app/javascript/dashboard/store/modules/contacts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DuplicateContactException } from 'shared/helpers/CustomErrors';
import * as types from '../mutation-types';
import ContactAPI from '../../api/contacts';
import ContactSearchAPI from '../../api/contactsSearch';
import Vue from 'vue';

const state = {
Expand Down Expand Up @@ -71,6 +72,15 @@ export const actions = {
setContact({ commit }, data) {
commit(types.default.SET_CONTACT_ITEM, data);
},

async searchContact({ commit }, {keyWords}) {
try {
const response = await ContactSearchAPI.getContacts(keyWords);
return response.data.payload;
} catch (error) {
// Ignore error
}
}
};

export const mutations = {
Expand Down

0 comments on commit fca2c9b

Please sign in to comment.