/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useState, useRef } from 'react'; import { API, showError, showSuccess } from '../../../../helpers'; import { useIsMobile } from '../../../../hooks/common/useIsMobile'; 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 AddUserModal = (props) => { const { t } = useTranslation(); const formApiRef = useRef(null); const [loading, setLoading] = useState(false); const isMobile = useIsMobile(); 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 AddUserModal;