From 761ea7cc9cc5fdfa0579380502da2adb186b6d42 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Wed, 11 Dec 2019 01:36:12 -0500 Subject: [PATCH] create group functionality --- .../contacts/src/js/components/lib/new.js | 108 +++++++++++++++--- 1 file changed, 95 insertions(+), 13 deletions(-) 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 (
-
+
+ {"⟵ All Groups"} +
+

Create New Group

Group Name

-

Alphanumeric characters only

+

Alphanumeric characters and hyphens only