@@ -8,18 +8,11 @@ import {
88import React , { FormEvent , useCallback , useEffect , useState } from 'react' ;
99import { useSettings } from '../helpers/AppSettings' ;
1010import { Button } from './Button' ;
11- import {
12- Agent ,
13- nameRegex ,
14- register ,
15- useServerURL ,
16- useStore ,
17- } from '@tomic/react' ;
11+ import { nameRegex , register , useServerURL , useStore } from '@tomic/react' ;
1812import Field from './forms/Field' ;
1913import { InputWrapper , InputStyled } from './forms/InputStyles' ;
2014import { Row } from './Row' ;
2115import { ErrorLook } from './ErrorLook' ;
22- import { CodeBlock } from './CodeBlock' ;
2316import { SettingsAgent } from './SettingsAgent' ;
2417
2518interface RegisterSignInProps {
@@ -34,9 +27,9 @@ interface RegisterSignInProps {
3427export function RegisterSignIn ( {
3528 children,
3629} : React . PropsWithChildren < RegisterSignInProps > ) : JSX . Element {
37- const { dialogProps, show } = useDialog ( ) ;
30+ const { dialogProps, show, close } = useDialog ( ) ;
3831 const { agent } = useSettings ( ) ;
39- const [ isRegister , setRegister ] = useState ( true ) ;
32+ const [ isRegistering , setRegister ] = useState ( true ) ;
4033
4134 if ( agent ) {
4235 return < > { children } </ > ;
@@ -63,23 +56,19 @@ export function RegisterSignIn({
6356 </ Button >
6457 </ Row >
6558 < Dialog { ...dialogProps } >
66- { isRegister ? < Register /> : < SignIn /> }
59+ { isRegistering ? < Register close = { close } /> : < SignIn /> }
6760 </ Dialog >
6861 </ >
6962 ) ;
7063}
7164
72- function Register ( ) {
65+ function Register ( { close } ) {
7366 const [ name , setName ] = useState ( '' ) ;
7467 const [ email , setEmail ] = useState ( '' ) ;
75- const [ secret , setSecret ] = useState ( '' ) ;
76- const [ driveURL , setDriveURL ] = useState ( '' ) ;
77- const [ newAgent , setNewAgent ] = useState < Agent | undefined > ( undefined ) ;
7868 const [ serverUrlStr ] = useServerURL ( ) ;
7969 const [ nameErr , setErr ] = useState < Error | undefined > ( undefined ) ;
80- const doRegister = useCallback ( register , [ ] ) ;
81- const { setAgent } = useSettings ( ) ;
8270 const store = useStore ( ) ;
71+ const [ mailSent , setMailSent ] = useState ( false ) ;
8372
8473 const serverUrl = new URL ( serverUrlStr ) ;
8574 serverUrl . host = `${ name } .${ serverUrl . host } ` ;
@@ -104,44 +93,31 @@ function Register() {
10493 }
10594
10695 try {
107- const { driveURL : newDriveURL , agent } = await doRegister (
108- store ,
109- name ,
110- email ,
111- ) ;
112- setDriveURL ( newDriveURL ) ;
113- setSecret ( agent . buildSecret ( ) ) ;
114- setNewAgent ( agent ) ;
96+ await register ( store , name , email ) ;
97+ setMailSent ( true ) ;
11598 } catch ( er ) {
11699 setErr ( er ) ;
117100 }
118101 } ,
119102 [ name , email ] ,
120103 ) ;
121104
122- const handleSaveAgent = useCallback ( ( ) => {
123- setAgent ( newAgent ) ;
124- } , [ newAgent ] ) ;
125-
126- if ( driveURL ) {
105+ if ( mailSent ) {
127106 return (
128107 < >
129108 < DialogTitle >
130- < h1 > Save your Passphrase, { name } </ h1 >
109+ < h1 > Go to your email inbox </ h1 >
131110 </ DialogTitle >
132111 < DialogContent >
133112 < p >
134- Your Passphrase is like your password. Never share it with anyone.
135- Use a password manager to store it securely. You will need this to
136- log in next!
113+ { "We've sent a confirmation link to " }
114+ < strong > { email } </ strong >
115+ { '.' }
137116 </ p >
138- < CodeBlock content = { secret } wrapContent / >
117+ < p > Your account will be created when you open that link. </ p >
139118 </ DialogContent >
140119 < DialogActions >
141- < Button onClick = { handleSaveAgent } > Continue here</ Button >
142- < a href = { driveURL } target = '_blank' rel = 'noreferrer' >
143- Open my new Drive!
144- </ a >
120+ < Button onClick = { close } > Ok, I will!</ Button >
145121 </ DialogActions >
146122 </ >
147123 ) ;
0 commit comments