Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit d3d87d8

Browse files
✨ Make pagination work for members
1 parent efca49f commit d3d87d8

File tree

5 files changed

+67
-17
lines changed

5 files changed

+67
-17
lines changed

components/Pagination.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export default class Pagination extends Vue {
6767
}
6868
@Watch("activePage")
6969
onPageChanged(activePage: number) {
70-
if (typeof this.onChange === "function")
71-
return this.onChange(activePage)
70+
if (typeof this.onChange === "function") return this.onChange(activePage);
7271
}
7372
}
7473
</script>

layouts/default.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ svg {
177177
opacity: 0.5;
178178
background-color: #eee;
179179
}
180+
span + .icon {
181+
margin-left: 0.5rem;
182+
}
180183
}
181184
@keyframes spin {
182185
from {
@@ -332,6 +335,9 @@ svg {
332335
text-align: right;
333336
}
334337
}
338+
+ .pagination {
339+
margin-top: 1rem;
340+
}
335341
}
336342
337343
h1 {

pages/manage/members/index.vue

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
<th></th>
1111
</thead>
1212
<tbody>
13-
<tr v-for="(member, index) in members" :key="`${member.id}_${index}`">
13+
<tr
14+
v-for="(member, index) in members.data"
15+
:key="`${member.id}_${index}`"
16+
>
1417
<td><User :user="member.user" /></td>
1518
<td><TimeAgo :date="member.createdAt" /></td>
1619
<td>{{ membershipRoles[member.role] || member.role }}</td>
@@ -45,7 +48,24 @@
4548
</tr>
4649
</tbody>
4750
</table>
48-
<Pagination :number-of-items="members.length" :items-per-page="5" />
51+
<div class="pagination text text--align-center">
52+
<button
53+
v-if="members.hasMore"
54+
class="button"
55+
:disabled="loadingMore"
56+
@click="loadMoreMembers"
57+
>
58+
<span>Load more members</span>
59+
<font-awesome-icon v-if="!loadingMore" class="icon" icon="arrow-down" />
60+
<font-awesome-icon
61+
v-else
62+
title="Available"
63+
class="icon icon--ml-2 icon--color-light"
64+
icon="sync"
65+
spin
66+
/>
67+
</button>
68+
</div>
4969
<h2>Invite another member</h2>
5070
<p>
5171
Use this form to invite another user from your team to this organization.
@@ -102,24 +122,28 @@ import { Component, Vue, Watch } from "vue-property-decorator";
102122
import { mapGetters } from "vuex";
103123
import Loading from "@/components/Loading.vue";
104124
import User from "@/components/User.vue";
105-
import Pagination from "@/components/Pagination.vue";
106125
import TimeAgo from "@/components/TimeAgo.vue";
107126
import Confirm from "@/components/Confirm.vue";
108127
import Input from "@/components/form/Input.vue";
109128
import Select from "@/components/form/Select.vue";
110129
import Checkbox from "@/components/form/Checkbox.vue";
111130
import { getAllCountries } from "countries-and-timezones";
131+
import { Email } from "@/types/settings";
112132
import locale from "@/locales/en";
113133
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
114134
import { library } from "@fortawesome/fontawesome-svg-core";
115-
import { faTrash, faPencilAlt } from "@fortawesome/free-solid-svg-icons";
116-
import { Email } from "@/types/settings";
117-
library.add(faTrash, faPencilAlt);
135+
import {
136+
faTrash,
137+
faPencilAlt,
138+
faArrowDown,
139+
faSync
140+
} from "@fortawesome/free-solid-svg-icons";
141+
import { Members } from "../../../types/manage";
142+
library.add(faTrash, faPencilAlt, faArrowDown, faSync);
118143
119144
@Component({
120145
components: {
121146
TimeAgo,
122-
Pagination,
123147
User,
124148
Loading,
125149
Input,
@@ -133,10 +157,11 @@ library.add(faTrash, faPencilAlt);
133157
})
134158
})
135159
export default class ManageMembers extends Vue {
136-
members!: any;
160+
members!: Members;
137161
loading = "";
138162
inviting = false;
139163
showDelete = null;
164+
loadingMore = false;
140165
membershipRoles = locale.membershipRoles;
141166
142167
newUserName = "";
@@ -151,6 +176,14 @@ export default class ManageMembers extends Vue {
151176
.catch(() => {})
152177
.finally(() => (this.loading = ""));
153178
}
179+
private loadMoreMembers() {
180+
this.loadingMore = true;
181+
this.$store
182+
.dispatch("manage/getMembers", this.$store.state.manage.members.next)
183+
.then(() => {})
184+
.catch(() => {})
185+
.finally(() => (this.loadingMore = false));
186+
}
154187
155188
private inviteMember() {
156189
this.inviting = true;

store/manage.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ import Vue from "vue";
55

66
const stripeProductId = "prod_CtJZklN9W4QmxA";
77
export const state = (): RootState => ({
8-
members: [],
8+
members: { data: [], hasMore: false },
99
isDownloading: false
1010
});
1111

1212
export const mutations: MutationTree<RootState> = {
1313
setOrganization(state: RootState, organization: Organization): void {
1414
Vue.set(state, "organization", organization);
1515
},
16-
setMembers(state: RootState, members: Member[]): void {
17-
Vue.set(state, "members", members);
16+
setMembers(state: RootState, { members, start }): void {
17+
if (start) {
18+
const currentMembers = state.members;
19+
members.data = [...currentMembers.data, ...members.data];
20+
Vue.set(state, "members", members);
21+
} else {
22+
Vue.set(state, "members", members);
23+
}
1824
},
1925
setBilling(state: RootState, billing: any): void {
2026
Vue.set(state, "billing", billing);
@@ -87,13 +93,13 @@ export const actions: ActionTree<RootState, RootState> = {
8793
);
8894
commit("stopDownloading");
8995
},
90-
async getMembers({ rootGetters, commit }) {
96+
async getMembers({ rootGetters, commit }, start = 0) {
9197
const org = rootGetters["auth/activeOrganization"];
9298
const organizationId = org.organizationId;
9399
const members = (await this.$axios.get(
94-
`/organizations/${organizationId}/memberships`
100+
`/organizations/${organizationId}/memberships?start=${start}`
95101
)).data;
96-
commit("setMembers", members);
102+
commit("setMembers", { members, start });
97103
},
98104
async inviteMember({ dispatch, rootGetters }, context) {
99105
const org = rootGetters["auth/activeOrganization"];

types/manage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ export interface Member {
1111
id: number;
1212
}
1313

14+
export interface Members {
15+
data: Member[];
16+
hasMore: boolean;
17+
next?: number;
18+
}
19+
1420
export interface RootState {
1521
membership?: Membership;
1622
organization?: Organization;
17-
members: Member[];
23+
members: Members;
1824
billing?: any;
1925
invoices?: any;
2026
subscriptions?: any;

0 commit comments

Comments
 (0)