2022-09-28 18:08:39 +02:00
|
|
|
import React from 'react';
|
2022-10-07 18:27:54 +02:00
|
|
|
import { ImageBackground, View, Image, Text, TextInput, Button, Alert } from 'react-native';
|
2022-12-28 13:27:14 +01:00
|
|
|
// Redux
|
|
|
|
|
import { connect } from 'react-redux';
|
2022-09-28 18:08:39 +02:00
|
|
|
// Helpers
|
2022-09-29 15:03:47 +02:00
|
|
|
import Helpers from '../Lib/Helpers';
|
2022-09-28 18:08:39 +02:00
|
|
|
// Common Styles
|
|
|
|
|
import commonStyles from '../../Resources/CommonStyles';
|
2022-09-30 17:40:03 +02:00
|
|
|
// Style
|
|
|
|
|
import styles from '../../Resources/Styles/InstallStyle';
|
2022-09-28 18:08:39 +02:00
|
|
|
// Translations
|
|
|
|
|
import i18n from "../../I18n";
|
|
|
|
|
// Controller
|
|
|
|
|
import InstallController from '../Controllers/InstallController';
|
2022-10-07 18:27:54 +02:00
|
|
|
import SyncController from '../Controllers/SyncController';
|
2022-12-28 13:27:14 +01:00
|
|
|
// Database
|
|
|
|
|
import { User } from '../../Database';
|
2022-09-28 18:08:39 +02:00
|
|
|
|
2022-12-28 13:27:14 +01:00
|
|
|
function mapStateToProps(state) {
|
|
|
|
|
return {
|
|
|
|
|
isSetup: state.app.isSetup
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-28 18:08:39 +02:00
|
|
|
class InstallScreen extends React.Component {
|
|
|
|
|
state = {
|
2022-10-07 18:27:54 +02:00
|
|
|
processing: false,
|
|
|
|
|
txtStep: '',
|
2022-09-29 15:03:47 +02:00
|
|
|
url: "https://dev-app.rhd-ldc.fr",
|
2022-09-28 18:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<ImageBackground source={require('../../Resources/assets/img/background_ldc.png')} style={commonStyles.background}>
|
2022-09-30 17:40:03 +02:00
|
|
|
<View style={styles.container}>
|
2022-09-28 18:08:39 +02:00
|
|
|
<Image source={require('../../Resources/assets/img/logo-square-ldc.png')} style={styles.logo} />
|
|
|
|
|
<View style={styles.actions}>
|
|
|
|
|
<TextInput
|
|
|
|
|
style={commonStyles.textInput}
|
|
|
|
|
placeholder={i18n.t("install.enter_url")}
|
|
|
|
|
onChangeText={(newText) => this.setState({ url: newText })}
|
|
|
|
|
value={this.state.url}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
2022-10-07 18:27:54 +02:00
|
|
|
disabled={this.state.processing}
|
2022-09-28 18:08:39 +02:00
|
|
|
color={'#D4021D'}
|
|
|
|
|
title={ i18n.t('install.install')}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
if (this.state.url.length === 0) {
|
2022-09-30 17:13:43 +02:00
|
|
|
Alert.alert(i18n.t("alert.error"), i18n.t("install.enter_url"));
|
2022-09-28 18:08:39 +02:00
|
|
|
} else {
|
|
|
|
|
if (Helpers.isUrlValid(this.state.url)) {
|
2022-10-07 18:27:54 +02:00
|
|
|
this.install();
|
2022-09-28 18:08:39 +02:00
|
|
|
} else {
|
2022-09-30 17:13:43 +02:00
|
|
|
Alert.alert(i18n.t("alert.error"), i18n.t("install.url_invalid"));
|
2022-09-28 18:08:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
2022-10-07 18:27:54 +02:00
|
|
|
<View style={styles.actions}>
|
|
|
|
|
<Text>
|
|
|
|
|
{this.state.txtStep}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
2022-09-28 18:08:39 +02:00
|
|
|
</View>
|
|
|
|
|
</ImageBackground>
|
|
|
|
|
);
|
2022-10-07 18:27:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-28 13:27:14 +01:00
|
|
|
async install() {
|
2022-10-07 18:27:54 +02:00
|
|
|
this.setState({ processing: true, txtStep: i18n.t("install.get_app_setting") });
|
|
|
|
|
if (InstallController.getConfig(this.state.url)) {
|
|
|
|
|
this.setState({ txtStep: i18n.t("install.get_content_setting") });
|
|
|
|
|
if (InstallController.getAppConfig(this.state.url)) {
|
2022-12-28 13:27:14 +01:00
|
|
|
// getUsers
|
|
|
|
|
this.setState({ txtStep: i18n.t('sync_s.updating_users') + '...' });
|
|
|
|
|
const resUsers = await SyncController.getUsers().then(res => {
|
|
|
|
|
User.clear();
|
|
|
|
|
return res.data;
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
Alert.alert(
|
|
|
|
|
i18n.t('error.error'),
|
|
|
|
|
i18n.t('error.error_has_occurred')
|
|
|
|
|
);
|
|
|
|
|
return
|
|
|
|
|
});
|
|
|
|
|
resUsers.forEach(user => {
|
|
|
|
|
User.add(user);
|
|
|
|
|
});
|
|
|
|
|
this.props.dispatch({ type: 'SET_ISSETUP' });
|
|
|
|
|
this.props.navigation.navigate('LoginScreen');
|
2022-10-07 18:27:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-28 13:27:14 +01:00
|
|
|
this.setState({ processing: false, txtStep: "" });
|
2022-10-07 18:27:54 +02:00
|
|
|
}
|
2022-09-28 18:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-28 13:27:14 +01:00
|
|
|
export default connect(mapStateToProps)(InstallScreen);
|