save tmp clean
This commit is contained in:
parent
064baab447
commit
43d2f21591
13 changed files with 114 additions and 58 deletions
|
|
@ -39,7 +39,7 @@ import MySpaceScreen from './Views/MySpace';
|
|||
// V2
|
||||
//SplashScreen.preventAutoHideAsync(); //Keep
|
||||
|
||||
store.dispatch({ type: 'INIT_APP' });
|
||||
store.dispatch({ type: 'INIT' });
|
||||
store.dispatch({ type: 'INIT_LOCALE' });
|
||||
store.dispatch({ type: 'INIT_USERS' });
|
||||
|
||||
|
|
|
|||
|
|
@ -8,5 +8,7 @@ export const INIT_CONTACT = "INIT_CONTACT";
|
|||
export const ADD_CONTACT = "ADD_CONTACT";
|
||||
export const EDIT_CONTACT = "EDIT_CONTACT";
|
||||
export const DELETE_CONTACT = "DELETE_CONTACT";
|
||||
// Directories
|
||||
export const INIT_DIRECTORIES = "INIT_DIRECTORIES";
|
||||
// Documents
|
||||
export const INIT_DOCUMENTS = "INIT_DOCUMENTS";
|
||||
|
|
@ -21,6 +21,7 @@ export const initContact = (currentUser, data) => {
|
|||
export const addContact = (currentUser, data) => {
|
||||
return {
|
||||
type: ADD_CONTACT,
|
||||
currentUser,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
|
@ -28,13 +29,12 @@ export const addContact = (currentUser, data) => {
|
|||
/**
|
||||
* Edit contact
|
||||
* @param {object} currentUser The currentUser
|
||||
* @param {string} uid The contact uid
|
||||
* @param {object} data The contact data
|
||||
*/
|
||||
export const editContact = (currentUser, uid, data) => {
|
||||
export const editContact = (currentUser, data) => {
|
||||
return {
|
||||
type: EDIT_CONTACT,
|
||||
uid,
|
||||
currentUser,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
16
ComApp/src/App/Store/Actions/directories.js
Normal file
16
ComApp/src/App/Store/Actions/directories.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { INIT_DIRECTORIES } from "./actionType";
|
||||
|
||||
/**
|
||||
* Init
|
||||
* @param {string} lang The lang
|
||||
* @param {object} user User
|
||||
* @param {object} data The document data
|
||||
*/
|
||||
export const initDirectories = (lang, user, data) => {
|
||||
return {
|
||||
type: INIT_DIRECTORIES,
|
||||
lang,
|
||||
user,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
|
@ -3,6 +3,7 @@ import { createStore, combineReducers } from "redux";
|
|||
import appReducer from "./Reducers/AppReducer";
|
||||
import contactsReducer from "./Reducers/contacts";
|
||||
import documentsReducer from "./Reducers/documents";
|
||||
import directoriesReducer from "./Reducers/directories";
|
||||
import localesReducer from "./Reducers/locales";
|
||||
import usersReducer from "./Reducers/users";
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ const rootReducer = combineReducers({
|
|||
app: appReducer,
|
||||
contacts: contactsReducer,
|
||||
documents: documentsReducer,
|
||||
directories: directoriesReducer,
|
||||
locale: localesReducer,
|
||||
users: usersReducer
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
import SyncController from "../../Controllers/SyncController";
|
||||
// Database
|
||||
import { Setting, Directory, SendBrochure } from '../../../Database';
|
||||
import { Setting, SendBrochure } from '../../../Database';
|
||||
|
||||
const initialState = {
|
||||
isSetup: false,
|
||||
locale: 'fr',
|
||||
currentUser: {},
|
||||
logged: false,
|
||||
directories: {},
|
||||
syncVersion: 0,
|
||||
currentOpenedDoc: {},
|
||||
ShowIsActive: 0,
|
||||
|
|
@ -16,11 +15,13 @@ const initialState = {
|
|||
const reducer = (state = initialState, action) => {
|
||||
let saved;
|
||||
switch (action.type) {
|
||||
case 'INIT_APP':
|
||||
case 'INIT':
|
||||
let ShowIsActive = Setting.get('ShowIsActive');
|
||||
saved = Setting.get('isSetup');
|
||||
return {
|
||||
...state,
|
||||
isSetup: saved === undefined ? false : saved.value === "true" ? true : false
|
||||
isSetup: saved === undefined ? false : saved.value === "true" ? true : false,
|
||||
ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value
|
||||
};
|
||||
case 'SET_ISSETUP':
|
||||
Setting.upsert({ key: 'isSetup', value: "true" });
|
||||
|
|
@ -29,19 +30,6 @@ const reducer = (state = initialState, action) => {
|
|||
...state,
|
||||
isSetup: saved === undefined ? false : saved.value === "true" ? true : false
|
||||
};
|
||||
case 'INIT':
|
||||
let directories = Directory.getAll(
|
||||
state.currentUser.role,
|
||||
state.currentUser.authorizedFolders,
|
||||
true,
|
||||
state.locale
|
||||
);
|
||||
let ShowIsActive = Setting.get('ShowIsActive');
|
||||
return {
|
||||
...state,
|
||||
directories: directories,
|
||||
ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value,
|
||||
};
|
||||
case 'SET_CURRENT_USER':
|
||||
let user = Setting.get('isLogged').value
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -7,31 +7,30 @@ const initialState = [];
|
|||
const reducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case INIT_CONTACT: {
|
||||
return {
|
||||
...state,
|
||||
contacts: Contact.getByUser(action.currentUser.id),
|
||||
};
|
||||
console.log("Init contact", Contact.getByUser(action.currentUser.id), action.currentUser.id)
|
||||
return Contact.getByUser(action.currentUser.id);
|
||||
}
|
||||
case ADD_CONTACT: {
|
||||
action.data.user_id = action.currentUser.id;
|
||||
Contact.add(action.data);
|
||||
return {
|
||||
return [
|
||||
...state,
|
||||
contacts: Contact.getByUser(action.currentUser.id),
|
||||
};
|
||||
Contact.getByUser(action.currentUser.id),
|
||||
];
|
||||
}
|
||||
case EDIT_CONTACT: {
|
||||
Contact.update(action.data);
|
||||
return {
|
||||
return [
|
||||
...state,
|
||||
contacts: Contact.getByUser(action.currentUser.id),
|
||||
};
|
||||
Contact.getByUser(action.currentUser.id),
|
||||
];
|
||||
}
|
||||
case DELETE_CONTACT: {
|
||||
Contact.delete(action.data);
|
||||
return {
|
||||
return [
|
||||
...state,
|
||||
contacts: Contact.getByUser(action.currentUser.id),
|
||||
};
|
||||
Contact.getByUser(action.currentUser.id),
|
||||
];
|
||||
}
|
||||
|
||||
default: {
|
||||
|
|
|
|||
27
ComApp/src/App/Store/Reducers/directories.js
Normal file
27
ComApp/src/App/Store/Reducers/directories.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { INIT_DIRECTORIES } from "../Actions/actionType";
|
||||
// Models
|
||||
import { Directory } from "../../../Database";
|
||||
|
||||
const initialState = [];
|
||||
|
||||
const reducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case INIT_DIRECTORIES: {
|
||||
return [
|
||||
...state,
|
||||
Directory.getAll(
|
||||
action.user.role,
|
||||
action.user.authorizedFolders,
|
||||
true,
|
||||
action.lang
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default reducer;
|
||||
|
|
@ -8,6 +8,9 @@ const reducer = (state = initialState, action) => {
|
|||
switch (action.type) {
|
||||
case INIT_DOCUMENTS: {
|
||||
let docs = Document.getAll(action.directories);
|
||||
if (docs.length === 0) {
|
||||
return state
|
||||
}
|
||||
return [
|
||||
...state,
|
||||
docs.filter(item => item.lang === action.lang)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
} from 'react-native';
|
||||
// Reduxs
|
||||
import { connect } from 'react-redux';
|
||||
import { addContact, editContact } from '../Store/Actions/contacts';
|
||||
// Helpers
|
||||
import Helpers from "../Lib/Helpers";
|
||||
// Translations
|
||||
|
|
@ -31,11 +32,18 @@ import { BarCodeScanner } from 'expo-barcode-scanner';
|
|||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
contacts: state.contacts.contacts,
|
||||
contacts: state.contacts,
|
||||
currentUser: state.app.currentUser,
|
||||
};
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
addContact: (user, data) => dispatch(addContact(user, data)),
|
||||
editContact: (user, data) => dispatch(editContact(user, data))
|
||||
};
|
||||
};
|
||||
|
||||
let date = new Date().getDate();
|
||||
if (date < 10) {
|
||||
date = '0' + date.toString();
|
||||
|
|
@ -57,9 +65,9 @@ class ContactDetailsScreen extends React.Component {
|
|||
showNewVisit: false,
|
||||
tmpID: 0,
|
||||
tmpNote: '',
|
||||
tmpName: '',
|
||||
tmpFirstname: '',
|
||||
tmpEmail: '',
|
||||
tmpName: 'test',
|
||||
tmpFirstname: 'test',
|
||||
tmpEmail: 'test@test.fr',
|
||||
tmpCompany: '',
|
||||
tmpAddress: '',
|
||||
tmpPhone: '',
|
||||
|
|
@ -162,7 +170,7 @@ class ContactDetailsScreen extends React.Component {
|
|||
};
|
||||
if (action === 'edit') {
|
||||
contact.id = this.state.tmpID;
|
||||
this.props.dispatch({ type: 'EDIT_CONTACT', data: contact });
|
||||
this.props.editContact(this.props.currentUser, contact);
|
||||
this.populate();
|
||||
showMessage({
|
||||
message: i18n.t('contact_details_s.contact_saved') + '.',
|
||||
|
|
@ -170,8 +178,7 @@ class ContactDetailsScreen extends React.Component {
|
|||
duration: 500,
|
||||
});
|
||||
} else {
|
||||
contact.user_id = this.props.currentUser.id;
|
||||
this.props.dispatch({ type: 'ADD_CONTACT', data: contact });
|
||||
this.props.addContact(this.props.currentUser, contact);
|
||||
this.props.navigation.navigate('ContactScreen', { contactAdded: true });
|
||||
}
|
||||
}
|
||||
|
|
@ -844,4 +851,4 @@ class ContactDetailsScreen extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(ContactDetailsScreen);
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ContactDetailsScreen);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ import styles from '../../Resources/Styles/ContactStyle';
|
|||
function mapStateToProps(state) {
|
||||
return {
|
||||
users: state.users.users,
|
||||
contacts: state.contacts.contacts,
|
||||
documents: state.app.documents,
|
||||
contacts: state.contacts,
|
||||
documents: state.documents,
|
||||
currentUser: state.app.currentUser,
|
||||
};
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ class ContactScreen extends React.Component {
|
|||
let arrayContacts = Object.keys(objContacts).map(function (key) { return objContacts[key]; });
|
||||
let arrayEmails = Object.keys(objContacts).map(function (key) { return objContacts[key]; });
|
||||
let arrayDocs = Object.keys(objDocs).map(function (key) { return objDocs[key]; });
|
||||
|
||||
console.log("Contacts", objContacts);
|
||||
this.setState({
|
||||
contacts: arrayContacts.sort(Helpers.compareValues('name', 'asc')),
|
||||
sortedDocuments: arrayDocs.sort(Helpers.compareValues('title', 'asc')),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import { View, ImageBackground, TouchableOpacity, Text, Image } from 'react-nati
|
|||
import commonStyles from '../../Resources/CommonStyles';
|
||||
// Redux
|
||||
import { connect } from 'react-redux';
|
||||
import { initDirectories } from '../Store/Actions/directories';
|
||||
import { initDocuments } from '../Store/Actions/documents';
|
||||
import { initContact } from '../Store/Actions/contacts';
|
||||
// Style
|
||||
import styles from '../../Resources/Styles/HomeStyle';
|
||||
// Translations
|
||||
|
|
@ -14,24 +16,28 @@ import * as FileSystem from 'expo-file-system';
|
|||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
directories: state.app.directories,
|
||||
directories: state.directories,
|
||||
locale: state.locale.locale,
|
||||
currentUser: state.app.currentUser
|
||||
};
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
init: (locale, directories) => {
|
||||
dispatch({ type: 'INIT' })
|
||||
dispatch(initDocuments(locale, directories))
|
||||
}
|
||||
init: () => dispatch({ type: 'INIT' }),
|
||||
initDirectories: (lang, user) => dispatch(initDirectories(lang, user)),
|
||||
initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)),
|
||||
initContact: currentUser => dispatch(initContact(currentUser)),
|
||||
};
|
||||
};
|
||||
|
||||
class HomeScreen extends React.Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.init(this.props.locale.value, this.props.directories);
|
||||
this.props.init();
|
||||
this.props.initDirectories(this.props.locale.value, this.props.currentUser);
|
||||
this.props.initDocuments(this.props.locale.value, this.props.directories);
|
||||
this.props.initContact(this.props.currentUser);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ import React from 'react';
|
|||
import { View, Button, Alert, Text } from 'react-native';
|
||||
// Redux
|
||||
import { connect } from 'react-redux';
|
||||
import { initDirectories } from '../Store/Actions/directories';
|
||||
import { initDocuments } from '../Store/Actions/documents';
|
||||
import { initContact } from '../Store/Actions/contacts';
|
||||
// Style
|
||||
import styles from '../../Resources/Styles/SyncStyle';
|
||||
// Translations
|
||||
|
|
@ -18,20 +20,20 @@ import * as FileSystem from 'expo-file-system';
|
|||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
documents: state.app.documents,
|
||||
documents: state.documents,
|
||||
syncVersion: state.app.syncVersion,
|
||||
currentUser: state.app.currentUser,
|
||||
directories: state.app.directories,
|
||||
directories: state.directories,
|
||||
locale: state.locale.locale,
|
||||
};
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
init: (locale, directories) => {
|
||||
dispatch({ type: 'INIT' })
|
||||
dispatch(initDocuments(locale, directories))
|
||||
},
|
||||
init: () => dispatch({ type: 'INIT' }),
|
||||
initDirectories: (lang, user) => dispatch(initDirectories(lang, user)),
|
||||
initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)),
|
||||
initContact: currentUser => dispatch(initContact(currentUser)),
|
||||
updateVersion: version => dispatch({
|
||||
type: 'UPDATE_VERSION',
|
||||
data: version,
|
||||
|
|
@ -294,7 +296,11 @@ class SyncScreen extends React.Component {
|
|||
}
|
||||
|
||||
finishSync(version) {
|
||||
this.props.init(this.props.locale.value, this.props.directories);
|
||||
this.props.init();
|
||||
this.props.initDirectories(this.props.locale.value, this.props.currentUser);
|
||||
this.props.initDocuments(this.props.locale.value, this.props.directories);
|
||||
this.props.initContact(this.props.currentUser);
|
||||
|
||||
SyncController.updateVersion(version);
|
||||
this.setState({ txtStep: i18n.t('sync_s.update_completed') + '.', processing: false });
|
||||
if (this.state.newApp === true) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue