2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<section class="section container">
|
|
|
|
<h1 class="title">{{ $t("My groups") }}</h1>
|
2020-08-31 12:40:30 +02:00
|
|
|
<p>
|
|
|
|
{{
|
|
|
|
$t(
|
|
|
|
"Groups are spaces for coordination and preparation to better organize events and manage your community."
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</p>
|
2020-09-29 09:53:48 +02:00
|
|
|
<div class="buttons">
|
|
|
|
<router-link class="button is-primary" :to="{ name: RouteName.CREATE_GROUP }">{{
|
|
|
|
$t("Create group")
|
|
|
|
}}</router-link>
|
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
2020-08-14 11:32:23 +02:00
|
|
|
<invitations
|
|
|
|
:invitations="invitations"
|
2020-10-02 16:19:15 +02:00
|
|
|
@accept-invitation="acceptInvitation"
|
|
|
|
@reject-invitation="rejectInvitation"
|
2020-08-14 11:32:23 +02:00
|
|
|
/>
|
2020-02-18 08:57:00 +01:00
|
|
|
<section v-if="memberships && memberships.length > 0">
|
2020-09-29 09:53:48 +02:00
|
|
|
<GroupMemberCard
|
|
|
|
class="group-member-card"
|
|
|
|
v-for="member in memberships"
|
|
|
|
:key="member.id"
|
|
|
|
:member="member"
|
|
|
|
@leave="leaveGroup(member.parent)"
|
|
|
|
/>
|
2020-02-18 08:57:00 +01:00
|
|
|
</section>
|
|
|
|
<b-message v-if="$apollo.loading === false && memberships.length === 0" type="is-danger">
|
|
|
|
{{ $t("No groups found") }}
|
|
|
|
</b-message>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
|
|
|
import { LOGGED_USER_MEMBERSHIPS } from "@/graphql/actor";
|
2020-09-29 09:53:48 +02:00
|
|
|
import { LEAVE_GROUP } from "@/graphql/group";
|
2020-08-05 14:39:17 +02:00
|
|
|
import GroupMemberCard from "@/components/Group/GroupMemberCard.vue";
|
2020-08-14 11:32:23 +02:00
|
|
|
import Invitations from "@/components/Group/Invitations.vue";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Paginate } from "@/types/paginate";
|
2020-09-29 09:53:48 +02:00
|
|
|
import { IGroup, IMember, MemberRole, usernameWithDomain } from "@/types/actor";
|
|
|
|
import { Route } from "vue-router";
|
2020-02-18 08:57:00 +01:00
|
|
|
import RouteName from "../../router/name";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
2020-08-05 14:39:17 +02:00
|
|
|
GroupMemberCard,
|
2020-08-14 11:32:23 +02:00
|
|
|
Invitations,
|
2020-02-18 08:57:00 +01:00
|
|
|
},
|
|
|
|
apollo: {
|
2020-07-09 17:24:28 +02:00
|
|
|
membershipsPages: {
|
2020-02-18 08:57:00 +01:00
|
|
|
query: LOGGED_USER_MEMBERSHIPS,
|
|
|
|
fetchPolicy: "network-only",
|
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
beforeDateTime: new Date().toISOString(),
|
|
|
|
},
|
|
|
|
update: (data) => data.loggedUser.memberships,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
// if no subcomponents specify a metaInfo.title, this title will be used
|
|
|
|
title: this.$t("My groups") as string,
|
|
|
|
// all titles will be injected into this template
|
|
|
|
titleTemplate: "%s | Mobilizon",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
})
|
2020-10-15 14:23:55 +02:00
|
|
|
export default class MyGroups extends Vue {
|
2020-07-09 17:24:28 +02:00
|
|
|
membershipsPages!: Paginate<IMember>;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
RouteName = RouteName;
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
acceptInvitation(member: IMember): Promise<Route> {
|
2020-08-14 11:32:23 +02:00
|
|
|
return this.$router.push({
|
|
|
|
name: RouteName.GROUP,
|
|
|
|
params: { preferredUsername: usernameWithDomain(member.parent) },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
rejectInvitation({ id: memberId }: { id: string }): void {
|
2020-08-14 11:32:23 +02:00
|
|
|
const index = this.membershipsPages.elements.findIndex(
|
|
|
|
(membership) => membership.role === MemberRole.INVITED && membership.id === memberId
|
|
|
|
);
|
|
|
|
if (index > -1) {
|
|
|
|
this.membershipsPages.elements.splice(index, 1);
|
|
|
|
this.membershipsPages.total -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
async leaveGroup(group: IGroup): Promise<void> {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: LEAVE_GROUP,
|
|
|
|
variables: {
|
|
|
|
groupId: group.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get invitations(): IMember[] {
|
2020-07-09 17:24:28 +02:00
|
|
|
if (!this.membershipsPages) return [];
|
|
|
|
return this.membershipsPages.elements.filter(
|
|
|
|
(member: IMember) => member.role === MemberRole.INVITED
|
|
|
|
);
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
get memberships(): IMember[] {
|
2020-07-09 17:24:28 +02:00
|
|
|
if (!this.membershipsPages) return [];
|
|
|
|
return this.membershipsPages.elements.filter(
|
2020-08-27 11:53:24 +02:00
|
|
|
(member: IMember) => ![MemberRole.INVITED, MemberRole.REJECTED].includes(member.role)
|
2020-07-09 17:24:28 +02:00
|
|
|
);
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
main > .container {
|
|
|
|
background: $white;
|
|
|
|
}
|
|
|
|
|
|
|
|
.participation {
|
|
|
|
margin: 1rem auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
section {
|
|
|
|
.upcoming-month {
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 09:53:48 +02:00
|
|
|
|
|
|
|
.group-member-card {
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
</style>
|