import React, {Component} from 'react'; import {FormattedMessage} from 'react-intl'; import {Input, Tooltip, Icon, Button} from 'antd'; import {graphqlUrl, manageUsers} from "../../../../../config"; import {ADD_NOTIFICATION, UPDATE_NOTIFICATION, UPDATE_PROJECT_ONLY_STATUS} from "../../../../../gql"; import {request} from 'graphql-request' import {idGen} from "../../../../../func"; const valueToKey = { 'dingding webhook': 'dingding webhook', 'notification name': 'requestMethod' }; const toolTipTitle = { 'dingding webhook': 'its dingding webhook', 'notification name': 'its notification name' }; const youMustFill = { 'dingding webhook': false, 'notification name': false }; class NotificationCardFetch extends Component { constructor(props) { super(props); if(props.notification !== '' && props.notification !== null) { let {type, webhook, name} = props.notification; this.state = { type, webhook, name } } else { this.state = { type: 'dingding', webhook: '', name: props.defaultName } } } componentWillReceiveProps(next) { if(next.notification !== '' && next.notification !== null) { let {type, webhook, name} = next.notification; this.setState({ type, webhook, name }) } else { this.setState({ type: 'dingding', webhook: '', name: next.defaultName }) } } ok = (id, userID, projectID, notification) => { let {type, webhook, name} = this.state; let varObj = { id, user_id: userID, type, webhook, name, createdAt: new Date().getTime(), updatedAt: '' }; if (notification === '') { request(graphqlUrl, ADD_NOTIFICATION, varObj).then( data => { if (data.create_notification !== null) { this.setState({ showOK: true }); // 写回 project request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, { id: projectID, updatedAt: new Date().getTime(), projectStatus: 'notificationed' }).then(data => { if (data.update_project !== null) this.props.stepByStep(4); }) } setTimeout(() => { this.setState({ showOK: false }) }, 1500) } ) } else { let varObj = { id: notification.id, type, webhook, name, updatedAt: new Date().getTime() }; request(graphqlUrl, UPDATE_NOTIFICATION, varObj).then( data => { if (data.update_notification !== null) { this.setState({ showOK: true }); request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, { id: projectID, updatedAt: new Date().getTime(), projectStatus: 'updated' }).then(data => { if (data.update_project !== null) this.props.stepByStep(4); }) } setTimeout(() => { this.setState({ showOK: false }) }, 1500) } ) } }; render() { return (

{ youMustFill['dingding webhook'] ? * : '' }   { this.setState({ webhook: e.target.value }) }}/>

{ youMustFill['notification name'] ? * : '' }   { this.setState({ name: e.target.value }) }}/>

{/*
*/} {/*

QQ

*/} {/*
*/} {/*

*/} {/**/} {/*Web hook */} {/**/} {/**/} {/**/} {/**/} {/**/} {/*

*/} {/*

*/} {/**/} {/*Notification Name */} {/**/} {/**/} {/**/} {/**/} {/*

*/} {/*
*/} {/*
*/}
{ manageUsers.includes(this.props.userID) ? : this.props.trialcase ? '' : }
) } } export default NotificationCardFetch;