@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 CHANGED
@@ -226,7 +226,7 @@ Main class for shift and work log operations.
226
226
 
227
227
  #### Properties
228
228
 
229
- **`hasStaffAuthorize`** (getter)
229
+ **`hasStaffAuthorization`** (getter)
230
230
 
231
231
  - Returns: `boolean` - Staff authorization status
232
232
 
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 hasStaffAuthorize() {
37
- const {hasStaffAuthorization} = getStaffAuthorizationData();
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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 = null;
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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.hasStaffAuthorize) {
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) || defaultValue;
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}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janiscommerce/app-tracking-shift",
3
- "version": "1.4.0-beta.3",
3
+ "version": "1.4.0-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "module": "lib/index.js",
6
6
  "exports": {