44 * See License.AGPL.txt in the project root for license information.
55 */
66
7- import React , { createContext , useContext , useState , useEffect } from "react" ;
7+ import React , { createContext , useContext , useState , useEffect , useMemo } from "react" ;
88import { getExperimentsClient } from "../experiments/client" ;
99import { ProjectContext } from "../projects/project-context" ;
1010import { useCurrentTeam , useTeams } from "../teams/teams-context" ;
@@ -14,17 +14,11 @@ interface FeatureFlagConfig {
1414 [ flagName : string ] : { defaultValue : boolean ; setter : React . Dispatch < React . SetStateAction < boolean > > } ;
1515}
1616
17- const FeatureFlagContext = createContext < {
18- startWithOptions : boolean ;
19- showUsageView : boolean ;
20- isUsageBasedBillingEnabled : boolean ;
21- showUseLastSuccessfulPrebuild : boolean ;
22- usePublicApiWorkspacesService : boolean ;
23- enablePersonalAccessTokens : boolean ;
24- oidcServiceEnabled : boolean ;
25- orgGitAuthProviders : boolean ;
26- switchToPAYG : boolean ;
27- } > ( {
17+ type FeatureFlagsType = {
18+ [ k in keyof typeof defaultFeatureFlags ] : boolean ;
19+ } ;
20+
21+ const defaultFeatureFlags = {
2822 startWithOptions : false ,
2923 showUsageView : false ,
3024 isUsageBasedBillingEnabled : false ,
@@ -34,7 +28,10 @@ const FeatureFlagContext = createContext<{
3428 oidcServiceEnabled : false ,
3529 orgGitAuthProviders : false ,
3630 switchToPAYG : false ,
37- } ) ;
31+ newSignupFlow : false ,
32+ } ;
33+
34+ const FeatureFlagContext = createContext < FeatureFlagsType > ( defaultFeatureFlags ) ;
3835
3936const FeatureFlagContextProvider : React . FC = ( { children } ) => {
4037 const { user } = useContext ( UserContext ) ;
@@ -50,6 +47,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
5047 const [ oidcServiceEnabled , setOidcServiceEnabled ] = useState < boolean > ( false ) ;
5148 const [ orgGitAuthProviders , setOrgGitAuthProviders ] = useState < boolean > ( false ) ;
5249 const [ switchToPAYG , setSwitchToPAYG ] = useState < boolean > ( false ) ;
50+ const [ newSignupFlow , setNewSignupFlow ] = useState < boolean > ( false ) ;
5351
5452 useEffect ( ( ) => {
5553 if ( ! user ) return ;
@@ -67,6 +65,7 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
6765 oidcServiceEnabled : { defaultValue : false , setter : setOidcServiceEnabled } ,
6866 orgGitAuthProviders : { defaultValue : false , setter : setOrgGitAuthProviders } ,
6967 switchToPAYG : { defaultValue : false , setter : setSwitchToPAYG } ,
68+ newSignupFlow : { defaultValue : false , setter : setNewSignupFlow } ,
7069 } ;
7170
7271 for ( const [ flagName , config ] of Object . entries ( featureFlags ) ) {
@@ -103,23 +102,33 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
103102 } ) ( ) ;
104103 } , [ user , teams , team , project ] ) ;
105104
106- return (
107- < FeatureFlagContext . Provider
108- value = { {
109- startWithOptions,
110- showUsageView,
111- isUsageBasedBillingEnabled,
112- showUseLastSuccessfulPrebuild,
113- enablePersonalAccessTokens,
114- usePublicApiWorkspacesService,
115- oidcServiceEnabled,
116- orgGitAuthProviders,
117- switchToPAYG,
118- } }
119- >
120- { children }
121- </ FeatureFlagContext . Provider >
122- ) ;
105+ const flags = useMemo ( ( ) => {
106+ return {
107+ startWithOptions,
108+ showUsageView,
109+ isUsageBasedBillingEnabled,
110+ showUseLastSuccessfulPrebuild,
111+ enablePersonalAccessTokens,
112+ usePublicApiWorkspacesService,
113+ oidcServiceEnabled,
114+ orgGitAuthProviders,
115+ newSignupFlow,
116+ switchToPAYG,
117+ } ;
118+ } , [
119+ enablePersonalAccessTokens ,
120+ isUsageBasedBillingEnabled ,
121+ newSignupFlow ,
122+ oidcServiceEnabled ,
123+ orgGitAuthProviders ,
124+ showUsageView ,
125+ showUseLastSuccessfulPrebuild ,
126+ startWithOptions ,
127+ switchToPAYG ,
128+ usePublicApiWorkspacesService ,
129+ ] ) ;
130+
131+ return < FeatureFlagContext . Provider value = { flags } > { children } </ FeatureFlagContext . Provider > ;
123132} ;
124133
125134export { FeatureFlagContext , FeatureFlagContextProvider } ;
0 commit comments