@monkvision/common 4.2.2 → 4.2.4

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.
@@ -0,0 +1,34 @@
1
+ import { Damage } from '@monkvision/types';
2
+ import { MonkAction, MonkActionType } from './monkAction';
3
+ import { MonkState } from '../state';
4
+ /**
5
+ * The payload of a MonkCreatedOneDamagePayload.
6
+ */
7
+ export interface MonkCreatedOneDamagePayload {
8
+ /**
9
+ * The damage created.
10
+ */
11
+ damage: Damage;
12
+ }
13
+ /**
14
+ * Action dispatched when a vehicle have been updated.
15
+ */
16
+ export interface MonkCreatedOneDamageAction extends MonkAction {
17
+ /**
18
+ * The type of the action : `MonkActionType.CREATED_ONE_DAMAGE`.
19
+ */
20
+ type: MonkActionType.CREATED_ONE_DAMAGE;
21
+ /**
22
+ * The payload of the action containing the fetched entities.
23
+ */
24
+ payload: MonkCreatedOneDamagePayload;
25
+ }
26
+ /**
27
+ * Matcher function that matches a CreatedOneDamage while also inferring its type using TypeScript's type predicate
28
+ * feature.
29
+ */
30
+ export declare function isCreatedOneDamageAction(action: MonkAction): action is MonkCreatedOneDamageAction;
31
+ /**
32
+ * Reducer function for a createdOneDamage action.
33
+ */
34
+ export declare function createdOneDamage(state: MonkState, action: MonkCreatedOneDamageAction): MonkState;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.createdOneDamage = exports.isCreatedOneDamageAction = void 0;
24
+ var monkAction_1 = require("./monkAction");
25
+ /**
26
+ * Matcher function that matches a CreatedOneDamage while also inferring its type using TypeScript's type predicate
27
+ * feature.
28
+ */
29
+ function isCreatedOneDamageAction(action) {
30
+ return action.type === monkAction_1.MonkActionType.CREATED_ONE_DAMAGE;
31
+ }
32
+ exports.isCreatedOneDamageAction = isCreatedOneDamageAction;
33
+ /**
34
+ * Reducer function for a createdOneDamage action.
35
+ */
36
+ function createdOneDamage(state, action) {
37
+ var damages = state.damages, inspections = state.inspections, parts = state.parts;
38
+ var payload = action.payload;
39
+ var inspection = inspections.find(function (value) { return value.id === payload.damage.inspectionId; });
40
+ if (inspection) {
41
+ inspection.damages.push(action.payload.damage.id);
42
+ }
43
+ var partsRelated = action.payload.damage.parts
44
+ .map(function (part) { var _a; return (_a = parts.find(function (value) { return value.type === part; })) === null || _a === void 0 ? void 0 : _a.id; })
45
+ .filter(function (v) { return v !== undefined; });
46
+ damages.push(__assign(__assign({}, action.payload.damage), { parts: partsRelated }));
47
+ return __assign(__assign({}, state), { damages: __spreadArray([], damages, true), inspections: __spreadArray([], inspections, true) });
48
+ }
49
+ exports.createdOneDamage = createdOneDamage;
@@ -11,7 +11,7 @@ export interface MonkCreatedOnePricingPayload {
11
11
  pricing: PricingV2;
12
12
  }
13
13
  /**
14
- * Action dispatched when a vehicle have been updated.
14
+ * Action dispatched when a pricing have been updated.
15
15
  */
16
16
  export interface MonkCreatedOnePricingAction extends MonkAction {
17
17
  /**
@@ -0,0 +1,37 @@
1
+ import { MonkAction, MonkActionType } from './monkAction';
2
+ import { MonkState } from '../state';
3
+ /**
4
+ * The payload of a MonkDeletedOneDamagePayload.
5
+ */
6
+ export interface MonkDeletedOneDamagePayload {
7
+ /**
8
+ * The ID of the inspection to which the damage was deleted.
9
+ */
10
+ inspectionId: string;
11
+ /**
12
+ * The damage ID deleted.
13
+ */
14
+ damageId: string;
15
+ }
16
+ /**
17
+ * Action dispatched when a vehicle have been updated.
18
+ */
19
+ export interface MonkDeletedOneDamageAction extends MonkAction {
20
+ /**
21
+ * The type of the action : `MonkActionType.DELETED_ONE_DAMAGE`.
22
+ */
23
+ type: MonkActionType.DELETED_ONE_DAMAGE;
24
+ /**
25
+ * The payload of the action containing the fetched entities.
26
+ */
27
+ payload: MonkDeletedOneDamagePayload;
28
+ }
29
+ /**
30
+ * Matcher function that matches a DeletedOneDamage while also inferring its type using TypeScript's type predicate
31
+ * feature.
32
+ */
33
+ export declare function isDeletedOneDamageAction(action: MonkAction): action is MonkDeletedOneDamageAction;
34
+ /**
35
+ * Reducer function for a deletedOneDamage action.
36
+ */
37
+ export declare function deletedOneDamage(state: MonkState, action: MonkDeletedOneDamageAction): MonkState;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.deletedOneDamage = exports.isDeletedOneDamageAction = void 0;
24
+ var monkAction_1 = require("./monkAction");
25
+ /**
26
+ * Matcher function that matches a DeletedOneDamage while also inferring its type using TypeScript's type predicate
27
+ * feature.
28
+ */
29
+ function isDeletedOneDamageAction(action) {
30
+ return action.type === monkAction_1.MonkActionType.DELETED_ONE_DAMAGE;
31
+ }
32
+ exports.isDeletedOneDamageAction = isDeletedOneDamageAction;
33
+ /**
34
+ * Reducer function for a deletedOneDamage action.
35
+ */
36
+ function deletedOneDamage(state, action) {
37
+ var _a;
38
+ var damages = state.damages, inspections = state.inspections;
39
+ var payload = action.payload;
40
+ var inspection = inspections.find(function (value) { return value.id === payload.inspectionId; });
41
+ if (inspection) {
42
+ inspection.damages = (_a = inspection.damages) === null || _a === void 0 ? void 0 : _a.filter(function (damageId) { return damageId !== payload.damageId; });
43
+ }
44
+ var newDamages = damages.filter(function (damage) { return damage.id !== payload.damageId; });
45
+ return __assign(__assign({}, state), { damages: __spreadArray([], newDamages, true), inspections: __spreadArray([], inspections, true) });
46
+ }
47
+ exports.deletedOneDamage = deletedOneDamage;
@@ -8,3 +8,5 @@ export * from './createdOnePricing';
8
8
  export * from './deletedOnePricing';
9
9
  export * from './updatedOnePricing';
10
10
  export * from './updatedOneInspectionAdditionalData';
11
+ export * from './createdOneDamage';
12
+ export * from './deletedOneDamage';
@@ -24,3 +24,5 @@ __exportStar(require("./createdOnePricing"), exports);
24
24
  __exportStar(require("./deletedOnePricing"), exports);
25
25
  __exportStar(require("./updatedOnePricing"), exports);
26
26
  __exportStar(require("./updatedOneInspectionAdditionalData"), exports);
27
+ __exportStar(require("./createdOneDamage"), exports);
28
+ __exportStar(require("./deletedOneDamage"), exports);
@@ -34,6 +34,14 @@ export declare enum MonkActionType {
34
34
  * A pricing has been deleted.
35
35
  */
36
36
  DELETED_ONE_PRICING = "deleted_one_pricing",
37
+ /**
38
+ * A damage has been uploaded to the API.
39
+ */
40
+ CREATED_ONE_DAMAGE = "created_one_damage",
41
+ /**
42
+ * A damage has been deleted.
43
+ */
44
+ DELETED_ONE_DAMAGE = "deleted_one_damage",
37
45
  /**
38
46
  * Clear and reset the state.
39
47
  */
@@ -38,6 +38,14 @@ var MonkActionType;
38
38
  * A pricing has been deleted.
39
39
  */
40
40
  MonkActionType["DELETED_ONE_PRICING"] = "deleted_one_pricing";
41
+ /**
42
+ * A damage has been uploaded to the API.
43
+ */
44
+ MonkActionType["CREATED_ONE_DAMAGE"] = "created_one_damage";
45
+ /**
46
+ * A damage has been deleted.
47
+ */
48
+ MonkActionType["DELETED_ONE_DAMAGE"] = "deleted_one_damage";
41
49
  /**
42
50
  * Clear and reset the state.
43
51
  */
@@ -6,7 +6,7 @@ import { MonkState } from '../state';
6
6
  */
7
7
  export interface MonkUpdatedOneInspectionAdditionalDataPayload {
8
8
  /**
9
- * The ID of the inspection to which the pricing was updated.
9
+ * The ID of the inspection to which the additionalData was updated.
10
10
  */
11
11
  inspectionId: string;
12
12
  /**
@@ -6,7 +6,7 @@ import { MonkState } from '../state';
6
6
  */
7
7
  export interface MonkUpdatedOnePricingPayload {
8
8
  /**
9
- * The pricing created.
9
+ * The pricing updated.
10
10
  */
11
11
  pricing: PricingV2;
12
12
  }
@@ -33,6 +33,12 @@ function monkReducer(state, action) {
33
33
  if ((0, actions_1.isUpdatedVehicleAction)(action)) {
34
34
  return (0, actions_1.updatedVehicle)(state, action);
35
35
  }
36
+ if ((0, actions_1.isCreatedOneDamageAction)(action)) {
37
+ return (0, actions_1.createdOneDamage)(state, action);
38
+ }
39
+ if ((0, actions_1.isDeletedOneDamageAction)(action)) {
40
+ return (0, actions_1.deletedOneDamage)(state, action);
41
+ }
36
42
  return state;
37
43
  }
38
44
  exports.monkReducer = monkReducer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/common",
3
- "version": "4.2.2",
3
+ "version": "4.2.4",
4
4
  "license": "BSD-3-Clause-Clear",
5
5
  "packageManager": "yarn@3.2.4",
6
6
  "description": "MonkJs common logic package",
@@ -28,10 +28,10 @@
28
28
  "lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
29
29
  },
30
30
  "dependencies": {
31
- "@monkvision/analytics": "4.2.2",
32
- "@monkvision/monitoring": "4.2.2",
33
- "@monkvision/sights": "4.2.2",
34
- "@monkvision/types": "4.2.2",
31
+ "@monkvision/analytics": "4.2.4",
32
+ "@monkvision/monitoring": "4.2.4",
33
+ "@monkvision/sights": "4.2.4",
34
+ "@monkvision/types": "4.2.4",
35
35
  "i18next": "^23.4.5",
36
36
  "jsonwebtoken": "^9.0.2",
37
37
  "jwt-decode": "^4.0.0",
@@ -47,13 +47,13 @@
47
47
  "react-router-dom": "^6.22.3"
48
48
  },
49
49
  "devDependencies": {
50
- "@monkvision/eslint-config-base": "4.2.2",
51
- "@monkvision/eslint-config-typescript": "4.2.2",
52
- "@monkvision/eslint-config-typescript-react": "4.2.2",
53
- "@monkvision/jest-config": "4.2.2",
54
- "@monkvision/prettier-config": "4.2.2",
55
- "@monkvision/test-utils": "4.2.2",
56
- "@monkvision/typescript-config": "4.2.2",
50
+ "@monkvision/eslint-config-base": "4.2.4",
51
+ "@monkvision/eslint-config-typescript": "4.2.4",
52
+ "@monkvision/eslint-config-typescript-react": "4.2.4",
53
+ "@monkvision/jest-config": "4.2.4",
54
+ "@monkvision/prettier-config": "4.2.4",
55
+ "@monkvision/test-utils": "4.2.4",
56
+ "@monkvision/typescript-config": "4.2.4",
57
57
  "@testing-library/react": "^12.1.5",
58
58
  "@testing-library/react-hooks": "^8.0.1",
59
59
  "@types/jest": "^29.2.2",
@@ -96,5 +96,5 @@
96
96
  "url": "https://github.com/monkvision/monkjs/issues"
97
97
  },
98
98
  "homepage": "https://github.com/monkvision/monkjs",
99
- "gitHead": "6b099cf04f90c80e519fd0cc22ebe0cff740e4cb"
99
+ "gitHead": "f746a694b9c441a4b1d5f6868f503b3d1099fd81"
100
100
  }