@@ -8,18 +8,11 @@ import {
8
8
import React , { FormEvent , useCallback , useEffect , useState } from 'react' ;
9
9
import { useSettings } from '../helpers/AppSettings' ;
10
10
import { 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' ;
18
12
import Field from './forms/Field' ;
19
13
import { InputWrapper , InputStyled } from './forms/InputStyles' ;
20
14
import { Row } from './Row' ;
21
15
import { ErrorLook } from './ErrorLook' ;
22
- import { CodeBlock } from './CodeBlock' ;
23
16
import { SettingsAgent } from './SettingsAgent' ;
24
17
25
18
interface RegisterSignInProps {
@@ -34,9 +27,9 @@ interface RegisterSignInProps {
34
27
export function RegisterSignIn ( {
35
28
children,
36
29
} : React . PropsWithChildren < RegisterSignInProps > ) : JSX . Element {
37
- const { dialogProps, show } = useDialog ( ) ;
30
+ const { dialogProps, show, close } = useDialog ( ) ;
38
31
const { agent } = useSettings ( ) ;
39
- const [ isRegister , setRegister ] = useState ( true ) ;
32
+ const [ isRegistering , setRegister ] = useState ( true ) ;
40
33
41
34
if ( agent ) {
42
35
return < > { children } </ > ;
@@ -63,23 +56,19 @@ export function RegisterSignIn({
63
56
</ Button >
64
57
</ Row >
65
58
< Dialog { ...dialogProps } >
66
- { isRegister ? < Register /> : < SignIn /> }
59
+ { isRegistering ? < Register close = { close } /> : < SignIn /> }
67
60
</ Dialog >
68
61
</ >
69
62
) ;
70
63
}
71
64
72
- function Register ( ) {
65
+ function Register ( { close } ) {
73
66
const [ name , setName ] = useState ( '' ) ;
74
67
const [ email , setEmail ] = useState ( '' ) ;
75
- const [ secret , setSecret ] = useState ( '' ) ;
76
- const [ driveURL , setDriveURL ] = useState ( '' ) ;
77
- const [ newAgent , setNewAgent ] = useState < Agent | undefined > ( undefined ) ;
78
68
const [ serverUrlStr ] = useServerURL ( ) ;
79
69
const [ nameErr , setErr ] = useState < Error | undefined > ( undefined ) ;
80
- const doRegister = useCallback ( register , [ ] ) ;
81
- const { setAgent } = useSettings ( ) ;
82
70
const store = useStore ( ) ;
71
+ const [ mailSent , setMailSent ] = useState ( false ) ;
83
72
84
73
const serverUrl = new URL ( serverUrlStr ) ;
85
74
serverUrl . host = `${ name } .${ serverUrl . host } ` ;
@@ -104,44 +93,31 @@ function Register() {
104
93
}
105
94
106
95
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 ) ;
115
98
} catch ( er ) {
116
99
setErr ( er ) ;
117
100
}
118
101
} ,
119
102
[ name , email ] ,
120
103
) ;
121
104
122
- const handleSaveAgent = useCallback ( ( ) => {
123
- setAgent ( newAgent ) ;
124
- } , [ newAgent ] ) ;
125
-
126
- if ( driveURL ) {
105
+ if ( mailSent ) {
127
106
return (
128
107
< >
129
108
< DialogTitle >
130
- < h1 > Save your Passphrase, { name } </ h1 >
109
+ < h1 > Go to your email inbox </ h1 >
131
110
</ DialogTitle >
132
111
< DialogContent >
133
112
< 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
+ { '.' }
137
116
</ p >
138
- < CodeBlock content = { secret } wrapContent / >
117
+ < p > Your account will be created when you open that link. </ p >
139
118
</ DialogContent >
140
119
< 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 >
145
121
</ DialogActions >
146
122
</ >
147
123
) ;
0 commit comments