/** * 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, 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, fetchDemaneAutorisationSoin, fetchDemaneAutorisationSoinReset, fetchGetConsultation, fetchGetConsultationReset, fetchGetListInsurance, fetchGetListInsuranceReset, 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 {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"; let moment = require('moment-timezone'); const {width, height} = Dimensions.get('window'); const DemandeAutorisationSoinScreen = ({ navigation, fetchGetNetworkActs, fetchAcceptRejectConsultation, fetchGetListInsurance, 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 [insurance, setInsurance] = useState(null); let insurancesRef = null; let codeActeRef = null; 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); fetchGetListInsurance(user.country_id, `&user_id=${user.id}`); //fetchGetConsultation(user.id, 'ACCEPTED', ''); }); //fetchGetNetworkActs(wallet.idNetwork, '', '&authorization_type=PRIOR'); }, []); useEffect(() => { if (getConsultation.error) { dropDownAlertRef.alertWithType( 'error', I18n.t('ERROR_LABEL'), Utils.getErrorMsg(getConsultation), ); dispatch(fetchGetConsultationReset()); } }, [getConsultation]); useEffect(() => { if (insuranceList.result !== null) { let insuranceListTemp = []; insuranceList.result.response.map((insuranceItem, index) => { insuranceListTemp.push(insuranceItem); }); setInsurances(insuranceListTemp); } if (insuranceList.error) { 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) { 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')} } ); 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, user_id: user.id, 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); dispatch(fetchGetConsultationReset()); fetchGetNetworkActs(value.id, '', '&authorization_type=PRIOR') }} valueExtractor={(value) => { return value }} labelExtractor={(value) => { return value.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); }} 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} )} {/* {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, fetchGetListInsurance, 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, }, });