2022-10-05 18:03:52 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { View, Button, Alert, Text } from 'react-native';
|
|
|
|
|
// Redux
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
// Style
|
|
|
|
|
import styles from '../../Resources/Styles/SyncStyle';
|
|
|
|
|
// Translations
|
|
|
|
|
import i18n from "../../I18n";
|
|
|
|
|
// Controller
|
|
|
|
|
import SyncController from '../Controllers/SyncController';
|
|
|
|
|
// Progress
|
|
|
|
|
import * as Progress from 'react-native-progress';
|
2022-10-06 10:28:41 +02:00
|
|
|
// Database
|
|
|
|
|
import { User, Contact, Directory } from '../../Database';
|
2022-10-05 18:03:52 +02:00
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
|
return {
|
2022-10-06 10:28:41 +02:00
|
|
|
documents: state.app.documents,
|
|
|
|
|
syncVersion: state.app.syncVersion,
|
|
|
|
|
currentUser: state.app.currentUser,
|
2022-10-05 18:03:52 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SyncScreen extends React.Component {
|
|
|
|
|
state = {
|
|
|
|
|
progress: 0,
|
|
|
|
|
txtStep: '',
|
|
|
|
|
downloadProgress: 0,
|
|
|
|
|
downloadingFile: false,
|
|
|
|
|
processing: false,
|
|
|
|
|
newApp: false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const fileProgress = this.fileProgress();
|
|
|
|
|
return (
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
<Progress.Circle
|
|
|
|
|
size={250}
|
|
|
|
|
progress={this.state.progress}
|
|
|
|
|
showsText={true}
|
|
|
|
|
color={'#ce3029'}
|
|
|
|
|
/>
|
|
|
|
|
<View style={styles.btnWrapper}>
|
|
|
|
|
<Button
|
|
|
|
|
disabled={this.state.processing}
|
|
|
|
|
color={'#ce3029'}
|
|
|
|
|
title={i18n.t('sync_s.start_sync')}
|
|
|
|
|
onPress={() => this.sync()}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
<View style={styles.btnWrapper}>
|
|
|
|
|
<Text>
|
|
|
|
|
{this.state.txtStep} {fileProgress}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async sync() {
|
2022-10-06 10:28:41 +02:00
|
|
|
// if (!SyncController.checkConnection()) {
|
|
|
|
|
// Alert.alert(
|
|
|
|
|
// i18n.t('global.warning'),
|
|
|
|
|
// i18n.t('error.must_be_connected_internet_sync')
|
|
|
|
|
// );
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// this.setState({ processing: true });
|
|
|
|
|
// // getVersion
|
|
|
|
|
// const resVersion = await SyncController.getVersion().then(res => {
|
|
|
|
|
// return res.data;
|
|
|
|
|
// }).catch(error => {
|
|
|
|
|
// console.log(error);
|
|
|
|
|
// Alert.alert(
|
|
|
|
|
// i18n.t('error.error'),
|
|
|
|
|
// i18n.t('error.error_has_occurred')
|
|
|
|
|
// );
|
|
|
|
|
// });
|
|
|
|
|
// this.props.dispatch({
|
|
|
|
|
// type: 'UPDATE_VERSION',
|
|
|
|
|
// data: resVersion.version,
|
|
|
|
|
// });
|
|
|
|
|
// this.props.dispatch({
|
|
|
|
|
// type: 'UPDATE_SHOW_IS_ACTIVE',
|
|
|
|
|
// data: resVersion.ShowIsActive,
|
|
|
|
|
// });
|
|
|
|
|
// this.setState({ newApp: resVersion.newApp });
|
|
|
|
|
// // getUsers
|
|
|
|
|
// this.setState({ txtStep: i18n.t('sync_s.updating_users') + '...' });
|
2022-10-05 18:03:52 +02:00
|
|
|
// const resUsers = await SyncController.getUsers().then(res => {
|
2022-10-06 10:28:41 +02:00
|
|
|
// User.clear();
|
|
|
|
|
// return res.data;
|
|
|
|
|
// }).catch(error => {
|
|
|
|
|
// console.log(error);
|
|
|
|
|
// Alert.alert(
|
|
|
|
|
// i18n.t('error.error'),
|
|
|
|
|
// i18n.t('error.error_has_occurred')
|
|
|
|
|
// );
|
|
|
|
|
// });
|
|
|
|
|
// resUsers.forEach(user => {
|
|
|
|
|
// User.add(user);
|
|
|
|
|
// });
|
|
|
|
|
// // getContacts
|
|
|
|
|
// this.setState({ progress: 0.1, txtStep: i18n.t('sync_s.updating_contacts') + '...' });
|
|
|
|
|
// const resContacts = await SyncController.getContacts().then(res => {
|
|
|
|
|
// Contact.clear();
|
2022-10-05 18:03:52 +02:00
|
|
|
// return res.data;
|
|
|
|
|
// }).catch(error => {
|
|
|
|
|
// console.log(error);
|
|
|
|
|
// Alert.alert(
|
|
|
|
|
// i18n.t('error.error'),
|
|
|
|
|
// i18n.t('error.error_has_occurred')
|
|
|
|
|
// );
|
|
|
|
|
// });
|
2022-10-06 10:28:41 +02:00
|
|
|
// resContacts.forEach(contact => {
|
|
|
|
|
// Contact.add(contact);
|
|
|
|
|
// });
|
|
|
|
|
// sendBrochures
|
|
|
|
|
// this.setState({ progress: 0.2, txtStep: i18n.t('sync_s.sending_flyers') + '...' });
|
|
|
|
|
// await SyncController.sendBrochures();
|
|
|
|
|
// getDirectories
|
|
|
|
|
this.setState({ progress: 0.3, txtStep: i18n.t('sync_s.updating_folders') + '...' });
|
|
|
|
|
const resDirectories = await SyncController.getDirectories().then(res => {
|
|
|
|
|
Directory.clear();
|
|
|
|
|
return res.data;
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
Alert.alert(
|
|
|
|
|
i18n.t('error.error'),
|
|
|
|
|
i18n.t('error.error_has_occurred')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
resDirectories.forEach(dir => {
|
|
|
|
|
Directory.add(dir);
|
|
|
|
|
});
|
2022-10-05 18:03:52 +02:00
|
|
|
// End
|
|
|
|
|
this.setState({ txtStep: i18n.t('sync_s.update_completed') + '.', processing: false });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileProgress() {
|
|
|
|
|
if (this.state.downloadingFile === true) {
|
|
|
|
|
return this.state.downloadProgress + ' %';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(SyncScreen);
|