/** * Project iLinkWorld * File DemandeAutorisationSoinScreen * Path screens/wallet/user * Created by BRICE ZELE * Date: 01/02/2022 */ import React, {useEffect, useState} from 'react'; import { ActivityIndicator, Alert, Dimensions, FlatList, KeyboardAvoidingView, Platform, ProgressBarAndroid, ScrollView, StyleSheet, TouchableOpacity, View, } from 'react-native'; import {connect, useDispatch} from 'react-redux'; import {Color} from "../../../config/Color"; import I18n from 'react-native-i18n'; import {ScreenComponent} from "../../../components/ScreenComponent"; import { fetchAcceptRejectConsultation, fetchAcceptRejectConsultationReset, fetchActivePaySubscription, fetchDeleteBeneficiaryReset, fetchDemaneAutorisationSoin, fetchDemaneAutorisationSoinReset, fetchGetConsultation, fetchGetConsultationReset, fetchGetListInsurance, fetchGetListInsuranceReset, fetchGetListInsuranceWithBeneficiaries, fetchGetNetworkActs } from "../../../redux/insurance/insurance.actions"; import DropdownAlert from "react-native-dropdownalert"; import {createStructuredSelector} from "reselect"; import { selectAcceptRefuseConsultation, selectActivatePaySubscription, selectDemandeAutorisationSoin, selectGetConsultation, selectGetNetworkAct, selectInsuranceList, selectSubscriptionList } from "../../../redux/insurance/insurance.selector"; import {readUser} from "../../../webservice/AuthApi"; import Text from '../../../components/Text'; import * as Utils from "../../../utils/UtilsFunction"; import {displayToast, uppercaseFirstLetter} from "../../../utils/UtilsFunction"; import Dialog from "react-native-dialog"; import {Typography} from "../../../config/typography"; import {store} from "../../../redux/store"; import {Formik} from "formik"; import * as Animatable from "react-native-animatable"; import {responsiveWidth} from "react-native-responsive-dimensions"; import {Dropdown} from "react-native-material-dropdown"; import PasswordInput from "../../../components/PasswordInput"; import FontAwesome from "react-native-vector-icons/FontAwesome"; import Button from "../../../components/Button"; import * as Yup from "yup"; import SpinnerOverlay from "../../../components/SpinnerOverlayComponent"; import Modal from "react-native-modal"; let moment = require('moment-timezone'); const {width, height} = Dimensions.get('window'); const DemandeAutorisationSoinScreen = ({ navigation, fetchGetNetworkActs, fetchAcceptRejectConsultation, fetchGetListInsuranceWithBeneficiaries, fetchDemaneAutorisationSoin, getConsultation, insuranceList, getNetworkAct, demandeAutorisationSoin }) => { const dispatch = useDispatch(); const [user, setUser] = useState(null); const [displayModalHistory, setDisplayModalHistory] = useState(false); const [historyItemDetail, setHistoryItemDetail] = useState({}); const [wallet] = useState(store.getState().walletDetailReducer.result.response); const [insurances, setInsurances] = useState([]); const [beneficiaries, setBeneficiaries] = useState([]); const [beneficiaryId, setBeneficiaryId] = useState(null); const [insurance, setInsurance] = useState(null); let insurancesRef = null; let codeActeRef = null; const [modalListAssure, setModalListAssure] = useState(false); let dropDownAlertRef: any = null; const RegisterSchema = Yup.object().shape({ password: Yup.string() .required(I18n.t('THIS_FIELD_IS_REQUIRED')) }); useEffect(() => { dispatch(fetchGetConsultationReset()); dispatch(fetchGetListInsuranceReset()); dispatch(fetchAcceptRejectConsultationReset()); readUser().then((user) => { setUser(user); console.log("User", user); fetchGetListInsuranceWithBeneficiaries(`?user_id=${user.id}`); //fetchGetConsultation(user.id, 'ACCEPTED', ''); }); //fetchGetNetworkActs(wallet.idNetwork, '', '&authorization_type=PRIOR'); }, []); useEffect(() => { if (getConsultation.error) { Alert.alert( I18n.t("ERROR_LABLE"), Utils.getErrorMsg(getConsultation), [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchGetConsultationReset()); } } ], { cancelable: false } ); /* dropDownAlertRef.alertWithType( 'error', I18n.t('ERROR_LABEL'), Utils.getErrorMsg(getConsultation), ); dispatch(fetchGetConsultationReset());*/ } }, [getConsultation]); useEffect(() => { if (insuranceList.result !== null) { let insuranceListTemp = []; let beneficiariesListTemp = []; insuranceList.result.response.map((insuranceItem, index) => { insuranceListTemp.push(insuranceItem.network); }); setInsurances(insuranceListTemp); console.log("beneficiariesListTemp",beneficiariesListTemp); } if (insuranceList.error) { Alert.alert( I18n.t("ERROR_LABLE"), Utils.getErrorMsg(insuranceList), [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchGetListInsuranceReset()); } } ], { cancelable: false } ); /* dropDownAlertRef.alertWithType( 'error', I18n.t('ERROR_LABEL'), Utils.getErrorMsg(insuranceList), ); dispatch(fetchGetListInsuranceReset());*/ } }, [insuranceList]); useEffect(() => { if (demandeAutorisationSoin.result !== null) { Alert.alert( I18n.t("SUCCESS"), demandeAutorisationSoin.result.response, [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchDemaneAutorisationSoinReset()); navigation.goBack(); } } ], {cancelable: false} ); } if (demandeAutorisationSoin.error) { Alert.alert( I18n.t("ERROR_LABLE"), Utils.getErrorMsg(demandeAutorisationSoin), [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchDemaneAutorisationSoinReset()); } } ], { cancelable: false } ); /* dropDownAlertRef.alertWithType( 'error', I18n.t('ERROR_LABEL'), Utils.getErrorMsg(demandeAutorisationSoin), ); dispatch(fetchDemaneAutorisationSoinReset());*/ } }, [demandeAutorisationSoin]); const renderLoader = () => ( {Platform.OS === 'android' ? ( <> {I18n.t('LOADING_DOTS')} ) : <> {I18n.t('LOADING_DOTS')} } ); const renderListAssure = () => ( { setModalListAssure(false); }} swipeDirection={['down']} style={styles.bottomModal}> {I18n.t('LIST_ASSURE')} {I18n.t('NO_ASSURE')}} keyExtractor={(item, index) => index} renderItem={({item, index}) => { return ( { if(item.id === user.id) setBeneficiaryId(null); else setBeneficiaryId(item.id); setModalListAssure(false); }}> {`${item.firstname} ${item.lastname} ${item.id === user.id ? '('+I18n.t('MY_ACCOUNT')+')' : ''}`} ) }}/> ); return ( (dropDownAlertRef = ref)}/> { if (user !== null) { if (insurance === null) { insurancesRef.shake(800); } else if (values.code_acte === '') codeActeRef.shake(200) else { fetchDemaneAutorisationSoin({ act_id: values.code_acte, insurance_id: insurance.id, beneficiary_id: beneficiaryId, password: values.password }); console.log(user); console.log("insurance", insurance); } } }}> {({ values, errors, touched, handleChange, handleBlur, setFieldValue, setFieldTouched, handleSubmit, isSubmitting, }) => (<> { insuranceList.loading ? renderLoader() : insuranceList.result ? { insurancesRef = comp }} style={{ width: responsiveWidth(90), height: 60, alignSelf: 'center', borderRadius: 10, paddingLeft: 20, paddingRight: 20, backgroundColor: 'white' }}> { console.log("Value", value); setInsurance(value); setBeneficiaries([...value.beneficiaries, {id: user.id, firstname: user.firstname, lastname: user.lastname}]); fetchGetNetworkActs(value.network.id, '', '&authorization_type=PRIOR') }} valueExtractor={(value) => { return value }} labelExtractor={(value) => { return value.network.name }} /> { codeActeRef = comp }} style={{ width: responsiveWidth(90), height: 60, alignSelf: 'center', borderRadius: 10, paddingLeft: 20, marginTop: 10, paddingRight: 20, backgroundColor: 'white' }}> { setFieldTouched('code_acte'); setFieldValue('code_acte', value.id); setModalListAssure(true); }} valueExtractor={(value) => { return value }} labelExtractor={(value) => { return value.name }} /> } value={values.password} onBlur={handleBlur('password')} success={touched.password && !errors.password} touched={touched.password} error={errors.password} /> : null} )} {modalListAssure && renderListAssure()} {/* {getConsultation.loading ? renderLoader() : getConsultation.result !== null ? ( { return ( {I18n.t('NO_CONSULTATION_DEMAND')} ) }} data={[]} keyExtractor={(item, index) => item.id} renderItem={({item, index}) => ( renderItem(item) )} /> ) : null}*/} ) }; const mapStateToProps = createStructuredSelector({ subscriptionList: selectSubscriptionList, insuranceList: selectInsuranceList, activatePaySubscription: selectActivatePaySubscription, getConsultation: selectGetConsultation, getNetworkAct: selectGetNetworkAct, demandeAutorisationSoin: selectDemandeAutorisationSoin }); export default connect(mapStateToProps, { fetchActivePaySubscription, fetchGetNetworkActs, fetchAcceptRejectConsultation, fetchGetListInsuranceWithBeneficiaries, fetchDemaneAutorisationSoin })( DemandeAutorisationSoinScreen, ); const styles = StyleSheet.create({ textInput: { height: 46, backgroundColor: Color.fieldColor, borderRadius: 5, marginTop: 10, padding: 10, width: '100%', }, lineRow: { flexDirection: 'row', justifyContent: 'space-between', paddingBottom: 20, }, contain: { marginTop: 20, paddingBottom: 20, paddingLeft: 10, paddingRight: 10, flex: 1, }, content: { padding: 10, marginBottom: 10, borderRadius: 8 }, contentTop: { flexDirection: "row", paddingBottom: 10, borderBottomWidth: 1 }, contentBottom: { flexDirection: "row", marginTop: 10, justifyContent: "space-between" }, bottomLeft: {flexDirection: "row", alignItems: "center"}, image: {width: 32, height: 32, marginRight: 10, borderRadius: 16}, blockView: { paddingVertical: 10, borderBottomWidth: 0.5, }, ineSeparator: { borderWidth: 1, width: '40%', height: 1, alignSelf: 'center', }, line: { width: 1, height: 14, backgroundColor: Color.grayColor, marginLeft: 10, }, contentModeView: { width: 30, height: '100%', alignItems: 'flex-end', justifyContent: 'center', }, contentFilter: { flexDirection: 'row', alignItems: 'center', marginLeft: 10, }, bottomModal: { justifyContent: 'flex-end', margin: 0, }, contentFilterBottom: { width: "100%", borderTopLeftRadius: 8, borderTopRightRadius: 8, paddingHorizontal: 20 }, contentSwipeDown: { paddingTop: 10, alignItems: 'center', }, lineSwipeDown: { width: 30, height: 2.5, backgroundColor: Color.dividerColor, }, contentActionModalBottom: { flexDirection: "row", paddingVertical: 10, marginBottom: 10, justifyContent: "space-between", borderBottomWidth: 1 }, containModal: { paddingVertical: 10, paddingHorizontal: 20, flexDirection: 'row', justifyContent: 'space-between', }, });