Fix accepting group invitations

Closes #1170

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-10-26 18:25:56 +02:00
parent e446df938f
commit 688bdccc24
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
1 changed files with 38 additions and 32 deletions

View File

@ -4,8 +4,8 @@
v-for="member in invitations"
:key="member.id"
:member="member"
@accept="acceptInvitation"
@reject="rejectInvitation"
@accept="acceptInvitation({ id: member.id })"
@reject="rejectInvitation({ id: member.id })"
/>
</section>
</template>
@ -25,21 +25,24 @@ defineProps<{
}>();
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) },
},
];
}
return [];
},
});
useMutation<{ acceptInvitation: IMember }, { id: string }>(
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) },
},
];
}
return [];
},
}
);
const notifier = inject<Notifier>("notifier");
@ -53,21 +56,24 @@ const onError = (error: ErrorResponse) => {
onAcceptInvitationError((err) => onError(err as unknown as ErrorResponse));
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) },
},
];
}
return [];
},
});
useMutation<{ rejectInvitation: IMember }, { id: string }>(
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) },
},
];
}
return [];
},
}
);
onRejectInvitationError((err) => onError(err as unknown as ErrorResponse));
</script>