From c1e666d02d767865f95219fcb85f5bc6a50f1f68 Mon Sep 17 00:00:00 2001 From: Brice Zele Date: Wed, 12 Aug 2020 19:24:56 +0100 Subject: [PATCH] Group demand OK --- ...icons_glyphmaps_fontawesome5free_meta.json | 2 +- android/gradlew | 0 redux/actions/NanoCreditAction.js | 20 +- redux/reducers/GetDemandsGroupReducer.js | 33 + redux/reducers/index.js | 4 +- redux/types/NanoCreditType.js | 5 + screens/history-request/HistoryItem.js | 2 +- screens/home/Home.js | 4 +- screens/nano-credit/DemandGroupDetail.js | 0 screens/nano-credit/DemandGroupNanoCredit.js | 889 +++++------------- .../DemandGroupNanoCreditDetail.js | 577 ++++++++++++ screens/optionMenu/OptionsMenu.js | 2 +- screens/wallet/WalletSelect.js | 1 - utils/UtilsFunction.js | 5 +- utils/i18n/en.json | 2 + utils/i18n/fr.json | 5 + webservice/IlinkConstants.js | 1 + webservice/user/NanoCreditApi.js | 44 + 18 files changed, 923 insertions(+), 673 deletions(-) mode change 100644 => 100755 android/gradlew create mode 100644 redux/reducers/GetDemandsGroupReducer.js create mode 100644 screens/nano-credit/DemandGroupDetail.js create mode 100644 screens/nano-credit/DemandGroupNanoCreditDetail.js create mode 100644 webservice/user/NanoCreditApi.js diff --git a/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta.json b/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta.json index e01cca4c..051deea6 100644 --- a/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta.json +++ b/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome5free_meta.json @@ -1508,4 +1508,4 @@ "yen-sign", "yin-yang" ] -} +} diff --git a/android/gradlew b/android/gradlew old mode 100644 new mode 100755 diff --git a/redux/actions/NanoCreditAction.js b/redux/actions/NanoCreditAction.js index 30d2503c..9320a6bb 100644 --- a/redux/actions/NanoCreditAction.js +++ b/redux/actions/NanoCreditAction.js @@ -1,4 +1,4 @@ -import { CREATE_GROUP_PENDING, CREATE_GROUP_SUCCESS, CREATE_GROUP_ERROR, CREATE_GROUP_RESET } from "../types/NanoCreditType"; +import { CREATE_GROUP_PENDING, CREATE_GROUP_SUCCESS, CREATE_GROUP_ERROR, CREATE_GROUP_RESET, GET_DEMAND_GROUP_PENDING, GET_DEMAND_GROUP_SUCCESS, GET_DEMAND_GROUP_ERROR, GET_DEMAND_GROUP_RESET } from "../types/NanoCreditType"; export const fetchCreateGroupPending = () => ({ type: CREATE_GROUP_PENDING @@ -16,4 +16,22 @@ export const fetchCreateGroupError = (error) => ({ export const fetchCreateGroupReset = () => ({ type: CREATE_GROUP_RESET +}); + +export const fetchGetDemandsGroupPending = () => ({ + type: GET_DEMAND_GROUP_PENDING +}); + +export const fetchGetDemandsGroupSuccess = (res) => ({ + type: GET_DEMAND_GROUP_SUCCESS, + result: res, +}); + +export const fetchGetDemandsGroupError = (error) => ({ + type: GET_DEMAND_GROUP_ERROR, + result: error +}); + +export const fetchGetDemandsGroupReset = () => ({ + type: GET_DEMAND_GROUP_RESET }); \ No newline at end of file diff --git a/redux/reducers/GetDemandsGroupReducer.js b/redux/reducers/GetDemandsGroupReducer.js new file mode 100644 index 00000000..9f0cad54 --- /dev/null +++ b/redux/reducers/GetDemandsGroupReducer.js @@ -0,0 +1,33 @@ +import { GET_DEMAND_GROUP_PENDING, GET_DEMAND_GROUP_SUCCESS, GET_DEMAND_GROUP_ERROR, GET_DEMAND_GROUP_RESET } from "../types/NanoCreditType"; + +const initialState = { + loading: false, + result: null, + error: null +}; + +export default (state = initialState, action) => { + switch (action.type) { + case GET_DEMAND_GROUP_PENDING: return { + ...state, + loading: true + } + case GET_DEMAND_GROUP_SUCCESS: return { + ...state, + loading: false, + result: action.result.data, + error: null + } + case GET_DEMAND_GROUP_ERROR: return { + ...state, + loading: false, + result: null, + error: action.result + } + case GET_DEMAND_GROUP_RESET: return initialState; + + default: { + return state; + } + } +}; diff --git a/redux/reducers/index.js b/redux/reducers/index.js index 8d1f07ac..0782edff 100644 --- a/redux/reducers/index.js +++ b/redux/reducers/index.js @@ -26,6 +26,7 @@ import LinkCardReducer from "./LinkCardReducer"; import RetraitCashAgentIdVerificationReducer from "./RetraitCashAgentIdVerificationReducer"; import CreateGroupReducer from "./CreateGroupReducer"; import SaveOnesignalReducer from "./SaveOnesignalReducer"; +import GetDemandsGroupReducer from "./GetDemandsGroupReducer"; const persistConfig = { key: 'root', @@ -61,7 +62,8 @@ const rootReducer = persistCombineReducers(persistConfig, { linkCardReduder: LinkCardReducer, retraitCashAgentIdVerificationReducer: RetraitCashAgentIdVerificationReducer, createGroupReducer: CreateGroupReducer, - saveOnesignalReducer: SaveOnesignalReducer + saveOnesignalReducer: SaveOnesignalReducer, + getDemandsGroupReducer: GetDemandsGroupReducer }); export default rootReducer; \ No newline at end of file diff --git a/redux/types/NanoCreditType.js b/redux/types/NanoCreditType.js index 51f02ee2..9aec1516 100644 --- a/redux/types/NanoCreditType.js +++ b/redux/types/NanoCreditType.js @@ -2,3 +2,8 @@ export const CREATE_GROUP_PENDING = 'CREATE_GROUP_PENDING'; export const CREATE_GROUP_SUCCESS = 'CREATE_GROUP_SUCCESS'; export const CREATE_GROUP_ERROR = 'CREATE_GROUP_ERROR'; export const CREATE_GROUP_RESET = 'CREATE_GROUP_RESET'; + +export const GET_DEMAND_GROUP_PENDING = 'GET_DEMAND_GROUP_PENDING'; +export const GET_DEMAND_GROUP_SUCCESS = 'GET_DEMAND_GROUP_SUCCESS'; +export const GET_DEMAND_GROUP_ERROR = 'GET_DEMAND_GROUP_ERROR'; +export const GET_DEMAND_GROUP_RESET = 'GET_DEMAND_GROUP_RESET'; diff --git a/screens/history-request/HistoryItem.js b/screens/history-request/HistoryItem.js index 058e2b21..3d43097a 100644 --- a/screens/history-request/HistoryItem.js +++ b/screens/history-request/HistoryItem.js @@ -102,7 +102,7 @@ export class HistoryItem extends React.Component { marginBottom: 10, color: this.state.colorstate, - }}>{this.state.status} + }}>{item.nombre_validation} {this.state.time} diff --git a/screens/home/Home.js b/screens/home/Home.js index aa987330..8ba3c3c2 100644 --- a/screens/home/Home.js +++ b/screens/home/Home.js @@ -1424,7 +1424,7 @@ class Home extends BaseScreen { translucent={true} /> {/* Start here to comment */} - +{/* { (this.state.loadingDialog || this.props.loading) ? { } }]) }} - /> + /> */} {this.makeCardSearch()} {this.makeSlidingUp()} {this.makeDialogLoader()} diff --git a/screens/nano-credit/DemandGroupDetail.js b/screens/nano-credit/DemandGroupDetail.js new file mode 100644 index 00000000..e69de29b diff --git a/screens/nano-credit/DemandGroupNanoCredit.js b/screens/nano-credit/DemandGroupNanoCredit.js index c9678e48..2aac4575 100644 --- a/screens/nano-credit/DemandGroupNanoCredit.js +++ b/screens/nano-credit/DemandGroupNanoCredit.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import { + Alert, Platform, StyleSheet, AppState, @@ -13,7 +14,7 @@ import { StatusBar } from 'react-native'; import ActionButton from 'react-native-action-button'; -import Icon from 'react-native-vector-icons/MaterialIcons'; +import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import { responsiveFontSize, responsiveHeight, responsiveWidth } from 'react-native-responsive-dimensions'; import { HistoryListItem, HistoryItemSectionned } from '../history-request/HistoryItem'; import { credrequester } from './../../route.json'; @@ -47,6 +48,13 @@ import { withNavigationFocus } from "react-navigation"; import IconWithBadge from "../IconWithBadge"; import { Appbar, Paragraph, Menu, Divider, Provider } from 'react-native-paper'; import DeviceInfo from 'react-native-device-info' +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; +import {getNanoCreditDemandsAction, getNanoCreditDemandsReset} from '../../webservice/user/NanoCreditApi'; +import { IlinkEmitter } from '../../utils/events'; +import { Typography } from '../../config/typography'; +import { ScrollView } from 'react-native-gesture-handler'; +import { Color } from '../../config/Color'; class DemandValidationGroup extends React.Component { @@ -87,180 +95,8 @@ class DemandValidationGroup extends React.Component { constructor(props) { super(props, true); - this.state = this.initState(); - readUser().then((user) => { this.setState({ user: user }) }) - this._populateIcons().then(() => { - }); - - this.navigation = this.props.navigation - this.currentLocale = DeviceInfo.getDeviceLocale().includes("fr") ? "fr" : "en-gb"; - //moment.locale(this.currentLocale); - - }; - - navigationButtonPressed({ buttonId }) { - if (buttonId === 'id') { - this.showFilter(); - } else if (buttonId === 'sectionned') { - this.setState({ isSectionned: !this.state.isSectionned }) - } - } - - - showFilter() { - - /*if (this.state.filter) { - Navigation.mergeOptions(route.stackRoot, - { - topBar: { - rightButtons: [ - { - title: 'Non Traité', - }, - { - title: 'Traité', - }, - { - title: 'Période', - }, - { - title: 'Tout', - }, - { - title: 'Trier par', - }, - { - title: '', - }, - ], - onButtonPressed: (index) => { - let data = this.state.conserve - console.log(index) - console.log(data); - - if (data !== null) { - let filtre = ""; - if (index < 2) { - switch (index) { - case 0: - filtre = I18n.t('NO_TREAT') - break; - case 1: - filtre = I18n.t('TREAT'); - break; - - } - let fi = data.filter(item => item.statut === filtre) - this.setState({listdata: fi, filter: true}) - } else if (index === 2) { - this.setState({panelVisible: true}) - } else { - this.setState({listdata: data, filter: false}) - } - } - } - }} - ); - - } else { - Navigation.mergeOptions(route.stackRoot, - { - topBar: { - rightButtons: [ - { - title: I18n.t('NO_TREAT'), - }, - { - title: I18n.t('TREAT'), - } - , { - title: I18n.t('PERIOD'), - }, - { - title: '', - }, - { - title: 'Trier par', - }, { - title: '', - }, - ], - onButtonPressed: (index) => { - let data = this.state.conserve - if (data != null && data.length > 0) { - var filtre = ""; - if (index < 2) { - switch (index) { - case 0: - filtre = I18n.t('NO_TREATED'); - break; - case 1: - filtre = I18n.t('TREATED'); - break; - - } - let fi = data.filter(item => item.statut === filtre) - this.setState({listdata: fi, filter: true}) - } else if (index === 2) { - this.setState({panelVisible: true}) - this.props.navigator.showContextualMenu( - { - rightButtons: [ - { - title: I18n.t('CANCEL'), - }, - { - title: I18n.t('FILTER'), - }, - - ], - onButtonPressed: (index) => { - console.log(index) - - switch (index) { - case 1: - let {dateend, datestart} = this.state; - this.onfilterPress(); - } - this.setState({panelVisible: false}); - } - } - ); - } else { - this.setState({listdata: data, filter: false}) - } - } - } - } - } - ); - - }*/ - } - - _populateIcons = function () { - return new Promise(function (resolve, reject) { - Promise.all( - [ - Icon.getImageSource('sort', 30), - Icon.getImageSource('layer-group', 30), - ] - ).then((values) => { - sortIcons = values[0]; - sectionIcons = values[1]; - resolve(true); - }).catch((error) => { - console.log(error); - reject(error); - }).done(); - }); - }; - - initState() { - return { + this.state = { user: {}, - listdata: [], - listdataSend: [], conserve: [], count: 0, translateAnim: new Animated.Value(0), @@ -277,31 +113,25 @@ class DemandValidationGroup extends React.Component { isLoaded: false, isSectionned: false, isDateTimePickerVisible: false, - isDateEndTimePickerVisible: false - } - } + isDateEndTimePickerVisible: false, + isDataSubmit: false + }; + readUser().then((user) => { + this.setState({ user: user }); + this.props.getNanoCreditDemandsAction(user.id); + }); - updateList(data) { - if (!this.state.filter) { - let rev = data.reverse() - this.setState({ listdata: rev, conserve: rev, isLoaded: true }); - } - } - updateMyList(data) { - if (!this.state.filter) { - let rev = data.reverse() - this.setState({ listdataSend: rev, conserve: rev, isLoaded: true }); - } + this.props.getNanoCreditDemandsReset(); + this.navigation = this.props.navigation + this.currentLocale = DeviceInfo.getDeviceLocale().includes("fr") ? "fr" : "en-gb"; + //moment.locale(this.currentLocale); - } + }; componentDidMount() { const { routeName } = this.navigation.state - this.setState({ position: routeName === "demandeValidationGroupe" ? 0 : 1 }) - this.refreshData() - /* this.intervaller = setInterval(() => { - this.refreshData(false) - }, 2000) */ + this.setState({ position: routeName === "demandeValidationGroupe" ? 0 : 1, isDataSubmit: true }); + this.refreshData(); this.animateSlidingUp(false) this.props.navigation.addListener("didFocus", () => { this.refreshData(false) @@ -315,40 +145,6 @@ class DemandValidationGroup extends React.Component { clearInterval(this.intervaller) } - renderOptionsMenu() { - return ( - - Show menu - } - > - { - this.setState({ isSectionned: !this.state.isSectionned }) - this._closeMenu() - }} - title="Section" /> - - { - - this.animateSlidingUp(!this.state.isSliding) - this._closeMenu() - }} title={I18n.t("FILTER_DATE")} /> - - - ) - } animateSlidingUp(state = false) { const height = responsiveHeight(100) let initialValue = !state ? 0 : height, @@ -356,7 +152,6 @@ class DemandValidationGroup extends React.Component { this.setState({ isSliding: state }) - this.state.translateAnim.setValue(initialValue); //Step 3 Animated.timing( //Step 4 this.state.translateAnim, @@ -367,10 +162,146 @@ class DemandValidationGroup extends React.Component { } ).start() } + _openMenu = () => this.setState({ visibleMenu: true }); _closeMenu = () => this.setState({ visibleMenu: false }); + renderDemandItem = (item) => { + let dateFormat = moment.tz(item.date_creation, 'Etc/GMT+0').format(); + dateFormat = moment(dateFormat).fromNow(); + + return ( + + this.props.navigator.navigate(route.historyItemDetails)}> + + + {item.nom} + + {`${I18n.t('CREATOR')}: ${item.createur}`} + + {/* {`Sponsor 1: ${item.sponsor1}`} + + {`Sponsor 2: ${item.sponsor2}`} + + {`Sponsor 3: ${item.sponsor3}`} */} + + + + + {item.nombre_validation === 3 ? I18n.t('VALIDATE') : I18n.t('NO_VALIDATE')} + {` (${item.nombre_validation} ${item.nombre_validation > 1 ? I18n.t('VALIDATIONS') : I18n.t('VALIDATION')})`} + + + + + + { item.country} + + + {dateFormat} + + + + + + + + ) + } + + rendeGetDemandsGroupResponse = () => { + + const { resultGetDemandsGroup, errorGetDemandsGroup } = this.props; + + if (errorGetDemandsGroup !== null) { + if (typeof errorGetDemandsGroup.data !== 'undefined') { + return ( + + {errorGetDemandsGroup.data.error} + + ) + } + else { + return ( + + {errorGetDemandsGroup} + + ) + } + } + + if (resultGetDemandsGroup !== null) { + if (resultGetDemandsGroup.response !== null) { + return ( + Array.isArray(resultGetDemandsGroup.response) && (resultGetDemandsGroup.response.length) > 0 ? + ( + { + resultGetDemandsGroup.response.map((item) => ( + this.renderDemandItem(item) + )) + } + ) : + ( + + {I18n.t('NO_DEMAND_CREATION_GROUP')} + + ) + ) + + } + } + } + + renderLoader = () => { + return ( + + {Platform.OS === 'android' + ? + ( + <> + + {I18n.t('LOADING_DOTS')} + + + ) : + <> + + {I18n.t('LOADING_DOTS')} + + } + + ) + } + + printOptions() { + return ( + { + this.props.navigation.push(route.createGroupNanoCredit); + }} + > + + + { + + }} + > + + + ) + } + + refreshData(autoref = true) { + + } + render() { return ( @@ -382,8 +313,6 @@ class DemandValidationGroup extends React.Component { translucent={false} /> - {this.renderSliding()} - { this.props.navigation.pop() }} @@ -393,442 +322,33 @@ class DemandValidationGroup extends React.Component { subtitle={this.state.position === 0 ? I18n.t('VALIDATION_DEMAND') : I18n.t('DELETE_DEMAND')} /> { this.refreshData() }} /> - { this._openMenu(); this.renderSliding(); }} /> + {/* { this._openMenu(); this.renderSliding(); }} /> */} - {this.renderOptionsMenu()} - - {this.state.position === 0 ? this._renderListDemandsSend() : this._renderListDemandReceive()} + {this.state.position === 0 ? + this.props.loadingGetDemandsGroup ? + this.renderLoader() : + this.rendeGetDemandsGroupResponse() + : null} ); } - renderSliding() { - return ( - - console.log(range)} - minDate="2018-04-20" - startDate="2018-04-30" - endDate="2018-05-05" - theme={{ - activeDayColor: {}, - monthTitleTextStyle: { - color: '#6d95da', - fontWeight: '300', - fontSize: 16, - }, - emptyMonthContainerStyle: {}, - emptyMonthTextStyle: { - fontWeight: '200', - }, - weekColumnsContainerStyle: {}, - weekColumnStyle: { - paddingVertical: 10, - }, - weekColumnTextStyle: { - color: '#b6c1cd', - fontSize: 13, - }, - nonTouchableDayContainerStyle: {}, - nonTouchableDayTextStyle: {}, - startDateContainerStyle: {}, - endDateContainerStyle: {}, - dayContainerStyle: {}, - dayTextStyle: { - color: '#2d4150', - fontWeight: '200', - fontSize: 15, - }, - dayOutOfRangeContainerStyle: {}, - dayOutOfRangeTextStyle: {}, - todayContainerStyle: {}, - todayTextStyle: { - color: '#6d95da', - }, - activeDayContainerStyle: { - backgroundColor: '#6d95da', - }, - activeDayTextStyle: { - color: 'white', - }, - nonTouchableLastMonthDayTextStyle: {} - }} - style={{ height: responsiveHeight(60) }} - /> - - - - - ) - } - renderSectionnedList(list) { - - if (this.state.isLoaded) { - let data = list; - if (data !== null) { - if (data.length > 0) { - return ( this.refreshData()} - style={styles.listbackground} />) - } else if (this.state.filter) { - - return ( - - {I18n.t('NO_ITEMS_REQUEST')} - - ) - } else { - return ( - - - {I18n.t('LOADING_DOTS')} - - ) - } - } else { - return ( - - {I18n.t('EMPTY_LIST_REQUEST')} - - ) - - } - } - } - - renderList(list) { - if (this.state.isLoaded && list instanceof Array) { - let data = list; - if (data !== null) { - if (data.length > 0) { - return ( { this.refreshData() }} - refresh={() => this.refreshData()} - isRefreshing={this.state.isRefreshing} - navigator={this.props.navigation} - style={styles.listbackground} - isDemandSend={this.state.position === 0} />) - } else if (this.state.filter) { - - return ( - - {I18n.t('NO_ITEM_REQUEST')} - - ) - } else if (data.length === 0) { - return ( - - {I18n.t('NO_ITEM_REQUEST')} - - ) - } else { - return ( - - - {I18n.t('LOADING_DOTS')} - - - ) - } - } else { - return ( - - {I18n.t('EMPTY_LIST_REQUEST')} - - ) - - } - - } else if (list.length === 0) { - return ( - - {I18n.t('NO_ITEM_REQUEST')} - - - ) - - } - - } - - renderLoading() { - return ({I18n.t('LOADING_DOTS')}) - } - showSlidingUpPanel() { - /* return ( this.panel = c} - draggableRange={{top: responsiveHeight(100), bottom: 0}} - onRequestClose={() => this.setState({panelVisible: false})}> - - {this.showSlidingUpView()} - - ) - } - - showSlidingUpView() { - /* return ( - - - this._handleDatePicked(fromdate,untildate)} - dayHeadings={['D', 'L', 'M', 'M', 'J', 'V', 'S']} - maxMonth={12} - startdate={moment('20180101').format('YYYYMMDD')} - untilDate='20181231' - minDate='20180101' - maxDate='20181231' - buttonColor='green' - showReset={false} - showClose={false} - placeHolderStart= 'Date de debut' - placeHolderUntil= 'Date fin' - selectedBackgroundColor= 'green' - selectedTextColor='white' - /> - - - - )*/ - } - - /* - onfilterPress() { - let { datestart, dateend } = this.state; - let data = this.state.conserve; - - if (data !== null) { - data = data.filter(item => { - let mda = moment(item.dateAjout) - return moment(item.dateAjout).isAfter(moment(datestart).toDate()) && (mda.isBefore(moment(dateend).toDate())) - }) - - this.setState({ listdata: data, panelVisible: false, filter: true }) - } - - } - */ - - _showDateTimePicker = (type) => { - if (type === 1) - this.setState({ - isDateTimePickerVisible: true - }); - else this.setState({ - isDateEndTimePickerVisible: true - }); - } - _showDateEndPicker = () => this.setState({ isDateEndTimePickerVisible: true }); - - _hideDateTimePicker = () => this.setState({ isDateTimePickerVisible: false, isDateEndTimePickerVisible: false }); - /* - _handleDatePicked = (fromdate, enddate) => { - console.log([fromdate, enddate]); - - this.setState({ - datestart: fromdate, - datestartformated: moment(fromdate).format('dddd Do ,MMMM YYYY'), - dateend: enddate, - dateendformated: moment(enddate).format('dddd Do ,MMMM YYYY') - }); - let startdate = this.state.datestart; - let enddatemo = moment(enddate); - let dif = moment(enddatemo).diff(startdate); - if (dif < 0) { - this.setState({ filder_disable: true }); - this.props.navigator.showSnackbar({ - text: I18n.t('DATE_WRONG'), - duration: 'long', - backgroundColor: 'red', - textColor: 'white' - }) - } else { - this.setState({ filder_disable: false }); - } - - this._hideDateTimePicker(); - }; - */ - - printOptions() { - if (this.state.user.category === "hyper") { - return ( - { - - }}> - - - ); - } else { - return ( - { - this.props.navigation.push(route.credrequester, { - onGoBack: () => this.refreshData() - }) - }} - > - - - { - - }}> - - - ) - } - } - - _renderListDemandsSend() { - console.log('this.state', this.state); - return ( - { - this.state.isLoaded ? - this.state.isSectionned ? - this.renderSectionnedList(this.state.listdataSend) : - this.renderList(this.state.listdataSend) : this.renderLoading() - } - {this.printOptions()} - {this.showSlidingUpPanel()} - - ) - } - - _renderListDemandReceive() { - - return ( - { - this.state.isLoaded ? - this.state.isSectionned ? - this.renderSectionnedList(this.state.listdata) : - this.renderList(this.state.listdata) : this.renderLoading() - } - {this.printOptions()} - {this.showSlidingUpPanel()} - - ) - } - - _renderTabGeolocated() { - let tabs = [{ - text: I18n.t('DEMAND_SEND'), - }] - return ; - } - - _renderTabHyper() { - let tabs = [{ - text: I18n.t('DEMAND_RECEIVE'), - }] - return ; - } - - _renderTabs() { - let tabs = [{ - text: I18n.t('VALIDATION_DEMAND'), - iconSource: this.state.usersicon - }, { - text: I18n.t('DELETE_DEMAND'), - iconSource: this.state.charticon - }] - return ; - } - - refreshData(autoref = true) { - if (autoref) - this.setState({ isRefreshing: true }) - loadDemandeCredit().then((data) => { - - if (data.success !== undefined) { - this.setState({ listdata: [] }) - this.updateList(data.demands); - if (this.state.position !== 0) this.props.navigation.setParams({ count: data.demands.length }) - this.setState({ isRefreshing: false }) - } - }).catch((e) => { - console.warn(e) - }); - - loadMyDemandeCredit().then((data) => { - if (data.success !== undefined) { - this.setState({ listdataSend: [] }) - this.setState({ isRefreshing: false }) - if (this.state.position === 0) this.props.navigation.setParams({ count: data.demands.length }) - - this.updateMyList(data.demands) - } - }).catch((e) => { - console.warn(e) - }); - } } -export default DemandValidationGroup; -const datefilter = StyleSheet.create({ - titleHeader: { - fontSize: 20, - fontWeight: 'bold', - color: 'black', - flex: 1, - }, - datetitle: { - fontSize: 17, - color: 'black', - marginLeft: responsiveWidth(2), - }, - datetext: { - fontSize: 16, - marginLeft: responsiveWidth(5) - }, - content: { - flex: 2, - }, - btnContainer: { - flexDirection: 'row', - width: responsiveWidth(100), - alignSelf: 'flex-end', - flex: 2, - }, - btn: { - flex: 1, - borderColor: 'transparent', - borderRadius: 0, - }, - btntext: { - fontWeight: 'bold', - color: accent - }, - container: { - flex: 1, - justifyContent: 'space-evenly' - } -}) +const mapStateToProps = state => ({ + loadingGetDemandsGroup: state.getDemandsGroupReducer.loading, + resultGetDemandsGroup: state.getDemandsGroupReducer.result, + errorGetDemandsGroup: state.getDemandsGroupReducer.error, +}); + +const mapDispatchToProps = dispatch => bindActionCreators({ + getNanoCreditDemandsAction: getNanoCreditDemandsAction, + getNanoCreditDemandsReset: getNanoCreditDemandsReset +}, dispatch); + +export default connect(mapStateToProps, mapDispatchToProps)(DemandValidationGroup); + const styles = StyleSheet.create({ slidingup: { position: "absolute", @@ -862,6 +382,11 @@ const styles = StyleSheet.create({ height: 22, color: 'white', }, + descriptionIcon: { + fontSize: 10, + height: 12, + top: 10 + }, welcome: { fontSize: 20, textAlign: 'center', @@ -884,10 +409,6 @@ const styles = StyleSheet.create({ color: 'black' }, - content: { - flex: 8 - }, - title: { fontSize: 20, marginLeft: 20, @@ -895,4 +416,46 @@ const styles = StyleSheet.create({ color: 'black', fontWeight: 'bold' }, + content: { + width: responsiveWidth(100), + borderBottomColor: '#FFFFFF', + flex: 1, + flexDirection: 'column', + paddingTop: 10, + + }, + listStyle: { + backgroundColor: 'white' + }, + bottomSeparator: { + width: responsiveWidth(100), + height: 5, + justifyContent: 'center', + alignSelf: 'center', + backgroundColor: '#EEE', + }, + title: { + color: '#000', + paddingLeft: 10, + fontSize: responsiveFontSize(2.2) + }, + description: { + fontSize: responsiveFontSize(1.8), + color: '#4f5b62', + paddingLeft: 10, + + }, + timeContent: { + justifyContent: 'space-between', + flex: 1, + marginTop: 10, + marginBottom: 5, + flexDirection: 'row', + }, + time: { + fontWeight: 'bold', + marginRight: 20, + marginBottom: 10, + color: theme.accent, + }, }); diff --git a/screens/nano-credit/DemandGroupNanoCreditDetail.js b/screens/nano-credit/DemandGroupNanoCreditDetail.js new file mode 100644 index 00000000..677e0970 --- /dev/null +++ b/screens/nano-credit/DemandGroupNanoCreditDetail.js @@ -0,0 +1,577 @@ +import React, { Component } from 'react' +import { StyleSheet, View, Text, Alert, Platform } from 'react-native' +import CardView from 'react-native-cardview' +import Button from 'apsl-react-native-button' +import { responsiveHeight, responsiveWidth } from 'react-native-responsive-dimensions' +import Icons from 'react-native-vector-icons/Ionicons' +import { updateCreditDemand } from "../../webservice/HistoryRequestApi"; +import { readUser } from "../../webservice/AuthApi"; +let typesta = 0 +let moment = require('moment-timezone') +var colorback = 'white' +import I18n from "react-native-i18n"; +import { treatCreditDemand, creditDemandResetReducer } from '../../webservice/CreditTreatDemandApi'; +import { treatCancelDemand, creditCancelResetReducer } from '../../webservice/CreditCancelDemandeApi'; +import { getAgentNetworksList } from "../../webservice/NetworkApi"; +import Icon from "./History"; +import { Header } from "react-native-elements"; +let theme = require('./../../utils/theme.json'); +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import Toast from 'react-native-root-toast'; +import { Color } from '../../config/Color' +const route = require("./../../route.json"); +import Dialog from "react-native-dialog"; +import { FontWeight } from '../../config/typography' +import DeviceInfo from 'react-native-device-info' + +class DemandGroupNanoCreditDetail extends Component { + + static navigatorStyle = { + navBarBackgroundColor: theme.accentLight, + statusBarColor: theme.accent, + navBarTextColor: '#FFFFFF', + navBarButtonColor: '#FFFFFF', + }; + static navigationOptions = ({ navigation }) => { + return { + drawerLabel: () => null, + title: "Transaction N°" + navigation.getParam("item", { id: "-" }).id + } + }; + + constructor(props) { + super(props); + this.item = this.props.navigation.getParam("item", null); + let sta = '' + if (this.item.status === '1') { + typesta = 1 + colorback = '#AEAEAE' + sta = I18n.t('TREAT_DEMAND') + } else if (this.item.status === '0') { + colorback = 'green' + typesta = 2 + sta = I18n.t('ACCEPTER_DEMANDE') + } + else { + colorback = '#AEAEAE' + typesta = 2 + sta = I18n.t('REFUSED') + } + + this.state = { + displayAmountModifyDialog: false, + statut: sta, + user: null, + networks: [], + loadingTreat: false, + loadingCancel: false, + triggerTreatmentClick: false, + triggerCancelClick: false, + color: colorback, + montant: null, + isBtnModifyAmountEnabled: false + } + readUser().then(async (user) => { + let networks = [] + networks = await getAgentNetworksList(user.agentId); + this.setState({ user: user, networks: networks.networks }) + + }); + + this.currentLocale = DeviceInfo.getDeviceLocale().includes("fr") ? "fr" : "en-gb"; + moment.locale(this.currentLocale); + + } + + isNormalInteger = (str) => { + return (/[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/.test(str)) ? false : true; + + } + + isMontantValid = () => { + const { montant } = this.state; + if ((parseInt(montant) == 0 || montant < 0)) + return false; + + else if (!this.isNormalInteger(montant)) + return false; + + else if (parseInt(montant) > parseInt(this.item.montant)) + return false; + + else + return true; + } + + displayToast = (message) => { + Toast.show(message, { + duration: Toast.durations.SHORT, + position: Toast.positions.BOTTOM, + backgroundColor: Color.primaryColor, + shadow: true, + animation: true, + hideOnPress: true, + delay: 0, + onShow: () => { + // calls on toast\`s appear animation start + }, + onShown: () => { + // calls on toast\`s appear animation end. + }, + onHide: () => { + // calls on toast\`s hide animation start. + }, + onHidden: () => { + // calls on toast\`s hide animation end. + } + }); + } + + onTreatDemand() { + if (this.item !== "1") { + this.props.creditDemandResetReducer(); + this.props.treatCreditDemand(this.item.id); + /* updateCreditDemand(this.item.phone, this.item.id).then((data) => { + this.setState({ loadingTreat: false }) + console.log(data); + + if (data.success === 1) { + this.setState({ statut: I18n.t('TREAT_DEMAND'), color: "#AEAEAE" }) + } else { + console.log(data); + } + }) */ + } + } + + onCancelDemand = () => { + if (this.item !== "1") { + this.props.treatCancelDemand(this.item.id); + } + } + + renderPromptModifyAmountToSend = () => { + return ( + + + {I18n.t('MODIFY_AMOUNT')} + + + {I18n.t('ENTER_NEW_AMOUNT_TO_SEND')} + + + { + + this.setState({ montant }, () => { + if (this.isMontantValid(montant)) { + this.setState({ + isBtnModifyAmountEnabled: true + }) + } + else + this.setState({ + isBtnModifyAmountEnabled: false + }); + + console.log("this.isMontantValid().isValid", this.isMontantValid()); + console.log("isBtnModifyAmountEnabled", this.state.isBtnModifyAmountEnabled); + }); + + }} /> + + this.setState({ displayAmountModifyDialog: false })} /> + { + this.props.creditDemandResetReducer(); + this.props.treatCreditDemand(this.item.id, this.state.montant); + }} /> + + ) + } + + renderAlertErrorTreatOrCancelDemand = () => { + const { errorTreatDemand, resultTreatDemand, resultCancelDemand, errorCancelDemand } = this.props; + + if (errorTreatDemand !== null) { + if (typeof errorTreatDemand.data !== 'undefined') { + if (errorTreatDemand.status === 426) { + Alert.alert( + I18n.t("ERROR_TREATMENT_DEMAND"), + errorTreatDemand.data.error, + [{ + text: I18n.t('CANCEL_LABEL'), + onPress: () => { }, + style: 'cancel' + }, + { + text: I18n.t("OK"), onPress: () => { + setTimeout(() => { + this.setState({ + displayAmountModifyDialog: true + }); + }, 10); + this.props.creditDemandResetReducer(); + this.props.creditCancelResetReducer(); + } + }], + { cancelable: false } + ); + } + else { + Alert.alert( + I18n.t("ERROR_TREATMENT_DEMAND"), + errorTreatDemand.data.error, + [ + { + text: I18n.t("OK"), onPress: () => { + this.props.creditDemandResetReducer(); + this.props.creditCancelResetReducer(); + } + } + ], + { cancelable: false } + ); + } + } + } + + if (errorCancelDemand !== null) { + if (typeof errorCancelDemand.data !== 'undefined') { + Alert.alert( + I18n.t("ERROR_TREATMENT_DEMAND"), + errorCancelDemand.data.error, + [ + { + text: I18n.t("OK"), onPress: () => { + this.props.creditCancelResetReducer(); + this.props.creditDemandResetReducer(); + } + } + ], + { cancelable: false } + ) + } + } + + if (resultTreatDemand !== null) { + console.log("resultTreatDemand", resultTreatDemand); + if (resultTreatDemand.status === 200) { + this.displayToast(resultTreatDemand.response); + this.props.navigation.goBack(); + this.props.navigation.state.params.onGoBack(); + this.props.creditCancelResetReducer(); + this.props.creditDemandResetReducer(); + } + } + + if (resultCancelDemand !== null) { + console.log("resultCancelDemand", resultCancelDemand); + if (resultCancelDemand.status === 200) { + + this.displayToast(resultCancelDemand.response); + this.props.navigation.goBack(); + this.props.navigation.state.params.onGoBack(); + this.props.creditCancelResetReducer(); + this.props.creditDemandResetReducer(); + + } + } + + } + + renderBtn() { + const { user } = this.state + console.warn("ITEM ITEM", this.item); + if (user) { + if (this.item.code_parrain === user.code_membre) { + if (this.item.status === '1') { + return ( + ) + } + else if (this.item.status === '2') { + return ( + ) + } + + else { + return ( + + + + + + + + + ) + } + } + } + } + + render() { + console.log("CREDIT MANAGE PROPS", this.props); + let ago = moment.tz(this.item.date_creation, 'Etc/GMT+0').format(); + ago = moment(ago) + return ( + + {this.renderPromptModifyAmountToSend()} + {(this.state.triggerTreatmentClick || this.state.triggerCancelClick) && this.renderAlertErrorTreatOrCancelDemand()} + {I18n.t('MEMBER_INFO')} + + + {this.item.phone} + + + + {this.item.code_membre} + + + + {I18n.t('DEMAND_INFO')} + + + {this.item.code_parrain} + + + + {this.item.reseau} + + + + {this.item.montant} + + + + {ago.format(" Do MMMM YYYY à HH:mm")} + + + + {ago.fromNow()} + + + {this.state.user ? this.renderBtn() : null} + ) + } + + +} + +const mapStateToProps = state => ({ + loadingTreatDemand: state.creditTreatDemandReducer.loadingTreatDemand, + resultTreatDemand: state.creditTreatDemandReducer.resultTreatDemand, + errorTreatDemand: state.creditTreatDemandReducer.errorTreatDemand, + + loadingCancelDemand: state.creditCancelDemandReducer.loadingCancelDemand, + resultCancelDemand: state.creditCancelDemandReducer.resultCancelDemand, + errorCancelDemand: state.creditCancelDemandReducer.errorCancelDemand +}); + +const mapDispatchToProps = dispatch => bindActionCreators({ + treatCreditDemand: treatCreditDemand, + creditDemandResetReducer: creditDemandResetReducer, + + treatCancelDemand: treatCancelDemand, + creditCancelResetReducer: creditCancelResetReducer +}, dispatch); + +export default connect(mapStateToProps, mapDispatchToProps)(DemandGroupNanoCreditDetail); + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + btnstyle: { + + }, + + inputAmountText: { + ...Platform.select({ + android: { + borderBottomColor: Color.borderColor, + borderBottomWidth: 0.5, + } + }) + }, + simpleuser: { + marginLeft: responsiveWidth(2), + fontSize: 16, + color: '#3E3E3E' + }, + textbtnstyle: { + color: "white", + fontWeight: "bold", + fontSize: 18 + }, + cardcontainer1: { + justifyContent: 'space-evenly', + flex: 2, + marginRight: 3, + marginLeft: 3, + + }, + cardcontainer: { + justifyContent: 'space-evenly', + + flex: 3, + margin: 3, + } +}) \ No newline at end of file diff --git a/screens/optionMenu/OptionsMenu.js b/screens/optionMenu/OptionsMenu.js index 56ef8bf1..7de9b02b 100644 --- a/screens/optionMenu/OptionsMenu.js +++ b/screens/optionMenu/OptionsMenu.js @@ -258,7 +258,7 @@ export default class OptionsMenu extends Component { || item === 'envoieWalletToCashUser' || item === 'linkCard' || item === 'envoieWalletToCardUser' || item === 'envoieWalletToBankUser' || item === 'retraitWalletVersCashUser' || item === 'retraitCarteVersWalletUser' || item === 'retraitEnCashAgent' || item === 'retraitCarteVersCashAgent' || item === 'envoieCashVersWalletAgent' || item === 'envoieCashVersAutreWalletAgent' || item === 'retraitCarteVersCashUser' || item === 'envoiCashVersCashAgent' || item === 'envoieCashVersCashAgent' - || item === 'envoieCashVersCarteAgent' || item === 'modifyIdentificationUser' || item === 'createGroupNanoCredit' || item === 'groupNanoCredit') { + || item === 'envoieCashVersCarteAgent' || item === 'modifyIdentificationUser' || item === 'createGroupNanoCredit' || item === 'groupNanoCredit' || item === 'demandGroupNanoCreditDetail') { return null } else { const color = this.state.currentId === item.id ? theme.accent : "grey" diff --git a/screens/wallet/WalletSelect.js b/screens/wallet/WalletSelect.js index f9c926a7..1dd77df5 100644 --- a/screens/wallet/WalletSelect.js +++ b/screens/wallet/WalletSelect.js @@ -37,7 +37,6 @@ class WalletSelect extends Component { activeColor: '#f0edf6', inactiveColor: '#3e2465', barStyle: { backgroundColor: '#694fad' }, - drawerLabel: I18n.t('CREDIT_MANAGE'), drawerIcon: ({ tintColor }) => ( { + + const auth = store.getState().authKeyReducer; + const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : ''; + + return dispatch => { + dispatch(fetchGetDemandsGroupPending()); + + axios({ + url: `${getCreditDemand}/all/${id}`, + method: 'GET', + headers: { + 'Authorization': authKey, + 'X-Localization': I18n.currentLocale() + } + }) + .then(response => { + console.log(response); + dispatch(fetchGetDemandsGroupSuccess(response)); + }) + .catch(error => { + if (error.response) + dispatch(fetchGetDemandsGroupError(error.response)); + else if (error.request) + dispatch(fetchGetDemandsGroupError(error.request)) + else + dispatch(fetchGetDemandsGroupError(error.message)) + }); + } +} + +export const getNanoCreditDemandsReset = () => { + return dispatch => { + dispatch(fetchGetDemandsGroupReset()); + } +} \ No newline at end of file