Skip to content

Commit a8ff194

Browse files
committed
feat(orgs): implement the orgs search functionality
1 parent e167794 commit a8ff194

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

components/Organizations.vue

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
/>
2424
</div>
2525
</div>
26-
<PaginationBar @fetch-current-page="fetchCurrentPage" />
26+
<div v-if="organizations?.length <= 0" class="flex justify-center py-14">
27+
<p class="">Sorry, no organizations were found</p>
28+
</div>
29+
<PaginationBar v-else @fetch-current-page="fetchCurrentPage" />
2730
</div>
2831
</template>
2932

@@ -32,7 +35,7 @@ import { mapState } from 'vuex'
3235
import OrganizationCard from './OrganizationCard.vue'
3336
import PaginationBar from './PaginationBar.vue'
3437
export default {
35-
name: 'Organizations',
38+
name: 'OrganizationsList',
3639
components: {
3740
OrganizationCard,
3841
PaginationBar,
@@ -44,14 +47,24 @@ export default {
4447
...mapState({
4548
sortBy: 'orgs_sortBy',
4649
currentPage: 'currentPage',
50+
orgSearchTerm: 'orgSearchTerm',
4751
}),
4852
},
4953
methods: {
5054
async fetchCurrentPage(page) {
51-
const response = await this.$axios.get(
52-
`/v1/orgs?page=${this.currentPage}&sort_by=${this.sortBy}`
53-
)
54-
this.$store.commit('setOrgs', response.data.orgs)
55+
if (this.orgSearchTerm) {
56+
const response = await this.$axios.get(
57+
`/v1/orgs?page=${this.currentPage}&sort_by=${this.sortBy}&search=${this.orgSearchTerm}`,
58+
)
59+
this.$store.commit('setOrgs', response.data.orgs)
60+
this.$store.commit('setPageCount', response.data.totalPages)
61+
} else {
62+
const response = await this.$axios.get(
63+
`/v1/orgs?page=${this.currentPage}&sort_by=${this.sortBy}`,
64+
)
65+
this.$store.commit('setOrgs', response.data.orgs)
66+
this.$store.commit('setPageCount', response.data.totalPages)
67+
}
5568
},
5669
},
5770
}

components/OrganizationsInput.vue

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<div :class="isOpen ? '' : 'hidden overflow-hidden lg:block'">
33
<div class="sort-section has-border">
4+
<div class="mb-5">
5+
<SearchInput
6+
placeholder="Search organization name or username"
7+
@on-search="onSearch"
8+
/>
9+
</div>
410
<h6 class="text-xs font-bold pb-2">Sort by:</h6>
511
<div class="flex lg:flex-col">
612
<RadioButton
@@ -45,15 +51,48 @@ export default {
4551
computed: {
4652
...mapGetters({
4753
getCurrentPage: 'getCurrentPage',
54+
getOrgsSortBy: 'getOrgsSortBy',
55+
getOrgSearchTerm: 'getOrgSearchTerm',
4856
}),
4957
},
5058
methods: {
5159
async onSortByChanged(sortBy) {
5260
this.$store.commit('setOrgsSortBy', sortBy)
53-
const response = await this.$axios.get(
54-
`v1/orgs?sort_by=${sortBy}&page=${this.getCurrentPage}`
55-
)
56-
this.$store.commit('setOrgs', response.data.orgs)
61+
62+
if (this.getOrgSearchTerm) {
63+
const response = await this.$axios.get(
64+
`v1/orgs?sort_by=${sortBy}&page=${this.getCurrentPage}&search=${this.getOrgSearchTerm}`,
65+
)
66+
67+
this.$store.commit('setOrgs', response.data.orgs)
68+
this.$store.commit('setPageCount', response.data.totalPages)
69+
} else {
70+
const response = await this.$axios.get(
71+
`v1/orgs?sort_by=${sortBy}&page=${this.getCurrentPage}`,
72+
)
73+
74+
this.$store.commit('setOrgs', response.data.orgs)
75+
this.$store.commit('setPageCount', response.data.totalPages)
76+
}
77+
},
78+
79+
async onSearch(searchTerm) {
80+
this.$store.commit('setCurrentPage', 1)
81+
if (searchTerm) {
82+
this.$store.commit('setOrgSearchTerm', searchTerm)
83+
const response = await this.$axios.get(
84+
`v1/orgs?sort_by=${this.getOrgsSortBy}&page=${this.getCurrentPage}&search=${searchTerm}`,
85+
)
86+
this.$store.commit('setOrgs', response.data.orgs)
87+
this.$store.commit('setPageCount', response.data.totalPages)
88+
} else {
89+
this.$store.commit('setOrgSearchTerm', '')
90+
const response = await this.$axios.get(
91+
`v1/orgs?sort_by=${this.getOrgsSortBy}&page=${this.getCurrentPage}`,
92+
)
93+
this.$store.commit('setOrgs', response.data.orgs)
94+
this.$store.commit('setPageCount', response.data.totalPages)
95+
}
5796
},
5897
},
5998
}

store/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const state = () => ({
1111
period: 'last_30_days',
1212
chartPeriod: 'last_year',
1313
show: 'all',
14+
orgSearchTerm: '',
1415
})
1516

1617
export const getters = {
@@ -21,6 +22,7 @@ export const getters = {
2122
getPeriod: (state) => state.period,
2223
getChartPeriod: (state) => state.chartPeriod,
2324
getShow: (state) => state.show,
25+
getOrgSearchTerm: (state) => state.orgSearchTerm,
2426
}
2527

2628
export const mutations = {
@@ -60,4 +62,7 @@ export const mutations = {
6062
setShow(state, show) {
6163
state.show = show
6264
},
65+
setOrgSearchTerm(state, searchTerm) {
66+
state.orgSearchTerm = searchTerm
67+
},
6368
}

0 commit comments

Comments
 (0)