@janiscommerce/app-tracking-shift 1.0.1
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 -0
- package/lib/Formatter.js +214 -0
- package/lib/OfflineData.js +91 -0
- package/lib/Shift.js +538 -0
- package/lib/ShiftWorklogs.js +92 -0
- package/lib/StaffApiServices.js +151 -0
- package/lib/TrackerRecords.js +103 -0
- package/lib/components/WithShiftTracking/index.js +36 -0
- package/lib/constant/index.js +33 -0
- package/lib/context/ShiftTrackingContext.js +7 -0
- package/lib/db/StorageService.js +5 -0
- package/lib/db/TimeTrackerService.js +5 -0
- package/lib/hooks/useMMKVObject/index.js +19 -0
- package/lib/index.js +7 -0
- package/lib/provider/ShiftTrackingProvider.js +174 -0
- package/lib/utils/crashlytics/index.js +5 -0
- package/lib/utils/helpers/index.js +20 -0
- package/lib/utils/provider/downloadWorkLogTypes/index.js +30 -0
- package/lib/utils/provider/getShiftWorkLogsFromJanis/index.js +18 -0
- package/lib/utils/provider/index.js +5 -0
- package/lib/utils/provider/isAuthorizedToUseStaffMS/index.js +39 -0
- package/lib/utils/provider/openShift/index.js +69 -0
- package/lib/utils/provider/saveWorkLogTimesInDB/index.js +38 -0
- package/lib/utils/request/index.js +15 -0
- package/lib/utils/storage/getShiftData/index.js +33 -0
- package/lib/utils/storage/getStaffAuthorizationData/index.js +24 -0
- package/lib/utils/storage/getWorkLogTypesData/index.js +37 -0
- package/lib/utils/storage/index.js +19 -0
- package/lib/utils/userInfo/getUserId/index.js +12 -0
- package/package.json +92 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import Storage from '../../../db/StorageService';
|
|
2
|
+
import Crashlytics from '../../crashlytics';
|
|
3
|
+
import {
|
|
4
|
+
SHIFT_ID,
|
|
5
|
+
SHIFT_STATUS,
|
|
6
|
+
SHIFT_DATA,
|
|
7
|
+
CURRENT_WORKLOG_ID,
|
|
8
|
+
CURRENT_WORKLOG_DATA,
|
|
9
|
+
} from '../../../constant';
|
|
10
|
+
import getUserId from '../../userInfo/getUserId';
|
|
11
|
+
import Shift from '../../../Shift';
|
|
12
|
+
import {isFunction} from '../../helpers';
|
|
13
|
+
import TimeTracker from '../../../db/TimeTrackerService';
|
|
14
|
+
|
|
15
|
+
const openShift = async (onOpenShiftError) => {
|
|
16
|
+
try {
|
|
17
|
+
const shiftId = Storage.getString(SHIFT_ID);
|
|
18
|
+
const userId = await getUserId();
|
|
19
|
+
|
|
20
|
+
if (!userId) {
|
|
21
|
+
await Shift.deleteShiftRegisters();
|
|
22
|
+
const openShiftId = await Shift.open();
|
|
23
|
+
return {
|
|
24
|
+
openShiftId,
|
|
25
|
+
getWorkLogs: true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const currentShift = await Shift.getUserOpenShift({id: shiftId, userId});
|
|
30
|
+
|
|
31
|
+
if (currentShift?.status !== 'opened') {
|
|
32
|
+
await Shift.deleteShiftRegisters();
|
|
33
|
+
const openShiftId = await Shift.open();
|
|
34
|
+
return {
|
|
35
|
+
openShiftId,
|
|
36
|
+
getWorkLogs: true,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (shiftId === currentShift.id)
|
|
41
|
+
return {
|
|
42
|
+
openShiftId: currentShift.id,
|
|
43
|
+
getWorkLogs: false,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
Storage.delete(CURRENT_WORKLOG_ID);
|
|
47
|
+
Storage.delete(CURRENT_WORKLOG_DATA);
|
|
48
|
+
Storage.set(SHIFT_ID, currentShift.id);
|
|
49
|
+
Storage.set(SHIFT_STATUS, currentShift.status);
|
|
50
|
+
Storage.set(SHIFT_DATA, JSON.stringify(currentShift));
|
|
51
|
+
|
|
52
|
+
await TimeTracker.addEvent({
|
|
53
|
+
id: currentShift.id,
|
|
54
|
+
time: currentShift.startDate,
|
|
55
|
+
type: 'start',
|
|
56
|
+
}).catch(() => null);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
openShiftId: currentShift.id,
|
|
60
|
+
getWorkLogs: true,
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
Crashlytics.recordError(error, 'Error opening shift in staff service');
|
|
64
|
+
if (isFunction(onOpenShiftError)) onOpenShiftError(error);
|
|
65
|
+
return Promise.reject(error?.result || error);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default openShift;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import TimeTracker from '../../../db/TimeTrackerService';
|
|
2
|
+
import {isEmptyObject, isObject} from '../../helpers';
|
|
3
|
+
|
|
4
|
+
const saveWorkLogTimesInDB = async (workLog = {}) => {
|
|
5
|
+
try {
|
|
6
|
+
if (!isObject(workLog) || isEmptyObject(workLog)) return false;
|
|
7
|
+
|
|
8
|
+
const {startDate, endDate, shiftId, id, referenceId, name} = workLog;
|
|
9
|
+
|
|
10
|
+
const dataForDB = {
|
|
11
|
+
shiftId,
|
|
12
|
+
referenceId,
|
|
13
|
+
name,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
await TimeTracker.addEvent({
|
|
17
|
+
id,
|
|
18
|
+
type: 'start',
|
|
19
|
+
time: startDate,
|
|
20
|
+
payload: dataForDB,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (endDate) {
|
|
24
|
+
await TimeTracker.addEvent({
|
|
25
|
+
id,
|
|
26
|
+
type: 'finish',
|
|
27
|
+
time: endDate,
|
|
28
|
+
payload: dataForDB,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return Promise.reject(error);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default saveWorkLogTimesInDB;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Request from '@janiscommerce/app-request';
|
|
2
|
+
import {getApplicationName} from '@janiscommerce/app-device-info';
|
|
3
|
+
|
|
4
|
+
const getAppEnvironment = () => {
|
|
5
|
+
const appName = getApplicationName();
|
|
6
|
+
|
|
7
|
+
if (!appName) return '';
|
|
8
|
+
|
|
9
|
+
if (appName.toLowerCase().includes('beta')) return 'janisdev';
|
|
10
|
+
if (appName.toLowerCase().includes('qa')) return 'janisqa';
|
|
11
|
+
|
|
12
|
+
return 'janis';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default new Request({JANIS_ENV: getAppEnvironment()});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Storage from '../../../db/StorageService';
|
|
2
|
+
import {SHIFT_DATA} from '../../../constant';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description Get the shift data from the storage
|
|
6
|
+
* @returns {Object} The shift data
|
|
7
|
+
* @example
|
|
8
|
+
* const shiftData = getShiftData();
|
|
9
|
+
* console.log(shiftData); // {
|
|
10
|
+
"id": "631fb04c8fe08f51a8ee5949",
|
|
11
|
+
"startDate": "2024-01-15T09:00:00.000Z",
|
|
12
|
+
"dateToClose": "2024-01-15T17:00:00.000Z",
|
|
13
|
+
"dateMaxToClose": "2024-01-15T17:00:00.000Z",
|
|
14
|
+
"userId": "6a1fc1eeb5b68406e0487a10",
|
|
15
|
+
"displayId": "240715-EARPIQ",
|
|
16
|
+
"dateCreated": "2019-07-12T19:00:00.000Z",
|
|
17
|
+
"dateModified": "2019-07-20T19:00:00.000Z",
|
|
18
|
+
"userCreated": "6a1fc1eeb5b68406e0487a10",
|
|
19
|
+
"userModified": "7e1fc1eeb5b68406e048796",
|
|
20
|
+
"status": "opened"
|
|
21
|
+
}
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const getShiftData = () => {
|
|
25
|
+
const shiftData = Storage.getString(SHIFT_DATA);
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(shiftData);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return shiftData;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default getShiftData;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Storage from '../../../db/StorageService';
|
|
2
|
+
import {STAFF_AUTH} from '../../../constant';
|
|
3
|
+
import Crashlytics from '../../crashlytics';
|
|
4
|
+
|
|
5
|
+
const getStaffAuthorizationData = () => {
|
|
6
|
+
try {
|
|
7
|
+
const staffAuthRaw = Storage.getString(STAFF_AUTH);
|
|
8
|
+
const parsedAuth = JSON.parse(staffAuthRaw);
|
|
9
|
+
const {hasStaffAuthorization = false, expirationTime = 0, isExpired = false} = parsedAuth;
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
hasStaffAuthorization,
|
|
13
|
+
isExpired: expirationTime <= Date.now() || isExpired,
|
|
14
|
+
};
|
|
15
|
+
} catch (error) {
|
|
16
|
+
Crashlytics.recordError(error, 'Error getting staff authorization data');
|
|
17
|
+
return {
|
|
18
|
+
hasStaffAuthorization: false,
|
|
19
|
+
isExpired: true,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default getStaffAuthorizationData;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Storage from '../../../db/StorageService';
|
|
2
|
+
import Crashlytics from '../../crashlytics';
|
|
3
|
+
import {WORKLOG_TYPES_DATA} from '../../../constant';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Get the worklog types data from the storage
|
|
7
|
+
* @returns {Object} The worklog types data
|
|
8
|
+
* @example
|
|
9
|
+
* const {workLogTypes, expirationTime, isExpired} = getWorkLogTypesData();
|
|
10
|
+
* console.log(workLogTypes); // [{id: 1, name: 'Test Type', referenceId: 'ref-123'}]
|
|
11
|
+
* console.log(expirationTime); // 1718035200000
|
|
12
|
+
* console.log(isExpired); // false
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const getWorkLogTypesData = () => {
|
|
16
|
+
try {
|
|
17
|
+
Crashlytics.log('getWorkLogTypesData');
|
|
18
|
+
const workLogRaw = Storage.getString(WORKLOG_TYPES_DATA);
|
|
19
|
+
const parsedWorkLogs = JSON.parse(workLogRaw);
|
|
20
|
+
const {workLogTypes = [], expirationTime = 0} = parsedWorkLogs;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
workLogTypes,
|
|
24
|
+
expirationTime,
|
|
25
|
+
isExpired: expirationTime <= Date.now() || !workLogTypes.length,
|
|
26
|
+
};
|
|
27
|
+
} catch (error) {
|
|
28
|
+
Crashlytics.recordError(error, 'Error getting worklogs data');
|
|
29
|
+
return {
|
|
30
|
+
workLogTypes: [],
|
|
31
|
+
expirationTime: 0,
|
|
32
|
+
isExpired: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default getWorkLogTypesData;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Storage from '../../db/StorageService';
|
|
2
|
+
|
|
3
|
+
export {default as getWorkLogTypesData} from './getWorkLogTypesData';
|
|
4
|
+
export {default as getShiftData} from './getShiftData';
|
|
5
|
+
export {default as getStaffAuthorizationData} from './getStaffAuthorizationData';
|
|
6
|
+
|
|
7
|
+
export const setObject = (key, value) => {
|
|
8
|
+
const jsonValue = JSON.stringify(value);
|
|
9
|
+
Storage.set(key, jsonValue);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getObject = (key, defaultValue = {}) => {
|
|
13
|
+
try {
|
|
14
|
+
const jsonValue = Storage.getString(key);
|
|
15
|
+
return JSON.parse(jsonValue);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@janiscommerce/app-tracking-shift",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"module": "lib/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./lib/index.js",
|
|
9
|
+
"require": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"lib",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test:coverage": "jest --coverage",
|
|
20
|
+
"lint": "eslint lib --ext .js,.jsx",
|
|
21
|
+
"prepare": "husky install",
|
|
22
|
+
"lint:fix": "eslint lib --ext .js,.jsx --fix"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/janis-commerce/app-tracking-shift.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"janiscommerce",
|
|
30
|
+
"app",
|
|
31
|
+
"trackingshift",
|
|
32
|
+
"time",
|
|
33
|
+
"react",
|
|
34
|
+
"context",
|
|
35
|
+
"shifts",
|
|
36
|
+
"work",
|
|
37
|
+
"schedule",
|
|
38
|
+
"tracking",
|
|
39
|
+
"realm"
|
|
40
|
+
],
|
|
41
|
+
"author": "Janis commerce",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/janis-commerce/app-tracking-shift/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/janis-commerce/app-tracking-shift#readme",
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@janiscommerce/app-crashlytics": ">=2.1.0",
|
|
49
|
+
"@janiscommerce/app-request": ">=2.0.0",
|
|
50
|
+
"@janiscommerce/app-tracking-time": ">=2.2.1",
|
|
51
|
+
"react": ">=17.0.2 <19",
|
|
52
|
+
"react-dom": ">=17.0.2 <19",
|
|
53
|
+
"react-native": ">=0.67.5 <0.75"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@janiscommerce/app-device-info": "^1.1.0",
|
|
57
|
+
"@janiscommerce/oauth-native": "^1.10.2",
|
|
58
|
+
"react-native-mmkv": "2.12.2",
|
|
59
|
+
"realm": "11.3.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@babel/core": "^7.0.0",
|
|
63
|
+
"@babel/eslint-parser": "^7.22.5",
|
|
64
|
+
"@babel/preset-env": "^7.0.0",
|
|
65
|
+
"@babel/preset-react": "^7.0.0",
|
|
66
|
+
"@janiscommerce/app-crashlytics": "^2.1.0",
|
|
67
|
+
"@janiscommerce/app-request": "^2.6.0",
|
|
68
|
+
"@janiscommerce/app-tracking-time": "^2.2.1",
|
|
69
|
+
"@testing-library/react": "^16.3.0",
|
|
70
|
+
"@testing-library/react-native": "^12.0.1",
|
|
71
|
+
"babel-jest": "^29.0.0",
|
|
72
|
+
"eslint": "^8.19.0",
|
|
73
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
74
|
+
"eslint-config-prettier": "^8.8.0",
|
|
75
|
+
"eslint-import-resolver-babel-module": "^5.3.2",
|
|
76
|
+
"eslint-plugin-import": "^2.27.5",
|
|
77
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
78
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
79
|
+
"eslint-plugin-react": "^7.32.2",
|
|
80
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
81
|
+
"husky": "^8.0.0",
|
|
82
|
+
"identity-obj-proxy": "^3.0.0",
|
|
83
|
+
"jest": "^29.0.0",
|
|
84
|
+
"jest-environment-jsdom": "^29.0.0",
|
|
85
|
+
"prettier": "^2.8.8",
|
|
86
|
+
"react": "18.2.0",
|
|
87
|
+
"react-native": "0.71.6",
|
|
88
|
+
"react-native-device-info": "^10.12.0",
|
|
89
|
+
"react-native-inappbrowser-reborn": "^3.7.0",
|
|
90
|
+
"react-test-renderer": "18.2.0"
|
|
91
|
+
}
|
|
92
|
+
}
|