import React, {Component} from 'react' import {Alert, Platform, ProgressBarAndroid, ScrollView, StyleSheet, Text, TouchableOpacity, View} from 'react-native' import Button from 'apsl-react-native-button' import {responsiveHeight, responsiveWidth} from 'react-native-responsive-dimensions' import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {readUser} from "../../../webservice/AuthApi"; import I18n from "react-native-i18n"; import {creditDemandResetReducer, treatCreditDemand} from '../../../webservice/CreditTreatDemandApi'; import {creditCancelResetReducer, treatCancelDemand} from '../../../webservice/CreditCancelDemandeApi'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; import Toast from 'react-native-root-toast'; import {Color} from '../../../config/Color' import isNil from 'lodash/isNil'; import isEqual from 'lodash/isEqual'; import _ from "lodash"; import {getNanoCreditUniqueDemandsAction, getNanoCreditUniqueDemandsReset} from '../../../webservice/user/NanoCreditApi' import {cancelDemandGroupAction, treatDemandGroupAction, treatDemandGroupReset} from '../../../webservice/NanoCreditApi' import * as Animatable from "react-native-animatable"; import {Dropdown} from "react-native-material-dropdown-v2"; import {Fumi} from "react-native-textinput-effects"; import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"; import {modifyAvisImpositionReset, modifyvisImpositionAction} from "../../../webservice/regisseur/WalletRegisseurApi"; let typesta = 0 let moment = require('moment-timezone') var colorback = 'white' let theme = require('../../../utils/theme.json'); const route = require("../../../route.json"); class AvisImpositionDetail extends Component { static navigatorStyle = { navBarBackgroundColor: theme.accentLight, statusBarColor: theme.accent, navBarTextColor: '#FFFFFF', navBarButtonColor: '#FFFFFF', }; static navigationOptions = ({navigation}) => { return { drawerLabel: () => null, title: I18n.t('AVIS_IMPOSITION') + ' N°' + navigation.getParam("item", "-").id_tax_notice, headerTintColor: 'white', headerStyle: { backgroundColor: Color.primaryColor, marginTop: 20, color: 'white' }, headerTitleStyle: { color: "white" }, } }; constructor(props) { super(props); this.state = { displayAmountModifyDialog: false, /* statut: sta, */ user: null, networks: [], loadingTreat: false, loadingCancel: false, triggerTreatmentClick: false, triggerCancelClick: false, color: colorback, montant: null, isBtnModifyAmountEnabled: false, id: this.props.navigation.getParam("id", null), item: this.props.navigation.getParam("item", null), tabTaxe: [0], taxes_selected: [], taxes: [], isTaxesLoaded: false, password: null, assign_network: false }; console.log("STATE", this.state); this.currentLocale = I18n.locale.includes("fr") ? "fr" : "en-gb"; this.props.modifyAvisImpositionReset(); moment.locale(this.currentLocale); } componentDidMount() { if (!this.state.isTaxesLoaded) { let taxesTemp = new Array(); this.state.item.taxes.map((taxes, index) => { taxesTemp.push(taxes); }); this.setState({ taxes: taxesTemp, isTaxesLoaded: true }); } readUser().then((user) => { if (user) { if (user !== undefined) { this.setState({user}); } } }); } displayToast = (message) => { Toast.show(message, { duration: Toast.durations.LONG, 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. } }); } ckeckIfFieldIsOK(champ) { return (isNil(champ) || isEqual(champ.length, 0)); } renderModifyResponse = () => { const {errorModifyAvis, resultModifyAvis, resultCancelDemand, errorCancelDemand} = this.props; if (errorModifyAvis !== null) { if (typeof errorModifyAvis.data !== 'undefined') { Alert.alert( I18n.t("ERROR_TREATMENT_DEMAND"), errorModifyAvis.data.error, [ { text: I18n.t("OK"), onPress: () => { this.props.modifyAvisImpositionReset(); } } ], {cancelable: false} ); } } if (resultModifyAvis !== null) { console.log("resultModifyAvis", resultModifyAvis); if (resultModifyAvis.status === 200) { Alert.alert( I18n.t("SUCCESS"), I18n.t("AVIS_MODIFY_SUCCESS"), [ { text: I18n.t("OK"), onPress: () => { this.props.navigation.goBack(); this.props.modifyAvisImpositionReset(); } } ], {cancelable: false} ); } } } renderLabelState = (state) => { if (state === 0) return I18n.t('NO_TREAT') else if (state === 1) return I18n.t('TREAT') else return I18n.t('REFUSED') } renderLoader = () => { return ( {Platform.OS === 'android' ? ( <> {I18n.t('LOADING_DOTS')} ) : <> {I18n.t('LOADING_DOTS')} } ) } renderTaxesDropdown = (item, index) => { return ( <> { return value }} value={item.name} labelExtractor={(value) => { return value.name }} /> { item.required_tax === 0 && this.state.item.is_company === 0 && { Alert.alert( I18n.t("TITLE_SUPPRESS_CONFIRM"), I18n.t("TEXT_SUPPRESS_CONFIRM_TAXE"), [ { text: I18n.t("SUBMIT_LABEL"), onPress: () => { let itemState = this.state.item; let taxes = _.pull(itemState.taxes, item); let taxesState = _.pull(this.state.taxes, item); itemState.taxes = taxes; this.setState({ item: itemState, taxes: taxesState }); } }, { text: I18n.t("CANCEL_LABEL") } ], {cancelable: false} ); }} activeOpacity={0.9}> } { item.measurement_unit !== "forfait" && <> { let tax_units_count = this.state.taxes; tax_units_count[index].tax_units_count = value; this.setState({taxes: tax_units_count}); }} > { item.labels.length === 2 && { let units_per_tax_unit_count = this.state.taxes; units_per_tax_unit_count[index].units_per_tax_unit_count = value; this.setState({taxes: units_per_tax_unit_count}); }} > } } { item.billing_period === 'jour' && ( { let units_per_tax_unit_count = this.state.taxes; units_per_tax_unit_count[index].number_of_days = value; this.setState({taxes: units_per_tax_unit_count}); }} style={styles.input} > ) } ) } renderDetail = () => { const {resultGetUniqueDemand} = this.props; const {item} = this.state; let created_at = moment.tz(item.created_at, moment.tz.guess()).format(); let updated_at = moment.tz(item.updated_at, moment.tz.guess()).format(); created_at = moment(created_at); updated_at = moment(updated_at); return ( {I18n.t('AGENT_INFORMATION')} {`${item.lastname} | ${item.email}`} {`${item.email} | ${item.phone}`} {`${item.adresse}`} {/* {`${I18n.t('CODE_PARRAIN')}: ${item.code_parrain}`} */} {I18n.t('TAXES')} {`${this.state.item.amount}`} {`${I18n.t('CREATION_DATE')}: ${created_at.format(" Do MMMM YYYY à HH:mm")}`} {`${I18n.t('UPDATE_DATE')}: ${updated_at.format(" Do MMMM YYYY à HH:mm")}`} { item.taxes.map((element, index) => ( this.renderTaxesDropdown(element, index) )) } { this.passwordAnim = comp }}> { this.setState({password}) }} style={styles.input} > { this.state.item.is_company === 0 && } ); } onSubmitModificationAvisImposition = () => { const {password, item, taxes, assign_network} = this.state; if (this.ckeckIfFieldIsOK(password)) { this.passwordAnim.shake(200); } else { let dataToSubmit = { id_agent: parseInt(this.state.user.agentId), password: password, id_tax_notice: item.id, taxes: taxes, assign_network: false } this.props.modifyvisImpositionAction(dataToSubmit); } } render() { return ( <> {this.renderModifyResponse()} {(this.state.triggerTreatmentClick || this.state.triggerCancelClick) && this.renderModifyResponse()} { this.renderDetail() } ); } } const mapStateToProps = state => ({ loadingGetUniqueDemand: state.getUniqueDemandsGroupReducer.loading, resultGetUniqueDemand: state.getUniqueDemandsGroupReducer.result, errorGetUniqueDemand: state.getUniqueDemandsGroupReducer.error, loadingModifyAvis: state.modifyAvisImpositionReducer.loading, resultModifyAvis: state.modifyAvisImpositionReducer.result, errorModifyAvis: state.modifyAvisImpositionReducer.error, }); const mapDispatchToProps = dispatch => bindActionCreators({ getNanoCreditUniqueDemandsAction: getNanoCreditUniqueDemandsAction, getNanoCreditUniqueDemandsReset: getNanoCreditUniqueDemandsReset, treatDemandGroupAction: treatDemandGroupAction, cancelDemandGroupAction: cancelDemandGroupAction, treatDemandGroupReset: treatDemandGroupReset, treatCreditDemand: treatCreditDemand, creditDemandResetReducer: creditDemandResetReducer, treatCancelDemand: treatCancelDemand, creditCancelResetReducer: creditCancelResetReducer, modifyvisImpositionAction, modifyAvisImpositionReset }, dispatch); export default connect(mapStateToProps, mapDispatchToProps)(AvisImpositionDetail); 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 }, input: { height: 60, marginTop: responsiveHeight(2), marginLeft: responsiveWidth(5), marginRight: responsiveWidth(5), borderRadius: 5, borderWidth: 1 }, cardcontainer1: { justifyContent: 'space-evenly', flex: 2, marginRight: 3, marginLeft: 3, }, cardcontainer: { margin: 3, marginTop: 25 }, checkboxContainer: { flexDirection: "row", marginBottom: 20, }, checkbox: { alignSelf: "center", color: "white" }, })