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 <tcit@tcit.fr>
This commit is contained in:
parent
688bdccc24
commit
2454fe2aa4
|
@ -137,7 +137,9 @@ const close = () => {
|
||||||
*/
|
*/
|
||||||
const cancel = (source: string) => {
|
const cancel = (source: string) => {
|
||||||
emit("cancel", source);
|
emit("cancel", source);
|
||||||
props.onCancel?.apply(null, [source]);
|
if (props?.onCancel) {
|
||||||
|
props?.onCancel(source);
|
||||||
|
}
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -806,15 +806,20 @@ const openLeaveGroupModal = async (): Promise<void> => {
|
||||||
"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.",
|
"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: `<b>${displayName(group.value)}</b>` }
|
{ groupName: `<b>${displayName(group.value)}</b>` }
|
||||||
),
|
),
|
||||||
onConfirm: () => leaveGroup(),
|
onConfirm: leaveGroup,
|
||||||
confirmText: t("Leave group"),
|
confirmText: t("Leave group"),
|
||||||
cancelText: t("Cancel"),
|
cancelText: t("Cancel"),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const {
|
||||||
|
mutate: leaveGroupMutation,
|
||||||
|
onError: onLeaveGroupError,
|
||||||
|
onDone: onLeaveGroupDone,
|
||||||
|
} = useLeaveGroup();
|
||||||
|
|
||||||
const leaveGroup = () => {
|
const leaveGroup = () => {
|
||||||
const { mutate: leaveGroupMutation, onError: onLeaveGroupError } =
|
console.debug("called leaveGroup");
|
||||||
useLeaveGroup();
|
|
||||||
|
|
||||||
const [groupFederatedUsername, currentActorId] = [
|
const [groupFederatedUsername, currentActorId] = [
|
||||||
usernameWithDomain(group.value),
|
usernameWithDomain(group.value),
|
||||||
|
@ -837,13 +842,17 @@ const leaveGroup = () => {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
onLeaveGroupError((error: any) => {
|
onLeaveGroupError((error: any) => {
|
||||||
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
||||||
notifier?.error(error.graphQLErrors[0].message);
|
notifier?.error(error.graphQLErrors[0].message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
onLeaveGroupDone(() => {
|
||||||
|
console.debug("done");
|
||||||
|
});
|
||||||
|
|
||||||
const { mutate: followGroupMutation, onError: onFollowGroupError } =
|
const { mutate: followGroupMutation, onError: onFollowGroupError } =
|
||||||
useMutation(FOLLOW_GROUP, () => ({
|
useMutation(FOLLOW_GROUP, () => ({
|
||||||
|
|
|
@ -341,6 +341,10 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
||||||
{:group, nil} ->
|
{:group, nil} ->
|
||||||
{:error, dgettext("errors", "Group not found")}
|
{: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, :is_not_only_admin} ->
|
||||||
{:error,
|
{:error,
|
||||||
dgettext("errors", "You can't leave this group because you are the only administrator")}
|
dgettext("errors", "You can't leave this group because you are the only administrator")}
|
||||||
|
|
Loading…
Reference in a new issue