diff --git a/pkg/interface/contacts/src/js/components/lib/new.js b/pkg/interface/contacts/src/js/components/lib/new.js index b4fcdb1ee..93314f51d 100644 --- a/pkg/interface/contacts/src/js/components/lib/new.js +++ b/pkg/interface/contacts/src/js/components/lib/new.js @@ -1,6 +1,8 @@ import React, { Component } from 'react' import { Route, Link } from 'react-router-dom'; +import { deSig } from '/lib/util'; +import urbitOb from 'urbit-ob'; export class NewScreen extends Component { constructor(props) { @@ -9,8 +11,10 @@ export class NewScreen extends Component { this.state = { groupName: '', invites: '', - color: '' - } + color: '', + groupNameError: false, + inviteError: false + }; this.groupNameChange = this.groupNameChange.bind(this); this.invChange = this.invChange.bind(this); @@ -35,13 +39,87 @@ export class NewScreen extends Component { // }); // } + onClickCreate() { + const { props, state } = this; + if (!state.groupName) { + this.setState({ + groupNameError: true, + inviteError: false + }); + return; + } + let group = `/~${window.ship}` + `/${state.groupName}`; + + let aud = []; + let isValid = true; + + if (state.invites.length > 2) { + aud = state.invites.split(',') + .map((mem) => `~${deSig(mem.trim())}`); + + aud.forEach((mem) => { + if (!urbitOb.isValidPatp(mem)) { + isValid = false; + } + }); + } + + if (!isValid) { + this.setState({ + inviteError: true, + groupNameError: false + }); + return; + } + + if (this.textarea) { + this.textarea.value = ''; + } + this.setState({ + error: false, + success: true, + invites: '' + }, () => { + props.setSpinner(true); + props.api.contactCreate(group); + //TODO add YOU to the group, but without invites + aud.forEach((ship) => { + if (ship !== `~${window.ship}`) { + props.api.invite.invite(group, ship); + } + }); + }); + } + render() { + + let groupNameErrElem = (); + if (this.state.groupNameError) { + groupNameErrElem = ( + + Group must have a valid name. + + ); + } + + let invErrElem = (); + if (this.state.inviteError) { + invErrElem = ( + + Invites must be validly formatted ship names. + + ); + } + return (
Alphanumeric characters only
+Alphanumeric characters and hyphens only
+ onChange={this.groupNameChange}/> + {groupNameErrElem} {/*Select a color to represent your group @@ -68,31 +147,34 @@ export class NewScreen extends Component { /> */}
- Search for ships to invite to your group + Invite ships to your group