feat(UserCreate): add loading animation
This commit is contained in:
parent
919758ab69
commit
a7e813b447
@ -8,12 +8,15 @@ import {
|
|||||||
UploadFile,
|
UploadFile,
|
||||||
GetProp,
|
GetProp,
|
||||||
UploadProps,
|
UploadProps,
|
||||||
|
message,
|
||||||
|
Spin,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useUserSelector } from '@/store/userStore';
|
import { useUserSelector } from '@/store/userStore';
|
||||||
import { UserUpdate } from '@/types/user';
|
import { UserUpdate } from '@/types/user';
|
||||||
import { UserService } from '@/services/userService';
|
import { UserService } from '@/services/userService';
|
||||||
|
import { LoadingOutlined } from '@ant-design/icons';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
|
||||||
@ -36,6 +39,7 @@ export default function UserCreate({ closeDrawer }: UserCreateProps) {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [previewOpen, setPreviewOpen] = useState(false);
|
const [previewOpen, setPreviewOpen] = useState(false);
|
||||||
const [previewImage, setPreviewImage] = useState('');
|
const [previewImage, setPreviewImage] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||||||
|
|
||||||
@ -52,9 +56,11 @@ export default function UserCreate({ closeDrawer }: UserCreateProps) {
|
|||||||
setFileList(newFileList);
|
setFileList(newFileList);
|
||||||
|
|
||||||
const onFinish = async (values: UserUpdate) => {
|
const onFinish = async (values: UserUpdate) => {
|
||||||
console.log(values);
|
setLoading(true);
|
||||||
await UserService.createUser(values);
|
await UserService.createUser(values);
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
|
setLoading(false);
|
||||||
|
message.info(t('createdAccountMessage'), 4);
|
||||||
};
|
};
|
||||||
|
|
||||||
const customUploadButton = (
|
const customUploadButton = (
|
||||||
@ -231,12 +237,21 @@ export default function UserCreate({ closeDrawer }: UserCreateProps) {
|
|||||||
block
|
block
|
||||||
style={{ color: '#000' }}
|
style={{ color: '#000' }}
|
||||||
>
|
>
|
||||||
<img
|
{loading ? (
|
||||||
src="/icons/drawer/reg.svg"
|
<>
|
||||||
alt="save"
|
<Spin indicator={<LoadingOutlined spin />} size="small"></Spin>{' '}
|
||||||
style={{ height: '18px', width: '18px' }}
|
{t('saving')}
|
||||||
/>{' '}
|
</>
|
||||||
{t('addAccount')}
|
) : (
|
||||||
|
<>
|
||||||
|
<img
|
||||||
|
src="/icons/drawer/reg.svg"
|
||||||
|
alt="save"
|
||||||
|
style={{ height: '18px', width: '18px' }}
|
||||||
|
/>{' '}
|
||||||
|
{t('addAccount')}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -47,6 +47,8 @@ i18n
|
|||||||
VIEWER: 'Viewer',
|
VIEWER: 'Viewer',
|
||||||
nameLogin: 'Name, login',
|
nameLogin: 'Name, login',
|
||||||
createdAt: 'Created',
|
createdAt: 'Created',
|
||||||
|
saving: 'Saving...',
|
||||||
|
createdAccountMessage: 'User successfully created!',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ru: {
|
ru: {
|
||||||
@ -86,6 +88,8 @@ i18n
|
|||||||
VIEWER: 'Наблюдатель',
|
VIEWER: 'Наблюдатель',
|
||||||
nameLogin: 'Имя, Логин',
|
nameLogin: 'Имя, Логин',
|
||||||
createdAt: 'Создано',
|
createdAt: 'Создано',
|
||||||
|
saving: 'Сохранение...',
|
||||||
|
createdAccountMessage: 'Пользователь успешно создан!'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user