import React, { useState, useRef } from 'react'; import { API, isMobile, showError, showSuccess } from '../../helpers'; import { Button, SideSheet, Space, Spin, Typography, Card, Tag, Avatar, Form, Row, Col, } from '@douyinfe/semi-ui'; import { IconSave, IconClose, IconUserAdd, } from '@douyinfe/semi-icons'; import { useTranslation } from 'react-i18next'; const { Text, Title } = Typography; const AddUser = (props) => { const { t } = useTranslation(); const formApiRef = useRef(null); const [loading, setLoading] = useState(false); const getInitValues = () => ({ username: '', display_name: '', password: '', remark: '', }); const submit = async (values) => { setLoading(true); const res = await API.post(`/api/user/`, values); const { success, message } = res.data; if (success) { showSuccess(t('用户账户创建成功!')); formApiRef.current?.setValues(getInitValues()); props.refresh(); props.handleClose(); } else { showError(message); } setLoading(false); }; const handleCancel = () => { props.handleClose(); }; return ( <> {t('新建')} {t('添加用户')} } bodyStyle={{ padding: '0' }} visible={props.visible} width={isMobile() ? '100%' : 600} footer={
} closeIcon={null} onCancel={() => handleCancel()} >
formApiRef.current = api} onSubmit={submit} onSubmitFail={(errs) => { const first = Object.values(errs)[0]; if (first) showError(Array.isArray(first) ? first[0] : first); formApiRef.current?.scrollToError(); }} >
{t('用户信息')}
{t('创建新用户账户')}
); }; export default AddUser;