Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/local feature flag #240

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import rootSaga from './src/sagas/rootSaga';

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];
const store = compose(applyMiddleware(...middleware))(createStore)(reducers);
export const store = compose(applyMiddleware(...middleware))(createStore)(reducers);
sagaMiddleware.run(rootSaga);

const App = () => {
Expand Down
23 changes: 23 additions & 0 deletions src/reducers/featureFlag.reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// TODO: by default read from env file
export const featureFlagState = {
isProdEnvironment: true,
};

const localFeatureFlag = (state = featureFlagState, action: any) => {
switch (action.type) {
case 'PROD':
return {
...state,
isProdEnvironment: true,
};
case 'DEV':
return {
...state,
isProdEnvironment: false,
};
default:
return state;
}
};

export default localFeatureFlag;
3 changes: 2 additions & 1 deletion src/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { combineReducers } from 'redux';
import user from './user.reducer';
import localFeatureFlag from './featureFlag.reducer';

const reducers = combineReducers({ user });
const reducers = combineReducers({ user, localFeatureFlag });

export default reducers;
3 changes: 3 additions & 0 deletions src/reducers/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { store } from '../../App';

export const baseStoreState = store.getState();
11 changes: 11 additions & 0 deletions src/screens/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import { urls } from '../../constants/appConstant/url';
import AuthApis from '../../constants/apiConstant/AuthApi';
import { CameraScreen } from 'react-native-camera-kit';
import CustomModal from '../../components/Modal/CustomModal';
import { useDispatch, useSelector } from 'react-redux';

const AuthScreen = () => {
// TODO: will revamp github signIn feature
const dispatch = useDispatch();
const { isProdEnvironment } = useSelector((store) => store.localFeatureFlag);
const { setLoggedInUserData } = useContext(AuthContext);
const [githubView, setGithubView] = useState<boolean>(false);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -238,6 +241,14 @@ const AuthScreen = () => {
<Text style={AuthViewStyle.cmpnyName}>{Strings.REAL_DEV_SQUAD}</Text>
</View>
<View style={AuthViewStyle.btnContainer}>
<AuthScreenButton
text={isProdEnvironment ? 'Switch to DEV' : 'Switch to Prod'}
onPress={() => {
isProdEnvironment
? dispatch({ type: 'DEV' })
: dispatch({ type: 'PROD' });
}}
/>
<View style={AuthViewStyle.btnContainer}>
<TouchableOpacity
onPress={handleSignIn}
Expand Down
14 changes: 12 additions & 2 deletions src/screens/ProfileScreen/ProfileScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { ImagePickerResponse } from 'react-native-image-picker';
import Strings from '../../i18n/en';
import { fetchContribution } from '../AuthScreen/Util';
import { useFocusEffect } from '@react-navigation/native';

import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { AuthScreenButton } from '../AuthScreen/Button';

const ProfileScreen = () => {
const dispatch = useDispatch();
const { isProdEnvironment } = useSelector((store) => store.localFeatureFlag);
const { data: userData } = useSelector((store) => store.user);
const [response, setResponse] = useState<ImagePickerResponse>({});
const [modalVisible, setModalVisible] = useState(false);
Expand Down Expand Up @@ -87,6 +89,14 @@ const ProfileScreen = () => {
{loggedInUserData?.name}
</Text>
<ButtonWidget title={'Update'} onPress={openModal} />
<ButtonWidget
title={isProdEnvironment ? 'Switch to DEV' : 'Switch to Prod'}
onPress={() => {
isProdEnvironment
? dispatch({ type: 'DEV' })
: dispatch({ type: 'PROD' });
}}
/>
</View>
</View>
);
Expand Down