486 lines
22 KiB
JavaScript
486 lines
22 KiB
JavaScript
import React, { Component } from 'react';
|
|
import { Alert, StyleSheet, Text, View, Image, ScrollView, Platform, ProgressBarAndroid, PermissionsAndroid, Keyboard } from 'react-native';
|
|
import PropTypes from 'prop-types';
|
|
import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
|
|
import Ionicons from 'react-native-vector-icons/Ionicons';
|
|
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
import { responsiveHeight, responsiveWidth, responsiveFontSize } from 'react-native-responsive-dimensions';
|
|
import { Fumi, Kaede } from 'react-native-textinput-effects'
|
|
import * as Animatable from 'react-native-animatable';
|
|
import Button from 'apsl-react-native-button';
|
|
let theme = require('./../../utils/theme.json');
|
|
let route = require('./../../route.json');
|
|
import I18n from 'react-native-i18n';
|
|
import isEqual from 'lodash/isEqual';
|
|
import { Color } from '../../config/Color';
|
|
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
import { Dropdown } from 'react-native-material-dropdown';
|
|
import { getPositionInformation } from './../../webservice/MapService';
|
|
import { getCountryNetwork, createGeolocatedAccount, createUserAccount, getTownInformationName, getListCountriesActive, getCodeInformation, readUser } from './../../webservice/AuthApi';
|
|
import { SinglePickerMaterialDialog, MultiPickerMaterialDialog, MaterialDialog } from "react-native-material-dialog";
|
|
import Geolocation from 'react-native-geolocation-service';
|
|
import { identityPieces } from '../../utils/UtilsFunction';
|
|
const GEOLOCATION_OPTIONS = { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000, useSignificantChanges: true };
|
|
const moment = require('moment');
|
|
|
|
export default class CreateIdentification extends Component {
|
|
static navigatorStyle = {
|
|
navBarBackgroundColor: Color.primaryColor,
|
|
statusBarColor: Color.primaryDarkColor,
|
|
navBarTextColor: '#FFFFFF',
|
|
navBarButtonColor: '#FFFFFF'
|
|
|
|
};
|
|
|
|
static navigationOptions = () => {
|
|
return {
|
|
drawerLabel: () => null,
|
|
headerTitle: I18n.t('CREATION_IDENTIFICATION_DESCRIPTION'),
|
|
headerTintColor: 'white',
|
|
headerStyle: {
|
|
backgroundColor: Color.primaryColor,
|
|
marginTop: 0,
|
|
color: 'white'
|
|
},
|
|
headerTitleStyle: {
|
|
color: "white"
|
|
},
|
|
title: I18n.t('CREATION_IDENTIFICATION_DESCRIPTION')
|
|
}
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
password: null,
|
|
enterPhone: null,
|
|
numeroIdentite: null,
|
|
nameanim: null,
|
|
dateNaissance: new Date(),
|
|
dateExpiration: new Date(),
|
|
networksinglePickerVisible: false,
|
|
passwordanim: null,
|
|
confirmpassanim: null,
|
|
isLoging: false,
|
|
countries: [],
|
|
town: [],
|
|
identityPieces: identityPieces(),
|
|
identityPiecesName: (identityPieces()[0]).name,
|
|
snackVisible: false,
|
|
snackText: '',
|
|
disableNetwork: false,
|
|
networks: [],
|
|
showPickerDateNaissance: false,
|
|
showPickerDateExpiration: false,
|
|
modalVisible: true,
|
|
select_network: I18n.t("SELECT_NETWORK"),
|
|
user: null
|
|
};
|
|
this.dateNaissanceRef = null;
|
|
this.surnameanim = null;
|
|
this.dateNaissanceFumiProps = {};
|
|
this.dateExpirationFumiProps = {};
|
|
}
|
|
|
|
componentDidMount() {
|
|
readUser().then((user) => {
|
|
if (user) {
|
|
if (user !== undefined) {
|
|
this.setState({ user });
|
|
}
|
|
}
|
|
});
|
|
if (Platform.OS === 'android') {
|
|
this.requestCameraPermission();
|
|
} else {
|
|
this.watchLocation();
|
|
}
|
|
}
|
|
|
|
componentWillUpdate(nextProps, nextState) {
|
|
if (this.state.showPickerDateNaissance)
|
|
this.dateNaissanceFumiProps.value = moment(nextState.dateNaissance).format('DD-MM-YYYY');
|
|
if (this.state.showPickerDateExpiration)
|
|
this.dateExpirationFumiProps.value = moment(nextState.dateExpiration).format('DD-MM-YYYY');
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.mounted = false;
|
|
if (this.watchID) Geolocation.clearWatch(this.watchID);
|
|
}
|
|
|
|
showErrorDialog() {
|
|
this.setState({ modalDialog: false })
|
|
Aler.alert("Une erreur est survenue", "Impossible de récuperer des informations du pays verifier que votre gps est activé," +
|
|
"et que vous êtes connecté à internet puis ressayer", [{
|
|
text: "Recommencer", onPress: () => {
|
|
this.watchLocation()
|
|
}
|
|
}, { text: "Annuler", onPress: () => { this.props.navigation.popToTop() } }])
|
|
}
|
|
|
|
async watchLocation() {
|
|
Geolocation.getCurrentPosition((position) => {
|
|
this.treatPosition(position)
|
|
}, (e) => {
|
|
this.showErrorDialog()
|
|
}, this.props.geolocationOptions);
|
|
if (!this.watchID) {
|
|
Geolocation.watchPosition((position) => { this.treatPosition(position) }, (e) => { this.showErrorDialog() }, this.props.geolocationOptions)
|
|
}
|
|
}
|
|
|
|
async requestCameraPermission() {
|
|
try {
|
|
const granted = await PermissionsAndroid.request(
|
|
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
|
|
{
|
|
'title': 'Cool Photo App Camera Permission',
|
|
'message': 'Cool Photo App needs access to your camera ' +
|
|
'so you can take awesome pictures.'
|
|
}
|
|
)
|
|
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
|
this.watchLocation();
|
|
} else {
|
|
this.setState({ modalDialog: false })
|
|
Alert.alert("Echec à l'autorisation",
|
|
"L'application n'est pas autorisé à acceder à votre position veuillez verifier que votre GPS est activé et configurer en mode Haute Precision",
|
|
[{
|
|
text: "Ok", onPress: () => {
|
|
this.props.navigation.popToTop()
|
|
}
|
|
}])
|
|
}
|
|
} catch (err) {
|
|
this.setState({ modalDialog: false })
|
|
Alert.alert("Une erreur est Survenue",
|
|
"Une erreur est survenu lors du demarrage de l'application veuillez relancer l'application",
|
|
[{
|
|
text: "Ok", onPress: () => {
|
|
BackHandler.exitApp()
|
|
}
|
|
}])
|
|
}
|
|
}
|
|
|
|
treatPosition(position) {
|
|
const myLastPosition = this.state.myPosition;
|
|
const myPosition = position.coords;
|
|
|
|
if (!isEqual(myPosition, myLastPosition)) {
|
|
getPositionInformation(myPosition).then((response) => {
|
|
if (response.results !== undefined) {
|
|
if (response.results.length > 0) {
|
|
let most = response.results[0]
|
|
let { address_components, formatted_address, place_id } = most
|
|
this.setState({ address: address_components, textadress: formatted_address, place: place_id })
|
|
|
|
let results = response.results;
|
|
let shortcountry;
|
|
let mcountry;
|
|
for (let i = 0; i < results[0].address_components.length; i++) {
|
|
for (let j = 0; j < results[0].address_components[i].types.length; j++) {
|
|
if (results[0].address_components[i].types[j] === "country") {
|
|
mcountry = results[0].address_components[i];
|
|
shortcountry = mcountry.short_name;
|
|
this.setState({ shortCountry: mcountry.short_name, longCountry: mcountry.long_name })
|
|
} else if (results[0].address_components[i].types[j] === "locality") {
|
|
const name = results[0].address_components[i].short_name;
|
|
this.setState({ townName: name });
|
|
getTownInformationName(name).then((result) => {
|
|
let town = null;
|
|
if (result instanceof Array) {
|
|
town = result[0];
|
|
} else
|
|
town = result;
|
|
|
|
this.setState({ modalVisible: false, town: new Array(town) });
|
|
})
|
|
}
|
|
}
|
|
}
|
|
getListCountriesActive().then((cnt) => {
|
|
this.setState({ countries: cnt })
|
|
console.debug(cnt, shortcountry);
|
|
var found = false
|
|
for (let i of cnt) {
|
|
if (i.code_country === shortcountry) {
|
|
found = true;
|
|
this.setState({ modalVisible: false, indicatif: i.code_dial, country: i.name })
|
|
/* this.getNetworks(i.code_dial); */
|
|
}
|
|
}
|
|
if (!found) {
|
|
Alert.alert("Impossible de recupérer vos informations", "Nous n'avons pas pu recuperer les informations de votre pays veuillez contacter les administrateurs", [{ text: "OK" }]);
|
|
|
|
}
|
|
})
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}).catch((e) => {
|
|
this.showErrorDialog()
|
|
});
|
|
this.setState({ myPosition: myPosition });
|
|
/* if (this.mapRef !== undefined && this.mapRef !== null) {
|
|
this.mapRef.animateToCoordinate({
|
|
latitude: myPosition.latitude,
|
|
longitude: myPosition.longitude
|
|
}, 1000);
|
|
this.mapRef.animateToRegion({
|
|
latitude: myPosition.latitude,
|
|
longitude: myPosition.longitude,
|
|
latitudeDelta: 0.03,
|
|
longitudeDelta: 0.01,
|
|
}, 1000)
|
|
} */
|
|
}
|
|
|
|
}
|
|
|
|
onChangeDateNaissance = (event, selectedDate) => {
|
|
const currentDate = selectedDate || this.state.dateNaissance;
|
|
this.setState({
|
|
showPickerDateNaissance: Platform.OS === 'ios' || false,
|
|
dateNaissance: currentDate,
|
|
});
|
|
};
|
|
|
|
onChangeDateExpiration = (event, selectedDate) => {
|
|
const currentDate = selectedDate || this.state.dateExpiration;
|
|
this.setState({
|
|
showPickerDateExpiration: Platform.OS === 'ios' || false,
|
|
dateExpiration: currentDate,
|
|
});
|
|
};
|
|
|
|
renderLoaderModal() {
|
|
return (<MaterialDialog
|
|
visible={this.state.modalVisible}
|
|
title={I18n.t("LOADING_INFO")}
|
|
>
|
|
<View style={{ justifyContent: 'center', alignItems: 'center' }}>
|
|
<Text>{I18n.t("LOADING_DESCRIPTION_COUNTRY")}</Text>
|
|
<ProgressBarAndroid />
|
|
</View>
|
|
</MaterialDialog>)
|
|
}
|
|
|
|
renderDateNaissancePicker = () => {
|
|
return (
|
|
<DateTimePicker
|
|
testID="dateTimePicker"
|
|
timeZoneOffsetInMinutes={0}
|
|
is24Hour={true}
|
|
value={this.state.dateNaissance}
|
|
mode='date'
|
|
maximumDate={new Date()}
|
|
display="spinner"
|
|
onChange={this.onChangeDateNaissance}
|
|
/>
|
|
);
|
|
}
|
|
|
|
renderDateExpirationPicker = () => {
|
|
return (
|
|
<DateTimePicker
|
|
testID="dateTimePicker"
|
|
timeZoneOffsetInMinutes={0}
|
|
is24Hour={true}
|
|
value={this.state.dateExpiration}
|
|
mode='date'
|
|
maximumDate={new Date(2300, 10, 20)}
|
|
display="spinner"
|
|
onChange={this.onChangeDateExpiration}
|
|
/>
|
|
);
|
|
}
|
|
|
|
render() {
|
|
console.log("STATE", this.state);
|
|
const { showPickerDateNaissance } = this.state;
|
|
return (
|
|
<>
|
|
{this.state.showPickerDateNaissance && this.renderDateNaissancePicker()}
|
|
{this.state.showPickerDateExpiration && this.renderDateExpirationPicker()}
|
|
{this.state.modalVisible && this.renderLoaderModal()}
|
|
<ScrollView style={styles.container}>
|
|
<Text style={styles.subbigtitle}>{I18n.t('CREATE_IDENTIFICATION_TITLE')}</Text>
|
|
<Animatable.View ref={(comp) => { this.nameanim = comp }}>
|
|
<Fumi iconClass={FontAwesomeIcon} iconName={'user'}
|
|
label={`${I18n.t('NAME')} ${I18n.t('AND')} ${I18n.t('FIRSTNAME')}`}
|
|
iconColor={'#f95a25'}
|
|
iconSize={20}
|
|
onChangeText={(text) => {
|
|
let use = this.state.user;
|
|
use.lastname = text;
|
|
this.setState({ user: use })
|
|
}}
|
|
style={styles.input}
|
|
>
|
|
</Fumi>
|
|
</Animatable.View>
|
|
<Animatable.View ref={(comp) => { this.surnameanim = comp }}>
|
|
<Fumi iconClass={FontAwesomeIcon} iconName={'calendar'}
|
|
label={I18n.t('DATE_NAISSANCE')}
|
|
iconColor={'#f95a25'}
|
|
iconSize={20}
|
|
style={styles.input}
|
|
onFocus={() => {
|
|
Keyboard.dismiss();
|
|
this.setState({ showPickerDateNaissance: true })
|
|
}}
|
|
{...this.dateNaissanceFumiProps}>
|
|
</Fumi>
|
|
</Animatable.View>
|
|
<View
|
|
style={{
|
|
width: responsiveWidth(90),
|
|
height: 60,
|
|
marginTop: 20,
|
|
alignSelf: 'center',
|
|
borderRadius: 10,
|
|
paddingLeft: 20,
|
|
paddingRight: 20,
|
|
backgroundColor: 'white'
|
|
}}>
|
|
<Dropdown
|
|
label={I18n.t('COUNTRY_CHOICE')}
|
|
data={this.state.countries}
|
|
useNativeDriver={true}
|
|
value={this.state.country === null ? "" :
|
|
this.state.country}
|
|
onChangeText={(value, index, data) => {
|
|
this.setState({ country: value });
|
|
}}
|
|
valueExtractor={(value) => { return value.name }}
|
|
labelExtractor={(value) => { return value.name }}
|
|
/>
|
|
</View>
|
|
<View
|
|
style={{
|
|
width: responsiveWidth(90),
|
|
height: 60,
|
|
marginTop: 20,
|
|
alignSelf: 'center',
|
|
borderRadius: 10,
|
|
paddingLeft: 20,
|
|
paddingRight: 20,
|
|
backgroundColor: 'white'
|
|
}}>
|
|
<Dropdown
|
|
label={I18n.t('CHOICE_TOWN')}
|
|
data={this.state.town}
|
|
useNativeDriver={true}
|
|
value={this.state.townName === null ? "" :
|
|
this.state.townName}
|
|
onChangeText={(value, index, data) => {
|
|
this.setState({ townName: value });
|
|
}}
|
|
valueExtractor={(value) => { return value.name }}
|
|
labelExtractor={(value) => { return value.name }}
|
|
/>
|
|
</View>
|
|
<View
|
|
style={{
|
|
width: responsiveWidth(90),
|
|
height: 60,
|
|
marginTop: 20,
|
|
alignSelf: 'center',
|
|
borderRadius: 10,
|
|
paddingLeft: 20,
|
|
paddingRight: 20,
|
|
backgroundColor: 'white'
|
|
}}>
|
|
<Dropdown
|
|
label={I18n.t('PIECE_IDENTITE')}
|
|
data={this.state.identityPieces}
|
|
useNativeDriver={true}
|
|
value={this.state.identityPiecesName}
|
|
onChangeText={(value, index, data) => {
|
|
this.setState({ identityPiecesName: value });
|
|
}}
|
|
valueExtractor={(value) => { return value.name }}
|
|
labelExtractor={(value) => { return value.name }}
|
|
/>
|
|
</View>
|
|
<Animatable.View ref={(comp) => { this.nameanim = comp }}>
|
|
<Fumi iconClass={FontAwesomeIcon} iconName={'address-card'}
|
|
label={`${I18n.t('NUMERO_IDENTITE')}`}
|
|
iconColor={'#f95a25'}
|
|
iconSize={20}
|
|
onChangeText={(numeroIdentite) => {
|
|
this.setState({ numeroIdentite })
|
|
}}
|
|
style={styles.input}
|
|
>
|
|
</Fumi>
|
|
</Animatable.View>
|
|
<Animatable.View ref={(comp) => { this.surnameanim = comp }}>
|
|
<Fumi iconClass={FontAwesomeIcon} iconName={'calendar-times-o'}
|
|
label={I18n.t('IDENTITY_PIECE_EXPIRY_DATE')}
|
|
iconColor={'#f95a25'}
|
|
iconSize={20}
|
|
style={styles.input}
|
|
onFocus={() => {
|
|
Keyboard.dismiss();
|
|
this.setState({ showPickerDateExpiration: true })
|
|
}}
|
|
{...this.dateExpirationFumiProps}>
|
|
</Fumi>
|
|
</Animatable.View>
|
|
|
|
<Button style={styles.btnvalide}
|
|
textStyle={styles.textbtnvalide}
|
|
isLoading={this.state.isLoging}
|
|
onPress={() => { }}>
|
|
{I18n.t('SUBMIT_LABEL')}</Button>
|
|
|
|
</ScrollView>
|
|
</>
|
|
)
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: Color.primaryDarkColor,
|
|
},
|
|
textbtnvalide: {
|
|
color: 'white',
|
|
fontWeight: 'bold'
|
|
},
|
|
bigtitle: {
|
|
color: 'white',
|
|
fontSize: 20,
|
|
flex: 1,
|
|
fontWeight: 'bold',
|
|
textAlign: 'center',
|
|
margin: 20,
|
|
},
|
|
subbigtitle: {
|
|
color: 'white',
|
|
fontSize: 17,
|
|
textAlign: 'center',
|
|
margin: 5,
|
|
},
|
|
btnvalide: {
|
|
marginTop: 20,
|
|
marginLeft: 20,
|
|
marginRight: 20,
|
|
borderColor: 'transparent',
|
|
backgroundColor: Color.accentLightColor,
|
|
height: 52
|
|
},
|
|
input: {
|
|
height: 60,
|
|
marginTop: responsiveHeight(2),
|
|
marginLeft: responsiveWidth(5),
|
|
marginRight: responsiveWidth(5),
|
|
borderRadius: 5,
|
|
}
|
|
}); |