import React, {Component} from 'react'; import {Button, Input, Spin, Icon} from 'antd'; import {SHOW_CLOUD, ADD_CLOUD, UPDATE_CLOUD} from "../gql"; import {request} from 'graphql-request' import {getCookie} from '../cookie'; import {idGen} from "../func"; class CloudConfig extends Component { constructor(props) { super(props); this.state = { show: false, showOK: '', showNotOK: '', tencentCLoudID: '', tenID: '', tenKey: '', aliyunCLoudID: '', aliID: '', aliKey: '', awsCLoudID: '', awsID: '', awsKey: '', userID: getCookie('user_id') }; request('http://123.206.193.98:3000/graphql', SHOW_CLOUD, {user_id: this.state.userID}).then( data => { let tencent = data.cloud_by_props.find(cloud => cloud.cloudName === 'tencent'); let aliyun = data.cloud_by_props.find(cloud => cloud.cloudName === 'aliyun'); let amazon = data.cloud_by_props.find(cloud => cloud.cloudName === 'amazon'); this.setState({ show: true, tencentCLoudID: tencent ? tencent.id : '', tenID: tencent ? tencent.secretId : '', tenKey: tencent ? tencent.secretKey : '', aliyunCLoudID: aliyun ? aliyun.id : '', aliID: aliyun ? aliyun.secretId : '', aliKey: aliyun ? aliyun.secretKey : '', awsCLoudID: amazon ? amazon.id : '', awsID: amazon ? amazon.secretId : '', awsKey: amazon ? amazon.secretKey : '' }); } ); } inputChange = (kind) => { return (e) => { this.setState({ [kind]: e.target.value }) } }; submit = (id, cloudName, secretId, secretKey) => { return () => { if (id === '') { let varObj = { id: idGen('cloud'), user_id: this.state.userID, appId: '', cloudName, secretId, secretKey, createdAt: new Date().getTime(), updatedAt: '' }; request('http://123.206.193.98:3000/graphql', ADD_CLOUD, varObj).then( data => { if (data.create_cloud.length !== null) { this.setState({ showOK: cloudName }); setTimeout(() => { this.setState({ showOK: '' }); }, 1500) } else { this.setState({ showNotOK: cloudName }); setTimeout(() => { this.setState({ showNotOK: '' }); }, 1500) } } ); } else { let varObj = { id, secretId, secretKey, updatedAt: new Date().getTime() }; request('http://123.206.193.98:3000/graphql', UPDATE_CLOUD, varObj).then( data => { if (data.update_cloud !== null) { this.setState({ showOK: cloudName }); setTimeout(() => { this.setState({ showOK: '' }); }, 1500) } else { this.setState({ showNotOK: cloudName }); setTimeout(() => { this.setState({ showNotOK: '' }); }, 1500) } } ); } } }; render() { return ( this.state.show ?