Skip to content

Commit

Permalink
[iOS] Setup store view dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolemos committed Mar 23, 2019
1 parent 303fb5b commit 8699f2c
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 59 deletions.
5 changes: 5 additions & 0 deletions packages/components/src/redux/reducers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface State {
error: AuthError | null
isDeletingAccount: boolean
isLoggingIn: boolean
loginCount: number
user: Pick<User, '_id' | 'createdAt' | 'lastLoginAt' | 'updatedAt'> | null
}

Expand All @@ -24,6 +25,7 @@ const initialState: State = {
error: null,
isDeletingAccount: false,
isLoggingIn: false,
loginCount: 0,
user: null,
}

Expand All @@ -37,10 +39,12 @@ export const authReducer: Reducer<State> = (state = initialState, action) => {

case 'LOGIN_REQUEST':
return {
...state,
appToken: action.payload.appToken,
error: null,
isDeletingAccount: false,
isLoggingIn: true,
loginCount: state.loginCount,
user: state.user,
}

Expand All @@ -50,6 +54,7 @@ export const authReducer: Reducer<State> = (state = initialState, action) => {
error: null,
isDeletingAccount: false,
isLoggingIn: false,
loginCount: (state.loginCount || 0) + 1,
user: action.payload.user && {
_id: action.payload.user._id,
lastLoginAt:
Expand Down
11 changes: 10 additions & 1 deletion packages/components/src/redux/sagas/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios, { AxiosResponse } from 'axios'
import * as StoreReview from 'react-native-store-review'
import { REHYDRATE } from 'redux-persist'
import { all, put, select, takeLatest } from 'redux-saga/effects'

Expand Down Expand Up @@ -141,7 +142,7 @@ function* onLoginRequest(
}
}

function onLoginSuccess(
function* onLoginSuccess(
action: ExtractActionFromActionCreator<typeof actions.loginSuccess>,
) {
const { user } = action.payload
Expand All @@ -156,6 +157,14 @@ function onLoginSuccess(
bugsnag.setUser(user._id, user.github.user.name || user.github.user.login)

clearOAuthQueryParams()

if (StoreReview.isAvailable) {
const loginCount = yield select(selectors.loginCountSelector)

if (loginCount >= 5 && loginCount % 5 === 0) {
StoreReview.requestReview()
}
}
}

function* onLoginFailure(
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/redux/selectors/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const authErrorSelector = (state: RootState) => s(state).error
export const isDeletingAccountSelector = (state: RootState) =>
s(state).isDeletingAccount

export const loginCountSelector = (state: RootState) => s(state).loginCount

export const isLoggingInSelector = (state: RootState) => s(state).isLoggingIn

export const isLoggedSelector = (state: RootState) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const migrations = {
updatedAt: '',
lastLoginAt: oldAuth.lastLoginAt || '',
} as any),
}
} as any
}),
5: (state: RootState) =>
immer(state, draft => {
Expand Down
30 changes: 30 additions & 0 deletions packages/mobile/ios/devhub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
2E745941223890110002D4FB /* Bugsnag.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E74593C22388D420002D4FB /* Bugsnag.framework */; };
2E745942223890110002D4FB /* Bugsnag.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 2E74593C22388D420002D4FB /* Bugsnag.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2E98FDAB22445E490083350D /* libRNInAppBrowser.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E98FDA622445E130083350D /* libRNInAppBrowser.a */; };
2E98FDB22246328A0083350D /* libRNStoreReview.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E98FDB1224632570083350D /* libRNStoreReview.a */; };
2EAFF5FE1FE1AEEE000A9A11 /* MaterialIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 486C758B88E34A52BFB2C474 /* MaterialIcons.ttf */; };
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
60EFC7011AA849D496DCEC2C /* libRNFirebase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27AA4F7C08944EB48AFA4996 /* libRNFirebase.a */; };
Expand Down Expand Up @@ -214,6 +215,13 @@
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RNInAppBrowser;
};
2E98FDB0224632570083350D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 2E98FDAC224632560083350D /* RNStoreReview.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RNStoreReview;
};
2EA58A552162FB5600B9EBEA /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 961B335E70A74BD9B59B6237 /* RNScreens.xcodeproj */;
Expand Down Expand Up @@ -467,6 +475,7 @@
2E74593522388D0B0002D4FB /* BugsnagReactNative.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = BugsnagReactNative.xcodeproj; path = "../../../node_modules/bugsnag-react-native/cocoa/BugsnagReactNative.xcodeproj"; sourceTree = "<group>"; };
2E74593C22388D420002D4FB /* Bugsnag.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Bugsnag.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2E98FD7522445E120083350D /* RNInAppBrowser.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNInAppBrowser.xcodeproj; path = "../../../node_modules/react-native-inappbrowser-reborn/ios/RNInAppBrowser.xcodeproj"; sourceTree = "<group>"; };
2E98FDAC224632560083350D /* RNStoreReview.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNStoreReview.xcodeproj; path = "../../../node_modules/react-native-store-review/ios/RNStoreReview.xcodeproj"; sourceTree = "<group>"; };
40B4448D993A4CA2ABDDA557 /* SplashScreen.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = SplashScreen.xcodeproj; path = "../../../node_modules/react-native-splash-screen/ios/SplashScreen.xcodeproj"; sourceTree = "<group>"; };
486C758B88E34A52BFB2C474 /* MaterialIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = MaterialIcons.ttf; path = "../../../node_modules/react-native-vector-icons/Fonts/MaterialIcons.ttf"; sourceTree = "<group>"; };
57716D5B6BA1484B8D9D4E4B /* RNFirebase.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNFirebase.xcodeproj; path = "../node_modules/react-native-firebase/ios/RNFirebase.xcodeproj"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -532,6 +541,7 @@
60EFC7011AA849D496DCEC2C /* libRNFirebase.a in Frameworks */,
2E74593B22388D200002D4FB /* libBugsnagReactNative.a in Frameworks */,
2E98FDAB22445E490083350D /* libRNInAppBrowser.a in Frameworks */,
2E98FDB22246328A0083350D /* libRNStoreReview.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -724,6 +734,14 @@
name = Products;
sourceTree = "<group>";
};
2E98FDAD224632560083350D /* Products */ = {
isa = PBXGroup;
children = (
2E98FDB1224632570083350D /* libRNStoreReview.a */,
);
name = Products;
sourceTree = "<group>";
};
2EA58A522162FB5600B9EBEA /* Products */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -823,6 +841,7 @@
57716D5B6BA1484B8D9D4E4B /* RNFirebase.xcodeproj */,
2E74593522388D0B0002D4FB /* BugsnagReactNative.xcodeproj */,
2E98FD7522445E120083350D /* RNInAppBrowser.xcodeproj */,
2E98FDAC224632560083350D /* RNStoreReview.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down Expand Up @@ -1084,6 +1103,10 @@
ProductGroup = 2EA58A522162FB5600B9EBEA /* Products */;
ProjectRef = 961B335E70A74BD9B59B6237 /* RNScreens.xcodeproj */;
},
{
ProductGroup = 2E98FDAD224632560083350D /* Products */;
ProjectRef = 2E98FDAC224632560083350D /* RNStoreReview.xcodeproj */;
},
{
ProductGroup = 2EAFEEB11FDDD3EA000A9A11 /* Products */;
ProjectRef = B6BF65C496E44E78BF211275 /* RNVectorIcons.xcodeproj */;
Expand Down Expand Up @@ -1244,6 +1267,13 @@
remoteRef = 2E98FDA522445E130083350D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
2E98FDB1224632570083350D /* libRNStoreReview.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRNStoreReview.a;
remoteRef = 2E98FDB0224632570083350D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
2EA58A562162FB5600B9EBEA /* libRNScreens.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
Expand Down
3 changes: 2 additions & 1 deletion packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"react-native-firebase": "5.2.3",
"react-native-google-analytics-bridge": "7.1.0",
"react-native-inappbrowser-reborn": "2.0.0",
"react-native-screens": "1.0.0-alpha.22"
"react-native-screens": "1.0.0-alpha.22",
"react-native-store-review": "0.1.5"
},
"jest": {
"preset": "react-native",
Expand Down
2 changes: 1 addition & 1 deletion packages/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {},
"devDependencies": {
"eslint": "^5.9.0",
"eslint": "5.9.0",
"now": "*"
}
}
Loading

0 comments on commit 8699f2c

Please sign in to comment.