diff --git a/redux/actions/WalletActions.js b/redux/actions/WalletActions.js index 5c146b95..f8afbe69 100644 --- a/redux/actions/WalletActions.js +++ b/redux/actions/WalletActions.js @@ -7,7 +7,8 @@ import { WALLET_HISTORY_ERROR, WALLET_TRANSFER_COMMISSION_PENDING, WALLET_TRANSFER_COMMISSION_SUCCESS, - WALLET_TRANSFER_COMMISSION_ERROR + WALLET_TRANSFER_COMMISSION_ERROR, + WALLET_TRANSFER_COMMISSION_RESET } from "../types/WalletType"; @@ -43,6 +44,10 @@ export const fetchWalletTransferCommissionPending = () => ({ type: WALLET_TRANSFER_COMMISSION_PENDING }); +export const walletTransferCommissionReset = () => ({ + type: WALLET_TRANSFER_COMMISSION_RESET +}); + export const fetchWalletTransferCommissionSuccess = (res) => ({ type: WALLET_TRANSFER_COMMISSION_SUCCESS, result: res, diff --git a/redux/reducers/WalletTransferCommission.js b/redux/reducers/WalletTransferCommission.js index 35dc5f24..c88c2415 100644 --- a/redux/reducers/WalletTransferCommission.js +++ b/redux/reducers/WalletTransferCommission.js @@ -1,4 +1,4 @@ -import { WALLET_TRANSFER_COMMISSION_PENDING, WALLET_TRANSFER_COMMISSION_SUCCESS, WALLET_TRANSFER_COMMISSION_ERROR } from "../types/WalletType"; +import { WALLET_TRANSFER_COMMISSION_PENDING, WALLET_TRANSFER_COMMISSION_SUCCESS, WALLET_TRANSFER_COMMISSION_ERROR, WALLET_TRANSFER_COMMISSION_RESET } from "../types/WalletType"; const initialState = { loadingTransferCommission: false, @@ -25,6 +25,8 @@ export default (state = initialState, action) => { errorTransferCommission: action.result } + case WALLET_TRANSFER_COMMISSION_RESET: return initialState; + default: { return state; } diff --git a/redux/types/WalletType.js b/redux/types/WalletType.js index 5436b5fa..ca200c1f 100644 --- a/redux/types/WalletType.js +++ b/redux/types/WalletType.js @@ -8,4 +8,5 @@ export const WALLET_HISTORY_ERROR = 'WALLET_HISTORY_ERROR'; export const WALLET_TRANSFER_COMMISSION_PENDING = 'WALLET_TRANSFER_COMMISSION_PENDING'; export const WALLET_TRANSFER_COMMISSION_SUCCESS = 'WALLET_TRANSFER_COMMISSION_SUCCESS'; -export const WALLET_TRANSFER_COMMISSION_ERROR = 'WALLET_TRANSFER_COMMISSION_ERROR'; \ No newline at end of file +export const WALLET_TRANSFER_COMMISSION_ERROR = 'WALLET_TRANSFER_COMMISSION_ERROR'; +export const WALLET_TRANSFER_COMMISSION_RESET = 'WALLET_TRANSFER_COMMISSION_RESET'; \ No newline at end of file diff --git a/screens/wallet/WalletDepot.js b/screens/wallet/WalletDepot.js index 1e3666ea..a808ae63 100644 --- a/screens/wallet/WalletDepot.js +++ b/screens/wallet/WalletDepot.js @@ -237,7 +237,7 @@ class WalletDepot extends Component { displayCardError: true }) } - this.setState({ isSubmitClick: true }) + this.setState({ isSubmitClick: !this.state.isSubmitClick }) } isHasError = () => { diff --git a/screens/wallet/WalletDetail.js b/screens/wallet/WalletDetail.js index a93846b8..b3ba0e01 100644 --- a/screens/wallet/WalletDetail.js +++ b/screens/wallet/WalletDetail.js @@ -15,7 +15,8 @@ import { Typography, FontWeight } from '../../config/typography'; import { responsiveHeight, responsiveWidth, } from 'react-native-responsive-dimensions'; import getWalletActivated from '../../webservice/WalletApi'; import getWalletTransactionHistory from '../../webservice/WalletTransactionHistoryApi'; -import transferCommissionAction from '../../webservice/WalletTransferCommission'; +import { transferCommissionAction } from '../../webservice/WalletTransferCommission'; +import { resetCommissionReducer } from '../../webservice/WalletTransferCommission'; import Dialog, { DialogContent, DialogTitle, DialogFooter, DialogButton } from 'react-native-popup-dialog'; import { baseUrl } from '../../webservice/IlinkConstants'; let moment = require('moment-timezone'); @@ -46,9 +47,11 @@ class WalletDetail extends Component { heightHeader: Utils.heightHeader(), isModalConfirmVisible: false, wallet: null, - triggerTransferCommission: false + triggerTransferCommission: false, + loading: false, }; + this.renderContent = null; slugify.extend({ '+': 'plus' }); this.scrollY = new Animated.Value(0); @@ -135,6 +138,16 @@ class WalletDetail extends Component { } } + componentWillReceiveProps(nextProps) { + if (nextProps.loading || nextProps.loadingTransferCommission) + this.setState({ + loading: true + }) + else + this.setState({ + loading: false + }) + } isEmptyObject = (obj) => { for (let prop in obj) { @@ -190,9 +203,8 @@ class WalletDetail extends Component { refresh = () => { const { agentId, wallet } = this.props.navigation.state.params; - if (typeof agentId !== "undefined") { + if (typeof agentId === "undefined") this.props.getWalletActivated(wallet.agentId); - } else this.props.getWalletActivated(agentId); } @@ -372,9 +384,9 @@ class WalletDetail extends Component { !this.isEmptyObject(wallet) ? (<> {this.state.triggerTransferCommission && this.renderDialogTransferCommissionResponse()} - {this.props.loading ? + {this.state.loading ? + style={{ position: "absolute", zIndex: 1, backgroundColor: "#00000050", width: this.state.loading ? responsiveWidth(100) : 0, height: this.state.loading ? responsiveHeight(100) : 0, flex: 1, justifyContent: 'center', alignItems: 'center' }}> {I18n.t("LOADING_DOTS")} : null } @@ -625,7 +637,7 @@ class WalletDetail extends Component { this.props.transferCommissionAction(this.state.wallet.id); this.refresh(); this.setState({ - triggerTransferCommission: !this.state.triggerTransferCommission + triggerTransferCommission: true }); } } @@ -638,35 +650,21 @@ class WalletDetail extends Component { renderDialogTransferCommissionResponse = () => { const { resultTransferCommission, errorTransferCommission } = this.props; + + console.log("resultTransferCommission", resultTransferCommission); + console.log("errorTransferCommission", errorTransferCommission); + if (errorTransferCommission !== null) { if (typeof errorTransferCommission.data !== 'undefined') { Alert.alert( - I18n.t("ERROR_LABLE"), - errorTransferCommission.data.error - , + I18n.t("ERROR_TRANSFER_COMMISSION"), + errorTransferCommission.data.error, [ { text: I18n.t("OK"), onPress: () => { - + this.props.resetCommissionReducer(); } } - - ], - { cancelable: false } - ) - } - else { - Alert.alert( - I18n.t("ERROR_LABLE"), - errorTransferCommission - , - [ - { - text: I18n.t("OK"), onPress: () => { - - } - } - ], { cancelable: false } ) @@ -677,11 +675,11 @@ class WalletDetail extends Component { if (resultTransferCommission.response !== null) { Alert.alert( I18n.t("SUCCESS"), - resultTransferCommission.response, + I18n.t("COMMISSION_TRANSFER_SUCCESS"), [ { text: I18n.t("OK"), onPress: () => { - + this.props.resetCommissionReducer(); } } @@ -692,21 +690,48 @@ class WalletDetail extends Component { } } - render() { - console.log('Wallet Detail props', this.props); + getWalletParam = () => { + const { result } = this.props; + const isHomeRootView = this.props.navigation.state.params.hasOwnProperty('agentId'); + + if (!isHomeRootView) + return this.props.navigation.state.params.wallet; + else + return this.props.response; + } + + render() { + console.log("THE PROPS", this.props); + const { resultTransaction, resultTransferCommission } = this.props; const isHomeRootView = this.props.navigation.state.params.hasOwnProperty('agentId'); - console.log("WALLET PARAMS", this.props.navigation.state.params.wallet); return ( - !isHomeRootView ? - this.renderDetailWallet(this.props.navigation.state.params.wallet) - : - ((this.props.loading || this.props.loadingTransferCommission) ? - this.renderLoader() : - ( - this.props.result !== null && - this.renderDetailWallet(this.props.result.response) - ) - ) + <> + { + !isHomeRootView ? ( + + (this.props.loading || this.props.loadingTransferCommission) ? + + this.renderDetailWallet(this.getWalletParam()) : ( + ((this.props.result !== null)) ? + + this.renderDetailWallet(this.props.result.response) : + + this.renderDetailWallet(this.props.navigation.state.params.wallet) + + ) + + ) : + ((this.props.loading || this.props.loadingTransferCommission) ? + this.renderLoader() : + ( + this.props.result !== null && + this.renderDetailWallet(this.props.result.response) + ) + ) + + } + + ); } } @@ -729,7 +754,8 @@ const mapStateToProps = state => ({ const mapDispatchToProps = dispatch => bindActionCreators({ getWalletActivated, getWalletTransactionHistory, - transferCommissionAction + transferCommissionAction, + resetCommissionReducer }, dispatch); export default connect(mapStateToProps, mapDispatchToProps)(WalletDetail); diff --git a/screens/wallet/WalletRetrait.js b/screens/wallet/WalletRetrait.js index c7f8b787..d173d97f 100644 --- a/screens/wallet/WalletRetrait.js +++ b/screens/wallet/WalletRetrait.js @@ -75,7 +75,6 @@ class WalletRetrait extends Component { } onCreditCardChange = (form) => { - console.log(form); this.setState({ creditCardInput: form, displayCardError: false @@ -174,7 +173,7 @@ class WalletRetrait extends Component { numCarte: parseInt((this.state.creditCardInput.values.number).replace(/ /g, ' ')), cvv: this.state.creditCardInput.values.cvc, expiration_date: this.state.creditCardInput.values.expiry, - type: "credit", + type: "debit", montant: this.state.montant, id_wallet: this.state.id }); @@ -223,6 +222,10 @@ class WalletRetrait extends Component { const { creditCardInput } = this.state; if (this.isMontantValid().isValid && creditCardInput.valid) { + + console.log("Is Montant Valid", this.isMontantValid.isValid); + console.log("creditCardInput Valid", creditCardInput.valid); + this.setState({ numCarte: parseInt((creditCardInput.values.number).replace(/ /g, ' ')), cvv: creditCardInput.values.cvc, diff --git a/utils/i18n/en.json b/utils/i18n/en.json index 87dc0662..9279d248 100644 --- a/utils/i18n/en.json +++ b/utils/i18n/en.json @@ -54,6 +54,7 @@ "DEMAND_SEND": "Demand send", "WITHDRAWAL_DESCRIPTION": "Make a withdrawal", "COMMISSION_ACCOUNT_TITLE": "Commission account", + "COMMISSION_TRANSFER_SUCCESS": "Commissions have been transferred to the main account", "CONFIRM": "Confirm", "CONFIRM_TRANSFER_COMMISSION": "Confirm commission transfer", "CREATION_DATE": "Creation date", @@ -138,6 +139,7 @@ }, "ERROR_FILTER": "Error occurred during the filter", "ERROR_LABLE": "Erreur", + "ERROR_TRANSFER_COMMISSION": "Commissions transfer error", "ERROR_FILTER_TEXT": "Problem encountered while filtering.", "YOUR_THERE": "You are here", "FILTER": "Filter", diff --git a/utils/i18n/fr.json b/utils/i18n/fr.json index 088bc6b3..93f1fec2 100644 --- a/utils/i18n/fr.json +++ b/utils/i18n/fr.json @@ -59,6 +59,7 @@ "CONFIRM": "Confirmer", "CONFIRM_TRANSFER_COMMISSION": "Confirmer le transfert des commissions", "PRINCIPAL_ACCOUNT_TITLE": "Cpt. principal", + "COMMISSION_TRANSFER_SUCCESS": "Les commissions ont été transférées vers le compte principal", "TRANSACTIONS": "Transactions", "TRANSACTION_HISTORY": "Historique des transactions", "WITHDRAWAL_TRANSACTION_HISTORY_DESCRIPTION": "Retrait de", @@ -140,6 +141,7 @@ }, "ERROR_FILTER": "Erreur survenue lors du filtre", "ERROR_LABLE": "Erreur", + "ERROR_TRANSFER_COMMISSION": "Erreur de transfert des commissions", "ERROR_FILTER_TEXT": "Probleme rencontré lors du filtrage.", "YOUR_THERE": "Vous êtes ici", "FILTER": "Filtrer", diff --git a/webservice/IlinkConstants.js b/webservice/IlinkConstants.js index b75b35b2..7f54844b 100644 --- a/webservice/IlinkConstants.js +++ b/webservice/IlinkConstants.js @@ -1,6 +1,6 @@ export const isDebugMode = false //base url test -//const baseUrl = "https://ilink-app.com/mobilebackendbeta" +//export const baseUrl = "https://ilink-app.com/mobilebackendbeta" //base url production //export const baseUrl = "https://ilink-app.com/mobilebackend"; //export const baseUrl = "https://test.ilink-app.com/mobilebackendtest"; diff --git a/webservice/WalletTransferCommission.js b/webservice/WalletTransferCommission.js index 355fb492..2fc1e870 100644 --- a/webservice/WalletTransferCommission.js +++ b/webservice/WalletTransferCommission.js @@ -2,9 +2,9 @@ import { transferCommission } from "./IlinkConstants"; import { store } from "../redux/store"; import axios from "axios"; -import { fetchWalletTransferCommissionPending, fetchWalletTransferCommissionSuccess, fetchWalletTransferCommssionError } from "../redux/actions/WalletActions"; +import { fetchWalletTransferCommissionPending, fetchWalletTransferCommissionSuccess, fetchWalletTransferCommssionError, walletTransferCommissionReset } from "../redux/actions/WalletActions"; -const transferCommissionAction = (walletID) => { +export const transferCommissionAction = (walletID) => { const auth = store.getState().authKeyReducer; const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : ''; @@ -36,4 +36,8 @@ const transferCommissionAction = (walletID) => { } } -export default transferCommissionAction; \ No newline at end of file +export const resetCommissionReducer = () => { + return dispatch => { + dispatch(walletTransferCommissionReset()); + } +}