@@ -5,41 +5,45 @@ import IconButton from '@material-ui/core/IconButton'
5
5
import Visibility from '@material-ui/icons/Visibility'
6
6
import VisibilityOff from '@material-ui/icons/VisibilityOff'
7
7
import i18n from '@dhis2/d2-i18n' //do translations!
8
- import { getInstance } from 'd2'
8
+ import { useD2 } from '@dhis2/app-runtime-adapter- d2'
9
9
import _ from 'lodash'
10
10
import '../styles/FileForm.css'
11
11
import config from '../utils/config'
12
+ import { getBaseUrl } from '../index'
12
13
13
14
14
- const FileForm = ( { cryptr } ) => {
15
+ const FileForm = ( ) => {
15
16
const [ formData , setFormData ] = useState ( config )
16
17
const [ isOk , setOk ] = useState ( true )
17
18
const [ isUploaded , setUploaded ] = useState ( false )
18
19
const [ wrong , setWrong ] = useState ( false )
19
20
const [ show1 , setShow1 ] = useState ( false )
20
21
const [ show2 , setShow2 ] = useState ( false )
22
+
23
+ const { d2 } = useD2 ( )
21
24
22
25
function onFormSubmit ( ) {
23
26
24
27
async function submit ( data ) {
25
- const d2 = await getInstance ( )
26
- if ( await d2 . currentUser . dataStore . has ( "interoperability" ) ) {
27
- const namespace = await d2 . currentUser . dataStore . get ( "interoperability" )
28
- await namespace . set ( "cred-config" , data )
28
+ const conf = _ . cloneDeep ( data )
29
+ conf . DHIS2APIConfig . baseURL = await getBaseUrl ( ) + '/api'
30
+
31
+ const password = conf . GoDataAPIConfig . credentials . password
32
+ conf . GoDataAPIConfig . credentials . password = null
33
+
34
+ if ( await d2 . currentUser . dataStore . has ( "dhis-godata-interoperability" ) ) {
35
+ const namespace = await d2 . currentUser . dataStore . get ( "dhis-godata-interoperability" )
36
+ await namespace . set ( "password" , { 'password' : password } , false , true )
37
+ await namespace . set ( "cred-config" , conf )
29
38
} else {
30
- const namespace = await d2 . currentUser . dataStore . create ( "interoperability" )
31
- await namespace . set ( "cred-config" , data )
39
+ const namespace = await d2 . currentUser . dataStore . create ( "dhis-godata-interoperability" )
40
+ await namespace . set ( "password" , { 'password' : password } , false , true )
41
+ await namespace . set ( "cred-config" , conf )
32
42
}
33
43
}
34
44
35
45
if ( isOk === true ) {
36
- const conf = _ . cloneDeep ( formData )
37
- const godataPass = formData . GoDataAPIConfig . credentials . password
38
- const dhis2Pass = formData . DHIS2APIConfig . credentials . password
39
-
40
- conf . GoDataAPIConfig . credentials . password = cryptr . encrypt ( godataPass )
41
- conf . DHIS2APIConfig . credentials . password = cryptr . encrypt ( dhis2Pass )
42
- submit ( conf )
46
+ submit ( formData )
43
47
setUploaded ( true )
44
48
} else {
45
49
setWrong ( true )
@@ -142,42 +146,8 @@ const FileForm = ({ cryptr }) => {
142
146
>
143
147
{ show1 ? < Visibility /> : < VisibilityOff /> }
144
148
</ IconButton >
145
- < p className = "p" > Dhis2 API Configuration</ p >
146
- < span className = "subtitle" > BaseURL:</ span >
147
- < input
148
- className = "text-input"
149
- size = "30"
150
- name = "DHIS2APIConfig.baseURL"
151
- value = { formData [ "DHIS2APIConfig" ] . baseURL }
152
- onChange = { handleOnChange }
153
- />
154
- < br />
155
- < span className = "subtitle" > User:</ span >
156
- < input
157
- className = "text-input"
158
- size = "15"
159
- name = "DHIS2APIConfig.credentials.user"
160
- value = { formData [ "DHIS2APIConfig" ] . credentials . user }
161
- onChange = { handleOnChange }
162
- />
163
- < br />
164
- < span className = "subtitle" > Password:</ span >
165
- < input
166
- className = "text-input"
167
- type = { show2 ? "text" : "password" }
168
- size = "15"
169
- name = "DHIS2APIConfig.credentials.password"
170
- value = { formData [ "DHIS2APIConfig" ] . credentials . password }
171
- onChange = { handleOnChange }
172
- />
173
- < IconButton
174
- className = "icon-button"
175
- aria-label = "toggle password visibility"
176
- onClick = { handleClickShowPassword2 }
177
- onMouseDown = { handleMouseDownPassword }
178
- >
179
- { show2 ? < Visibility /> : < VisibilityOff /> }
180
- </ IconButton >
149
+
150
+
181
151
</ div >
182
152
< div className = "import" >
183
153
< Button
0 commit comments