|
1 | 1 | <template> |
2 | 2 | <div :class="isOpen ? '' : 'hidden overflow-hidden lg:block'"> |
3 | 3 | <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> |
4 | 10 | <h6 class="text-xs font-bold pb-2">Sort by:</h6> |
5 | 11 | <div class="flex lg:flex-col"> |
6 | 12 | <RadioButton |
@@ -45,15 +51,48 @@ export default { |
45 | 51 | computed: { |
46 | 52 | ...mapGetters({ |
47 | 53 | getCurrentPage: 'getCurrentPage', |
| 54 | + getOrgsSortBy: 'getOrgsSortBy', |
| 55 | + getOrgSearchTerm: 'getOrgSearchTerm', |
48 | 56 | }), |
49 | 57 | }, |
50 | 58 | methods: { |
51 | 59 | async onSortByChanged(sortBy) { |
52 | 60 | 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 | + } |
57 | 96 | }, |
58 | 97 | }, |
59 | 98 | } |
|
0 commit comments