Fix Sendbrochure + Add Sentry to catch Sync Errors
This commit is contained in:
parent
9633d8c5cb
commit
4717659bd7
4 changed files with 66 additions and 22 deletions
|
|
@ -73,20 +73,16 @@ class SyncController {
|
|||
});
|
||||
}
|
||||
|
||||
async sendBrochures() {
|
||||
let brochures = SendBrochure.getAll();
|
||||
for (const brochure of brochures) {
|
||||
await axios({
|
||||
method: 'POST',
|
||||
url: this.getUrlBo() + '/api/sendBrochure',
|
||||
responseType: 'json',
|
||||
params: {
|
||||
token: api_token,
|
||||
emails: brochure,
|
||||
},
|
||||
});
|
||||
}
|
||||
SendBrochure.clear();
|
||||
async sendBrochure(brochure) {
|
||||
return axios({
|
||||
method: 'POST',
|
||||
url: this.getUrlBo() + '/api/sendBrochure',
|
||||
responseType: 'json',
|
||||
params: {
|
||||
token: api_token,
|
||||
emails: brochure,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getDirectories() {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,15 @@ class SendBrochureModel {
|
|||
});
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
const tmp = this.get(key);
|
||||
if (typeof tmp === 'object') {
|
||||
this.realm.write(() => {
|
||||
this.realm.delete(tmp);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default SendBrochureModel;
|
||||
|
|
|
|||
|
|
@ -496,6 +496,7 @@ class ContactScreen extends React.Component {
|
|||
{this.state.sendDocumentList.map((item, index) => {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
key={index}
|
||||
onPress={() => {
|
||||
let tmp = this.state.sendDocumentList;
|
||||
tmp.splice(this.props.documents[index], 1);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { View, Button, Alert, Text } from 'react-native';
|
|||
import { connect } from 'react-redux';
|
||||
import { initDirectories } from '../Store/Actions/directories';
|
||||
import { initContact } from '../Store/Actions/contacts';
|
||||
// Sentry
|
||||
import * as Sentry from "@sentry/react-native";
|
||||
// Style
|
||||
import styles from '../../Resources/Styles/SyncStyle';
|
||||
// Translations
|
||||
|
|
@ -13,7 +15,7 @@ import SyncController from '../Controllers/SyncController';
|
|||
// Progress
|
||||
import * as Progress from 'react-native-progress';
|
||||
// Database
|
||||
import { User, Contact, Directory, Document } from '../../Database';
|
||||
import { User, Contact, Directory, Document, SendBrochure } from '../../Database';
|
||||
// FileSytem
|
||||
import * as FileSystem from 'expo-file-system';
|
||||
|
||||
|
|
@ -91,6 +93,7 @@ class SyncScreen extends React.Component {
|
|||
}
|
||||
|
||||
async sync() {
|
||||
let errorStatus = false;
|
||||
const isConnected = await SyncController.checkConnection().then(state => {
|
||||
//console.log(state.isConnected)
|
||||
return state.isConnected
|
||||
|
|
@ -110,12 +113,16 @@ class SyncScreen extends React.Component {
|
|||
const resVersion = await SyncController.getVersion().then(res => {
|
||||
return res.data;
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
Sentry.captureException(error);
|
||||
Alert.alert(
|
||||
i18n.t('error.error'),
|
||||
i18n.t('error.error_has_occurred')
|
||||
);
|
||||
errorStatus = true
|
||||
});
|
||||
if (errorStatus) {
|
||||
return false;
|
||||
}
|
||||
this.props.updateVersion(resVersion.version);
|
||||
this.props.updateShowIsActive(resVersion.ShowIsActive);
|
||||
this.setState({ newApp: resVersion.newApp });
|
||||
|
|
@ -125,12 +132,16 @@ class SyncScreen extends React.Component {
|
|||
User.clear();
|
||||
return res.data;
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
Sentry.captureException(error);
|
||||
Alert.alert(
|
||||
i18n.t('error.error'),
|
||||
i18n.t('error.error_has_occurred')
|
||||
);
|
||||
errorStatus = true
|
||||
});
|
||||
if (errorStatus) {
|
||||
return false;
|
||||
}
|
||||
resUsers.forEach(user => {
|
||||
User.add(user);
|
||||
});
|
||||
|
|
@ -140,30 +151,53 @@ class SyncScreen extends React.Component {
|
|||
Contact.clear();
|
||||
return res.data;
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
Sentry.captureException(error);
|
||||
Alert.alert(
|
||||
i18n.t('error.error'),
|
||||
i18n.t('error.error_has_occurred')
|
||||
);
|
||||
errorStatus = true
|
||||
});
|
||||
if (errorStatus) {
|
||||
return false;
|
||||
}
|
||||
resContacts.forEach(contact => {
|
||||
Contact.add(contact);
|
||||
});
|
||||
//sendBrochures
|
||||
this.setState({ progress: 0.2, txtStep: i18n.t('sync_s.sending_flyers') + '...' });
|
||||
await SyncController.sendBrochures();
|
||||
let brochures = SendBrochure.getAll();
|
||||
for (const brochure of brochures) {
|
||||
await SyncController.sendBrochure(brochure).then(res => {
|
||||
SendBrochure.delete(brochure.id);
|
||||
}).catch(error => {
|
||||
Sentry.captureException(error);
|
||||
Alert.alert(
|
||||
i18n.t('error.error'),
|
||||
i18n.t('error.error_has_occurred') + ' : Brochures'
|
||||
);
|
||||
errorStatus = true;
|
||||
});
|
||||
}
|
||||
if (errorStatus) {
|
||||
return false;
|
||||
}
|
||||
//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);
|
||||
Sentry.captureException(error);
|
||||
Alert.alert(
|
||||
i18n.t('error.error'),
|
||||
i18n.t('error.error_has_occurred')
|
||||
);
|
||||
errorStatus = true
|
||||
});
|
||||
if (errorStatus) {
|
||||
return false;
|
||||
}
|
||||
resDirectories.forEach(dir => {
|
||||
Directory.add(dir);
|
||||
});
|
||||
|
|
@ -172,12 +206,16 @@ class SyncScreen extends React.Component {
|
|||
const resDocuments = await SyncController.getDocuments().then(res => {
|
||||
return res.data;
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
Sentry.captureException(error);
|
||||
Alert.alert(
|
||||
i18n.t('error.error'),
|
||||
i18n.t('error.error_has_occurred')
|
||||
);
|
||||
errorStatus = true
|
||||
});
|
||||
if (errorStatus) {
|
||||
return false;
|
||||
}
|
||||
const toDelete = Document.clear(resDocuments);
|
||||
resDocuments.forEach(document => {
|
||||
Document.update(document);
|
||||
|
|
@ -314,7 +352,7 @@ class SyncScreen extends React.Component {
|
|||
SyncController.updateVersion(version);
|
||||
this.setState({ txtStep: i18n.t('sync_s.update_completed') + '.', processing: false });
|
||||
if (this.state.newApp === true) {
|
||||
const appUUID = '1f6eda31-1f6d-49fe-aa81-4f0aece0f7ca';
|
||||
const appUUID = SyncController.getAppStoreUUID();
|
||||
const url = 'https://store.ldc.fr' + '/app/' + appUUID;
|
||||
Alert.alert(
|
||||
'LDC Store',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue