ldc-com-app/ComApp/src/App/Views/InstallScreen.js

73 lines
2.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
2022-10-07 18:27:54 +02:00
import { ImageBackground, View, Image, Text, TextInput, Button, Alert } from 'react-native';
// Helpers
2022-09-29 15:03:47 +02:00
import Helpers from '../Lib/Helpers';
// Common Styles
import commonStyles from '../../Resources/CommonStyles';
2022-09-30 17:40:03 +02:00
// Style
import styles from '../../Resources/Styles/InstallStyle';
// Translations
import i18n from "../../I18n";
// Controller
import InstallController from '../Controllers/InstallController';
2022-10-07 18:27:54 +02:00
import SyncController from '../Controllers/SyncController';
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",
}
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}>
<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}
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"));
} else {
if (Helpers.isUrlValid(this.state.url)) {
2022-10-07 18:27:54 +02:00
this.install();
} else {
2022-09-30 17:13:43 +02:00
Alert.alert(i18n.t("alert.error"), i18n.t("install.url_invalid"));
}
}
}}
/>
</View>
2022-10-07 18:27:54 +02:00
<View style={styles.actions}>
<Text>
{this.state.txtStep}
</Text>
</View>
</View>
</ImageBackground>
);
2022-10-07 18:27:54 +02:00
}
install() {
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)) {
this.props.navigation.navigate('SyncScreen', { forceSync: true });
}
}
this.setState({ processing: false });
}
}
export default InstallScreen;