407 lines
17 KiB
JavaScript
407 lines
17 KiB
JavaScript
|
/**
|
||
|
* 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 = () => (
|
||
|
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
|
||
|
{Platform.OS === 'android'
|
||
|
?
|
||
|
(
|
||
|
<>
|
||
|
<ProgressBarAndroid/>
|
||
|
<Text>{I18n.t('LOADING_DOTS')}</Text>
|
||
|
|
||
|
</>
|
||
|
) :
|
||
|
<>
|
||
|
<ActivityIndicator size="large" color={'#ccc'}/>
|
||
|
<Text>{I18n.t('LOADING_DOTS')}</Text>
|
||
|
</>
|
||
|
}
|
||
|
</View>
|
||
|
);
|
||
|
return (
|
||
|
<ScreenComponent>
|
||
|
<DropdownAlert ref={ref => (dropDownAlertRef = ref)}/>
|
||
|
<SpinnerOverlay show={getNetworkAct.loading} />
|
||
|
<KeyboardAvoidingView
|
||
|
behavior={Platform.OS === 'android' ? 'height' : 'padding'}
|
||
|
style={{flex: 1}}>
|
||
|
|
||
|
<ScrollView style={{flex: 1}}>
|
||
|
<Formik validationSchema={RegisterSchema}
|
||
|
initialValues={{
|
||
|
password: '',
|
||
|
code_acte: ''
|
||
|
}}
|
||
|
onSubmit={(values) => {
|
||
|
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 ?
|
||
|
<View style={styles.contain}>
|
||
|
<Animatable.View ref={(comp) => {
|
||
|
insurancesRef = comp
|
||
|
}}
|
||
|
style={{
|
||
|
width: responsiveWidth(90),
|
||
|
height: 60,
|
||
|
alignSelf: 'center',
|
||
|
borderRadius: 10,
|
||
|
paddingLeft: 20,
|
||
|
paddingRight: 20,
|
||
|
backgroundColor: 'white'
|
||
|
}}>
|
||
|
<Dropdown
|
||
|
label={I18n.t('SELECT_INSURANCE')}
|
||
|
data={insurances}
|
||
|
useNativeDriver={true}
|
||
|
onChangeText={(value, index, data) => {
|
||
|
console.log("Value", value);
|
||
|
setInsurance(value);
|
||
|
dispatch(fetchGetConsultationReset());
|
||
|
fetchGetNetworkActs(value.id, '', '&authorization_type=PRIOR')
|
||
|
}}
|
||
|
valueExtractor={(value) => {
|
||
|
return value
|
||
|
}}
|
||
|
labelExtractor={(value) => {
|
||
|
return value.name
|
||
|
}}
|
||
|
/>
|
||
|
</Animatable.View>
|
||
|
|
||
|
<Animatable.View ref={(comp) => {
|
||
|
codeActeRef = comp
|
||
|
}}
|
||
|
style={{
|
||
|
width: responsiveWidth(90),
|
||
|
height: 60,
|
||
|
alignSelf: 'center',
|
||
|
borderRadius: 10,
|
||
|
paddingLeft: 20,
|
||
|
marginTop: 10,
|
||
|
paddingRight: 20,
|
||
|
backgroundColor: 'white'
|
||
|
}}>
|
||
|
<Dropdown
|
||
|
label={I18n.t('CODE_ACTE')}
|
||
|
data={getNetworkAct.result !== null ? getNetworkAct.result?.response : []}
|
||
|
useNativeDriver={true}
|
||
|
onChangeText={(value, index, data) => {
|
||
|
setFieldTouched('code_acte');
|
||
|
setFieldValue('code_acte', value.id);
|
||
|
}}
|
||
|
valueExtractor={(value) => {
|
||
|
return value
|
||
|
}}
|
||
|
labelExtractor={(value) => {
|
||
|
return value.name
|
||
|
}}
|
||
|
/>
|
||
|
</Animatable.View>
|
||
|
|
||
|
<PasswordInput
|
||
|
style={{marginTop: 10}}
|
||
|
onChangeText={handleChange('password')}
|
||
|
placeholder={I18n.t('PASSWORD')}
|
||
|
secureTextEntry
|
||
|
icon={<FontAwesome name="lock" size={20}/>}
|
||
|
value={values.password}
|
||
|
onBlur={handleBlur('password')}
|
||
|
success={touched.password && !errors.password}
|
||
|
touched={touched.password}
|
||
|
error={errors.password}
|
||
|
/>
|
||
|
|
||
|
<Button
|
||
|
style={{marginTop: 20}}
|
||
|
full
|
||
|
loading={demandeAutorisationSoin.loading}
|
||
|
onPress={handleSubmit}>
|
||
|
{I18n.t('SUBMIT_LABEL')}
|
||
|
</Button>
|
||
|
</View>
|
||
|
: null}
|
||
|
</>)}
|
||
|
</Formik>
|
||
|
|
||
|
</ScrollView>
|
||
|
</KeyboardAvoidingView>
|
||
|
|
||
|
{/* {getConsultation.loading
|
||
|
? renderLoader()
|
||
|
: getConsultation.result !== null ?
|
||
|
(
|
||
|
<FlatList
|
||
|
style={{flex: 1}}
|
||
|
ListEmptyComponent={() => {
|
||
|
return (
|
||
|
<Text>{I18n.t('NO_CONSULTATION_DEMAND')}</Text>
|
||
|
)
|
||
|
}}
|
||
|
data={[]}
|
||
|
keyExtractor={(item, index) => item.id}
|
||
|
renderItem={({item, index}) => (
|
||
|
renderItem(item)
|
||
|
)}
|
||
|
/>
|
||
|
)
|
||
|
: null}*/}
|
||
|
</ScreenComponent>
|
||
|
)
|
||
|
};
|
||
|
|
||
|
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,
|
||
|
},
|
||
|
});
|