import intl from 'react-intl-universal'; import React, { useEffect, useState } from 'react'; import { Modal, message, Input, Form } from 'antd'; import { request } from '@/utils/http'; import config from '@/utils/config'; const SshKeyModal = ({ sshKey, handleCancel, }: { sshKey?: any; handleCancel: (keys?: any[]) => void; }) => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const handleOk = async (values: any) => { setLoading(true); const method = sshKey ? 'put' : 'post'; const payload = sshKey ? { ...values, id: sshKey.id } : [values]; try { const { code, data } = await request[method]( `${config.apiPrefix}sshKeys`, payload, ); if (code === 200) { message.success( sshKey ? '更新SSH密钥成功' : '创建SSH密钥成功', ); handleCancel(data); } setLoading(false); } catch (error: any) { setLoading(false); } }; return ( { form .validateFields() .then((values) => { handleOk(values); }) .catch((info) => { console.log('Validate Failed:', info); }); }} onCancel={() => handleCancel()} confirmLoading={loading} >
); }; export default SshKeyModal;