zhichyu's picture
Unified API response json schema (#3170)
196c662
raw
history blame
1.71 kB
import { useSetModalState, useShowDeleteConfirm } from '@/hooks/common-hooks';
import {
useAddTenantUser,
useAgreeTenant,
useDeleteTenantUser,
useFetchUserInfo,
} from '@/hooks/user-setting-hooks';
import { useCallback } from 'react';
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 handleDeleteTenantUser = (userId: string) => () => {
showDeleteConfirm({
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 };
};