@@ -195,26 +195,6 @@ export default defineComponent({
195
195
const orcidErrors = computed (() => {
196
196
const orcidErrors = orcidQueries (props .index )
197
197
.filter (byError (errors .value ))
198
- if (orcidErrors .length === 0 ) {
199
- // If a valid orcid is found, look for data in the orcid API (maybe only if we do not have data already)
200
- const orcid = ' 0000-0001-8555-849X' // This should come from props.orcid
201
- const orcidEndpoint = ' https://pub.sandbox.orcid.org/v3.0/expanded-search/?q=orcid:' + orcid + ' &rows=1'
202
- axios .get (orcidEndpoint ,
203
- {
204
- data: {},
205
- headers: {
206
- ' accept' : ' application/vnd.orcid+json'
207
- }
208
- }).then (resp => {
209
- console .log (' These values should be injected in the right places' )
210
- console .log (' email : ' + resp .data [' expanded-result' ][0 ][' email' ][0 ])
211
- console .log (' last-name : ' + resp .data [' expanded-result' ][0 ][' family-names' ])
212
- console .log (' first-name: ' + resp .data [' expanded-result' ][0 ][' given-names' ])
213
- console .log (' Institution: ' + resp .data [' expanded-result' ][0 ][' institution-name' ])
214
- console .log (' Orcid : ' + resp .data [' expanded-result' ][0 ][' orcid-id' ])
215
-
216
- })
217
- }
218
198
return orcidErrors
219
199
.map (query => query .replace .message )
220
200
})
@@ -228,6 +208,35 @@ export default defineComponent({
228
208
orcidErrors
229
209
}
230
210
},
211
+ watch: {
212
+ orcid(oldVal , newVal ) {
213
+ if (this .orcid .length === 37 && this .orcidErrors .length === 0 ) {
214
+ // If a valid orcid is found, look for data in the orcid API (maybe only if we do not have data already)
215
+ const orcidSearchApi = ' https://pub.orcid.org/v3.0/expanded-search/?q=orcid:' ;
216
+ const orcidEndpoint = this .orcid .replace (' https://orcid.org/' , orcidSearchApi ) + ' &rows=1' ;
217
+ // This is a test endpoint on Zenodo sandbox.
218
+ // const orcidEndpoint = 'https://pub.sandbox.orcid.org/v3.0/expanded-search/?q=orcid:0000-0001-8555-849X&rows=1';
219
+
220
+ axios .interceptors .request .use ((config ) => {
221
+ config .props = this ;
222
+ return config ;
223
+ });
224
+
225
+ void axios .get (orcidEndpoint ,
226
+ {
227
+ data: {},
228
+ headers: {
229
+ accept: ' application/vnd.orcid+json'
230
+ }
231
+ }).then (resp => {
232
+ resp .config .props .$emit (' update' , ' givenNames' , resp .data [' expanded-result' ][0 ][' given-names' ]);
233
+ resp .config .props .$emit (' update' , ' familyNames' , resp .data [' expanded-result' ][0 ][' family-names' ]);
234
+ resp .config .props .$emit (' update' , ' email' , resp .data [' expanded-result' ][0 ].email [0 ]);
235
+ resp .config .props .$emit (' update' , ' affiliation' , resp .data [' expanded-result' ][0 ][' institution-name' ][0 ]);
236
+ })
237
+ }
238
+ }
239
+ },
231
240
emits: [' closePressed' , ' removePressed' , ' update' ]
232
241
})
233
242
</script >
0 commit comments