@janiscommerce/app-tracking-shift 1.4.0-beta.3 → 1.4.0-beta.5
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/README.md +1 -1
- package/lib/Shift.js +20 -14
- package/lib/hooks/useStorageValue/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/Shift.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
CURRENT_WORKLOG_ID,
|
|
21
21
|
EXCLUDED_WORKLOG_TYPES,
|
|
22
22
|
DEFAULT_REOPENING_EXTENSION_TIME,
|
|
23
|
+
WORKLOG_TYPES_DATA,
|
|
23
24
|
} from './constant';
|
|
24
25
|
import Formatter from './Formatter';
|
|
25
26
|
import OfflineData from './OfflineData';
|
|
@@ -33,9 +34,8 @@ class Shift {
|
|
|
33
34
|
* @returns {boolean} hasStaffAuthorization => true if the user has staff MS authorization, false otherwise
|
|
34
35
|
*/
|
|
35
36
|
|
|
36
|
-
get
|
|
37
|
-
|
|
38
|
-
return hasStaffAuthorization;
|
|
37
|
+
get hasStaffAuthorization() {
|
|
38
|
+
return getStaffAuthorizationData().hasStaffAuthorization;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -62,6 +62,12 @@ class Shift {
|
|
|
62
62
|
Storage.set(SHIFT_STATUS, status);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
get hasWorkTypes() {
|
|
66
|
+
const {workLogTypes = []} = Storage.get(WORKLOG_TYPES_DATA) || {};
|
|
67
|
+
|
|
68
|
+
return !!workLogTypes?.length;
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
/**
|
|
66
72
|
* Get the shift data
|
|
67
73
|
* @returns {Object} data => The shift data
|
|
@@ -128,7 +134,7 @@ class Shift {
|
|
|
128
134
|
try {
|
|
129
135
|
Crashlytics.log('openShift:');
|
|
130
136
|
|
|
131
|
-
if (!this.
|
|
137
|
+
if (!this.hasStaffAuthorization) {
|
|
132
138
|
this._throwAuthorizationError();
|
|
133
139
|
}
|
|
134
140
|
|
|
@@ -162,7 +168,7 @@ class Shift {
|
|
|
162
168
|
try {
|
|
163
169
|
Crashlytics.log('closeShift:');
|
|
164
170
|
|
|
165
|
-
if (!this.
|
|
171
|
+
if (!this.hasStaffAuthorization) {
|
|
166
172
|
this._throwAuthorizationError();
|
|
167
173
|
}
|
|
168
174
|
|
|
@@ -178,7 +184,6 @@ class Shift {
|
|
|
178
184
|
const {id: shiftId = ''} = shift || {};
|
|
179
185
|
const endDate = date || new Date().toISOString();
|
|
180
186
|
|
|
181
|
-
this.status = 'closed';
|
|
182
187
|
this.data = {
|
|
183
188
|
...this.data,
|
|
184
189
|
endDate,
|
|
@@ -212,9 +217,10 @@ class Shift {
|
|
|
212
217
|
|
|
213
218
|
if (!isValidObject(workLog)) return null;
|
|
214
219
|
|
|
215
|
-
if (!this.
|
|
220
|
+
if (!this.hasStaffAuthorization) {
|
|
216
221
|
this._throwAuthorizationError();
|
|
217
222
|
}
|
|
223
|
+
delete workLog.endDate;
|
|
218
224
|
|
|
219
225
|
if (this.hasWorkLogInProgress) {
|
|
220
226
|
const {startDate, ...currentRest} = this.getCurrentWorkLog();
|
|
@@ -278,7 +284,7 @@ class Shift {
|
|
|
278
284
|
|
|
279
285
|
if (!isValidObject(workLog)) return null;
|
|
280
286
|
|
|
281
|
-
if (!this.
|
|
287
|
+
if (!this.hasStaffAuthorization) {
|
|
282
288
|
this._throwAuthorizationError();
|
|
283
289
|
}
|
|
284
290
|
|
|
@@ -295,7 +301,7 @@ class Shift {
|
|
|
295
301
|
}
|
|
296
302
|
|
|
297
303
|
workLog.endDate = new Date().toISOString();
|
|
298
|
-
workLog.startDate
|
|
304
|
+
delete workLog.startDate;
|
|
299
305
|
|
|
300
306
|
if (this.isPaused) {
|
|
301
307
|
this.status = 'opened';
|
|
@@ -388,7 +394,7 @@ class Shift {
|
|
|
388
394
|
try {
|
|
389
395
|
Crashlytics.log('sendPendingWorkLogs:');
|
|
390
396
|
|
|
391
|
-
if (!this.
|
|
397
|
+
if (!this.hasStaffAuthorization) {
|
|
392
398
|
this._throwAuthorizationError();
|
|
393
399
|
}
|
|
394
400
|
|
|
@@ -426,7 +432,7 @@ class Shift {
|
|
|
426
432
|
try {
|
|
427
433
|
Crashlytics.log('getUserOpenShift:', params);
|
|
428
434
|
|
|
429
|
-
if (!this.
|
|
435
|
+
if (!this.hasStaffAuthorization) {
|
|
430
436
|
this._throwAuthorizationError();
|
|
431
437
|
}
|
|
432
438
|
|
|
@@ -460,7 +466,7 @@ class Shift {
|
|
|
460
466
|
try {
|
|
461
467
|
Crashlytics.log('getWorkLogs:');
|
|
462
468
|
|
|
463
|
-
if (!this.
|
|
469
|
+
if (!this.hasStaffAuthorization) {
|
|
464
470
|
this._throwAuthorizationError();
|
|
465
471
|
}
|
|
466
472
|
|
|
@@ -491,7 +497,7 @@ class Shift {
|
|
|
491
497
|
try {
|
|
492
498
|
Crashlytics.log('reOpenShift:');
|
|
493
499
|
|
|
494
|
-
if (!this.
|
|
500
|
+
if (!this.hasStaffAuthorization) {
|
|
495
501
|
this._throwAuthorizationError();
|
|
496
502
|
}
|
|
497
503
|
|
|
@@ -539,7 +545,7 @@ class Shift {
|
|
|
539
545
|
try {
|
|
540
546
|
Crashlytics.log('fetchWorklogTypes:');
|
|
541
547
|
|
|
542
|
-
if (!this.
|
|
548
|
+
if (!this.hasStaffAuthorization) {
|
|
543
549
|
this._throwAuthorizationError();
|
|
544
550
|
}
|
|
545
551
|
|
|
@@ -6,7 +6,7 @@ import errorParser from '../../utils/errorParser';
|
|
|
6
6
|
export const useStorageValue = (key, defaultValue = null) => {
|
|
7
7
|
const readValue = useCallback(() => {
|
|
8
8
|
try {
|
|
9
|
-
return Storage.get(key)
|
|
9
|
+
return Storage.get(key) ?? defaultValue;
|
|
10
10
|
} catch (error) {
|
|
11
11
|
const parsedError = errorParser(error);
|
|
12
12
|
Crashlytics.recordError(parsedError, `[useStorageValue] Error with key: ${key}`);
|