mg-library 1.0.267 → 1.0.269

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mg-library",
3
- "version": "1.0.267",
3
+ "version": "1.0.269",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,16 +9,8 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@react-native-async-storage/async-storage": "1.21.0",
13
- "expo": "~50.0.5",
14
- "expo-camera": "~14.0.3",
15
- "expo-constants": "~15.4.5",
16
- "expo-image-manipulator": "~11.8.0",
17
- "moment": "^2.27.0",
18
- "moment-timezone": "^0.5.31",
19
- "native-base": "^3.4.28",
12
+ "expo": "~50.0.6",
20
13
  "react": "18.2.0",
21
- "react-native": "0.73.2",
22
- "react-native-root-toast": "^3.5.1"
14
+ "react-native": "0.73.2"
23
15
  }
24
16
  }
package/actions.js DELETED
@@ -1,106 +0,0 @@
1
- // Constants
2
-
3
- export const APP_MODULE_ACTIVATION = 'APP_MODULE_ACTIVATION';
4
- export const APP_API_REQUEST = 'APP_API_REQUEST';
5
- export const APP_API_SUCCESS = 'APP_API_SUCCESS';
6
- export const APP_API_ERROR = 'APP_API_ERROR';
7
- export const APP_MODAL_SET_ISVISIBLE = 'APP_MODAL_SET_ISVISIBLE';
8
-
9
- export const SESSION_LOGIN = 'SESSION_LOGIN';
10
- export const SESSION_LOGOUT = 'SESSION_LOGOUT';
11
- export const SESSION_LANGUAGE_CHANGE = 'SESSION_LANGUAGE_CHANGE';
12
- export const SESSION_PUSH_TOKEN_UPDATE = 'SESSION_PUSH_TOKEN_UPDATE';
13
- export const SESSION_BELL_RING = 'SESSION_BELL_RING';
14
- export const SESSION_LOADING_START = 'SESSION_LOADING_START';
15
- export const SESSION_LOADING_END = 'SESSION_LOADING_END';
16
-
17
- // App -> Actions Creators
18
-
19
- export function moduleActivation(module) {
20
- return {
21
- type: APP_MODULE_ACTIVATION,
22
- payload: {
23
- module
24
- }
25
- }
26
- }
27
-
28
- export function apiRequest() {
29
- return {
30
- type: APP_API_REQUEST
31
- }
32
- }
33
-
34
- export function apiSuccess() {
35
- return {
36
- type: APP_API_SUCCESS
37
- }
38
- }
39
-
40
- export function apiError() {
41
- return {
42
- type: APP_API_ERROR
43
- }
44
- }
45
-
46
- export function modalSetIsVisible(isModalVisible) {
47
- return {
48
- type: APP_MODAL_SET_ISVISIBLE,
49
- payload: {
50
- isModalVisible
51
- }
52
- }
53
- }
54
-
55
- // Session -> Actions Creators
56
-
57
- export function sessionLoadingStart() {
58
- return {
59
- type: SESSION_LOADING_START
60
- }
61
- }
62
-
63
- export function sessionLoadingEnd() {
64
- return {
65
- type: SESSION_LOADING_END
66
- }
67
- }
68
-
69
- export function sessionLogin(session) {
70
- return {
71
- type: SESSION_LOGIN,
72
- payload: {
73
- session
74
- }
75
- }
76
- }
77
-
78
- export function sessionLogout() {
79
- return {
80
- type: SESSION_LOGOUT
81
- }
82
- }
83
-
84
- export function sessionLanguageChange(language) {
85
- return {
86
- type: SESSION_LANGUAGE_CHANGE,
87
- payload: {
88
- language
89
- }
90
- }
91
- }
92
-
93
- export function sessionPushTokenUpdate(pushToken) {
94
- return {
95
- type: SESSION_PUSH_TOKEN_UPDATE,
96
- payload: {
97
- pushToken
98
- }
99
- }
100
- }
101
-
102
- export function sessionBellRing() {
103
- return {
104
- type: SESSION_BELL_RING
105
- }
106
- }
package/blocks.js DELETED
@@ -1,333 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { Container, Card, CardItem, Icon, Button, Header, Body, Right, Title } from 'native-base';
3
- import { View, TouchableOpacity, ActivityIndicator, Text, Modal, StyleSheet, Image } from "react-native";
4
- import axios from 'axios';
5
- import { Camera } from 'expo-camera';
6
- import * as ImageManipulator from 'expo-image-manipulator';
7
- import * as mgConstants from './constants.js';
8
- import * as mgActions from './actions.js';
9
- import * as mgFunctions from './functions.js';
10
-
11
- // Camera
12
-
13
- export function MGCamera(props) {
14
-
15
- let camera;
16
-
17
- const __takePicture = async () => {
18
- if (!camera)
19
- return;
20
- const photo = await camera.takePictureAsync({quality: 1});
21
- const PhotoResized = await ImageManipulator.manipulateAsync(
22
- photo.uri,
23
- [{resize: { width: 205, height: 275 }}],
24
- { compress: 1, format: ImageManipulator.SaveFormat.JPEG }
25
- );
26
- props.process.fileUri = PhotoResized.uri;
27
- props.process.goForward(props.nextStep);
28
- }
29
-
30
- const [type, setType] = useState(Camera.Constants.Type.front);
31
-
32
- return (
33
- <View>
34
- <MGGoBack process={props.process} store={props.store} />
35
- <Card>
36
- <CardItem style={{flex: 1, alignSelf: 'center'}}>
37
- <Camera style={{width: 205, height: 275}}
38
- type={type}
39
- ref={(r) => {
40
- camera = r
41
- }}>
42
- </Camera>
43
- </CardItem>
44
- </Card>
45
- <Card>
46
- <CardItem>
47
- <View style={{flex: 1, flexDirection: 'row'}}>
48
- <View style={{flex: 0.5, alignItems: 'center'}}>
49
- <TouchableOpacity onPress={() => {
50
- setType(
51
- type === Camera.Constants.Type.back
52
- ? Camera.Constants.Type.front
53
- : Camera.Constants.Type.back
54
- )
55
- }}>
56
- <Icon type={mgConstants.ICON_FAMILY}
57
- name='refresh'
58
- style={{color: mgConstants.COLOR_PRIMARY}}>
59
- </Icon>
60
- </TouchableOpacity>
61
- </View>
62
- <View style={{flex: 0.5, alignItems: 'center'}}>
63
- <TouchableOpacity onPress={__takePicture}>
64
- <Icon type={mgConstants.ICON_FAMILY}
65
- name='camera'
66
- style={{color: mgConstants.COLOR_PRIMARY}}>
67
- </Icon>
68
- </TouchableOpacity>
69
- </View>
70
- </View>
71
- </CardItem>
72
- </Card>
73
- </View>
74
- )
75
- }
76
-
77
- export function MGCameraPreview(props) {
78
- const __savePicture = async () => {
79
- let fileName = 'photo-' + Math.random().toString(36).substring(7) + '-' + Math.random().toString(36).substring(7);
80
- const uploadCareUrl = 'https://upload.uploadcare.com/base/';
81
- let body = new FormData();
82
- body.append('file', {
83
- name: fileName,
84
- type: 'image/jpg',
85
- uri: props.process.fileUri
86
- });
87
- body.append('UPLOADCARE_PUB_KEY', props.mediaAppPublicKey);
88
- body.append('UPLOADCARE_STORE', '1');
89
- props.store.dispatch(mgActions.apiRequest());
90
- try {
91
- let response = await axios.post(uploadCareUrl, body, { timeout: 20000 });
92
- props.store.dispatch(mgActions.apiSuccess());
93
- let fileUUID = response.data.file;
94
- let requestData = props.requestData;
95
- requestData.photoMediaAppId = fileUUID;
96
- requestData.photoMediaAppFileName = fileName;
97
- props.store.dispatch(mgActions.apiRequest());
98
- axios.post(props.url,requestData,mgFunctions.getRequestHeader())
99
- .then(response => {
100
- props.store.dispatch(mgActions.apiSuccess());
101
- props.onSavePicture(response.data.photoUrl);
102
- })
103
- .catch(error => {
104
- props.store.dispatch(mgActions.apiError());
105
- mgFunctions.showToastError(error);
106
- })
107
- } catch (e) {
108
- props.store.dispatch(mgActions.apiError());
109
- mgFunctions.showToastError(error);
110
- }
111
- }
112
-
113
- return (
114
- <View>
115
- <MGGoBack process={props.process} store={props.store} />
116
- <Card>
117
- <CardItem style={{flex: 1, alignSelf: 'center'}}>
118
- <Image source={{uri: props.process.fileUri}}
119
- style={{width: 200, height: 200}} />
120
- </CardItem>
121
- </Card>
122
- <Card>
123
- <CardItem style={{flex: 1, alignSelf: 'center'}}>
124
- <TouchableOpacity onPress={__savePicture}>
125
- <Icon type={mgConstants.ICON_FAMILY}
126
- name='check'
127
- style={{color: mgConstants.COLOR_PRIMARY}}>
128
- </Icon>
129
- </TouchableOpacity>
130
- </CardItem>
131
- </Card>
132
- </View>
133
- )
134
- }
135
-
136
- // Header
137
-
138
- export function MGHeader(props) {
139
- return (
140
- <Header>
141
- <Body>
142
- <Title>{props.title}</Title>
143
- </Body>
144
- <Right>
145
- <Button outline onPress={props.callbackLogout}>
146
- <Icon type={mgConstants.ICON_FAMILY} name='sign-out'></Icon>
147
- </Button>
148
- </Right>
149
- </Header>
150
- )
151
- }
152
-
153
- // Activity Indicator
154
-
155
- export function MGActivityIndicator(props) {
156
- return (
157
- <Container>
158
- {props.header}
159
- <View style={{flex: 1, flexDirection: 'column', justifyContent: 'center', alignContent: 'center'}}>
160
- <ActivityIndicator size="large" color={mgConstants.COLOR_PRIMARY} />
161
- </View>
162
- {props.footer}
163
- </Container>
164
- )
165
- }
166
-
167
- // Subtitles
168
-
169
- export function MGSubtitle(props) {
170
- return (
171
- <Text style={{marginTop: 10, marginBottom: 10, alignSelf: 'center', fontWeight: 'bold', fontSize: 16}}>
172
- {props.text}
173
- </Text>
174
- )
175
- }
176
-
177
- export function MGSubtitleWithBackground(props) {
178
- return (
179
- <View style={{marginTop: 5, alignSelf: 'stretch', justifyContent: 'center', height: 30, backgroundColor: mgConstants.COLOR_TERTIARY}}>
180
- <Text style={{fontSize: 16, fontWeight: 'bold', alignSelf: 'center'}}>{props.text}</Text>
181
- </View>
182
- )
183
- }
184
-
185
- // GoBack
186
-
187
- export function MGGoBack(props) {
188
- return (
189
- <TouchableOpacity onPress={() => props.process.goBack()}>
190
- <View>
191
- <Card>
192
- <CardItem>
193
- <Icon style={{color: mgConstants.COLOR_PRIMARY}} type={mgConstants.ICON_FAMILY} name='arrow-left'></Icon>
194
- </CardItem>
195
- </Card>
196
- </View>
197
- </TouchableOpacity>
198
- )
199
- }
200
-
201
- // Buttons
202
-
203
- export function MGButtonWithIcon(props) {
204
- return buttonWithoutConfirm(props);
205
- }
206
-
207
- export function MGButtonOutlineWithIcon(props) {
208
- props.isOutline = true;
209
- return buttonWithoutConfirm(props);
210
- }
211
-
212
- function buttonWithoutConfirm(props) {
213
- return (
214
- <>
215
- <TouchableOpacity onPress={props.callback}>
216
- {props.isOutline &&
217
- buttonOutline(props)
218
- }
219
- {!props.isOutline &&
220
- button(props)
221
- }
222
- </TouchableOpacity>
223
- </>
224
- )
225
- }
226
-
227
- export function MGButtonWithIconAndConfirm(props) {
228
- return buttonWithConfirm(props);
229
- }
230
-
231
- export function MGButtonOutlineWithIconAndConfirm(props) {
232
- props.isOutline = true;
233
- return buttonWithoutConfirm(props);
234
- }
235
-
236
- function buttonWithConfirm(props) {
237
- return (
238
- <>
239
- <TouchableOpacity onPress={() => props.setMvConfirm(true)}>
240
- {props.isOutline &&
241
- buttonOutline(props)
242
- }
243
- {!props.isOutline &&
244
- button(props)
245
- }
246
- </TouchableOpacity>
247
- {confirm(props)}
248
- </>
249
- )
250
- }
251
-
252
- function button(props) {
253
- return (
254
- <View style={{marginLeft: 30, marginRight: 30}}>
255
- <Card>
256
- <CardItem style={{backgroundColor: mgConstants.COLOR_PRIMARY}}>
257
- <View style={{flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center'}}>
258
- <Icon style={{color: 'white'}} type={mgConstants.ICON_FAMILY} name={props.icon}></Icon>
259
- <Text style={{color: 'white', marginLeft: 5}}>{props.title}</Text>
260
- </View>
261
- </CardItem>
262
- </Card>
263
- </View>
264
- )
265
- }
266
-
267
- function buttonOutline(props) {
268
- return (
269
- <View>
270
- <Card>
271
- <CardItem>
272
- <View style={{flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center'}}>
273
- <Icon style={{color: mgConstants.COLOR_PRIMARY}} type={mgConstants.ICON_FAMILY} name={props.icon}></Icon>
274
- <Text style={{marginLeft: 5}}>{props.title}</Text>
275
- </View>
276
- </CardItem>
277
- </Card>
278
- </View>
279
- )
280
- }
281
-
282
- function confirm(props) {
283
- let language = props.store.getState().reducerSession.language;
284
- props.store.dispatch(mgActions.modalSetIsVisible(props.mvConfirm));
285
- let view = (<></>);
286
- if(props.mvConfirm) {
287
- view = (
288
- <View style={stylesConfirm.viewExternal}>
289
- <Modal
290
- animationType='fade'
291
- transparent={true}
292
- visible={props.mvConfirm}>
293
- <View style={{flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}>
294
- <View style={stylesConfirm.viewInternal}>
295
- <Icon style={{color: 'white'}} type={mgConstants.ICON_FAMILY} name='exclamation-triangle'></Icon>
296
- <Text style={{color: 'white'}}>{mgFunctions.i18nString('confirm', language)} ?</Text>
297
- <View style={{marginTop: 30, flexDirection: 'row', justifyContent: 'center'}}>
298
- <Button style={stylesConfirm.button} onPress={() => {props.setMvConfirm(false); props.callback()}}>
299
- <Text style={{color: mgConstants.COLOR_PRIMARY}}>{mgFunctions.i18nString('yes', language)}</Text>
300
- </Button>
301
- <Button style={stylesConfirm.button} onPress={() => {props.setMvConfirm(false)}}>
302
- <Text style={{color: mgConstants.COLOR_PRIMARY}}>{mgFunctions.i18nString('no', language)}</Text>
303
- </Button>
304
- </View>
305
- </View>
306
- </View>
307
- </Modal>
308
- </View>
309
- )
310
- }
311
- return view;
312
- }
313
-
314
- const stylesConfirm = StyleSheet.create({
315
- viewExternal: {
316
- },
317
- viewInternal: {
318
- flex: 0.5,
319
- justifyContent: 'center',
320
- alignItems: 'center',
321
- backgroundColor: mgConstants.COLOR_PRIMARY,
322
- borderRadius: 10,
323
- paddingTop: 30,
324
- paddingBottom: 30
325
- },
326
- button: {
327
- backgroundColor: 'white',
328
- flex: 1,
329
- marginLeft: 20,
330
- marginRight: 20,
331
- justifyContent: 'center'
332
- }
333
- })
package/classes.js DELETED
@@ -1,55 +0,0 @@
1
- import * as mgConstants from './constants.js';
2
- import * as mgActions from './actions.js';
3
-
4
- class ProcessNavigator {
5
-
6
- constructor(stepAtStart) {
7
- this.road = [stepAtStart];
8
- }
9
-
10
- goForward(step) {
11
- this.road.push(step);
12
- }
13
-
14
- goBack() {
15
- this.road.pop();
16
- }
17
-
18
- getStep() {
19
- return this.road[this.road.length - 1];
20
- }
21
-
22
- }
23
-
24
- export class Process {
25
-
26
- constructor(store, stepAtStart) {
27
- this.store = store;
28
- this.stepAtStart = stepAtStart;
29
- this.navigator = new ProcessNavigator(this.stepAtStart);
30
- }
31
-
32
- restart() {
33
- this.goForward(this.stepAtStart);
34
- }
35
-
36
- goForward(step) {
37
- this.navigator.goForward(step);
38
- this.initProps();
39
- this.store.dispatch(mgActions.sessionBellRing());
40
- }
41
-
42
- goBack() {
43
- this.navigator.goBack();
44
- this.initProps();
45
- this.store.dispatch(mgActions.sessionBellRing());
46
- }
47
-
48
- getStep() {
49
- return this.navigator.getStep();
50
- }
51
-
52
- initProps() {
53
- }
54
-
55
- }
package/functions.js DELETED
@@ -1,304 +0,0 @@
1
- //import Toast from 'react-native-root-toast';
2
- import moment from 'moment';
3
- import 'moment/locale/es';
4
- import 'moment/locale/en-gb';
5
- import { Camera } from 'expo-camera';
6
- import { AsyncStorage } from 'react-native';
7
- import axios from 'axios';
8
- import * as mgConstants from './constants.js';
9
- import * as mgActions from './actions.js';
10
-
11
- // App
12
-
13
- export function isFetching(store) {
14
- if(store.getState().reducerApp!=undefined)
15
- return store.getState().reducerApp.isFetching;
16
- return false;
17
- }
18
-
19
- export function isModalVisible(store) {
20
- if(store.getState().reducerApp!=undefined)
21
- return store.getState().reducerApp.isModalVisible;
22
- return false;
23
- }
24
-
25
- export async function onAutoLogin(store, app, apiUrl) {
26
- await readFromLocalStorage(mgConstants.ACCESS_TOKEN)
27
- .then(value => {
28
- accessToken = value;
29
- });
30
- try {
31
- let requestData = {
32
- app: app,
33
- language: store.getState().reducerSession.language.code,
34
- pushToken: store.getState().reducerSession.pushToken,
35
- accessToken: accessToken
36
- }
37
- store.dispatch(mgActions.apiRequest());
38
- let promise = await axios.post(apiUrl + '/Login',requestData,getRequestHeader());
39
- store.dispatch(mgActions.apiSuccess());
40
- return promise.data;
41
- } catch(error) {
42
- store.dispatch(mgActions.apiError());
43
- return {};
44
- }
45
- }
46
-
47
- export function onLogout(store, url, app) {
48
- readFromLocalStorage(mgConstants.ACCESS_TOKEN)
49
- .then(value => {
50
- accessToken = value;
51
- });
52
- let requestData = {
53
- app: app,
54
- accessToken: accessToken
55
- }
56
- store.dispatch(mgActions.apiRequest());
57
- axios.post(url + '/Logout',requestData,getRequestHeader())
58
- .then(response => {
59
- store.dispatch(mgActions.apiSuccess());
60
- writeToLocalStorage(mgConstants.ACCESS_TOKEN,'');
61
- })
62
- .catch(error => {
63
- store.dispatch(mgActions.apiError());
64
- showToastError(error);
65
- })
66
- }
67
-
68
- // Session
69
-
70
- export function hasNotices(session) {
71
- if(session.notices!=undefined)
72
- if(session.notices.length > 0)
73
- return true;
74
- return false;
75
- }
76
-
77
- // Local Storage
78
-
79
- export async function writeToLocalStorage(key, value) {
80
- await AsyncStorage.setItem(key, value);
81
- }
82
-
83
- export async function readFromLocalStorage(key) {
84
- return await AsyncStorage.getItem(key);
85
- }
86
-
87
- // Strings
88
-
89
- export function isEmpty(value) {
90
- if (Array.isArray(value))
91
- if (value.length == 0)
92
- return true;
93
- if (typeof value == 'string')
94
- if (value.trim() == '')
95
- return true;
96
- if (typeof value == 'undefined')
97
- return true;
98
- if (typeof value == 'null')
99
- return true;
100
- if (typeof value == 'object' && value !== null)
101
- return Object.keys(value).length == 0;
102
- if (value == null)
103
- return true;
104
- return false;
105
- }
106
-
107
- // Email
108
-
109
- export function isValidEmail(email) {
110
- const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
111
- return re.test(String(email).toLowerCase());
112
- }
113
-
114
- // Toast
115
-
116
- function showToast(config) {
117
- /* Toast.show(config.message, {
118
- duration: Toast.durations.LONG,
119
- position: Toast.positions.CENTER,
120
- shadow: true,
121
- animation: true,
122
- hideOnPress: true,
123
- backgroundColor: config.backgroundColor,
124
- textColor: 'white',
125
- delay: 0
126
- }); */
127
- }
128
-
129
- export function showToastError(message) {
130
- let config = {
131
- message: message,
132
- backgroundColor: 'red'
133
- }
134
- showToast(config);
135
- }
136
-
137
- export function showToastSuccess(message) {
138
- let config = {
139
- message: message,
140
- backgroundColor: 'green'
141
- }
142
- showToast(config);
143
- }
144
-
145
- export function showToastInfo(message) {
146
- let config = {
147
- message: message,
148
- backgroundColor: 'blue'
149
- }
150
- showToast(config);
151
- }
152
-
153
- export function showToastWarn(message) {
154
- let config = {
155
- message: message,
156
- backgroundColor: 'orange'
157
- }
158
- showToast(config);
159
- }
160
-
161
- // Api
162
-
163
- export function getRequestHeader() {
164
- let abortController = new AbortController();
165
- let signal = abortController.signal;
166
- setTimeout(() => abortController.abort(), 1000);
167
- let requestHeader = {
168
- 'signal': signal,
169
- 'content-type': 'application/json',
170
- 'accept': 'application/json'
171
- }
172
- return requestHeader;
173
- }
174
-
175
- // Date & Time
176
-
177
- export function getTimeFormat() {
178
- return 'HH:mm';
179
- }
180
-
181
- export function isValidDate(strDate, language) {
182
- return moment(strDate, language.dateFormat, true).isValid();
183
- }
184
-
185
- export function getDateForBackEnd(date) {
186
- return new Date(moment(date).format('DD/MM/YYYY HH:mm'));
187
- }
188
-
189
- export function capitalize(str) {
190
- if (typeof str !== 'string')
191
- return '';
192
- return str.charAt(0).toUpperCase() + str.slice(1);
193
- }
194
-
195
- export function getDateForExposition(date, language) {
196
- let m = moment(date, language.dateFormat);
197
- let day = m.format('D');
198
- let dayName = capitalize(m.format('dddd'));
199
- let monthName = capitalize(m.format('MMMM'));
200
- let year = m.format('YYYY');
201
- return dayName + ', ' + day + ' '+ monthName + ' ' + year;
202
- }
203
-
204
- export function getTimeForExposition(date) {
205
- return moment(date).format('HH:mm');
206
- }
207
-
208
- // i18n
209
-
210
- const mgStringsSpanish = require('./i18n/spanish').strings;
211
- const mgStringsEnglish = require('./i18n/english').strings;
212
-
213
- export function i18nString(key, language, stringsSpanish, stringsEnglish) {
214
- let value = undefined;
215
- switch(language.code) {
216
- case mgConstants.LANGUAGE_SPANISH.code: {
217
- value = mgStringsSpanish[key];
218
- if(value===undefined)
219
- value = stringsSpanish[key];
220
- break;
221
- }
222
- case mgConstants.LANGUAGE_ENGLISH.code: {
223
- value = mgStringsEnglish[key];
224
- if(value===undefined)
225
- value = stringsEnglish[key];
226
- break;
227
- }
228
- }
229
- if(value===undefined)
230
- value = '???' + key + '???';
231
- return value;
232
- }
233
-
234
- const mgMessagesSpanish = require('./i18n/spanish').messages;
235
- const mgMessagesEnglish = require('./i18n/english').messages;
236
-
237
- export function i18nMessage(key, language, messagesSpanish, messagesEnglish) {
238
- let value = undefined;
239
- switch(language.code) {
240
- case mgConstants.LANGUAGE_SPANISH.code: {
241
- value = mgMessagesSpanish[key];
242
- if(value===undefined)
243
- value = messagesSpanish[key];
244
- break;
245
- }
246
- case mgConstants.LANGUAGE_ENGLISH.code: {
247
- value = mgMessagesEnglish[key];
248
- if(value===undefined)
249
- value = messagesEnglish[key];
250
- break;
251
- }
252
- }
253
- if(value===undefined)
254
- value = '???' + key + '???';
255
- return value;
256
- }
257
-
258
- // Push Notifications
259
-
260
- /* export const registerPushToken = async (store) => {
261
- if (Constants.isDevice) {
262
- const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
263
- let finalStatus = existingStatus;
264
- if (existingStatus !== 'granted') {
265
- const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
266
- finalStatus = status;
267
- }
268
- if (finalStatus !== 'granted') {
269
- return;
270
- }
271
- const pushToken = await Notifications.getExpoPushTokenAsync();
272
- if (Platform.OS === 'android') {
273
- Notifications.createChannelAndroidAsync('default', {
274
- name: 'default',
275
- sound: true,
276
- priority: 'max',
277
- vibrate: [0, 250, 250, 250],
278
- });
279
- }
280
- store.dispatch(mgActions.sessionPushTokenUpdate(pushToken));
281
- }
282
- } */
283
-
284
- // Camera
285
-
286
- /* export async function isCameraAvailable() {
287
- let isAvailable = false;
288
- await Camera.requestPermissionsAsync()
289
- .then(response => {
290
- if(response.status === 'granted')
291
- isAvailable = true;
292
- });
293
- return isAvailable;
294
- } */
295
-
296
- export async function isCameraAvailable() {
297
- let isAvailable = false;
298
- await Camera.requestCameraPermissionsAsync()
299
- .then(response => {
300
- if(response.status === 'granted')
301
- isAvailable = true;
302
- });
303
- return isAvailable;
304
- }
package/login.js DELETED
@@ -1,224 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Container, Content, Label, Card, CardItem, Body, Item, Form, Input, Button, Icon } from 'native-base';
3
- //import { Keyboard, StyleSheet, Image, Text, ImageBackground, View, ActivityIndicator, TouchableOpacity } from "react-native";
4
- import { StyleSheet, Image, Text, ImageBackground, View, ActivityIndicator, TouchableOpacity } from "react-native";
5
- import { useForm } from 'react-hook-form';
6
- import axios from 'axios';
7
- import moment from 'moment';
8
- import 'moment/locale/es';
9
- import 'moment/locale/en-gb';
10
- import Constants from 'expo-constants';
11
- import * as mgFunctions from './functions.js';
12
- import * as mgConstants from './constants.js';
13
- import * as mgActions from './actions.js';
14
-
15
- export function MGLogin(props) {
16
-
17
- const {register, handleSubmit, setValue} = useForm();
18
-
19
- const [isKeyboardVisible, setIsKeyboardVisible] = useState(false);
20
-
21
- const language = props.store.getState().reducerSession.language;
22
-
23
- /* useEffect(() => {
24
- register('userName');
25
- register('password');
26
- //mgFunctions.registerPushToken(props.store);
27
- Keyboard.addListener("keyboardDidShow", () => setIsKeyboardVisible(true));
28
- Keyboard.addListener("keyboardDidHide", () => setIsKeyboardVisible(false));
29
- return () => {
30
- Keyboard.removeAllListeners("keyboardDidShow");
31
- Keyboard.removeAllListeners("keyboardDidHide");
32
- };
33
- }, [register]); */
34
-
35
- useEffect(() => {
36
- register('userName');
37
- register('password');
38
- }, [register]);
39
-
40
- let view = (
41
- <Container>
42
- <Content contentContainerStyle={styles.content}>
43
- <ImageBackground source={require('./assets/background.jpg')}
44
- style={styles.imageBackground}>
45
- <View style={styles.logo}>
46
- <Image source={require('./assets/clubonline.png')}
47
- style={{ width: 300, height: 150 }} / >
48
- {!isKeyboardVisible &&
49
- <Text>{props.appDescription}</Text>
50
- }
51
- </View>
52
- {!isKeyboardVisible &&
53
- <View style={styles.viewLanguages}>
54
- <TouchableOpacity onPress={() => onLanguage(props.store, mgConstants.LANGUAGE_SPANISH)}>
55
- <Image source={require('./assets/spain.png')}
56
- style={styles.imageLanguages} />
57
- </TouchableOpacity>
58
- <TouchableOpacity onPress={() => onLanguage(props.store, mgConstants.LANGUAGE_ENGLISH)}>
59
- <Image source={require('./assets/united_kingdom.png')}
60
- style={styles.imageLanguages} />
61
- </TouchableOpacity>
62
- </View>
63
- }
64
- <View style={styles.credentials}>
65
- <Card transparent>
66
- <CardItem header bordered>
67
- <Text style={styles.headerTextCredentials}>{mgFunctions.i18nString('credentials', language)}</Text>
68
- </CardItem>
69
- <CardItem>
70
- <Body style={styles.cardBodyCredentials}>
71
- <Form style={styles.formCredentials}>
72
- <Item stackedLabel>
73
- <Label>{mgFunctions.i18nString('userName', language)}</Label>
74
- <Input name="userName"
75
- defaultValue=""
76
- onChangeText={text => {
77
- setValue('userName', text);
78
- }}
79
- />
80
- </Item>
81
- <Item stackedLabel>
82
- <Label>{mgFunctions.i18nString('password', language)}</Label>
83
- <Input name="password"
84
- defaultValue=""
85
- secureTextEntry={true}
86
- onChangeText={text => {
87
- setValue('password', text);
88
- }}
89
- />
90
- </Item>
91
- </Form>
92
- </Body>
93
- </CardItem>
94
- <CardItem style={{flexDirection: 'column'}}>
95
- <Button full rounded onPress={handleSubmit(props.onLogin)}>
96
- <Text>{mgFunctions.i18nString('login', language)}</Text>
97
- <Icon type={mgConstants.ICON_FAMILY} name='sign-in'></Icon>
98
- </Button>
99
- </CardItem>
100
- </Card>
101
- </View>
102
- {!isKeyboardVisible &&
103
- <View>
104
- <Text style={{fontSize: 12}}>{mgFunctions.i18nString('version', language)}: {Constants.expoConfig.version}</Text>
105
- </View>
106
- }
107
- </ImageBackground>
108
- </Content>
109
- </Container>
110
- )
111
-
112
- if(props.isFetching) {
113
- view = (
114
- <View style={styles.activityIndicator}>
115
- <ActivityIndicator size="large" color={mgConstants.COLOR_PRIMARY} />
116
- </View>
117
- )
118
- }
119
-
120
- return view;
121
-
122
- }
123
-
124
- export function onPressLogin(store, app, apiUrl, rootNavigation, moduleAtStart, data) {
125
- try {
126
- if(validateForm(store, data)) {
127
- let requestData = {
128
- userName: data.userName.toLowerCase(),
129
- password: data.password,
130
- app: app,
131
- language: store.getState().reducerSession.language.code,
132
- pushToken: store.getState().reducerSession.pushToken
133
- }
134
- store.dispatch(mgActions.apiRequest());
135
- axios.post(apiUrl + '/Login',requestData,mgFunctions.getRequestHeader())
136
- .then(response => {
137
- store.dispatch(mgActions.apiSuccess());
138
- let session = response.data;
139
- store.dispatch(mgActions.sessionLogin(session));
140
- store.dispatch(mgActions.moduleActivation(moduleAtStart));
141
- mgFunctions.writeToLocalStorage(mgConstants.ACCESS_TOKEN, session.accessToken);
142
- rootNavigation.navigate('Home');
143
- })
144
- .catch(error => {
145
- store.dispatch(mgActions.apiError());
146
- mgFunctions.showToastError(mgFunctions.i18nMessage('credentialsInvalid', store.getState().reducerSession.language));
147
- })
148
- }
149
- } catch(error) {
150
- mgFunctions.showToastError(error);
151
- }
152
- }
153
-
154
- function onLanguage(store, language) {
155
- moment.locale(language.locale);
156
- store.dispatch(mgActions.sessionLanguageChange(language));
157
- }
158
-
159
- function validateForm(store, data) {
160
- if(mgFunctions.isEmpty(data.userName))
161
- throw mgFunctions.i18nMessage('userRequired', store.getState().reducerSession.language);
162
- if(mgFunctions.isEmpty(data.password))
163
- throw mgFunctions.i18nMessage('passwordRequired', store.getState().reducerSession.language);
164
- return true;
165
- }
166
-
167
- const styles = StyleSheet.create({
168
- activityIndicator: {
169
- flex: 1,
170
- flexDirection: 'column',
171
- justifyContent: 'center',
172
- alignContent: 'center'
173
- },
174
- imageBackground: {
175
- flex: 1
176
- },
177
- viewInput: {
178
- flex: 1,
179
- flexDirection: 'row'
180
- },
181
- content: {
182
- flex: 1,
183
- flexDirection: 'column'
184
- },
185
- logo: {
186
- flex: 0.7,
187
- flexDirection: 'column',
188
- justifyContent: 'center',
189
- alignItems: 'center'
190
- },
191
- viewLanguages: {
192
- flex: 0.15,
193
- flexDirection: 'row',
194
- justifyContent: 'center'
195
- },
196
- imageLanguages: {
197
- width: 36,
198
- height: 36,
199
- marginLeft: 20,
200
- marginRight: 20
201
- },
202
- credentials: {
203
- flex: 1,
204
- flexDirection: 'row',
205
- justifyContent: 'center',
206
- alignContent: 'center',
207
- marginLeft: 30,
208
- marginRight: 30
209
- },
210
- formCredentials: {
211
- flex: 1
212
- },
213
- cardBodyCredentials: {
214
- flex: 1,
215
- flexDirection: 'row'
216
- },
217
- headerTextCredentials: {
218
- width: '100%',
219
- textAlign: 'center'
220
- },
221
- cardFooterCredentials: {
222
- justifyContent: 'flex-end'
223
- }
224
- })
package/prototypes.js DELETED
@@ -1,77 +0,0 @@
1
- import * as mgFunctions from './functions.js';
2
-
3
- // String
4
-
5
- String.prototype._asTime = function () {
6
- return this + ' hs';
7
- };
8
-
9
- String.prototype._format = function () {
10
- let value = this;
11
- for (let arg in arguments) {
12
- value = value.split('{' + arg + '}').join(arguments[arg]);
13
- }
14
- return value;
15
- };
16
-
17
- String.prototype._truncate = function (length, postfix) {
18
- if(postfix==undefined)
19
- postfix = '';
20
- return this.substring(0, length) + postfix;
21
- }
22
-
23
- // Numbers
24
-
25
- Number.prototype._asCurrency = function (currencySymbol, decPlaces, thouSeparator, decSeparator) {
26
- let value = this;
27
- if(currencySymbol==undefined)
28
- currencySymbol = '';
29
- if(value==undefined)
30
- value = 0;
31
- var n = value,
32
- decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
33
- decSeparator = decSeparator == undefined ? "," : decSeparator,
34
- thouSeparator = thouSeparator == undefined ? "." : thouSeparator,
35
- sign = n < 0 ? "-" : "",
36
- i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
37
- j = (j = i.length) > 3 ? j % 3 : 0;
38
- return currencySymbol + sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "") + '.-';
39
- };
40
-
41
- Number.prototype._asInteger = function (thouSeparator, decSeparator) {
42
- let value = this;
43
- if(value==undefined)
44
- value = 0;
45
- var n = value,
46
- decSeparator = decSeparator == undefined ? "," : decSeparator,
47
- thouSeparator = thouSeparator == undefined ? "." : thouSeparator,
48
- sign = n < 0 ? "-" : "",
49
- i = parseInt(n = Math.abs(+n || 0).toFixed(0)) + "",
50
- j = (j = i.length) > 3 ? j % 3 : 0;
51
- return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator);
52
- }
53
-
54
- Number.prototype._asFloat = function (decPlaces, thouSeparator, decSeparator) {
55
- let value = this;
56
- if(value==undefined)
57
- value = 0;
58
- var n = value,
59
- decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
60
- decSeparator = decSeparator == undefined ? "," : decSeparator,
61
- thouSeparator = thouSeparator == undefined ? "." : thouSeparator,
62
- sign = n < 0 ? "-" : "",
63
- i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
64
- j = (j = i.length) > 3 ? j % 3 : 0;
65
- return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
66
- };
67
-
68
- Number.prototype._asAge = function (language) {
69
- let value = this;
70
- if(value==undefined)
71
- return 0;
72
- if(value==0)
73
- return 0;
74
- if(value==1)
75
- return value + ' ' + mgFunctions.i18nString('year', language);
76
- return value + ' ' + mgFunctions.i18nString('years', language);
77
- };
package/reducers.js DELETED
@@ -1,114 +0,0 @@
1
- import * as mgActions from './actions.js';
2
- import * as mgConstants from './constants.js';
3
- import * as mgClasses from './classes.js';
4
-
5
- // Constants
6
-
7
- export const initialStateApp = {
8
- isReady: true,
9
- isFetching: false,
10
- module: undefined,
11
- modalVisible: false
12
- }
13
-
14
- export const initialStateSession = {
15
- server: undefined,
16
- userName: '',
17
- password: '',
18
- language: mgConstants.LANGUAGE_SPANISH,
19
- company: undefined,
20
- pushToken: '',
21
- bell: false
22
- };
23
-
24
- // Functions
25
-
26
- export function runReducerApp(state, action) {
27
- switch (action.type) {
28
- case mgActions.APP_MODULE_ACTIVATION: {
29
- return {
30
- ...state,
31
- module: action.payload.module
32
- }
33
- }
34
- case mgActions.APP_API_REQUEST: {
35
- return {
36
- ...state,
37
- isFetching: true
38
- }
39
- }
40
- case mgActions.APP_API_SUCCESS: {
41
- return {
42
- ...state,
43
- isFetching: false
44
- }
45
- }
46
- case mgActions.APP_API_ERROR: {
47
- return {
48
- ...state,
49
- isFetching: false
50
- }
51
- }
52
- case mgActions.APP_MODAL_SET_ISVISIBLE: {
53
- return {
54
- ...state,
55
- isModalVisible: action.payload.isModalVisible
56
- }
57
- }
58
- default: {
59
- return state;
60
- }
61
- }
62
- }
63
-
64
- export function runReducerSession(state, initialStateSession, action) {
65
- switch (action.type) {
66
- case mgActions.SESSION_LOADING_START: {
67
- return {
68
- ...state,
69
- isLoading: true
70
- }
71
- }
72
- case mgActions.SESSION_LOADING_END: {
73
- return {
74
- ...state,
75
- isLoading: false
76
- }
77
- }
78
- case mgActions.SESSION_LOGIN: {
79
- return {
80
- ...state,
81
- server: action.payload.session.server,
82
- company: action.payload.session.company,
83
- accessToken: action.payload.session.accessToken
84
- }
85
- }
86
- case mgActions.SESSION_LOGOUT: {
87
- return {
88
- ...state,
89
- accessToken: ''
90
- }
91
- }
92
- case mgActions.SESSION_LANGUAGE_CHANGE: {
93
- return {
94
- ...state,
95
- language: action.payload.language
96
- }
97
- }
98
- case mgActions.SESSION_PUSH_TOKEN_UPDATE: {
99
- return {
100
- ...state,
101
- pushToken: action.payload.pushToken
102
- }
103
- }
104
- case mgActions.SESSION_BELL_RING: {
105
- return {
106
- ...state,
107
- bell: !state.bell
108
- }
109
- }
110
- default: {
111
- return state;
112
- }
113
- }
114
- }
package/welcome.js DELETED
@@ -1,131 +0,0 @@
1
- import React from 'react';
2
- import { StyleSheet, View, Image, FlatList, Text, TouchableOpacity } from 'react-native';
3
- import { Card, CardItem } from 'native-base';
4
- import { MGSubtitle } from './blocks.js';
5
- import * as mgFunctions from './functions.js';
6
-
7
- export function MGWelcome(props) {
8
-
9
- const language = props.session.language;
10
-
11
- let companyInfoComponent = (
12
- <Card style={styles.cardCompany}>
13
- <CardItem style={styles.cardItemCompanyLogo}>
14
- <Image source={{uri: props.session.company.logoUrl}} style={{width: 100, height: 100}} />
15
- </CardItem>
16
- <CardItem style={styles.cardItemCompanyInfo}>
17
- <Text style={styles.textCompanyLegalName}>{props.session.company.legalName}</Text>
18
- <Text style={styles.textCompanyInfo}>{props.session.company.address}</Text>
19
- <Text style={styles.textCompanyInfo}>{props.session.company.city}, {props.session.company.province}</Text>
20
- <Text style={styles.textCompanyInfo}>{props.session.company.phone}</Text>
21
- <Text style={styles.textCompanyInfo}>{props.session.company.email}</Text>
22
- </CardItem>
23
- </Card>
24
- )
25
-
26
- let listHeaderComponent = (
27
- <View style={styles.viewHeader}>
28
- {companyInfoComponent}
29
- <MGSubtitle text={mgFunctions.i18nString('notices', language)} />
30
- </View>
31
- )
32
-
33
- if(mgFunctions.hasNotices(props.session)) {
34
- return (
35
- <FlatList
36
- data={props.session.notices}
37
- keyExtractor={item => item.idNotice.toString()}
38
- ListHeaderComponent={listHeaderComponent}
39
- renderItem={({ item }) => (
40
- <Card>
41
- <CardItem header bordered style={styles.cardItemNoticeTitle}>
42
- <Text style={styles.textNoticeDescription}>{item.description}</Text>
43
- <Text style={styles.textNoticeDate}>{mgFunctions.getDateForExposition(item.noticeDate, language)}, {item.noticeTime._asTime()}</Text>
44
- </CardItem>
45
- {item.imageUrl!=undefined &&
46
- <CardItem bordered style={styles.cardItemNoticeImage}>
47
- <Image source={{uri: item.imageUrl}} style={{width: 150, height: 150}} />
48
- </CardItem>
49
- }
50
- <CardItem bordered>
51
- <Text>{item.content}</Text>
52
- </CardItem>
53
- </Card>
54
- )}
55
- />
56
- )
57
- } else {
58
- return (
59
- <>
60
- {companyInfoComponent}
61
- <Card style={{flex: 1, flexDirection: 'column', alignItems:'center'}}>
62
- <CardItem>
63
- <Image style={{width: 300, height: 150, marginTop: 30, marginBottom: 30}} source={require('./assets/welcome.png')} />
64
- </CardItem>
65
- </Card>
66
- </>
67
- )
68
- }
69
-
70
- }
71
-
72
- function MGAttachedFiles(props) {
73
- return (
74
- <View>
75
- <FlatList
76
- data={props.notice.attachedFiles}
77
- keyExtractor={item => item.idAttachedFile.toString()}
78
- renderItem={({ item }) => (
79
- <TouchableOpacity>
80
- <Card>
81
- <CardItem>
82
- <Text>{item.url}</Text>
83
- </CardItem>
84
- </Card>
85
- </TouchableOpacity>
86
- )}
87
- />
88
- </View>
89
- )
90
- }
91
-
92
- const styles = StyleSheet.create({
93
- viewHeader: {
94
- flex: 1,
95
- flexDirection: 'column'
96
- },
97
- cardCompany: {
98
- flex: 1,
99
- flexDirection: 'row'
100
- },
101
- cardItemCompanyLogo: {
102
- alignSelf: 'flex-start'
103
- },
104
- cardItemCompanyInfo: {
105
- flex: 1,
106
- flexDirection: 'column',
107
- alignSelf: 'center'
108
- },
109
- textCompanyLegalName: {
110
- textAlign: 'center'
111
- },
112
- textCompanyInfo: {
113
- fontSize: 10,
114
- textAlign: 'center'
115
- },
116
- cardItemNoticeTitle: {
117
- flex: 1,
118
- flexDirection: 'column',
119
- alignItems: 'flex-start'
120
- },
121
- cardItemNoticeImage: {
122
- alignSelf: 'center'
123
- },
124
- textNoticeDescription: {
125
- fontSize: 16,
126
- fontWeight: 'bold'
127
- },
128
- textNoticeDate: {
129
- fontSize: 11
130
- }
131
- })