Navigate on notification open

This commit is contained in:
Brice Zele 2020-08-17 06:25:16 +01:00
parent a0a2be9878
commit 3fd1528ae7
7 changed files with 137 additions and 1824 deletions

40
App.js
View File

@ -76,6 +76,7 @@ import CreateGroupNanoCredit from './screens/nano-credit/CreateGroupNanoCredit';
import { bindActionCreators } from 'redux';
import DemandValidationGroup from './screens/nano-credit/DemandGroupNanoCredit';
import DemandGroupNanoCreditDetail from './screens/nano-credit/DemandGroupNanoCreditDetail';
import NavigationService from './utils/NavigationService';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
@ -397,6 +398,7 @@ class App extends React.Component {
onOpened(openResult) {
let data = openResult.notification.payload.additionalData;
NavigationService.navigate('useraccount');
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
@ -421,12 +423,48 @@ class App extends React.Component {
});
}
handleDeepLink = openResult => {
const data = openResult.notification.payload.additionalData;
//this.props.setInitialNotification(openResult);
if (data && data.id) {
/* this.goToScreen(data.screen, {
id: data.id,
goToScreen: this.goToScreen
}); */
this.goToScreen("useraccount", {
goToScreen: this.goToScreen
});
} else {
console.log("notification is invalid data");
}
};
goToScreen = (routeName, params, isReset = true) => {
const { navigator } = this.refs;
navigator.dispatch({
type: "Navigation/NAVIGATE",
routeName,
params
});
// if (isReset) {
// const resetAction = NavigationActions.reset({
// index: 0,
// actions: [NavigationActions.navigate({routeName, params})]
// });
// navigator.dispatch(resetAction);
// } else {
// navigator.dispatch({type: 'Navigation/NAVIGATE', routeName: routeName, params});
// }
// this.closeSideMenu();
};
render() {
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<ActionSheetProvider>
<AppContainer />
<AppContainer ref="navigator" />
</ActionSheetProvider>
</PersistGate>
</Provider>

File diff suppressed because one or more lines are too long

View File

@ -51,6 +51,7 @@ import { connect } from 'react-redux';
import getWalletActivated from '../../webservice/WalletApi';
import { saveOnesignalIdsAction } from '../../webservice/OnesignalApi';
import OneSignal from 'react-native-onesignal';
import NavigationService from '../../utils/NavigationService';
const slideHeight = responsiveHeight(30) > 270 ? 270 : responsiveHeight(30)
@ -658,14 +659,14 @@ class Home extends BaseScreen {
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
//OneSignal.addEventListener('ids', this.onIds);
};
componentWillUnmount() {
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('opened', this.onOpened);
OneSignal.removeEventListener('ids', this.onIds);
//OneSignal.removeEventListener('ids', this.onIds);
}
onReceived(notification) {
@ -674,9 +675,12 @@ class Home extends BaseScreen {
onOpened(openResult) {
let data = openResult.notification.payload.additionalData;
this.props.navigation.navigate(data.screen, {
this.props.navigation.push()
/* this.props.navigation.navigate(data.screen, {
id: data.data.id
});
}); */
//NavigationService.navigate('useraccount');
}
/* updateLangue() {

View File

@ -24,6 +24,7 @@ import Dialog from "react-native-dialog";
import { FontWeight } from '../../config/typography'
import DeviceInfo from 'react-native-device-info'
import { getNanoCreditUniqueDemandsAction, getNanoCreditUniqueDemandsReset } from '../../webservice/user/NanoCreditApi'
import { treatDemandGroupAction, treatDemandGroupReset } from '../../webservice/NanoCreditApi'
class DemandGroupNanoCreditDetail extends Component {
@ -118,16 +119,21 @@ class DemandGroupNanoCreditDetail extends Component {
}
onTreatDemand() {
if (this.item !== "1") {
this.props.creditDemandResetReducer();
this.props.treatCreditDemand(this.item.id);
}
this.props.treatDemandGroupReset();
this.props.treatDemandGroupAction({
id_demande: this.props.resultGetUniqueDemand.response.id,
id_user: this.state.user.id,
type: "creation"
});
}
onCancelDemand = () => {
if (this.item !== "1") {
this.props.treatCancelDemand(this.item.id);
}
this.props.treatDemandGroupReset();
this.props.treatDemandGroupAction({
id_demande: this.props.resultGetUniqueDemand.response.id,
id_user: this.state.user.id,
type: "suppression"
});
}
@ -291,10 +297,10 @@ class DemandGroupNanoCreditDetail extends Component {
}}
isLoading={this.props.loadingTreatDemand}
onPress={() => {
/* this.setState({
this.setState({
triggerTreatmentClick: true
});
this.onTreatDemand() */
this.onTreatDemand();
}}
textStyle={styles.textbtnstyle}
>
@ -316,10 +322,10 @@ class DemandGroupNanoCreditDetail extends Component {
}}
isLoading={this.props.loadingCancelDemand}
onPress={() => {
/* this.setState({
this.setState({
triggerCancelClick: true
});
this.onCancelDemand(); */
this.onCancelDemand();
}}
textStyle={styles.textbtnstyle}
>
@ -481,6 +487,7 @@ class DemandGroupNanoCreditDetail extends Component {
//ago = moment(ago)
return (
<>
{(this.state.triggerTreatmentClick || this.state.triggerCancelClick) && this.renderAlertErrorTreatOrCancelDemand()}
{
this.props.loadingGetUniqueDemand ?
this.renderLoader() :
@ -507,6 +514,9 @@ const mapDispatchToProps = dispatch => bindActionCreators({
getNanoCreditUniqueDemandsAction: getNanoCreditUniqueDemandsAction,
getNanoCreditUniqueDemandsReset: getNanoCreditUniqueDemandsReset,
treatDemandGroupAction: treatDemandGroupAction,
treatDemandGroupReset: treatDemandGroupReset,
treatCreditDemand: treatCreditDemand,
creditDemandResetReducer: creditDemandResetReducer,

View File

@ -0,0 +1,23 @@
import { NavigationActions } from 'react-navigation';
let _navigator;
function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
function navigate(routeName, params) {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params,
})
);
}
// add other navigation functions that you need and export them
export default {
navigate,
setTopLevelNavigator,
};

View File

@ -53,6 +53,7 @@ export const getCreditDemand = testBaseUrl + '/walletService/groups/demands';
export const linkCardUrl = testBaseUrl + '/walletService/identifications/rattach_card';
export const groupUrl = testBaseUrl + '/walletService/groups';
export const treatDemandUrl = testBaseUrl + '/walletService/groups/demands/validate';
export const saveOnesignalIds = testBaseUrl + '/notificationService/onesignal';
export const authKeyUrl = testBaseUrl + '/oauth/token';

View File

@ -1,9 +1,9 @@
import axios from "axios";
import I18n from 'react-native-i18n';
import { fetchCreateGroupError, fetchCreateGroupPending, fetchCreateGroupReset, fetchCreateGroupSuccess } from "../redux/actions/NanoCreditAction";
import { fetchCreateGroupError, fetchCreateGroupPending, fetchCreateGroupReset, fetchCreateGroupSuccess, fetchTreatDemandsGroupPending, fetchTreatDemandsGroupSuccess, fetchTreatDemandsGroupError, fetchTreatDemandsGroupReset } from "../redux/actions/NanoCreditAction";
import { store } from "../redux/store";
import { groupUrl } from "./IlinkConstants";
import { groupUrl, treatDemandUrl } from "./IlinkConstants";
export const createGroupAction = (data) => {
@ -42,3 +42,41 @@ export const createGroupReset = () => {
dispatch(fetchCreateGroupReset());
}
}
export const treatDemandGroupAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchTreatDemandsGroupPending());
axios({
url: `${treatDemandUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchTreatDemandsGroupSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchTreatDemandsGroupError(error.response));
else if (error.request)
dispatch(fetchTreatDemandsGroupError(error.request))
else
dispatch(fetchTreatDemandsGroupError(error.message))
});
}
}
export const treatDemandGroupReset = () => {
return dispatch => {
dispatch(fetchTreatDemandsGroupReset());
}
}