@monkvision/common 4.2.5 → 4.2.7

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.
@@ -89,7 +89,7 @@ const action: Monk = {
89
89
  ```
90
90
 
91
91
  ## CreatedOneImage Action
92
- This action can be dispatched after an image has beencreated and uploaded to the API. The payload of this action should
92
+ This action can be dispatched after an image has been created and uploaded to the API. The payload of this action should
93
93
  contain the details about the image that has been created, as well as the ID of the inspection. You can also start by
94
94
  creating a local image (with a custom local ID), and then update this image when the API has returned the actual ID of
95
95
  the image. To do so, re-dispatch another time the same action, but with the new Id and the property `localId` in the
@@ -122,4 +122,127 @@ const action: Monk = {
122
122
  { id: '4097bc0e-02d0-4ed8-9411-b18f0cb922f2', status: ProgressStatus.IN_PROGRESS },
123
123
  ]
124
124
  }
125
+
126
+ ```
127
+ ## CreatedOnePricing Action
128
+ This action can be dispatched after pricing has been created and uploaded to the API. Similar to the image, you can
129
+ first create a local pricing entry with a custom local ID and then update it once the API returns the actual ID.
130
+
131
+ ```typescript
132
+ import { MonkResetStateAction, MonkActionType } from '@monkvision/common';
133
+ import { PricingV2RelatedItemType} from '@monkvision/types';
134
+
135
+ const action: Monk = {
136
+ type: MonkActionType.CREATED_ONE_PRICING,
137
+ payload: {
138
+ pricing: {
139
+ entityType: MonkEntityType.PRICING,
140
+ id: '2b2ac131-c613-41a9-ac04-d00b942e2290',
141
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
142
+ relatedItemType: PricingV2RelatedItemType.PART,
143
+ pricing: 500,
144
+ },
145
+ }
146
+ };
147
+ ```
148
+
149
+ ## UpdatedOnePricing Action
150
+ This action can be dispatched after a pricing entry has been updated. The payload should contain the details of the
151
+ pricing that has been updated along with the inspection ID.
152
+
153
+ ```typescript
154
+ import { MonkResetStateAction, MonkActionType } from '@monkvision/common';
155
+
156
+ const action: Monk = {
157
+ type: MonkActionType.UPDATED_ONE_PRICING,
158
+ payload: {
159
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
160
+ pricing: {
161
+ id: 'pricing-id',
162
+ ...updatedPricingDetails,
163
+ },
164
+ }
165
+ };
166
+
167
+ ```
168
+
169
+ ## DeletedOnePricing Action
170
+ This action can be dispatched after a pricing entry has been deleted from the API. The payload contains the ID of the
171
+ inspection and the ID of the pricing that was deleted.
172
+
173
+ ```typescript
174
+ import { MonkResetStateAction, MonkActionType } from '@monkvision/common';
175
+
176
+ const action: Monk = {
177
+ type: MonkActionType.DELETED_ONE_PRICING,
178
+ payload: {
179
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
180
+ pricingId: 'pricing-id-to-be-deleted',
181
+ }
182
+ };
183
+
184
+ ```
185
+
186
+ ## CreatedOneDamage Action
187
+ This action can be dispatched after a damage has been created and uploaded to the API. You can start with a locally
188
+ created damage and update it later once the API returns the actual ID.
189
+
190
+ ```typescript
191
+ import { MonkResetStateAction, MonkActionType } from '@monkvision/common';
192
+
193
+ const action: Monk = {
194
+ type: MonkActionType.CREATED_ONE_DAMAGE,
195
+ payload: {
196
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
197
+ damage: {
198
+ entityType: MonkEntityType.DAMAGE,
199
+ id: '2b2ac131-c613-41a9-ac04-d00b942e2290',
200
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
201
+ parts: [VehiclePart.BUMPER_BACK],
202
+ relatedImages: [],
203
+ type: DamageType.BODY_CRACK,
204
+ },
205
+ }
206
+ };
207
+ ```
208
+
209
+ ## DeletedOneDamage Action
210
+ This action can be dispatched after a damage entry has been deleted from the API. The payload contains the ID of the
211
+ inspection and the ID of the damage that was deleted.
212
+
213
+ ```typescript
214
+ import { MonkResetStateAction, MonkActionType } from '@monkvision/common';
215
+
216
+ const action: Monk = {
217
+ type: MonkActionType.DELETED_ONE_DAMAGE,
218
+ payload: {
219
+ pricing: {
220
+ entityType: MonkEntityType.PRICING,
221
+ id: '2b2ac131-c613-41a9-ac04-d00b942e2290',
222
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
223
+ relatedItemType: PricingV2RelatedItemType.PART,
224
+ pricing: 800,
225
+ },
226
+ }
227
+ };
228
+ ```
229
+
230
+ ## UpdatedOneInspectionAdditionalData Action
231
+ This action can be dispatched after the additional data of an inspection has been updated in the API. The payload
232
+ contains the ID of the inspection and any additional data used for the update.
233
+
234
+ ```typescript
235
+ import { MonkResetStateAction, MonkActionType } from '@monkvision/common';
236
+ import { AdditionalData } from '@monkvision/types';
237
+
238
+ const action: Monk = {
239
+ type: MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA,
240
+ payload: {
241
+ inspectionId: 'e1cb2852-77f3-4fb5-a851-e700cf31a7d1',
242
+ additionalData: {
243
+ someKey: 'someValue',
244
+ ...otherData,
245
+ },
246
+ },
247
+ };
125
248
  ```
@@ -9,6 +9,12 @@ export interface MonkCreatedOneDamagePayload {
9
9
  * The damage created.
10
10
  */
11
11
  damage: Damage;
12
+ /**
13
+ * This ID is used when you first want to create the entity locally while you wait for the API to give you the true
14
+ * ID of the damage. You first create the damage with a custom local ID, then you dispatch the action a second time
15
+ * and specify this custom ID in the `localId` param. The damage will then be updated instead of added.
16
+ */
17
+ localId?: string;
12
18
  }
13
19
  /**
14
20
  * Action dispatched when a damage have been created.
@@ -38,8 +38,10 @@ function createdOneDamage(state, action) {
38
38
  var payload = action.payload;
39
39
  var inspection = inspections.find(function (value) { return value.id === payload.damage.inspectionId; });
40
40
  if (inspection) {
41
- inspection.damages.push(action.payload.damage.id);
41
+ inspection.damages = inspection.damages.filter(function (damageId) { return ![payload.damage.id, payload.localId].includes(damageId); });
42
+ inspection.damages.push(payload.damage.id);
42
43
  }
44
+ var newDamages = damages.filter(function (damage) { return ![payload.damage.id, payload.localId].includes(damage.id); });
43
45
  var partsRelated = action.payload.damage.parts
44
46
  .map(function (part) { var _a; return (_a = parts.find(function (value) { return value.type === part; })) === null || _a === void 0 ? void 0 : _a.id; })
45
47
  .filter(function (v) { return v !== undefined; });
@@ -49,7 +51,7 @@ function createdOneDamage(state, action) {
49
51
  }
50
52
  return part;
51
53
  });
52
- damages.push(__assign(__assign({}, payload.damage), { parts: partsRelated }));
53
- return __assign(__assign({}, state), { parts: newParts, damages: __spreadArray([], damages, true), inspections: __spreadArray([], inspections, true) });
54
+ newDamages.push(__assign(__assign({}, payload.damage), { parts: partsRelated }));
55
+ return __assign(__assign({}, state), { parts: newParts, damages: newDamages, inspections: __spreadArray([], inspections, true) });
54
56
  }
55
57
  exports.createdOneDamage = createdOneDamage;
@@ -9,6 +9,12 @@ export interface MonkCreatedOnePricingPayload {
9
9
  * The pricing created.
10
10
  */
11
11
  pricing: PricingV2;
12
+ /**
13
+ * This ID is used when you first want to create the entity locally while you wait for the API to give you the true
14
+ * ID of the damage. You first create the damage with a custom local ID, then you dispatch the action a second time
15
+ * and specify this custom ID in the `localId` param. The damage will then be updated instead of added.
16
+ */
17
+ localId?: string;
12
18
  }
13
19
  /**
14
20
  * Action dispatched when a pricing have been updated.
@@ -34,14 +34,16 @@ exports.isCreatedOnePricingAction = isCreatedOnePricingAction;
34
34
  * Reducer function for a createdOnePricing action.
35
35
  */
36
36
  function createdOnePricing(state, action) {
37
- var _a;
37
+ var _a, _b;
38
38
  var pricings = state.pricings, inspections = state.inspections;
39
39
  var payload = action.payload;
40
40
  var inspection = inspections.find(function (value) { return value.id === payload.pricing.inspectionId; });
41
41
  if (inspection) {
42
- (_a = inspection.pricings) === null || _a === void 0 ? void 0 : _a.push(action.payload.pricing.id);
42
+ inspection.pricings = (_a = inspection.pricings) === null || _a === void 0 ? void 0 : _a.filter(function (pricingId) { return ![payload.pricing.id, payload.localId].includes(pricingId); });
43
+ (_b = inspection.pricings) === null || _b === void 0 ? void 0 : _b.push(payload.pricing.id);
43
44
  }
44
- pricings.push(action.payload.pricing);
45
- return __assign(__assign({}, state), { pricings: __spreadArray([], pricings, true), inspections: __spreadArray([], inspections, true) });
45
+ var newPricings = pricings.filter(function (pricing) { return ![payload.pricing.id, payload.localId].includes(pricing.id); });
46
+ newPricings.push(action.payload.pricing);
47
+ return __assign(__assign({}, state), { pricings: newPricings, inspections: __spreadArray([], inspections, true) });
46
48
  }
47
49
  exports.createdOnePricing = createdOnePricing;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/common",
3
- "version": "4.2.5",
3
+ "version": "4.2.7",
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.5",
32
- "@monkvision/monitoring": "4.2.5",
33
- "@monkvision/sights": "4.2.5",
34
- "@monkvision/types": "4.2.5",
31
+ "@monkvision/analytics": "4.2.7",
32
+ "@monkvision/monitoring": "4.2.7",
33
+ "@monkvision/sights": "4.2.7",
34
+ "@monkvision/types": "4.2.7",
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.5",
51
- "@monkvision/eslint-config-typescript": "4.2.5",
52
- "@monkvision/eslint-config-typescript-react": "4.2.5",
53
- "@monkvision/jest-config": "4.2.5",
54
- "@monkvision/prettier-config": "4.2.5",
55
- "@monkvision/test-utils": "4.2.5",
56
- "@monkvision/typescript-config": "4.2.5",
50
+ "@monkvision/eslint-config-base": "4.2.7",
51
+ "@monkvision/eslint-config-typescript": "4.2.7",
52
+ "@monkvision/eslint-config-typescript-react": "4.2.7",
53
+ "@monkvision/jest-config": "4.2.7",
54
+ "@monkvision/prettier-config": "4.2.7",
55
+ "@monkvision/test-utils": "4.2.7",
56
+ "@monkvision/typescript-config": "4.2.7",
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": "707896a1d1442de97c52985a00d2e8a590935d71"
99
+ "gitHead": "b87808ad7b226a42e589da0fe14da0457d63454e"
100
100
  }