@@ -41,7 +41,7 @@ const PROMPTS = require("system/util/prompts");
4141const SESSION = require ( "unisys/common-session" ) ;
4242const PR = PROMPTS . Pad ( "SessionShell" ) ;
4343const ReactStrap = require ( "reactstrap" ) ;
44- const { Col, FormGroup, FormFeedback, Input, Label } = ReactStrap ;
44+ const { InputGroup , InputGroupAddon , Button , Col, Row , Form , FormGroup, FormFeedback, Input, Label } = ReactStrap ;
4545const { Redirect } = require ( "react-router-dom" ) ;
4646const UNISYS = require ( "unisys/client" ) ;
4747
@@ -50,7 +50,6 @@ const UNISYS = require("unisys/client");
5050/// these styles are copied from AutoComplete.css
5151const INPUT_STYLE = {
5252 border : "1px solid #aaa" ,
53- borderRadius : "4px" ,
5453 fontFamily : "Helvetica, sans-serif" ,
5554 fontWeight : 300 ,
5655 fontSize : "10px" ,
@@ -76,14 +75,18 @@ class SessionShell extends UNISYS.Component {
7675 this . renderLogin = this . renderLogin . bind ( this ) ;
7776 this . renderLoggedIn = this . renderLoggedIn . bind ( this ) ;
7877 this . handleChange = this . handleChange . bind ( this ) ;
78+ this . onSubmit = this . onSubmit . bind ( this ) ;
7979 this . state = {
80+ token : null ,
8081 classId : null ,
8182 projId : null ,
8283 hashedId : null ,
8384 subId : null ,
8485 groupId : null ,
86+ subId : null ,
8587 isValid : false
8688 } ;
89+
8790 }
8891
8992 /// ROUTE RENDER FUNCTIONS ////////////////////////////////////////////////////
@@ -119,43 +122,49 @@ class SessionShell extends UNISYS.Component {
119122 /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120123 /*/ render must login (readonly)
121124 /*/
122- renderLogin ( token ) {
123- let decoded = token ? SESSION . DecodeToken ( token ) : this . state ;
124- let { classId, projId, groupId, subId, hashedId, isValid } = decoded ;
125- let formFeedback , tip ;
126- if ( classId ) tip = "keep entering..." ;
127- else tip = "enter group ID" ;
125+ renderLogin ( ) {
126+ let { token, classId, projId, groupId, subId, hashedId, isValid } = this . state ;
127+ if ( token ) token = token . toUpperCase ( ) ;
128+ let formFeedback , tip , input ;
129+ tip = "type group ID" ;
130+ if ( classId ) tip = "scanning for valid code..." ;
131+ if ( projId ) tip = "waiting for valid code..." ;
132+ if ( groupId ) tip = "waiting for extra ID..." ;
128133 if ( hashedId ) {
129134 if ( hashedId . length >= 3 ) {
130- if ( ! isValid ) tip = `'${ token } ' is an invalid code` ;
135+ if ( ! groupId ) tip = `'${ token } ' is an invalid code` ;
136+ else {
137+ if ( subId ) tip = `login in as GROUP ${ groupId } ${ subId } ` ;
138+ else tip = `login as GROUP ${ groupId } or add -ID<num>` ;
139+ }
131140 }
132141 }
133- formFeedback = tip ? (
134- < FormFeedback className = "text-right" >
135- < small > { tip } </ small >
136- </ FormFeedback >
137- ) : (
138- undefined
139- ) ;
142+ if ( groupId ) {
143+ if ( subId === 0 ) {
144+ tip = `e.g. ${ classId } -${ projId } -${ hashedId } followed by -ID<num>` ;
145+ input = < Input invalid name = "sessionToken" id = "sessionToken" bsSize = "sm" style = { INPUT_STYLE } className = "text-right" placeholder = "CLASSID-PROJID-CODE" onChange = { this . handleChange } />
146+ formFeedback = < FormFeedback className = "text-right" > < small > { tip } </ small > </ FormFeedback >
147+ } else {
148+ input = < Input valid name = "sessionToken" id = "sessionToken" bsSize = "sm" style = { INPUT_STYLE } className = "text-right" placeholder = "CLASSID-PROJID-CODE" onChange = { this . handleChange } />
149+ formFeedback = < FormFeedback valid className = "text-right" > < small > { tip } </ small > </ FormFeedback >
150+ }
151+ } else {
152+ input = < Input invalid name = "sessionToken" id = "sessionToken" bsSize = "sm" style = { INPUT_STYLE } className = "text-right" placeholder = "CLASSID-PROJID-CODE" onChange = { this . handleChange } />
153+ formFeedback = < FormFeedback className = "text-right" > < small > { tip } </ small > </ FormFeedback >
154+ }
155+
140156 return (
157+ < Form onSubmit = { this . onSubmit } >
141158 < FormGroup row >
142- < Col sm = { 3 } >
143- < Label className = "small text-muted" > Login</ Label >
144- </ Col >
145- < Col sm = { 9 } >
146- < Input
147- invalid
148- name = "sessionToken"
149- id = "sessionToken"
150- bsSize = "sm"
151- style = { INPUT_STYLE }
152- className = "text-right"
153- placeholder = "CLASS-PROJECT-XYZ"
154- onChange = { this . handleChange }
155- />
159+ < Col >
160+ < InputGroup >
161+ < InputGroupAddon addonType = "prepend" > < Button style = { { fontSize :'10px' } } color = "secondary" size = "sm" disabled = { ! isValid } onSubmit = { this . onSubmit } > LOGIN</ Button > </ InputGroupAddon >
162+ { input }
156163 { formFeedback }
164+ </ InputGroup >
157165 </ Col >
158166 </ FormGroup >
167+ </ Form >
159168 ) ;
160169 }
161170 /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -196,26 +205,35 @@ class SessionShell extends UNISYS.Component {
196205 // try to decode token
197206 let decoded = SESSION . DecodeToken ( token ) ;
198207 if ( decoded . isValid ) {
199- this . AppCall ( "GROUPID_CHANGE" , token ) ;
200208 return this . renderLoggedIn ( decoded ) ;
209+ } else {
210+ return this . renderLogin ( token ) ;
201211 }
202- // error in decode so render login field
203- return this . renderLogin ( token ) ;
204212 }
205213
206214 /// EVENT HANDLERS ////////////////////////////////////////////////////////////
207215 /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208216 handleChange ( event ) {
209217 let token = event . target . value ;
210218 let decoded = SESSION . DecodeToken ( token ) ;
211- let { classId, projId, hashedId, groupId , subId } = decoded ;
219+ let { classId, projId, hashedId, subId , groupId } = decoded ;
212220 this . setState ( decoded ) ;
213- this . SetAppState ( "SESSION" , decoded ) ;
214- if ( decoded . groupId ) {
221+ }
222+ /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223+ onSubmit ( event ) {
224+ event . preventDefault ( ) ;
225+ const BRUTAL_REDIRECT = true ;
226+ if ( this . state . isValid ) {
215227 // force a page URL change
216- let redirect = `/edit/${ event . target . value } ` ;
217- this . props . history . push ( redirect ) ;
228+ if ( BRUTAL_REDIRECT ) {
229+ const redirect = `/#/edit/${ this . state . token } ` ;
230+ window . location = redirect ;
231+ } else {
232+ const redirect = `/edit/${ this . state . token } `
233+ this . props . history . push ( redirect ) ;
234+ }
218235 }
236+ /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219237 }
220238} // UNISYS.Component SessionShell
221239
0 commit comments