require('./notificationAdd.less'); const React = require('react'); const createClass = require('create-react-class'); const cx = require('classnames'); const request = require('superagent'); const fields = ['dismissKey', 'title', 'text', 'startAt', 'stopAt']; const NotificationAdd = createClass({ displayName : 'NotificationAdd', getDefaultProps() { return {}; }, getInitialState() { return { query : '', notificationResult : null, searching : false, error : null, dismissKey : '', title : '', text : '', startAt : '', stopAt : '' }; }, handleChange(e, field){ const data = {}; data[field] = e.target.value; this.setState(data); }, saveNotification : async function(){ if(!this.state.dismissKey) return 'No notification key!'; const data = { dismissKey : this.state.dismissKey, title : this.state.title, text : this.state.text, startAt : this.state.startAt, stopAt : this.state.stopAt }; const notification = await request.post('/admin/notification/add') .send(data) .then((response)=>{ return response.body; }); console.log(notification); const update = { notificationResult : `Created notification: ${JSON.stringify(notification, null, 2)}` }; if(notification.err) { update.notificationResult = err; }; if(!notification.err) { update.dismissKey = ''; update.title = ''; update.text = ''; update.startAt = ''; update.stopAt = ''; } console.log(update); this.setState(update); }, render(){ return

Add

{fields.map((field, idx)=>{ return
this.handleChange(e, field)} placeholder={field} />
; })} {this.state.notificationResult} {/* */} {this.state.error &&
{this.state.error.toString()}
}
; } }); module.exports = NotificationAdd;