fix: admin can not delete own

This commit is contained in:
jialin
2025-10-23 17:09:30 +08:00
parent a815e71bfe
commit bf57290197
12 changed files with 57 additions and 18 deletions
+14 -3
View File
@@ -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;