import React from 'react'; import { Grid, Row, Col, Fade, FormControl, FormGroup, ControlLabel, HelpBlock, Checkbox } from 'react-bootstrap'; import { validateForm } from '../commons/validator'; import { server } from '../commons/server'; import Success from './success'; import Callout from '../components/callout'; import Card from '../components/card'; import AsyncButton from '../components/async-button'; /** * Form validation model */ const form = { wsname: { required: true, min: 3, max: 250 }, email: { required: true, email: true }, pwd: { required: true, password: true }, pwd2: { required: true, validate: function() { if (this.pwd2 !== this.pwd) { return __('validation.pwdNotSame'); } return null; } } }; export default class NewWorkspace extends React.Component { constructor(props) { super(props); this.contClick = this.contClick.bind(this); this.onDemoChange = this.onDemoChange.bind(this); this.state = { data: { demoData: true } }; } /** * Called when user clicks on the continue button */ contClick() { const vals = validateForm(this, form); // there is any validation error ? if (vals.errors) { this.setState({ errors: vals.errors }); return; } this.setState({ errors: {}, fetching: true }); const v = vals.value; const data = { workspaceName: v.wsname, adminPassword: v.pwd, adminEmail: v.email, demoData: this.state.data.demoData }; const self = this; // request server to register workspace server.post('/api/init/workspace', data) .then(res => { if (res.errors) { self.setState({ errors: res.errors, fetching: false }); } else { self.setState({ success: true, wsname: v.wsname, fetching: false }); } }) .catch(() => self.setState({ fetching: false })); } onDemoChange(evt) { const checked = evt.target.checked; const data = this.state.data; data.demoData = checked; this.setState({ data: data }); } /** * Render the component */ render() { const err = this.state.errors || {}; const fetching = this.state.fetching; const success = this.state.success; let content; if (success) { content = ; } else { content = (
{__('init.ws.name') + ':'} {err.wsname}

{'Administrator'}

{__('init.ws.admininfo')}

{__('init.ws.adminname') + ':'} {__('init.ws.adminemail') + ':'} {err.email} {__('init.ws.adminpwd') + ':'} {err.pwd} {__('init.ws.adminpwd2') + ':'} {err.pwd2} {__('init.adddemodata')}
{__('action.create')}
); } return ( {content} ); } }