2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
2020-06-25 11:36:35 +02:00
|
|
|
<div>
|
|
|
|
<nav class="breadcrumb" aria-label="breadcrumbs">
|
2020-08-14 11:32:23 +02:00
|
|
|
<ul v-if="group">
|
2020-06-25 11:36:35 +02:00
|
|
|
<li>
|
2020-07-09 17:24:28 +02:00
|
|
|
<router-link
|
|
|
|
:to="{
|
|
|
|
name: RouteName.GROUP,
|
|
|
|
params: { preferredUsername: usernameWithDomain(group) },
|
|
|
|
}"
|
|
|
|
>{{ group.name }}</router-link
|
|
|
|
>
|
2020-06-25 11:36:35 +02:00
|
|
|
</li>
|
|
|
|
<li>
|
2020-07-09 17:24:28 +02:00
|
|
|
<router-link
|
|
|
|
:to="{
|
|
|
|
name: RouteName.GROUP_SETTINGS,
|
|
|
|
params: { preferredUsername: usernameWithDomain(group) },
|
|
|
|
}"
|
|
|
|
>{{ $t("Settings") }}</router-link
|
|
|
|
>
|
2020-06-25 11:36:35 +02:00
|
|
|
</li>
|
|
|
|
<li class="is-active">
|
2020-07-09 17:24:28 +02:00
|
|
|
<router-link
|
|
|
|
:to="{
|
|
|
|
name: RouteName.GROUP_MEMBERS_SETTINGS,
|
|
|
|
params: { preferredUsername: usernameWithDomain(group) },
|
|
|
|
}"
|
|
|
|
>{{ $t("Members") }}</router-link
|
|
|
|
>
|
2020-06-25 11:36:35 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
<section class="container section" v-if="group">
|
|
|
|
<form @submit.prevent="inviteMember">
|
|
|
|
<b-field :label="$t('Invite a new member')" custom-class="add-relay" horizontal>
|
|
|
|
<b-field grouped expanded size="is-large">
|
|
|
|
<p class="control">
|
|
|
|
<b-input v-model="newMemberUsername" :placeholder="$t('Ex: someone@mobilizon.org')" />
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<b-button type="is-primary" native-type="submit">{{ $t("Invite member") }}</b-button>
|
|
|
|
</p>
|
|
|
|
</b-field>
|
2020-02-18 08:57:00 +01:00
|
|
|
</b-field>
|
2020-06-25 11:36:35 +02:00
|
|
|
</form>
|
|
|
|
<h1>{{ $t("Group Members") }} ({{ group.members.total }})</h1>
|
2020-07-09 17:24:28 +02:00
|
|
|
<b-field :label="$t('Status')" horizontal>
|
|
|
|
<b-select v-model="roles">
|
|
|
|
<option value="">
|
|
|
|
{{ $t("Everything") }}
|
|
|
|
</option>
|
|
|
|
<option :value="MemberRole.ADMINISTRATOR">
|
|
|
|
{{ $t("Administrator") }}
|
|
|
|
</option>
|
|
|
|
<option :value="MemberRole.MODERATOR">
|
|
|
|
{{ $t("Moderator") }}
|
|
|
|
</option>
|
|
|
|
<option :value="MemberRole.MEMBER">
|
|
|
|
{{ $t("Member") }}
|
|
|
|
</option>
|
|
|
|
<option :value="MemberRole.INVITED">
|
|
|
|
{{ $t("Invited") }}
|
|
|
|
</option>
|
|
|
|
<option :value="MemberRole.NOT_APPROVED">
|
|
|
|
{{ $t("Not approved") }}
|
|
|
|
</option>
|
|
|
|
<option :value="MemberRole.REJECTED">
|
|
|
|
{{ $t("Rejected") }}
|
|
|
|
</option>
|
|
|
|
</b-select>
|
|
|
|
</b-field>
|
|
|
|
<b-table
|
|
|
|
:data="group.members.elements"
|
|
|
|
ref="queueTable"
|
|
|
|
:loading="this.$apollo.loading"
|
|
|
|
paginated
|
|
|
|
backend-pagination
|
|
|
|
:pagination-simple="true"
|
|
|
|
:aria-next-label="$t('Next page')"
|
|
|
|
:aria-previous-label="$t('Previous page')"
|
|
|
|
:aria-page-label="$t('Page')"
|
|
|
|
:aria-current-label="$t('Current page')"
|
|
|
|
:total="group.members.total"
|
|
|
|
:per-page="MEMBERS_PER_PAGE"
|
|
|
|
backend-sorting
|
|
|
|
:default-sort-direction="'desc'"
|
|
|
|
:default-sort="['insertedAt', 'desc']"
|
|
|
|
@page-change="(newPage) => (page = newPage)"
|
|
|
|
@sort="(field, order) => $emit('sort', field, order)"
|
|
|
|
>
|
2020-08-18 15:50:50 +02:00
|
|
|
<b-table-column field="actor.preferredUsername" :label="$t('Member')" v-slot="props">
|
|
|
|
<article class="media">
|
|
|
|
<figure class="media-left image is-48x48" v-if="props.row.actor.avatar">
|
|
|
|
<img class="is-rounded" :src="props.row.actor.avatar.url" alt="" />
|
|
|
|
</figure>
|
|
|
|
<b-icon class="media-left" v-else size="is-large" icon="account-circle" />
|
|
|
|
<div class="media-content">
|
|
|
|
<div class="content">
|
|
|
|
<span v-if="props.row.actor.name">{{ props.row.actor.name }}</span
|
|
|
|
><br />
|
|
|
|
<span class="is-size-7 has-text-grey"
|
|
|
|
>@{{ usernameWithDomain(props.row.actor) }}</span
|
|
|
|
>
|
2020-07-09 17:24:28 +02:00
|
|
|
</div>
|
2020-08-18 15:50:50 +02:00
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
</b-table-column>
|
|
|
|
<b-table-column field="role" :label="$t('Role')" v-slot="props">
|
|
|
|
<b-tag type="is-primary" v-if="props.row.role === MemberRole.ADMINISTRATOR">
|
|
|
|
{{ $t("Administrator") }}
|
|
|
|
</b-tag>
|
|
|
|
<b-tag type="is-primary" v-else-if="props.row.role === MemberRole.MODERATOR">
|
|
|
|
{{ $t("Moderator") }}
|
|
|
|
</b-tag>
|
|
|
|
<b-tag v-else-if="props.row.role === MemberRole.MEMBER">
|
|
|
|
{{ $t("Member") }}
|
|
|
|
</b-tag>
|
|
|
|
<b-tag type="is-warning" v-else-if="props.row.role === MemberRole.NOT_APPROVED">
|
|
|
|
{{ $t("Not approved") }}
|
|
|
|
</b-tag>
|
|
|
|
<b-tag type="is-danger" v-else-if="props.row.role === MemberRole.REJECTED">
|
|
|
|
{{ $t("Rejected") }}
|
|
|
|
</b-tag>
|
|
|
|
<b-tag type="is-danger" v-else-if="props.row.role === MemberRole.INVITED">
|
|
|
|
{{ $t("Invited") }}
|
|
|
|
</b-tag>
|
|
|
|
</b-table-column>
|
|
|
|
<b-table-column field="insertedAt" :label="$t('Date')" v-slot="props">
|
|
|
|
<span class="has-text-centered">
|
|
|
|
{{ props.row.insertedAt | formatDateString }}<br />{{
|
|
|
|
props.row.insertedAt | formatTimeString
|
|
|
|
}}
|
|
|
|
</span>
|
|
|
|
</b-table-column>
|
|
|
|
<b-table-column field="actions" :label="$t('Actions')" v-slot="props">
|
|
|
|
<b-button
|
|
|
|
v-if="props.row.role === MemberRole.MEMBER"
|
|
|
|
@click="removeMember(props.row.id)"
|
|
|
|
type="is-danger"
|
|
|
|
>{{ $t("Remove") }}</b-button
|
|
|
|
>
|
|
|
|
</b-table-column>
|
2020-07-09 17:24:28 +02:00
|
|
|
<template slot="empty">
|
|
|
|
<section class="section">
|
|
|
|
<div class="content has-text-grey has-text-centered">
|
|
|
|
<p>{{ $t("No member matches the filters") }}</p>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
</b-table>
|
2020-06-25 11:36:35 +02:00
|
|
|
</section>
|
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-07-09 17:24:28 +02:00
|
|
|
import { Component, Vue, Watch } from "vue-property-decorator";
|
2020-02-18 08:57:00 +01:00
|
|
|
import RouteName from "../../router/name";
|
2020-08-14 11:32:23 +02:00
|
|
|
import { INVITE_MEMBER, GROUP_MEMBERS, REMOVE_MEMBER } from "../../graphql/member";
|
2020-07-09 17:24:28 +02:00
|
|
|
import { IGroup, usernameWithDomain } from "../../types/actor";
|
|
|
|
import { IMember, MemberRole } from "../../types/actor/group.model";
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
group: {
|
2020-07-09 17:24:28 +02:00
|
|
|
query: GROUP_MEMBERS,
|
|
|
|
// fetchPolicy: "network-only",
|
2020-02-18 08:57:00 +01:00
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
name: this.$route.params.preferredUsername,
|
2020-07-09 17:24:28 +02:00
|
|
|
page: 1,
|
|
|
|
limit: this.MEMBERS_PER_PAGE,
|
|
|
|
roles: this.roles,
|
2020-02-18 08:57:00 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.$route.params.preferredUsername;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class GroupMembers extends Vue {
|
|
|
|
group!: IGroup;
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
|
|
|
|
RouteName = RouteName;
|
|
|
|
|
|
|
|
newMemberUsername = "";
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
MemberRole = MemberRole;
|
|
|
|
|
|
|
|
roles: MemberRole | "" = "";
|
|
|
|
|
|
|
|
page = 1;
|
|
|
|
|
|
|
|
MEMBERS_PER_PAGE = 10;
|
|
|
|
|
|
|
|
usernameWithDomain = usernameWithDomain;
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
const roleQuery = this.$route.query.role as string;
|
|
|
|
if (Object.values(MemberRole).includes(roleQuery as MemberRole)) {
|
|
|
|
this.roles = roleQuery as MemberRole;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
async inviteMember() {
|
|
|
|
await this.$apollo.mutate<{ inviteMember: IMember }>({
|
|
|
|
mutation: INVITE_MEMBER,
|
|
|
|
variables: {
|
|
|
|
groupId: this.group.id,
|
|
|
|
targetActorUsername: this.newMemberUsername,
|
|
|
|
},
|
2020-08-14 11:32:23 +02:00
|
|
|
update: (store, { data }) => {
|
|
|
|
if (data == null) return;
|
|
|
|
const query = {
|
|
|
|
query: GROUP_MEMBERS,
|
|
|
|
variables: {
|
|
|
|
name: this.$route.params.preferredUsername,
|
|
|
|
page: 1,
|
|
|
|
limit: this.MEMBERS_PER_PAGE,
|
|
|
|
roles: this.roles,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const memberData: IMember = data.inviteMember;
|
|
|
|
const groupData = store.readQuery<{ group: IGroup }>(query);
|
|
|
|
if (!groupData) return;
|
|
|
|
const { group } = groupData;
|
|
|
|
const index = group.members.elements.findIndex((m) => m.actor.id === memberData.actor.id);
|
|
|
|
if (index === -1) {
|
|
|
|
group.members.elements.push(memberData);
|
|
|
|
group.members.total += 1;
|
|
|
|
} else {
|
|
|
|
group.members.elements.splice(index, 1, memberData);
|
|
|
|
}
|
|
|
|
store.writeQuery({ ...query, data: { group } });
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
});
|
2020-08-14 11:32:23 +02:00
|
|
|
this.newMemberUsername = "";
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
@Watch("page")
|
|
|
|
loadMoreMembers() {
|
|
|
|
this.$apollo.queries.event.fetchMore({
|
|
|
|
// New variables
|
|
|
|
variables: {
|
|
|
|
page: this.page,
|
|
|
|
limit: this.MEMBERS_PER_PAGE,
|
|
|
|
},
|
|
|
|
// Transform the previous result with new data
|
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
|
|
|
const oldMembers = previousResult.group.members;
|
|
|
|
const newMembers = fetchMoreResult.group.members;
|
|
|
|
|
|
|
|
return {
|
|
|
|
group: {
|
|
|
|
...previousResult.event,
|
|
|
|
members: {
|
|
|
|
elements: [...oldMembers.elements, ...newMembers.elements],
|
|
|
|
total: newMembers.total,
|
|
|
|
__typename: oldMembers.__typename,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-08-14 11:32:23 +02:00
|
|
|
|
|
|
|
async removeMember(memberId: string) {
|
|
|
|
await this.$apollo.mutate<{ removeMember: IMember }>({
|
|
|
|
mutation: REMOVE_MEMBER,
|
|
|
|
variables: {
|
|
|
|
groupId: this.group.id,
|
|
|
|
memberId,
|
|
|
|
},
|
|
|
|
update: (store, { data }) => {
|
|
|
|
if (data == null) return;
|
|
|
|
const query = {
|
|
|
|
query: GROUP_MEMBERS,
|
|
|
|
variables: {
|
|
|
|
name: this.$route.params.preferredUsername,
|
|
|
|
page: 1,
|
|
|
|
limit: this.MEMBERS_PER_PAGE,
|
|
|
|
roles: this.roles,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const groupData = store.readQuery<{ group: IGroup }>(query);
|
|
|
|
if (!groupData) return;
|
|
|
|
const { group } = groupData;
|
|
|
|
const index = group.members.elements.findIndex((m) => m.id === memberId);
|
|
|
|
if (index !== -1) {
|
|
|
|
group.members.elements.splice(index, 1);
|
|
|
|
group.members.total -= 1;
|
|
|
|
store.writeQuery({ ...query, data: { group } });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
</script>
|