mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-25 16:26:51 +08:00
### What problem does this PR solve? Feat: Quit from jointed team #3759 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import { useSetModalState, useShowDeleteConfirm } from '@/hooks/common-hooks';
|
|
import {
|
|
useAddTenantUser,
|
|
useAgreeTenant,
|
|
useDeleteTenantUser,
|
|
useFetchUserInfo,
|
|
} from '@/hooks/user-setting-hooks';
|
|
import { useCallback } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
export const useAddUser = () => {
|
|
const { addTenantUser } = useAddTenantUser();
|
|
const {
|
|
visible: addingTenantModalVisible,
|
|
hideModal: hideAddingTenantModal,
|
|
showModal: showAddingTenantModal,
|
|
} = useSetModalState();
|
|
|
|
const handleAddUserOk = useCallback(
|
|
async (email: string) => {
|
|
const code = await addTenantUser(email);
|
|
if (code === 0) {
|
|
hideAddingTenantModal();
|
|
}
|
|
},
|
|
[addTenantUser, hideAddingTenantModal],
|
|
);
|
|
|
|
return {
|
|
addingTenantModalVisible,
|
|
hideAddingTenantModal,
|
|
showAddingTenantModal,
|
|
handleAddUserOk,
|
|
};
|
|
};
|
|
|
|
export const useHandleDeleteUser = () => {
|
|
const { deleteTenantUser, loading } = useDeleteTenantUser();
|
|
const showDeleteConfirm = useShowDeleteConfirm();
|
|
const { t } = useTranslation();
|
|
|
|
const handleDeleteTenantUser = (userId: string) => () => {
|
|
showDeleteConfirm({
|
|
title: t('setting.sureDelete'),
|
|
onOk: async () => {
|
|
const code = await deleteTenantUser({ userId });
|
|
if (code === 0) {
|
|
}
|
|
return;
|
|
},
|
|
});
|
|
};
|
|
|
|
return { handleDeleteTenantUser, loading };
|
|
};
|
|
|
|
export const useHandleAgreeTenant = () => {
|
|
const { agreeTenant } = useAgreeTenant();
|
|
const { deleteTenantUser } = useDeleteTenantUser();
|
|
const { data: user } = useFetchUserInfo();
|
|
|
|
const handleAgree = (tenantId: string, isAgree: boolean) => () => {
|
|
if (isAgree) {
|
|
agreeTenant(tenantId);
|
|
} else {
|
|
deleteTenantUser({ tenantId, userId: user.id });
|
|
}
|
|
};
|
|
|
|
return { handleAgree };
|
|
};
|
|
|
|
export const useHandleQuitUser = () => {
|
|
const { deleteTenantUser, loading } = useDeleteTenantUser();
|
|
const showDeleteConfirm = useShowDeleteConfirm();
|
|
const { t } = useTranslation();
|
|
|
|
const handleQuitTenantUser = (userId: string, tenantId: string) => () => {
|
|
showDeleteConfirm({
|
|
title: t('setting.sureQuit'),
|
|
onOk: async () => {
|
|
deleteTenantUser({ userId, tenantId });
|
|
},
|
|
});
|
|
};
|
|
|
|
return { handleQuitTenantUser, loading };
|
|
};
|