mirror of
https://github.com/whyour/qinglong.git
synced 2025-12-14 07:58:12 +08:00
72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import { Modal, message, Input, Form } from 'antd';
|
|
import { request } from '@/utils/http';
|
|
import config from '@/utils/config';
|
|
|
|
const EditNameModal = ({
|
|
ids,
|
|
handleCancel,
|
|
visible,
|
|
}: {
|
|
ids?: string[];
|
|
visible: boolean;
|
|
handleCancel: () => void;
|
|
}) => {
|
|
const [form] = Form.useForm();
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const handleOk = async (values: any) => {
|
|
setLoading(true);
|
|
const { code, data } = await request.put(`${config.apiPrefix}envs/name`, {
|
|
data: {
|
|
ids,
|
|
name: values.name,
|
|
},
|
|
});
|
|
if (code === 200) {
|
|
message.success('更新环境变量名称成功');
|
|
} else {
|
|
message.error(data);
|
|
}
|
|
setLoading(false);
|
|
handleCancel();
|
|
};
|
|
|
|
useEffect(() => {
|
|
form.resetFields();
|
|
}, [ids, visible]);
|
|
|
|
return (
|
|
<Modal
|
|
title="修改环境变量名称"
|
|
visible={visible}
|
|
forceRender
|
|
centered
|
|
maskClosable={false}
|
|
onOk={() => {
|
|
form
|
|
.validateFields()
|
|
.then((values) => {
|
|
handleOk(values);
|
|
})
|
|
.catch((info) => {
|
|
console.log('Validate Failed:', info);
|
|
});
|
|
}}
|
|
onCancel={() => handleCancel()}
|
|
confirmLoading={loading}
|
|
>
|
|
<Form form={form} layout="vertical" name="edit_name_modal">
|
|
<Form.Item
|
|
name="name"
|
|
rules={[{ required: true, message: '请输入新的环境变量名称' }]}
|
|
>
|
|
<Input placeholder="请输入新的环境变量名称" />
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default EditNameModal;
|