1
1
import { useDashboard } from "modules/dashboard/useDashboard" ;
2
- import { createContext , type FC } from "react" ;
2
+ import { createContext , type FC , useState } from "react" ;
3
3
import CreateWorkspacePage from "./CreateWorkspacePage" ;
4
4
import CreateWorkspacePageExperimental from "./CreateWorkspacePageExperimental" ;
5
5
import { useParams } from "react-router-dom" ;
@@ -24,16 +24,26 @@ const CreateWorkspaceExperimentRouter: FC = () => {
24
24
if ( templateQuery . isLoading ) {
25
25
return < Loader /> ;
26
26
}
27
-
28
27
if ( ! templateQuery . data ) {
29
28
return < ErrorAlert error = { templateQuery . error } /> ;
30
29
}
31
30
32
- const hasOptedOut =
33
- localStorage . Item ( `parameters.${ templateQuery . data . id } .optOut` ) == "true" ;
31
+ const optOut = `parameters.${ templateQuery . data . id } .optOut` ;
32
+ const [ optedOut , setOptedOut ] = useState (
33
+ localStorage . getItem ( optOut ) == "true" ,
34
+ ) ;
35
+
36
+ const toggleOptedOut = ( ) => {
37
+ setOptedOut ( ( prev ) => {
38
+ const next = ! prev ;
39
+ localStorage . setItem ( optOut , next . toString ( ) ) ;
40
+ return next ;
41
+ } ) ;
42
+ } ;
43
+
34
44
return (
35
- < CreateWorkspaceContext . Provider value = { { } } >
36
- { hasOptedOut ? (
45
+ < CreateWorkspaceContext . Provider value = { { toggleOptedOut } } >
46
+ { optedOut ? (
37
47
< CreateWorkspacePage />
38
48
) : (
39
49
< CreateWorkspacePageExperimental />
@@ -47,4 +57,6 @@ const CreateWorkspaceExperimentRouter: FC = () => {
47
57
48
58
export default CreateWorkspaceExperimentRouter ;
49
59
50
- const CreateWorkspaceContext = createContext < { } > ( { } ) ;
60
+ const CreateWorkspaceContext = createContext <
61
+ { toggleOptedOut : ( ) => void } | undefined
62
+ > ( undefined ) ;
0 commit comments