1
1
import { customAlphabet } from "nanoid" ;
2
2
import AuthCheck from "../../components/AuthCheck" ;
3
- import {
4
- doc ,
5
- getDoc ,
6
- writeBatch ,
7
- arrayUnion ,
8
- } from "firebase/firestore" ;
3
+ import { doc , getDoc , writeBatch , arrayUnion } from "firebase/firestore" ;
9
4
import { db , auth } from "../../lib/firebase" ;
10
5
import { useContext , useState } from "react" ;
11
6
import { UserContext } from "../../lib/context" ;
@@ -26,6 +21,7 @@ import {
26
21
FormHelperText ,
27
22
VStack ,
28
23
Text ,
24
+ Select ,
29
25
} from "@chakra-ui/react" ;
30
26
31
27
export default function NewExperimentPage ( { } ) {
@@ -42,7 +38,7 @@ function NewExperimentForm() {
42
38
const [ osfError , setOsfError ] = useState ( false ) ;
43
39
const [ titleError , setTitleError ] = useState ( false ) ;
44
40
const [ dataComponentError , setDataComponentError ] = useState ( false ) ;
45
-
41
+
46
42
const [ data , loading , error ] = useDocumentData ( doc ( db , "users" , user . uid ) ) ;
47
43
48
44
return (
@@ -53,8 +49,10 @@ function NewExperimentForm() {
53
49
< Heading > Create a New Experiment</ Heading >
54
50
< FormControl id = "title" isInvalid = { titleError } >
55
51
< FormLabel > Title</ FormLabel >
56
- < Input type = "text" onChange = { ( ) => setTitleError ( false ) } />
57
- < FormErrorMessage color = { "red" } > This field is required</ FormErrorMessage >
52
+ < Input type = "text" onChange = { ( ) => setTitleError ( false ) } />
53
+ < FormErrorMessage color = { "red" } >
54
+ This field is required
55
+ </ FormErrorMessage >
58
56
</ FormControl >
59
57
< FormControl id = "osf-repo" isInvalid = { osfError } >
60
58
< FormLabel > Existing OSF Project</ FormLabel >
@@ -70,9 +68,26 @@ function NewExperimentForm() {
70
68
</ FormControl >
71
69
< FormControl id = "osf-component-name" isInvalid = { dataComponentError } >
72
70
< FormLabel > New OSF Data Component Name</ FormLabel >
73
- < Input type = "text" onChange = { ( ) => setDataComponentError ( false ) } />
74
- < FormErrorMessage color = { "red" } > This field is required</ FormErrorMessage >
75
- < FormHelperText color = "gray" > DataPipe will create a new component with this name in the OSF project and store all data in it.</ FormHelperText >
71
+ < Input type = "text" onChange = { ( ) => setDataComponentError ( false ) } />
72
+ < FormErrorMessage color = { "red" } >
73
+ This field is required
74
+ </ FormErrorMessage >
75
+ < FormHelperText color = "gray" >
76
+ DataPipe will create a new component with this name in the OSF
77
+ project and store all data in it.
78
+ </ FormHelperText >
79
+ </ FormControl >
80
+ < FormControl id = "osf-component-region" >
81
+ < FormLabel > Storage Location</ FormLabel >
82
+ < Select defaultValue = "us" sx = { { '> option' : { background : 'black' , color : 'white' } } } >
83
+ < option value = "us" > United States</ option >
84
+ < option value = "de-1" > Germany - Frankfurt</ option >
85
+ < option value = "au-1" > Australia - Sydney</ option >
86
+ < option value = "ca-1" > Canada - Montreal</ option >
87
+ </ Select >
88
+ < FormHelperText color = "gray" >
89
+ Choose the region where the data will be stored.
90
+ </ FormHelperText >
76
91
</ FormControl >
77
92
< Button
78
93
onClick = { ( ) =>
@@ -120,6 +135,7 @@ async function handleCreateExperiment(
120
135
const user = auth . currentUser ;
121
136
const title = document . querySelector ( "#title" ) . value ;
122
137
let osfRepo = document . querySelector ( "#osf-repo" ) . value ;
138
+ const region = document . querySelector ( "#osf-component-region" ) . value ;
123
139
const osfComponentName = document . querySelector ( "#osf-component-name" ) . value ;
124
140
const nConditions = 1 ;
125
141
const useValidation = true ;
@@ -128,13 +144,13 @@ async function handleCreateExperiment(
128
144
const useSessionLimit = false ;
129
145
const maxSessions = 1 ;
130
146
131
- if ( title . length === 0 ) {
147
+ if ( title . length === 0 ) {
132
148
setTitleError ( true ) ;
133
149
setIsSubmitting ( false ) ;
134
150
return ;
135
151
}
136
152
137
- if ( osfComponentName . length === 0 ) {
153
+ if ( osfComponentName . length === 0 ) {
138
154
setDataComponentError ( true ) ;
139
155
setIsSubmitting ( false ) ;
140
156
return ;
@@ -160,7 +176,7 @@ async function handleCreateExperiment(
160
176
}
161
177
162
178
const osfResult = await fetch (
163
- `https://api.osf.io/v2/nodes/${ osfRepo } /children/` ,
179
+ `https://api.osf.io/v2/nodes/${ osfRepo } /children/?region= ${ region } ` ,
164
180
{
165
181
method : "POST" ,
166
182
headers : {
0 commit comments