@bjsdistribution/dms-client-return 0.1.46-prod → 0.1.47-prod
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/dist/dms-client-return.cjs.development.js +82 -251
- package/dist/dms-client-return.cjs.development.js.map +1 -1
- package/dist/dms-client-return.cjs.production.min.js +1 -1
- package/dist/dms-client-return.cjs.production.min.js.map +1 -1
- package/dist/dms-client-return.esm.js +82 -251
- package/dist/dms-client-return.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +134 -209
package/package.json
CHANGED
|
@@ -119,99 +119,42 @@ function ConfirmOrder(props: IProps) {
|
|
|
119
119
|
};
|
|
120
120
|
}, []);
|
|
121
121
|
|
|
122
|
-
function hasOnlyIdKey(obj: any) {
|
|
123
|
-
return Object.keys(obj).length === 1 && obj.hasOwnProperty('id');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const handleSuccess = (message: string, res?: any) => {
|
|
127
|
-
const apiMessage =
|
|
128
|
-
res?.data?.message || res?.message || res?.data?.data?.message;
|
|
129
|
-
|
|
130
|
-
notification.success({
|
|
131
|
-
message: 'Success',
|
|
132
|
-
description: apiMessage || message,
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const handleError = (error: any, fallback: string) => {
|
|
137
|
-
const err = error as any;
|
|
138
|
-
notification.error({
|
|
139
|
-
message: 'Request Failed',
|
|
140
|
-
description:
|
|
141
|
-
err?.response?.data?.error ||
|
|
142
|
-
err?.response?.data?.message ||
|
|
143
|
-
err?.message ||
|
|
144
|
-
fallback,
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
122
|
const executeActions = async () => {
|
|
149
123
|
switch (selectedAction) {
|
|
150
124
|
case 'decline_and_propose_new_date':
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
handleSuccess('Previous date declined successfully', response);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const response = (await proposeDate()) as any;
|
|
158
|
-
handleSuccess('New date proposed successfully', response);
|
|
159
|
-
} catch (error) {
|
|
160
|
-
handleError(error, 'Failed to propose new date');
|
|
125
|
+
// Decline → Propose
|
|
126
|
+
if (confirmedDate?.previousDate !== null) {
|
|
127
|
+
await declineDate();
|
|
161
128
|
}
|
|
129
|
+
await proposeDate();
|
|
162
130
|
break;
|
|
163
131
|
|
|
164
132
|
case 'decline_and_confirm_new_date':
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
handleSuccess('Previous date declined successfully', response);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const response = (await confirmDeliveryDate()) as any;
|
|
172
|
-
handleSuccess('New date confirmed successfully', response);
|
|
173
|
-
} catch (error) {
|
|
174
|
-
handleError(error, 'Failed to confirm new date');
|
|
133
|
+
// Decline → Confirm
|
|
134
|
+
if (confirmedDate?.previousDate !== null) {
|
|
135
|
+
await declineDate();
|
|
175
136
|
}
|
|
137
|
+
await confirmDeliveryDate();
|
|
176
138
|
break;
|
|
177
139
|
|
|
178
140
|
case 'declined_proposed_date(outstanding)':
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
handleSuccess('Proposed date declined successfully', response);
|
|
183
|
-
}
|
|
184
|
-
} catch (error) {
|
|
185
|
-
handleError(error, 'Failed to decline proposed date');
|
|
141
|
+
// Only Decline
|
|
142
|
+
if (confirmedDate?.previousDate !== null) {
|
|
143
|
+
await declineDate();
|
|
186
144
|
}
|
|
187
145
|
break;
|
|
188
146
|
|
|
189
147
|
case 'no_response_propose_new_date':
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
handleSuccess('Previous date declined successfully', response);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const response = (await noResponseApi()) as any;
|
|
197
|
-
handleSuccess('No response date proposed successfully', response);
|
|
198
|
-
} catch (error) {
|
|
199
|
-
handleError(error, 'Failed to propose date (no response)');
|
|
148
|
+
// Decline (always previous date) → No Response Propose
|
|
149
|
+
if (confirmedDate?.previousDate !== null) {
|
|
150
|
+
await declineDate();
|
|
200
151
|
}
|
|
152
|
+
await noResponseApi();
|
|
201
153
|
break;
|
|
202
154
|
|
|
203
155
|
case 'confirmed':
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const response = (await declineDate()) as any;
|
|
207
|
-
handleSuccess('Previous date declined successfully', response);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const response = (await confirmDeliveryDate()) as any;
|
|
211
|
-
handleSuccess('Delivery date confirmed successfully', response);
|
|
212
|
-
} catch (error) {
|
|
213
|
-
handleError(error, 'Failed to confirm delivery date');
|
|
214
|
-
}
|
|
156
|
+
// Only Confirm
|
|
157
|
+
await confirmDeliveryDate();
|
|
215
158
|
break;
|
|
216
159
|
|
|
217
160
|
default:
|
|
@@ -224,26 +167,16 @@ function ConfirmOrder(props: IProps) {
|
|
|
224
167
|
case 'left_message':
|
|
225
168
|
case 'contact_made':
|
|
226
169
|
case 'no_contact':
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
handleSuccess('Notification sent successfully', response);
|
|
230
|
-
} catch (error) {
|
|
231
|
-
handleError(error, 'Failed to send notification');
|
|
232
|
-
}
|
|
170
|
+
// Only send comms (Update Order already handled in confirmOrder)
|
|
171
|
+
notificationCall();
|
|
233
172
|
break;
|
|
234
173
|
|
|
235
174
|
case 'precall':
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
handleSuccess('Previous date declined successfully', response);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const response = (await sendComs()) as any;
|
|
243
|
-
handleSuccess('Precall communication sent successfully', response);
|
|
244
|
-
} catch (error) {
|
|
245
|
-
handleError(error, 'Failed to send precall communication');
|
|
175
|
+
// Decline → Send Comms
|
|
176
|
+
if (confirmedDate?.previousDate !== null) {
|
|
177
|
+
await declineDate();
|
|
246
178
|
}
|
|
179
|
+
await sendComs();
|
|
247
180
|
break;
|
|
248
181
|
|
|
249
182
|
default:
|
|
@@ -252,139 +185,131 @@ function ConfirmOrder(props: IProps) {
|
|
|
252
185
|
};
|
|
253
186
|
|
|
254
187
|
const confirmOrder = async () => {
|
|
255
|
-
|
|
188
|
+
if (
|
|
189
|
+
selectedAction === 'left_message' ||
|
|
190
|
+
selectedAction === 'contact_made' ||
|
|
191
|
+
selectedAction === 'no_contact' ||
|
|
192
|
+
selectedAction === 'precall'
|
|
193
|
+
) {
|
|
256
194
|
if (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
selectedAction === 'precall'
|
|
195
|
+
contactHome?.length === 0 &&
|
|
196
|
+
contactMobile?.length === 0 &&
|
|
197
|
+
contactWork?.length === 0
|
|
261
198
|
) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
notification.info({
|
|
268
|
-
message: 'Info',
|
|
269
|
-
description: 'Please add contact information',
|
|
270
|
-
});
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
confirmedDate?.previousDate === null &&
|
|
276
|
-
confirmedDate?.currentDate === null
|
|
277
|
-
) {
|
|
278
|
-
notification.info({
|
|
279
|
-
message: 'Info',
|
|
280
|
-
description: 'Please add delivery date',
|
|
281
|
-
});
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
199
|
+
notification.info({
|
|
200
|
+
message: 'Info',
|
|
201
|
+
description: 'Please add contact information',
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
284
204
|
}
|
|
205
|
+
if (
|
|
206
|
+
confirmedDate?.previousDate === null &&
|
|
207
|
+
confirmedDate?.currentDate === null
|
|
208
|
+
) {
|
|
209
|
+
notification.info({
|
|
210
|
+
message: 'Info',
|
|
211
|
+
description: 'Please add delivery date',
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
285
216
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
217
|
+
const keysToRemovefromOrders = [
|
|
218
|
+
'order_locked',
|
|
219
|
+
'order_communications',
|
|
220
|
+
'updated_at',
|
|
221
|
+
'updated_by',
|
|
222
|
+
'stock_alias',
|
|
223
|
+
'order_delivery_declined_dates',
|
|
224
|
+
'order_eta_updates',
|
|
225
|
+
'order_status',
|
|
226
|
+
'tomtom_status',
|
|
227
|
+
'refused_service',
|
|
228
|
+
'order_type',
|
|
229
|
+
'order_failures',
|
|
230
|
+
'order_on_hold',
|
|
231
|
+
'order_cancellations',
|
|
232
|
+
'order_routes',
|
|
233
|
+
'order_services',
|
|
234
|
+
'labels',
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
const filteredOrderDetails = filterObject(
|
|
238
|
+
orderDetailsConfirmOrder,
|
|
239
|
+
keysToRemovefromOrders
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const filteredPrevOrderDetails = filterObject(
|
|
243
|
+
prevOrderDetails,
|
|
244
|
+
keysToRemovefromOrders
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
const payload = compareOrderDetailsStates(
|
|
248
|
+
filteredPrevOrderDetails,
|
|
249
|
+
filteredOrderDetails
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const restrictedActions = [
|
|
253
|
+
'decline_and_confirm_new_date',
|
|
254
|
+
'decline_and_propose_new_date',
|
|
255
|
+
'declined_proposed_date(outstanding)',
|
|
256
|
+
'confirmed',
|
|
257
|
+
'no_response_propose_new_date',
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
const isRestrictedAction = restrictedActions.includes(selectedAction);
|
|
261
|
+
|
|
262
|
+
const updatedPayload: any = {
|
|
263
|
+
...payload,
|
|
264
|
+
action_date: confirmedDate?.currentDate,
|
|
265
|
+
};
|
|
323
266
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const response = (await callUpdateOrderAPI({
|
|
329
|
-
payload: [updatedPayload],
|
|
330
|
-
})) as any;
|
|
331
|
-
|
|
332
|
-
if (response?.data?.length > 0) {
|
|
333
|
-
const updatedOrder = response?.data[0];
|
|
334
|
-
setOrderDetails(updatedOrder);
|
|
335
|
-
setPrevOrderDetails(updatedOrder);
|
|
336
|
-
handleSuccess('Order updated successfully', response);
|
|
337
|
-
} else {
|
|
338
|
-
setOrderDetails(prevOrderDetails);
|
|
339
|
-
}
|
|
340
|
-
} catch (error) {
|
|
341
|
-
handleError(error, 'Failed to update order');
|
|
342
|
-
setOrderDetails(prevOrderDetails);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
267
|
+
// ✅ Remove action_date for restricted actions
|
|
268
|
+
if (isRestrictedAction) {
|
|
269
|
+
delete updatedPayload.action_date;
|
|
270
|
+
}
|
|
345
271
|
|
|
346
|
-
|
|
347
|
-
await executeActions();
|
|
348
|
-
} catch (error) {
|
|
349
|
-
handleError(error, 'Failed to execute actions');
|
|
350
|
-
}
|
|
272
|
+
const keys = Object.keys(updatedPayload);
|
|
351
273
|
|
|
352
|
-
|
|
353
|
-
await executeSendComs();
|
|
354
|
-
} catch (error) {
|
|
355
|
-
handleError(error, 'Failed to send communications');
|
|
356
|
-
}
|
|
274
|
+
const notUpdateOrder = keys.length === 1 && keys.includes('id');
|
|
357
275
|
|
|
358
|
-
|
|
359
|
-
const formattedDate = format(new Date(deliveryDate), 'yyyy-MM-dd');
|
|
360
|
-
setDeliveryDate(formattedDate);
|
|
361
|
-
}
|
|
276
|
+
const shouldUpdateOrder = !notUpdateOrder;
|
|
362
277
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
278
|
+
if (shouldUpdateOrder) {
|
|
279
|
+
const response = (await callUpdateOrderAPI({
|
|
280
|
+
payload: [updatedPayload],
|
|
281
|
+
})) as {
|
|
282
|
+
code: number | null;
|
|
283
|
+
error?: string | null | undefined;
|
|
284
|
+
[key: string]: any;
|
|
285
|
+
};
|
|
369
286
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
287
|
+
if (response?.data?.length > 0) {
|
|
288
|
+
const updatedOrder = response?.data[0];
|
|
289
|
+
setOrderDetails(updatedOrder);
|
|
290
|
+
setPrevOrderDetails(updatedOrder);
|
|
291
|
+
} else {
|
|
292
|
+
setOrderDetails(prevOrderDetails);
|
|
375
293
|
}
|
|
294
|
+
}
|
|
376
295
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
handleSuccess('Orders refreshed successfully');
|
|
380
|
-
} catch (error) {
|
|
381
|
-
handleError(error, 'Failed to refresh orders');
|
|
382
|
-
}
|
|
296
|
+
// ✅ Execute action flow
|
|
297
|
+
await executeActions();
|
|
383
298
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
299
|
+
// ✅ Execute comms flow
|
|
300
|
+
await executeSendComs();
|
|
301
|
+
|
|
302
|
+
if (orderId && deliveryDate) {
|
|
303
|
+
const formattedDate = format(new Date(deliveryDate), 'yyyy-MM-dd');
|
|
304
|
+
setDeliveryDate(formattedDate);
|
|
387
305
|
}
|
|
306
|
+
|
|
307
|
+
setTimeout(() => {
|
|
308
|
+
props?.callOrderStatusApi();
|
|
309
|
+
}, 1000);
|
|
310
|
+
|
|
311
|
+
await props?.callOrderAlertsApi();
|
|
312
|
+
await props?.callOrdersApi();
|
|
388
313
|
};
|
|
389
314
|
|
|
390
315
|
const errorFound = () => {
|