style: user activation

This commit is contained in:
jialin
2025-10-09 11:07:09 +08:00
parent 521bf211a2
commit 67552c14af
3 changed files with 51 additions and 22 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
import ModalFooter from '@/components/modal-footer'; import ModalFooter from '@/components/modal-footer';
import ScrollerModal from '@/components/scroller-modal'; import ScrollerModal from '@/components/scroller-modal';
import SealCheckbox from '@/components/seal-form/seal-checkbox';
import SealInput from '@/components/seal-form/seal-input'; import SealInput from '@/components/seal-form/seal-input';
import SealSelect from '@/components/seal-form/seal-select'; import SealSelect from '@/components/seal-form/seal-select';
import SealSwitch from '@/components/seal-form/seal-switch';
import { PageAction, PasswordReg } from '@/config'; import { PageAction, PasswordReg } from '@/config';
import { PageActionType } from '@/config/types'; import { PageActionType } from '@/config/types';
import { UserOutlined, UserSwitchOutlined } from '@ant-design/icons'; import { UserOutlined, UserSwitchOutlined } from '@ant-design/icons';
@@ -36,7 +36,7 @@ const AddModal: React.FC<AddModalProps> = ({
form.setFieldsValue({ form.setFieldsValue({
...data, ...data,
is_admin: data?.is_admin ? UserRoles.ADMIN : UserRoles.USER, is_admin: data?.is_admin ? UserRoles.ADMIN : UserRoles.USER,
is_active: data?.is_active !== undefined ? data.is_active : true is_active: !!data?.is_active
}); });
} else if (action === PageAction.CREATE && open) { } else if (action === PageAction.CREATE && open) {
form.setFieldsValue({ form.setFieldsValue({
@@ -125,7 +125,7 @@ const AddModal: React.FC<AddModalProps> = ({
rules={[{ required: false }]} rules={[{ required: false }]}
valuePropName="checked" valuePropName="checked"
> >
<SealCheckbox <SealSwitch
label={intl.formatMessage({ id: 'users.form.active' })} label={intl.formatMessage({ id: 'users.form.active' })}
description={intl.formatMessage({ description={intl.formatMessage({
id: 'users.form.active.description' id: 'users.form.active.description'
+8 -13
View File
@@ -1,16 +1,3 @@
export interface ListItem {
name: string;
is_admin: boolean;
full_name: string;
id: number;
source: string;
avatar_url: string;
username: string;
created_at: string;
updated_at: string;
is_active?: boolean;
}
export interface FormData { export interface FormData {
username: string; username: string;
id?: number; id?: number;
@@ -19,3 +6,11 @@ export interface FormData {
password: string; password: string;
is_active?: boolean; is_active?: boolean;
} }
export interface ListItem extends FormData {
id: number;
source: string;
avatar_url: string;
created_at: string;
updated_at: string;
}
+40 -6
View File
@@ -20,18 +20,28 @@ import {
ConfigProvider, ConfigProvider,
Empty, Empty,
Input, Input,
message,
Space, Space,
Switch,
Table, Table,
message Tag
} from 'antd'; } from 'antd';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useState } from 'react'; import { useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook'; import { useHotkeys } from 'react-hotkeys-hook';
import styled from 'styled-components';
import { createUser, deleteUser, queryUsersList, updateUser } from './apis'; import { createUser, deleteUser, queryUsersList, updateUser } from './apis';
import AddModal from './components/add-modal'; import AddModal from './components/add-modal';
import { FormData, ListItem } from './config/types'; import { FormData, ListItem } from './config/types';
const { Column } = Table; const { Column } = Table;
const StyledSwitch = styled(Switch)`
.ant-switch-handle::before {
inset-inline-end: 0 !important;
inset-inline-start: 0 !important;
}
`;
const ActionList = [ const ActionList = [
{ {
key: 'edit', key: 'edit',
@@ -105,6 +115,7 @@ const Users: React.FC = () => {
message.success(intl.formatMessage({ id: 'common.message.success' })); message.success(intl.formatMessage({ id: 'common.message.success' }));
} catch (error) { } catch (error) {
setOpenAddModal(false); setOpenAddModal(false);
message.error(intl.formatMessage({ id: 'common.message.fail' }));
} }
}; };
@@ -128,6 +139,22 @@ const Users: React.FC = () => {
} }
}; };
const handleActiveChange = async (checked: boolean, row: ListItem) => {
try {
await updateUser({
data: {
...row,
is_active: checked,
id: row?.id
}
});
handleSearch();
message.success(intl.formatMessage({ id: 'common.message.success' }));
} catch (error) {
message.error(intl.formatMessage({ id: 'common.message.fail' }));
}
};
const renderEmpty = (type?: string) => { const renderEmpty = (type?: string) => {
if (type !== 'Table') return; if (type !== 'Table') return;
if ( if (
@@ -304,11 +331,18 @@ const Users: React.FC = () => {
}} }}
render={(text, record: ListItem) => { render={(text, record: ListItem) => {
return ( return (
<AutoTooltip ghost minWidth={20}> <>
{record.is_active <Tag
? intl.formatMessage({ id: 'users.status.active' }) style={{ marginRight: 0 }}
: intl.formatMessage({ id: 'users.status.inactive' })} color={record.is_active ? 'success' : 'default'}
</AutoTooltip> >
{intl.formatMessage({
id: record.is_active
? 'users.status.active'
: 'users.status.inactive'
})}
</Tag>
</>
); );
}} }}
/> />