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

View File

@ -4,8 +4,8 @@
v-for="member in invitations" v-for="member in invitations"
:key="member.id" :key="member.id"
:member="member" :member="member"
@accept="acceptInvitation" @accept="acceptInvitation({ id: member.id })"
@reject="rejectInvitation" @reject="rejectInvitation({ id: member.id })"
/> />
</section> </section>
</template> </template>
@ -25,21 +25,24 @@ defineProps<{
}>(); }>();
const { mutate: acceptInvitation, onError: onAcceptInvitationError } = const { mutate: acceptInvitation, onError: onAcceptInvitationError } =
useMutation(ACCEPT_INVITATION, { useMutation<{ acceptInvitation: IMember }, { id: string }>(
refetchQueries({ data }) { ACCEPT_INVITATION,
const profile = data?.acceptInvitation?.actor as IPerson; {
const group = data?.acceptInvitation?.parent as IGroup; refetchQueries({ data }) {
if (profile && group) { const profile = data?.acceptInvitation?.actor as IPerson;
return [ const group = data?.acceptInvitation?.parent as IGroup;
{ if (profile && group) {
query: PERSON_STATUS_GROUP, return [
variables: { id: profile.id, group: usernameWithDomain(group) }, {
}, query: PERSON_STATUS_GROUP,
]; variables: { id: profile.id, group: usernameWithDomain(group) },
} },
return []; ];
}, }
}); return [];
},
}
);
const notifier = inject<Notifier>("notifier"); const notifier = inject<Notifier>("notifier");
@ -53,21 +56,24 @@ const onError = (error: ErrorResponse) => {
onAcceptInvitationError((err) => onError(err as unknown as ErrorResponse)); onAcceptInvitationError((err) => onError(err as unknown as ErrorResponse));
const { mutate: rejectInvitation, onError: onRejectInvitationError } = const { mutate: rejectInvitation, onError: onRejectInvitationError } =
useMutation(REJECT_INVITATION, { useMutation<{ rejectInvitation: IMember }, { id: string }>(
refetchQueries({ data }) { REJECT_INVITATION,
const profile = data?.rejectInvitation?.actor as IPerson; {
const group = data?.rejectInvitation?.parent as IGroup; refetchQueries({ data }) {
if (profile && group) { const profile = data?.rejectInvitation?.actor as IPerson;
return [ const group = data?.rejectInvitation?.parent as IGroup;
{ if (profile && group) {
query: PERSON_STATUS_GROUP, return [
variables: { id: profile.id, group: usernameWithDomain(group) }, {
}, query: PERSON_STATUS_GROUP,
]; variables: { id: profile.id, group: usernameWithDomain(group) },
} },
return []; ];
}, }
}); return [];
},
}
);
onRejectInvitationError((err) => onError(err as unknown as ErrorResponse)); onRejectInvitationError((err) => onError(err as unknown as ErrorResponse));
</script> </script>