fix: admin can not delete own
This commit is contained in:
@@ -3,7 +3,8 @@ import AutoTooltip from '@/components/auto-tooltip';
|
||||
import DropdownButtons from '@/components/drop-down-buttons';
|
||||
import IconFont from '@/components/icon-font';
|
||||
import icons from '@/components/icon-font/icons';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { useIntl, useModel } from '@umijs/max';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import { Tag } from 'antd';
|
||||
import type { SortOrder } from 'antd/es/table/interface';
|
||||
import { ColumnsType } from 'antd/lib/table';
|
||||
@@ -35,6 +36,16 @@ const useUsersColumns = ({
|
||||
sortOrder
|
||||
}: ColumnsHookProps): ColumnsType<ListItem> => {
|
||||
const intl = useIntl();
|
||||
const { initialState } = useModel('@@initialState') || {};
|
||||
|
||||
const setActions = useMemoizedFn((record: ListItem) => {
|
||||
return actionList.filter((action) => {
|
||||
if (initialState?.currentUser?.id === record.id) {
|
||||
return action.key !== 'delete';
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
return useMemo(() => {
|
||||
return [
|
||||
@@ -168,13 +179,13 @@ const useUsersColumns = ({
|
||||
span: 3,
|
||||
render: (text, record) => (
|
||||
<DropdownButtons
|
||||
items={actionList}
|
||||
items={setActions(record)}
|
||||
onSelect={(val) => handleSelect(val, record)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
];
|
||||
}, [sortOrder, intl, handleSelect]);
|
||||
}, [sortOrder, intl, handleSelect, setActions]);
|
||||
};
|
||||
|
||||
export default useUsersColumns;
|
||||
|
||||
@@ -5,10 +5,10 @@ import { PageAction } from '@/config';
|
||||
import type { PageActionType } from '@/config/types';
|
||||
import useTableFetch from '@/hooks/use-table-fetch';
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { useIntl, useModel } from '@umijs/max';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import { Button, ConfigProvider, message, Table } from 'antd';
|
||||
import { useState } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import NoResult from '../_components/no-result';
|
||||
import { createUser, deleteUser, queryUsersList, updateUser } from './apis';
|
||||
import AddModal from './components/add-modal';
|
||||
@@ -35,6 +35,7 @@ const Users: React.FC = () => {
|
||||
contentForDelete: 'users.table.user'
|
||||
});
|
||||
|
||||
const { initialState } = useModel('@@initialState') || {};
|
||||
const intl = useIntl();
|
||||
const [openAddModalStatus, setOpenAddModalStatus] = useState<{
|
||||
action: PageActionType;
|
||||
@@ -155,6 +156,13 @@ const Users: React.FC = () => {
|
||||
sortOrder
|
||||
});
|
||||
|
||||
const dataList = useMemo(() => {
|
||||
return dataSource.dataList.map((item) => ({
|
||||
...item,
|
||||
disabled: initialState?.currentUser?.id === item.id
|
||||
}));
|
||||
}, [dataSource.dataList, initialState?.currentUser?.id]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageContainer
|
||||
@@ -182,7 +190,7 @@ const Users: React.FC = () => {
|
||||
<ConfigProvider renderEmpty={renderEmpty}>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={dataSource.dataList}
|
||||
dataSource={dataList}
|
||||
rowSelection={rowSelection}
|
||||
loading={dataSource.loading}
|
||||
rowKey="id"
|
||||
|
||||
Reference in New Issue
Block a user