importReact,{useState}from'react';importIconfrom'../Icon.jsx';import{teamNames}from'../seed.js';import{authenticateTeam}from'../access.js';import{useStudio,log,visibleWorkspaces}from'../store.jsx';import{Button,Field}from'../ui.jsx';exportdefaultfunctionLogin({navigate}){const{state:s,mutate}=useStudio();const[team,setTeam]=useState(s.session.team);const[password,setPassword]=useState(''),[show,setShow]=useState(false);const[busy,setBusy]=useState(false),[error,setError]=useState('');asyncfunctionlogin(event){event.preventDefault();if (busy)return;setBusy(true);setError('');try{constsession=awaitauthenticateTeam(s,team,password);mutate(d=>{d.session=session;d.activeWorkspaceId=visibleWorkspaces(d)[0]?.id||'';log(d,`Signed in to ${team} as ${session.role==='administrator'?'Administrator':'User'}`);});setPassword('');navigate('overview');}catch (failure){setError(failure.message);}finally{setBusy(false);}}return<divclassName="login-page"><sectionclassName="login-story"><divclassName="login-brand"><spanclassName="brand-symbol"><Iconname="layers"size={29}/></span><span>Testcraft Studio</span></div><divclassName="login-story-body"><spanclassName="eyebrow">EVIDENCE. CLARITY. CONFIDENCE.</span><h1>Clear evidence.<br/>Confident testing.</h1><p>Bring your system knowledge and change requests together to create traceable test cases.</p></div><divclassName="login-story-footer">Built for clear decisions at every step.</div></section><sectionclassName="login-form-area"><formonSubmit={login}><spanclassName="eyebrow login-eyebrow">TESTCRAFT STUDIO</span><h2>Welcome back</h2><p>Sign in to your workspace.</p><Fieldlabel="Team"><divclassName="login-select-field"><Iconname="users"size={18}/><selectvalue={team}title={teamNames[team]||team}onChange={e=>{setTeam(e.target.value);setPassword('');setError('');}}>{s.teams.map(t=><optionkey={t}value={t}>{t}</option>)}</select></div></Field><Fieldlabel="System password"><divclassName="password-field"><Iconname="lock"size={18}/><inputtype={show?'text':'password'}requiredautoComplete="current-password"aria-label="System password"value={password}onChange={e=>setPassword(e.target.value)}placeholder="Enter your system password"/><buttontype="button"onClick={()=>setShow(value=>!value)}aria-label={show?'Hide password':'Show password'}title={show?'Hide password':'Show password'}><Iconname={show?'eyeOff':'eye'}size={18}/></button></div></Field>{error&&<pclassName="form-error"role="alert">{error}</p>}<Buttontype="submit"variant="primary"className="full-width"disabled={busy||!password}>{busy?'Signing inβ¦':'Sign in'}<Iconname="arrow"size={16}/></Button></form><divclassName="login-footer">Testcraft Studio</div></section></div>;}
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)