@janiscommerce/app-tracking-shift 1.7.0-beta.1 → 1.7.0-beta.3
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/lib/Formatter.js +1 -1
- package/lib/OfflineData.js +1 -1
- package/lib/Shift.js +24 -30
- package/lib/ShiftWorklogs.js +11 -1
- package/lib/StaffApiServices.js +4 -4
- package/lib/helpers/index.js +30 -0
- package/lib/{utils → helpers}/provider/downloadWorkLogTypes/index.js +1 -1
- package/lib/{utils → helpers}/provider/openShift/index.js +1 -1
- package/lib/hooks/useStorageValue/index.js +2 -2
- package/lib/provider/ShiftTrackingProvider.js +5 -4
- package/package.json +3 -2
- package/lib/utils/helpers/index.js +0 -49
- /package/lib/{utils → helpers}/crashlytics/index.js +0 -0
- /package/lib/{utils → helpers}/errorParser/index.js +0 -0
- /package/lib/{utils/helpers → helpers}/isApiError/index.js +0 -0
- /package/lib/{utils/helpers → helpers}/isInternetReachable/index.js +0 -0
- /package/lib/{utils → helpers}/provider/getShiftWorkLogsFromJanis/index.js +0 -0
- /package/lib/{utils → helpers}/provider/index.js +0 -0
- /package/lib/{utils → helpers}/provider/isAuthorizedToUseStaffMS/index.js +0 -0
- /package/lib/{utils → helpers}/request/index.js +0 -0
- /package/lib/{utils → helpers}/storage/getStaffAuthorizationData/index.js +0 -0
- /package/lib/{utils → helpers}/storage/getWorkLogTypesData/index.js +0 -0
- /package/lib/{utils → helpers}/storage/index.js +0 -0
- /package/lib/{utils → helpers}/userInfo/getUserId/index.js +0 -0
package/lib/Formatter.js
CHANGED
package/lib/OfflineData.js
CHANGED
package/lib/Shift.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
+
import {isArray, isEmptyArray, isNumber} from '@janiscommerce/apps-helpers';
|
|
1
2
|
import StaffService from './StaffApiServices';
|
|
2
3
|
import Storage from './db/StorageService';
|
|
3
|
-
import Crashlytics from './
|
|
4
|
+
import Crashlytics from './helpers/crashlytics';
|
|
4
5
|
import ShiftWorklogs from './ShiftWorklogs';
|
|
5
|
-
import errorParser from './
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
isEmptyArray,
|
|
9
|
-
isNumber,
|
|
10
|
-
isValidObject,
|
|
11
|
-
isApiError,
|
|
12
|
-
isInternetReachable,
|
|
13
|
-
isValidDate,
|
|
14
|
-
parseToISOString,
|
|
15
|
-
} from './utils/helpers';
|
|
16
|
-
import {getStaffAuthorizationData} from './utils/storage';
|
|
6
|
+
import errorParser from './helpers/errorParser';
|
|
7
|
+
import {isApiError, isInternetReachable, isValidDate, parseToISOString} from './helpers';
|
|
8
|
+
import {getStaffAuthorizationData} from './helpers/storage';
|
|
17
9
|
import {
|
|
18
10
|
SHIFT_ID,
|
|
19
11
|
SHIFT_STATUS,
|
|
@@ -252,34 +244,34 @@ class Shift {
|
|
|
252
244
|
* @param {string} workLog.name => Name related to the work log
|
|
253
245
|
* @param {string} workLog.type => Type related to the work log
|
|
254
246
|
* @param {number} workLog.suggestedTime => Suggested time related to the work log
|
|
255
|
-
* @param {string|number}
|
|
247
|
+
* @param {string|number} workLog.startDate => Start date related to the work log. Accepts an ISO 8601 string (e.g. "2026-03-05T10:00:00.000Z") or milliseconds since epoch (e.g. 1709636400000). Defaults to current date if omitted or invalid.
|
|
256
248
|
* @throws {Error} error
|
|
257
249
|
* @returns {Promise<string>} workLogId => ID related to the work log that has just been opened for the user
|
|
258
250
|
*/
|
|
259
251
|
|
|
260
|
-
async openWorkLog(workLog = {}
|
|
252
|
+
async openWorkLog(workLog = {}) {
|
|
261
253
|
let previousWorkLog = {};
|
|
262
254
|
|
|
263
255
|
try {
|
|
264
256
|
Crashlytics.log('openWorkLog:', workLog);
|
|
265
257
|
|
|
266
|
-
|
|
267
|
-
? parseToISOString(startDate)
|
|
268
|
-
: new Date().toISOString();
|
|
269
|
-
|
|
270
|
-
if (!isValidObject(workLog)) return null;
|
|
258
|
+
if (!ShiftWorklogs.isValidWorkLog(workLog)) return null;
|
|
271
259
|
|
|
272
260
|
if (!this.hasStaffAuthorization) {
|
|
273
261
|
this._throwAuthorizationError();
|
|
274
262
|
}
|
|
263
|
+
|
|
264
|
+
workLog.startDate = isValidDate(workLog.startDate)
|
|
265
|
+
? parseToISOString(workLog.startDate)
|
|
266
|
+
: new Date().toISOString();
|
|
267
|
+
|
|
275
268
|
delete workLog.endDate;
|
|
276
269
|
|
|
277
270
|
if (this.hasWorkLogInProgress) {
|
|
278
|
-
|
|
279
|
-
previousWorkLog
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
};
|
|
271
|
+
previousWorkLog = this.getCurrentWorkLog();
|
|
272
|
+
delete previousWorkLog.startDate;
|
|
273
|
+
|
|
274
|
+
previousWorkLog.endDate = workLog.startDate;
|
|
283
275
|
}
|
|
284
276
|
|
|
285
277
|
if (this._hasToPause(workLog.referenceId)) {
|
|
@@ -287,7 +279,6 @@ class Shift {
|
|
|
287
279
|
}
|
|
288
280
|
|
|
289
281
|
workLog.id = ShiftWorklogs.createId(workLog.referenceId);
|
|
290
|
-
workLog.startDate = currentDate;
|
|
291
282
|
this.setCurrentWorkLog(workLog);
|
|
292
283
|
|
|
293
284
|
const hasInternet = await isInternetReachable();
|
|
@@ -326,6 +317,7 @@ class Shift {
|
|
|
326
317
|
* Finish a work log in the staff MS and record this event in the time tracking database.
|
|
327
318
|
* @param {Object} workLog
|
|
328
319
|
* @param {string} workLog.referenceId => Reference ID related to the work log
|
|
320
|
+
* @param {string|number} workLog.endDate => End date related to the work log. Accepts an ISO 8601 string (e.g. "2026-03-05T10:00:00.000Z") or milliseconds since epoch (e.g. 1709636400000). Defaults to current date if omitted or invalid.
|
|
329
321
|
* @throws {Error} error
|
|
330
322
|
* @returns {Promise<string>} workLogId => ID related to the work log that has just been closed for the user
|
|
331
323
|
*/
|
|
@@ -334,7 +326,7 @@ class Shift {
|
|
|
334
326
|
try {
|
|
335
327
|
Crashlytics.log('finishWorkLog:', workLog);
|
|
336
328
|
|
|
337
|
-
if (!
|
|
329
|
+
if (!ShiftWorklogs.isValidWorkLog(workLog)) return null;
|
|
338
330
|
|
|
339
331
|
if (!this.hasStaffAuthorization) {
|
|
340
332
|
this._throwAuthorizationError();
|
|
@@ -342,7 +334,7 @@ class Shift {
|
|
|
342
334
|
|
|
343
335
|
const currentWorkLog = this.getCurrentWorkLog();
|
|
344
336
|
|
|
345
|
-
if (!
|
|
337
|
+
if (!ShiftWorklogs.isValidWorkLog(currentWorkLog)) {
|
|
346
338
|
throw new Error('There is no active worklog to close');
|
|
347
339
|
}
|
|
348
340
|
|
|
@@ -352,7 +344,9 @@ class Shift {
|
|
|
352
344
|
);
|
|
353
345
|
}
|
|
354
346
|
|
|
355
|
-
workLog.endDate =
|
|
347
|
+
workLog.endDate = isValidDate(workLog.endDate)
|
|
348
|
+
? parseToISOString(workLog.endDate)
|
|
349
|
+
: new Date().toISOString();
|
|
356
350
|
delete workLog.startDate;
|
|
357
351
|
|
|
358
352
|
if (this.isPaused) {
|
|
@@ -406,7 +400,7 @@ class Shift {
|
|
|
406
400
|
|
|
407
401
|
return {
|
|
408
402
|
...(!!id && {id}),
|
|
409
|
-
...(
|
|
403
|
+
...(ShiftWorklogs.isValidWorkLog(data) && {...data}),
|
|
410
404
|
};
|
|
411
405
|
}
|
|
412
406
|
|
package/lib/ShiftWorklogs.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject,
|
|
3
|
+
isEmptyObject,
|
|
4
|
+
isArray,
|
|
5
|
+
isEmptyArray,
|
|
6
|
+
generateRandomId,
|
|
7
|
+
} from '@janiscommerce/apps-helpers';
|
|
1
8
|
import {INTERNAL_WORKLOGS} from './constant';
|
|
2
9
|
import StaffApiServices from './StaffApiServices';
|
|
3
|
-
import {generateRandomId, isArray, isEmptyArray} from './utils/helpers';
|
|
4
10
|
|
|
5
11
|
class ShiftWorklogs {
|
|
6
12
|
async open(params) {
|
|
@@ -101,6 +107,10 @@ class ShiftWorklogs {
|
|
|
101
107
|
})
|
|
102
108
|
.filter(Boolean);
|
|
103
109
|
}
|
|
110
|
+
|
|
111
|
+
isValidWorkLog(workLog = {}) {
|
|
112
|
+
return isObject(workLog) && !isEmptyObject(workLog);
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
export default new ShiftWorklogs();
|
package/lib/StaffApiServices.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import {isString} from '@janiscommerce/apps-helpers';
|
|
2
|
+
import Request from './helpers/request';
|
|
3
3
|
|
|
4
4
|
class StaffApiServices {
|
|
5
5
|
constructor() {
|
|
@@ -19,7 +19,7 @@ class StaffApiServices {
|
|
|
19
19
|
service: this.service,
|
|
20
20
|
namespace: 'shift-open',
|
|
21
21
|
body: {
|
|
22
|
-
...(
|
|
22
|
+
...(isString(warehouseId) && !!warehouseId && {warehouseId}),
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
} catch (error) {
|
|
@@ -40,7 +40,7 @@ class StaffApiServices {
|
|
|
40
40
|
service: this.service,
|
|
41
41
|
namespace: 'shift-update',
|
|
42
42
|
body: {
|
|
43
|
-
...(
|
|
43
|
+
...(isString(warehouseId) && !!warehouseId && {warehouseId}),
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
46
|
} catch (error) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {isNumber, isString} from '@janiscommerce/apps-helpers';
|
|
2
|
+
|
|
3
|
+
export {default as isApiError} from './isApiError';
|
|
4
|
+
|
|
5
|
+
export {default as isInternetReachable} from './isInternetReachable';
|
|
6
|
+
|
|
7
|
+
export const reverseArray = (arr) => arr.slice().reverse();
|
|
8
|
+
|
|
9
|
+
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
10
|
+
const isIsoStringDate = (str) => ISO_DATE_REGEX.test(str);
|
|
11
|
+
|
|
12
|
+
export const isValidDate = (date = '') => {
|
|
13
|
+
if (isNumber(date) && date > 0) {
|
|
14
|
+
const dateTime = new Date(date).getTime();
|
|
15
|
+
return isNumber(dateTime);
|
|
16
|
+
}
|
|
17
|
+
if (!isString(date) || !date?.length) return false;
|
|
18
|
+
|
|
19
|
+
if (!isIsoStringDate(date)) return false;
|
|
20
|
+
|
|
21
|
+
const dateTime = new Date(date).getTime();
|
|
22
|
+
return isNumber(dateTime);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const parseToISOString = (date = '') => {
|
|
26
|
+
if (isNumber(date) && date > 0) return new Date(date).toISOString();
|
|
27
|
+
if (!isString(date) || !date?.length) return '';
|
|
28
|
+
|
|
29
|
+
return date;
|
|
30
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import {isFunction} from '@janiscommerce/apps-helpers';
|
|
1
2
|
import Shift from '../../../Shift';
|
|
2
3
|
import {getWorkLogTypesData} from '../../storage';
|
|
3
4
|
import {WORKLOG_TYPES_DATA, WORKLOG_TYPES_EXPIRATION_TIME} from '../../../constant';
|
|
4
5
|
import Storage from '../../../db/StorageService';
|
|
5
6
|
import Crashlytics from '../../crashlytics';
|
|
6
|
-
import {isFunction} from '../../helpers';
|
|
7
7
|
import errorParser from '../../errorParser';
|
|
8
8
|
|
|
9
9
|
const downloadWorkLogTypes = async (onDownloadError) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import {isFunction} from '@janiscommerce/apps-helpers';
|
|
1
2
|
import Crashlytics from '../../crashlytics';
|
|
2
3
|
import getUserId from '../../userInfo/getUserId';
|
|
3
4
|
import Shift from '../../../Shift';
|
|
4
|
-
import {isFunction} from '../../helpers';
|
|
5
5
|
import errorParser from '../../errorParser';
|
|
6
6
|
|
|
7
7
|
const openShift = async ({onOpenShiftError, warehouseId}) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useEffect, useState, useCallback} from 'react';
|
|
2
2
|
import Storage from '../../db/StorageService';
|
|
3
|
-
import Crashlytics from '../../
|
|
4
|
-
import errorParser from '../../
|
|
3
|
+
import Crashlytics from '../../helpers/crashlytics';
|
|
4
|
+
import errorParser from '../../helpers/errorParser';
|
|
5
5
|
|
|
6
6
|
export const useStorageValue = (key, defaultValue = null) => {
|
|
7
7
|
const readValue = useCallback(() => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, {useEffect, useMemo, useState} from 'react';
|
|
2
|
+
import {promiseWrapper} from '@janiscommerce/apps-helpers';
|
|
2
3
|
import {useStorageValue} from '../hooks/useStorageValue';
|
|
3
4
|
import ShiftTrackingContext from '../context/ShiftTrackingContext';
|
|
4
5
|
import {
|
|
@@ -6,7 +7,7 @@ import {
|
|
|
6
7
|
downloadWorkLogTypes,
|
|
7
8
|
isAuthorizedToUseStaffMS,
|
|
8
9
|
getShiftWorkLogsFromJanis,
|
|
9
|
-
} from '../
|
|
10
|
+
} from '../helpers/provider';
|
|
10
11
|
import {
|
|
11
12
|
CURRENT_WORKLOG_DATA,
|
|
12
13
|
CURRENT_WORKLOG_ID,
|
|
@@ -17,8 +18,8 @@ import {
|
|
|
17
18
|
STAFF_AUTH,
|
|
18
19
|
WORKLOG_TYPES_DATA,
|
|
19
20
|
} from '../constant';
|
|
20
|
-
import {isValidObject, promiseWrapper} from '../utils/helpers';
|
|
21
21
|
import Shift from '../Shift';
|
|
22
|
+
import ShiftWorklogs from '../ShiftWorklogs';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* ShiftTrackingProvider component
|
|
@@ -145,11 +146,11 @@ const ShiftTrackingProvider = ({children, additionalInfo = {}, onError = null})
|
|
|
145
146
|
const [currentWorkLog = {}] = openWorkLogs;
|
|
146
147
|
const isExcludedWork = EXCLUDED_WORKLOG_TYPES.includes(currentWorkLog?.referenceId);
|
|
147
148
|
|
|
148
|
-
if (
|
|
149
|
+
if (ShiftWorklogs.isValidWorkLog(currentWorkLog)) {
|
|
149
150
|
Shift.setCurrentWorkLog(currentWorkLog);
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
if (
|
|
153
|
+
if (ShiftWorklogs.isValidWorkLog(currentWorkLog) && !isExcludedWork) {
|
|
153
154
|
Shift.status = 'paused';
|
|
154
155
|
}
|
|
155
156
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janiscommerce/app-tracking-shift",
|
|
3
|
-
"version": "1.7.0-beta.
|
|
3
|
+
"version": "1.7.0-beta.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@janiscommerce/app-crashlytics": "^2.1.0",
|
|
61
61
|
"@janiscommerce/app-request": "^2.6.0",
|
|
62
62
|
"@janiscommerce/app-storage": "^1.1.0",
|
|
63
|
+
"@janiscommerce/apps-helpers": "^2.2.0",
|
|
63
64
|
"@janiscommerce/oauth-native": "^1.10.2",
|
|
64
65
|
"@testing-library/react": "^16.3.0",
|
|
65
66
|
"@testing-library/react-native": "^12.0.1",
|
|
@@ -81,8 +82,8 @@
|
|
|
81
82
|
"react": "18.2.0",
|
|
82
83
|
"react-native": "0.71.6",
|
|
83
84
|
"react-native-device-info": "^10.12.0",
|
|
84
|
-
"react-native-mmkv": "2.12.2",
|
|
85
85
|
"react-native-inappbrowser-reborn": "^3.7.0",
|
|
86
|
+
"react-native-mmkv": "2.12.2",
|
|
86
87
|
"react-test-renderer": "18.2.0"
|
|
87
88
|
}
|
|
88
89
|
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export {default as isApiError} from './isApiError';
|
|
2
|
-
|
|
3
|
-
export {default as isInternetReachable} from './isInternetReachable';
|
|
4
|
-
|
|
5
|
-
export const generateRandomId = () => Math.random().toString(32).slice(2);
|
|
6
|
-
|
|
7
|
-
export const isFunction = (fn) => !!({}.toString.call(fn) === '[object Function]');
|
|
8
|
-
|
|
9
|
-
export const isObject = (obj) => !!(obj && obj.constructor === Object);
|
|
10
|
-
|
|
11
|
-
export const isEmptyObject = (obj) => isObject(obj) && !Object.keys(obj).length;
|
|
12
|
-
|
|
13
|
-
export const promiseWrapper = (promise) =>
|
|
14
|
-
promise.then((data) => [data, null]).catch((error) => Promise.resolve([null, error]));
|
|
15
|
-
|
|
16
|
-
export const isArray = (arr) => Array.isArray(arr);
|
|
17
|
-
|
|
18
|
-
export const isEmptyArray = (arr) => isArray(arr) && !arr.length;
|
|
19
|
-
|
|
20
|
-
export const reverseArray = (arr) => arr.slice().reverse();
|
|
21
|
-
|
|
22
|
-
export const isNumber = (num) => typeof num === 'number' && !Number.isNaN(Number(num));
|
|
23
|
-
|
|
24
|
-
export const isValidObject = (obj) => isObject(obj) && !!Object.keys(obj).length;
|
|
25
|
-
|
|
26
|
-
export const isValidString = (str) => typeof str === 'string' && str.length > 0;
|
|
27
|
-
|
|
28
|
-
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
29
|
-
export const isIsoStringDate = (str) => ISO_DATE_REGEX.test(str);
|
|
30
|
-
|
|
31
|
-
export const isValidDate = (date = '') => {
|
|
32
|
-
if (isNumber(date) && date > 0) {
|
|
33
|
-
const dateTime = new Date(date).getTime();
|
|
34
|
-
return !Number.isNaN(dateTime);
|
|
35
|
-
}
|
|
36
|
-
if (!isValidString(date)) return false;
|
|
37
|
-
|
|
38
|
-
if (!isIsoStringDate(date)) return false;
|
|
39
|
-
|
|
40
|
-
const dateTime = new Date(date).getTime();
|
|
41
|
-
return !Number.isNaN(dateTime);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const parseToISOString = (date = '') => {
|
|
45
|
-
if (isNumber(date) && date > 0) return new Date(date).toISOString();
|
|
46
|
-
if (!isValidString(date)) return '';
|
|
47
|
-
|
|
48
|
-
return date;
|
|
49
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|