@@ -5,6 +5,8 @@ import CreateWorkspacePageExperimental from "./CreateWorkspacePageExperimental";
5
5
import { useParams } from "react-router-dom" ;
6
6
import { useQuery } from "react-query" ;
7
7
import { templateByName } from "api/queries/templates" ;
8
+ import { Loader } from "components/Loader/Loader" ;
9
+ import { ErrorAlert } from "components/Alert/ErrorAlert" ;
8
10
9
11
const CreateWorkspaceExperimentRouter : FC = ( ) => {
10
12
const { experiments } = useDashboard ( ) ;
@@ -13,20 +15,36 @@ const CreateWorkspaceExperimentRouter: FC = () => {
13
15
const { organization : organizationName = "default" , template : templateName } =
14
16
useParams ( ) as { organization ?: string ; template : string } ;
15
17
const templateQuery = useQuery (
16
- templateByName ( organizationName , templateName ) ,
17
- ) ;
18
-
19
- const something = JSON . parse (
20
- localStorage . getItem ( `parameters.${ templateQuery . data ?. id } .optOut` ) ?? "" ,
18
+ dynamicParametersEnabled
19
+ ? templateByName ( organizationName , templateName )
20
+ : { enabled : false } ,
21
21
) ;
22
22
23
23
if ( dynamicParametersEnabled ) {
24
- return < CreateWorkspacePageExperimental /> ;
24
+ if ( templateQuery . isLoading ) {
25
+ return < Loader /> ;
26
+ }
27
+
28
+ if ( ! templateQuery . data ) {
29
+ return < ErrorAlert error = { templateQuery . error } /> ;
30
+ }
31
+
32
+ const hasOptedOut =
33
+ localStorage . Item ( `parameters.${ templateQuery . data . id } .optOut` ) == "true" ;
34
+ return (
35
+ < CreateWorkspaceContext . Provider value = { { } } >
36
+ { hasOptedOut ? (
37
+ < CreateWorkspacePage />
38
+ ) : (
39
+ < CreateWorkspacePageExperimental />
40
+ ) }
41
+ </ CreateWorkspaceContext . Provider >
42
+ ) ;
25
43
}
26
44
27
45
return < CreateWorkspacePage /> ;
28
46
} ;
29
47
30
48
export default CreateWorkspaceExperimentRouter ;
31
49
32
- const CreateWorkspaceProvider = createContext ( undefined ) ;
50
+ const CreateWorkspaceContext = createContext < { } > ( { } ) ;
0 commit comments