mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com> Co-authored-by: Abhay Mishra <grabhaymishra@gmail.com> Co-authored-by: Hyun Han <62870362+smosco@users.noreply.github.com> Co-authored-by: Nhan Nguyen <nhan13574@gmail.com> Co-authored-by: Bharath A V <avbharath1221@gmail.com> Co-authored-by: hieptl <hieptl.developer@gmail.com> Co-authored-by: Chloe <chloe@openhands.com> Co-authored-by: HeyItsChloe <54480367+HeyItsChloe@users.noreply.github.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { organizationService } from "#/api/organization-service/organization-service.api";
|
|
import { useSelectedOrganizationId } from "#/context/use-selected-organization";
|
|
import { I18nKey } from "#/i18n/declaration";
|
|
import {
|
|
displayErrorToast,
|
|
displaySuccessToast,
|
|
} from "#/utils/custom-toast-handlers";
|
|
import { retrieveAxiosErrorMessage } from "#/utils/retrieve-axios-error-message";
|
|
|
|
export const useRemoveMember = () => {
|
|
const queryClient = useQueryClient();
|
|
const { organizationId } = useSelectedOrganizationId();
|
|
const { t } = useTranslation();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ userId }: { userId: string }) => {
|
|
if (!organizationId) {
|
|
throw new Error("Organization ID is required");
|
|
}
|
|
return organizationService.removeMember({
|
|
orgId: organizationId,
|
|
userId,
|
|
});
|
|
},
|
|
onSuccess: () => {
|
|
displaySuccessToast(t(I18nKey.ORG$REMOVE_MEMBER_SUCCESS));
|
|
queryClient.invalidateQueries({
|
|
queryKey: ["organizations", "members", organizationId],
|
|
});
|
|
},
|
|
onError: (error) => {
|
|
const errorMessage = retrieveAxiosErrorMessage(error);
|
|
displayErrorToast(errorMessage || t(I18nKey.ORG$REMOVE_MEMBER_ERROR));
|
|
},
|
|
});
|
|
};
|