2020-08-14 11:32:23 +02:00
|
|
|
<template>
|
2021-11-12 15:42:52 +01:00
|
|
|
<section class="card my-3" v-if="invitations && invitations.length > 0">
|
2020-08-14 11:32:23 +02:00
|
|
|
<InvitationCard
|
|
|
|
v-for="member in invitations"
|
|
|
|
:key="member.id"
|
|
|
|
:member="member"
|
|
|
|
@accept="acceptInvitation"
|
|
|
|
@reject="rejectInvitation"
|
|
|
|
/>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { ACCEPT_INVITATION, REJECT_INVITATION } from "@/graphql/member";
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
|
|
|
import InvitationCard from "@/components/Group/InvitationCard.vue";
|
2021-11-12 15:42:52 +01:00
|
|
|
import { PERSON_STATUS_GROUP } from "@/graphql/actor";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { IMember } from "@/types/actor/member.model";
|
2021-11-12 15:42:52 +01:00
|
|
|
import { IGroup, IPerson, usernameWithDomain } from "@/types/actor";
|
2020-08-14 11:32:23 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
InvitationCard,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Invitations extends Vue {
|
|
|
|
@Prop({ required: true, type: Array }) invitations!: IMember;
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
async acceptInvitation(id: string): Promise<void> {
|
|
|
|
try {
|
2021-11-12 15:42:52 +01:00
|
|
|
await this.$apollo.mutate<{ acceptInvitation: IMember }>({
|
|
|
|
mutation: ACCEPT_INVITATION,
|
|
|
|
variables: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
refetchQueries({ data }) {
|
|
|
|
const profile = data?.acceptInvitation?.actor as IPerson;
|
|
|
|
const group = data?.acceptInvitation?.parent as IGroup;
|
|
|
|
if (profile && group) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
query: PERSON_STATUS_GROUP,
|
|
|
|
variables: { id: profile.id, group: usernameWithDomain(group) },
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
});
|
2021-09-29 18:20:33 +02:00
|
|
|
} catch (error: any) {
|
2020-10-02 16:19:15 +02:00
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
|
|
|
this.$notifier.error(error.graphQLErrors[0].message);
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
2020-08-14 11:32:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
async rejectInvitation(id: string): Promise<void> {
|
|
|
|
try {
|
2021-11-12 15:42:52 +01:00
|
|
|
await this.$apollo.mutate<{ rejectInvitation: IMember }>({
|
|
|
|
mutation: REJECT_INVITATION,
|
|
|
|
variables: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
refetchQueries({ data }) {
|
|
|
|
const profile = data?.rejectInvitation?.actor as IPerson;
|
|
|
|
const group = data?.rejectInvitation?.parent as IGroup;
|
|
|
|
if (profile && group) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
query: PERSON_STATUS_GROUP,
|
|
|
|
variables: { id: profile.id, group: usernameWithDomain(group) },
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
});
|
2021-09-29 18:20:33 +02:00
|
|
|
} catch (error: any) {
|
2020-10-02 16:19:15 +02:00
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
|
|
|
this.$notifier.error(error.graphQLErrors[0].message);
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
2020-08-14 11:32:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|