-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create redux slice for featureFlags
- Loading branch information
1 parent
c707f74
commit 1c5ae0a
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { PayloadAction, createSlice } from '@reduxjs/toolkit'; | ||
|
||
export interface FeatureFlagsState { | ||
featureFlags: object[] | null; | ||
loading: boolean; | ||
error: string | null; | ||
} | ||
|
||
export const initialState: FeatureFlagsState = { | ||
featureFlags: null, | ||
loading: false, | ||
error: null, | ||
}; | ||
|
||
const name = 'featureFlags'; | ||
|
||
const slice = createSlice({ | ||
name, | ||
initialState, | ||
reducers: { | ||
/** | ||
* Initiates the fetching of feature flags. | ||
* @param state - The current state of the featureFlags slice. | ||
*/ | ||
getFeatureFlags: (state: FeatureFlagsState) => { | ||
state.loading = true; | ||
state.error = null; | ||
}, | ||
/** | ||
* Handles the successful fetching of feature flags. | ||
* @param state - The current state of the featureFlags slice. | ||
* @param action - An action with the fetched feature flags as payload. | ||
*/ | ||
getFeatureFlagsSuccess: ( | ||
state: FeatureFlagsState, | ||
action: PayloadAction<object>, | ||
) => { | ||
state.featureFlags = action.payload; | ||
state.loading = false; | ||
state.error = null; | ||
}, | ||
/** | ||
* Handles errors that occur during the fetching of feature flags. | ||
* @param state - The current state of the featureFlags slice. | ||
* @param action - An action with the error message as payload. | ||
*/ | ||
getFeatureFlagsError: ( | ||
state: FeatureFlagsState, | ||
action: PayloadAction<string>, | ||
) => { | ||
state.loading = false; | ||
state.error = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
const { actions, reducer } = slice; | ||
|
||
export default reducer; | ||
|
||
export const { getFeatureFlags, getFeatureFlagsSuccess, getFeatureFlagsError } = | ||
actions; | ||
|
||
export const FETCH_FEATURE_FLAGS = 'getFeatureFlags'; | ||
export type FETCH_FEATURE_FLAGS = typeof FETCH_FEATURE_FLAGS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters