From 2454fe2aa4d26162cc6ab82e6382914dbc2bb649 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 26 Oct 2022 18:45:47 +0200 Subject: [PATCH] Fix leaving a group There's still an issue because the call is made twice, but at least it works Signed-off-by: Thomas Citharel --- js/src/components/core/CustomDialog.vue | 4 +++- js/src/views/Group/GroupView.vue | 27 ++++++++++++++++--------- lib/graphql/resolvers/group.ex | 4 ++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/js/src/components/core/CustomDialog.vue b/js/src/components/core/CustomDialog.vue index 599d6df33..c1e01576b 100644 --- a/js/src/components/core/CustomDialog.vue +++ b/js/src/components/core/CustomDialog.vue @@ -137,7 +137,9 @@ const close = () => { */ const cancel = (source: string) => { emit("cancel", source); - props.onCancel?.apply(null, [source]); + if (props?.onCancel) { + props?.onCancel(source); + } close(); }; diff --git a/js/src/views/Group/GroupView.vue b/js/src/views/Group/GroupView.vue index 8a72a61b4..b6ceb4391 100644 --- a/js/src/views/Group/GroupView.vue +++ b/js/src/views/Group/GroupView.vue @@ -806,15 +806,20 @@ const openLeaveGroupModal = async (): Promise => { "Are you sure you want to leave the group {groupName}? You'll loose access to this group's private content. This action cannot be undone.", { groupName: `${displayName(group.value)}` } ), - onConfirm: () => leaveGroup(), + onConfirm: leaveGroup, confirmText: t("Leave group"), cancelText: t("Cancel"), }); }; +const { + mutate: leaveGroupMutation, + onError: onLeaveGroupError, + onDone: onLeaveGroupDone, +} = useLeaveGroup(); + const leaveGroup = () => { - const { mutate: leaveGroupMutation, onError: onLeaveGroupError } = - useLeaveGroup(); + console.debug("called leaveGroup"); const [groupFederatedUsername, currentActorId] = [ usernameWithDomain(group.value), @@ -837,14 +842,18 @@ const leaveGroup = () => { ], } ); - - onLeaveGroupError((error: any) => { - if (error.graphQLErrors && error.graphQLErrors.length > 0) { - notifier?.error(error.graphQLErrors[0].message); - } - }); }; +onLeaveGroupError((error: any) => { + if (error.graphQLErrors && error.graphQLErrors.length > 0) { + notifier?.error(error.graphQLErrors[0].message); + } +}); + +onLeaveGroupDone(() => { + console.debug("done"); +}); + const { mutate: followGroupMutation, onError: onFollowGroupError } = useMutation(FOLLOW_GROUP, () => ({ refetchQueries: [ diff --git a/lib/graphql/resolvers/group.ex b/lib/graphql/resolvers/group.ex index 3eb3a1e51..9bc26198c 100644 --- a/lib/graphql/resolvers/group.ex +++ b/lib/graphql/resolvers/group.ex @@ -341,6 +341,10 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do {:group, nil} -> {:error, dgettext("errors", "Group not found")} + # Actions.Leave.leave can also return nil if the member isn't found. Probably something to fix. + nil -> + {:error, dgettext("errors", "Member not found")} + {:error, :is_not_only_admin} -> {:error, dgettext("errors", "You can't leave this group because you are the only administrator")}