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>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2020-08-14 11:32:23 +02:00
|
|
|
import { ACCEPT_INVITATION, REJECT_INVITATION } from "@/graphql/member";
|
|
|
|
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";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { useMutation } from "@vue/apollo-composable";
|
|
|
|
import { ErrorResponse } from "@/types/errors.model";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { inject } from "vue";
|
|
|
|
import type { Notifier } from "@/plugins/notifier";
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
defineProps<{
|
2022-07-12 10:55:28 +02:00
|
|
|
invitations: IMember[];
|
|
|
|
}>();
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { mutate: acceptInvitation, onError: onAcceptInvitationError } =
|
|
|
|
useMutation(ACCEPT_INVITATION, {
|
|
|
|
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) },
|
|
|
|
},
|
|
|
|
];
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return [];
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const notifier = inject<Notifier>("notifier");
|
|
|
|
|
|
|
|
const onError = (error: ErrorResponse) => {
|
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
2022-08-12 16:46:44 +02:00
|
|
|
notifier?.error(error.graphQLErrors[0].message);
|
2020-08-14 11:32:23 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
onAcceptInvitationError((err) => onError(err as unknown as ErrorResponse));
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { mutate: rejectInvitation, onError: onRejectInvitationError } =
|
|
|
|
useMutation(REJECT_INVITATION, {
|
|
|
|
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) },
|
|
|
|
},
|
|
|
|
];
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return [];
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
onRejectInvitationError((err) => onError(err as unknown as ErrorResponse));
|
2020-08-14 11:32:23 +02:00
|
|
|
</script>
|