6
6
FormPrimaryButton ,
7
7
FormBlockquote ,
8
8
FormSecondaryButton ,
9
+ FormHeading ,
9
10
} from '../atoms/form'
10
11
import FormFolderSelector from '../atoms/FormFolderSelector'
11
12
import { useDb } from '../../lib/db'
@@ -19,22 +20,30 @@ import { usePreferences } from '../../lib/preferences'
19
20
interface ConvertPouchStorageProps {
20
21
storageId : string
21
22
storageName : string
22
- closeForm : ( ) => void
23
23
}
24
24
25
25
const ConvertPouchStorage = ( {
26
26
storageId,
27
27
storageName,
28
- closeForm,
29
28
} : ConvertPouchStorageProps ) => {
30
- const [ newStorageName , setNewStorageName ] = useState (
31
- `${ storageName } - Converted`
32
- )
29
+ const { push } = useRouter ( )
33
30
const { setClosed } = usePreferences ( )
34
- const [ newStorageLocation , setNewStorageLocation ] = useState ( '' )
35
31
const { storageMap, createStorage } = useDb ( )
32
+ const [ newStorageLocation , setNewStorageLocation ] = useState ( '' )
36
33
const [ errorMessage , setErrorMessage ] = useState < string | null > ( null )
37
- const { push } = useRouter ( )
34
+ const [ newStorageName , setNewStorageName ] = useState ( '' )
35
+ const [ opened , setOpened ] = useState ( false )
36
+
37
+ const openForm = useCallback ( ( ) => {
38
+ setNewStorageName ( `${ storageName } - Converted` )
39
+ setNewStorageLocation ( '' )
40
+ setErrorMessage ( null )
41
+ setOpened ( true )
42
+ } , [ storageName ] )
43
+
44
+ const closeForm = useCallback ( ( ) => {
45
+ setOpened ( false )
46
+ } , [ ] )
38
47
39
48
const updateNewStorageName = useCallback (
40
49
( event : ChangeEvent < HTMLInputElement > ) => {
@@ -113,29 +122,43 @@ const ConvertPouchStorage = ({
113
122
114
123
return (
115
124
< >
116
- < FormBlockquote variant = { errorMessage == null ? 'primary' : 'danger' } >
117
- { errorMessage == null
118
- ? 'This operation will clone data to File System based Storage.'
119
- : errorMessage }
120
- </ FormBlockquote >
125
+ < FormHeading depth = { 2 } > Convert File System based Storage</ FormHeading >
126
+ { ! opened ? (
127
+ < FormGroup >
128
+ < FormSecondaryButton onClick = { openForm } > Convert</ FormSecondaryButton >
129
+ </ FormGroup >
130
+ ) : (
131
+ < >
132
+ < FormBlockquote variant = { errorMessage == null ? 'primary' : 'danger' } >
133
+ { errorMessage == null
134
+ ? 'This operation will clone data to File System based Storage.'
135
+ : errorMessage }
136
+ </ FormBlockquote >
121
137
122
- < FormGroup >
123
- < FormLabel > Converted Storage Name</ FormLabel >
124
- < FormTextInput value = { newStorageName } onChange = { updateNewStorageName } />
125
- </ FormGroup >
126
- < FormGroup >
127
- < FormLabel > Converted Storage Location</ FormLabel >
128
- < FormFolderSelector
129
- value = { newStorageLocation }
130
- setValue = { setNewStorageLocation }
131
- />
132
- </ FormGroup >
133
- < FormGroup >
134
- < FormPrimaryButton onClick = { cloneAndConvertStorage } >
135
- Convert to File System based Storage
136
- </ FormPrimaryButton >
137
- < FormSecondaryButton onClick = { closeForm } > Cancel</ FormSecondaryButton >
138
- </ FormGroup >
138
+ < FormGroup >
139
+ < FormLabel > Converted Storage Name</ FormLabel >
140
+ < FormTextInput
141
+ value = { newStorageName }
142
+ onChange = { updateNewStorageName }
143
+ />
144
+ </ FormGroup >
145
+ < FormGroup >
146
+ < FormLabel > Converted Storage Location</ FormLabel >
147
+ < FormFolderSelector
148
+ value = { newStorageLocation }
149
+ setValue = { setNewStorageLocation }
150
+ />
151
+ </ FormGroup >
152
+ < FormGroup >
153
+ < FormPrimaryButton onClick = { cloneAndConvertStorage } >
154
+ Convert to File System based Storage
155
+ </ FormPrimaryButton >
156
+ < FormSecondaryButton onClick = { closeForm } >
157
+ Cancel
158
+ </ FormSecondaryButton >
159
+ </ FormGroup >
160
+ </ >
161
+ ) }
139
162
</ >
140
163
)
141
164
}
0 commit comments