@bjsdistribution/dms-client-return 0.1.20-dev → 0.1.20-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.
Files changed (177) hide show
  1. package/dist/common/date-picker/header/ClearDate.d.ts +1 -1
  2. package/dist/components/client-portal/DateFilterStore.d.ts +15 -0
  3. package/dist/components/client-portal/ReturnRTFilters.d.ts +3 -0
  4. package/dist/components/order-daily-overview/header/route-header/ClientRouterHeader.d.ts +11 -0
  5. package/dist/components/order-daily-overview/table-view/TableStyle.d.ts +4 -4
  6. package/dist/components/order-view/DynamicTable.d.ts +2 -1
  7. package/dist/components/order-view/general-information/Status.d.ts +1 -1
  8. package/dist/components/order-view/general-information/index.d.ts +1 -1
  9. package/dist/components/order-view/index.d.ts +1 -1
  10. package/dist/components/order-view/notes/AddNote.d.ts +1 -0
  11. package/dist/components/order-view/notes/order-dropdown/NewReturnDropdown.d.ts +3 -0
  12. package/dist/components/order-view/order-actions/actions/clear-booking-status/ClearBookingStatus.d.ts +4 -1
  13. package/dist/components/order-view/order-actions/actions/confirm-order/index.d.ts +4 -1
  14. package/dist/components/order-view/order-actions/actions/force-debrief/BaseChargeConfirmationModal.d.ts +7 -0
  15. package/dist/components/order-view/order-actions/actions/force-debrief/ForceDebriefModal.d.ts +11 -0
  16. package/dist/components/order-view/order-actions/actions/force-debrief/Selector.d.ts +11 -0
  17. package/dist/components/order-view/order-actions/actions/force-debrief/charges/adhoc/index.d.ts +3 -0
  18. package/dist/components/order-view/order-actions/actions/force-debrief/charges/base-charge/index.d.ts +8 -0
  19. package/dist/components/order-view/order-actions/actions/force-debrief/charges/collection-add-ons/index.d.ts +7 -0
  20. package/dist/components/order-view/order-actions/actions/force-debrief/charges/delivery-add-ons/index.d.ts +7 -0
  21. package/dist/components/order-view/order-actions/actions/force-debrief/charges/disposal-charges/index.d.ts +7 -0
  22. package/dist/components/order-view/order-actions/actions/force-debrief/charges/order-charges/index.d.ts +7 -0
  23. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/EscalationCategory.d.ts +3 -0
  24. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/EscalationLevel.d.ts +3 -0
  25. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/EscalationReason.d.ts +3 -0
  26. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/index.d.ts +3 -0
  27. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/FlagsTemplate.d.ts +3 -0
  28. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/OrderTemplate.d.ts +3 -0
  29. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/Tabs.d.ts +3 -0
  30. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/index.d.ts +3 -0
  31. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/RadioButtons.d.ts +7 -0
  32. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/CancellationReasonDropdown.d.ts +3 -0
  33. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/FailureReasonDropdown.d.ts +3 -0
  34. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/OrderHoldReasonDropdown.d.ts +3 -0
  35. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/StatusDropdown.d.ts +3 -0
  36. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/ZoneDropdown.d.ts +3 -0
  37. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/failure-content/index.d.ts +3 -0
  38. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/index.d.ts +4 -0
  39. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/success-content/index.d.ts +3 -0
  40. package/dist/components/order-view/order-actions/actions/force-debrief/styles.d.ts +8 -0
  41. package/dist/components/order-view/order-actions/actions/hold-order/HoldOrderModal.d.ts +1 -0
  42. package/dist/components/order-view/order-actions/actions/remove-from-route/RemoveFromRoute.d.ts +1 -1
  43. package/dist/components/order-view/order-actions/actions/unhold-order/UnholdOrder.d.ts +1 -0
  44. package/dist/components/order-view/order-actions/types.d.ts +3 -3
  45. package/dist/components/order-view/order-details/expanded-content/index.d.ts +1 -1
  46. package/dist/components/order-view/order-details/index.d.ts +1 -1
  47. package/dist/components/order-view/order-resources/expanded-content/index.d.ts +1 -1
  48. package/dist/components/order-view/products-info/expanded-content/index.d.ts +6 -1
  49. package/dist/components/order-view/products-info/index.d.ts +1 -1
  50. package/dist/components/order-view/return-client-products/ProductTable.d.ts +6 -1
  51. package/dist/components/order-view/return-client-products/product-table/ReturnProductTable.d.ts +6 -1
  52. package/dist/components/order-view/store.d.ts +15 -3
  53. package/dist/components/order-view/system-event-logs/expanded-content/index.d.ts +1 -1
  54. package/dist/components/order-view/types.d.ts +55 -1
  55. package/dist/components/order-view/utils.d.ts +11 -2
  56. package/dist/components/store.d.ts +1 -1
  57. package/dist/dms-client-return.cjs.development.js +7157 -4661
  58. package/dist/dms-client-return.cjs.development.js.map +1 -1
  59. package/dist/dms-client-return.cjs.production.min.js +1 -1
  60. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  61. package/dist/dms-client-return.esm.js +7173 -4677
  62. package/dist/dms-client-return.esm.js.map +1 -1
  63. package/package.json +6 -4
  64. package/src/assets/icons/ActionIcon.tsx +1 -1
  65. package/src/assets/icons/ArrowDownIcon.tsx +2 -2
  66. package/src/components/client-portal/DateFilterStore.ts +139 -0
  67. package/src/components/client-portal/OutstandingTable.tsx +16 -72
  68. package/src/components/client-portal/ReturnAfterSearchBar.tsx +42 -87
  69. package/src/components/client-portal/ReturnOverview.tsx +11 -2
  70. package/src/components/client-portal/ReturnRTFilters.tsx +140 -43
  71. package/src/components/client-portal/ReturnSearchBar.tsx +42 -153
  72. package/src/components/client-portal/ReturnStatus.tsx +33 -82
  73. package/src/components/client-portal/return-confirm/ConfirmedMain.tsx +12 -23
  74. package/src/components/client-portal/return-confirm/ReturnConfirmedTable.tsx +9 -86
  75. package/src/components/order-daily-overview/header/route-header/ClientRouterHeader.tsx +166 -0
  76. package/src/components/order-daily-overview/header/route-header/RouterHeader.tsx +2 -86
  77. package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +46 -15
  78. package/src/components/order-daily-overview/index.tsx +23 -4
  79. package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +6 -1
  80. package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +3 -0
  81. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +36 -36
  82. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +12 -2
  83. package/src/components/order-daily-overview/return-order-table/ReturnTable.tsx +16 -0
  84. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +25 -11
  85. package/src/components/order-daily-overview/table/ReturnTable.tsx +8 -4
  86. package/src/components/order-view/DynamicTable.tsx +21 -8
  87. package/src/components/order-view/details-filters/left-side-filters/dropdowns/DropDowns.tsx +1 -1
  88. package/src/components/order-view/details-filters/left-side-filters/dropdowns/OptionsDropDown.tsx +9 -0
  89. package/src/components/order-view/details-filters/right-side-filters/Details.tsx +28 -3
  90. package/src/components/order-view/flags-action-modal/Dropdowns.tsx +2 -0
  91. package/src/components/order-view/general-information/Status.tsx +92 -18
  92. package/src/components/order-view/general-information/index.tsx +2 -2
  93. package/src/components/order-view/generic-table/AuditLogs.tsx +39 -12
  94. package/src/components/order-view/index.tsx +50 -8
  95. package/src/components/order-view/modalsPopup/ModalManager.tsx +1 -1
  96. package/src/components/order-view/notes/AddNote.tsx +95 -65
  97. package/src/components/order-view/notes/order-dropdown/NewReturnDropdown.tsx +8 -10
  98. package/src/components/order-view/notification/FlagTemplate.tsx +21 -10
  99. package/src/components/order-view/notification/OrderTemplate.tsx +192 -41
  100. package/src/components/order-view/notification/ReminderTemplate.tsx +28 -13
  101. package/src/components/order-view/notification/index.tsx +100 -55
  102. package/src/components/order-view/order-actions/actions/add-resources/DocFileUpload.tsx +92 -72
  103. package/src/components/order-view/order-actions/actions/add-resources/index.tsx +27 -10
  104. package/src/components/order-view/order-actions/actions/cancel-order/ReturnAction.tsx +25 -4
  105. package/src/components/order-view/order-actions/actions/cancel-order/ReturnReason.tsx +24 -4
  106. package/src/components/order-view/order-actions/actions/clear-booking-status/ClearBookingStatus.tsx +9 -2
  107. package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +12 -35
  108. package/src/components/order-view/order-actions/actions/confirm-order/tables/NotesTable.tsx +1 -0
  109. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.tsx +88 -30
  110. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateTaskModal.tsx +5 -3
  111. package/src/components/order-view/order-actions/actions/create-task-reminder/TaskModal.tsx +2 -2
  112. package/src/components/order-view/order-actions/actions/force-debrief/BaseChargeConfirmationModal.tsx +94 -0
  113. package/src/components/order-view/order-actions/actions/force-debrief/ForceDebriefModal.tsx +635 -0
  114. package/src/components/order-view/order-actions/actions/force-debrief/Selector.tsx +65 -0
  115. package/src/components/order-view/order-actions/actions/force-debrief/charges/adhoc/index.tsx +94 -0
  116. package/src/components/order-view/order-actions/actions/force-debrief/charges/base-charge/index.tsx +106 -0
  117. package/src/components/order-view/order-actions/actions/force-debrief/charges/collection-add-ons/index.tsx +77 -0
  118. package/src/components/order-view/order-actions/actions/force-debrief/charges/delivery-add-ons/index.tsx +78 -0
  119. package/src/components/order-view/order-actions/actions/force-debrief/charges/disposal-charges/index.tsx +77 -0
  120. package/src/components/order-view/order-actions/actions/force-debrief/charges/order-charges/index.tsx +124 -0
  121. package/src/components/order-view/order-actions/actions/force-debrief/escalation/EscalationCategory.tsx +92 -0
  122. package/src/components/order-view/order-actions/actions/force-debrief/escalation/EscalationLevel.tsx +90 -0
  123. package/src/components/order-view/order-actions/actions/force-debrief/escalation/EscalationReason.tsx +122 -0
  124. package/src/components/order-view/order-actions/actions/force-debrief/escalation/index.tsx +16 -0
  125. package/src/components/order-view/order-actions/actions/force-debrief/notifications/FlagsTemplate.tsx +46 -0
  126. package/src/components/order-view/order-actions/actions/force-debrief/notifications/OrderTemplate.tsx +117 -0
  127. package/src/components/order-view/order-actions/actions/force-debrief/notifications/Tabs.tsx +32 -0
  128. package/src/components/order-view/order-actions/actions/force-debrief/notifications/index.tsx +180 -0
  129. package/src/components/order-view/order-actions/actions/force-debrief/order-info/RadioButtons.tsx +150 -0
  130. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/CancellationReasonDropdown.tsx +40 -0
  131. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/FailureReasonDropdown.tsx +108 -0
  132. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/OrderHoldReasonDropdown.tsx +37 -0
  133. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/StatusDropdown.tsx +48 -0
  134. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/ZoneDropdown.tsx +27 -0
  135. package/src/components/order-view/order-actions/actions/force-debrief/order-info/failure-content/index.tsx +187 -0
  136. package/src/components/order-view/order-actions/actions/force-debrief/order-info/index.tsx +55 -0
  137. package/src/components/order-view/order-actions/actions/force-debrief/order-info/success-content/index.tsx +221 -0
  138. package/src/components/order-view/order-actions/actions/force-debrief/styles.tsx +51 -0
  139. package/src/components/order-view/order-actions/actions/hold-order/HoldOrderModal.tsx +2 -0
  140. package/src/components/order-view/order-actions/actions/remove-from-route/RemoveFromRoute.tsx +7 -2
  141. package/src/components/order-view/order-actions/actions/unhold-order/UnholdOrder.tsx +2 -0
  142. package/src/components/order-view/order-actions/index.tsx +19 -10
  143. package/src/components/order-view/order-actions/store.ts +1 -1
  144. package/src/components/order-view/order-actions/types.ts +3 -3
  145. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactHome.tsx +102 -45
  146. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactMobile.tsx +93 -34
  147. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactWork.tsx +88 -31
  148. package/src/components/order-view/order-details/expanded-content/footer/index.tsx +55 -80
  149. package/src/components/order-view/order-details/expanded-content/index.tsx +37 -16
  150. package/src/components/order-view/order-details/expanded-content/instruction-section/index.tsx +1 -1
  151. package/src/components/order-view/order-details/expanded-content/services-section/AssemblyType.tsx +9 -91
  152. package/src/components/order-view/order-details/expanded-content/services-section/OrderServices.tsx +10 -182
  153. package/src/components/order-view/order-details/expanded-content/services-section/ServiceLevel.tsx +3 -4
  154. package/src/components/order-view/order-details/index.tsx +5 -2
  155. package/src/components/order-view/order-resources/expanded-content/index.tsx +2 -2
  156. package/src/components/order-view/products-info/expanded-content/index.tsx +33 -11
  157. package/src/components/order-view/products-info/index.tsx +10 -6
  158. package/src/components/order-view/return-client-products/ProductTable.tsx +12 -2
  159. package/src/components/order-view/return-client-products/product-table/ReturnProductTable.tsx +73 -23
  160. package/src/components/order-view/store.ts +113 -1
  161. package/src/components/order-view/system-event-logs/expanded-content/index.tsx +6 -2
  162. package/src/components/order-view/types.ts +60 -1
  163. package/src/components/order-view/utils.ts +49 -33
  164. package/src/components/order-view/view-reminder/AssigneeDropdown.tsx +85 -26
  165. package/src/components/order-view/view-reminder/ViewReminder.tsx +31 -14
  166. package/src/components/store.ts +2 -2
  167. package/src/index.tsx +23 -5
  168. package/dist/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.d.ts +0 -7
  169. package/dist/components/order-view/order-actions/actions/log-service-refusal/Notes.d.ts +0 -7
  170. package/dist/components/order-view/order-actions/actions/log-service-refusal/OrderServices.d.ts +0 -7
  171. package/dist/components/order-view/order-actions/actions/log-service-refusal/helper.d.ts +0 -3
  172. package/dist/components/order-view/order-actions/actions/log-service-refusal/index.d.ts +0 -3
  173. package/src/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.tsx +0 -50
  174. package/src/components/order-view/order-actions/actions/log-service-refusal/Notes.tsx +0 -50
  175. package/src/components/order-view/order-actions/actions/log-service-refusal/OrderServices.tsx +0 -57
  176. package/src/components/order-view/order-actions/actions/log-service-refusal/helper.ts +0 -26
  177. package/src/components/order-view/order-actions/actions/log-service-refusal/index.tsx +0 -130
@@ -0,0 +1,635 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import OrderActionModal from '../../../../../common/modals/order-action-modal/OrderActionModal';
3
+ import {
4
+ useActiveTab,
5
+ useChargesState,
6
+ useCurrentAction,
7
+ useCustomerDetails,
8
+ useCustomerInfo,
9
+ useEscalationCategory,
10
+ useEscalationLevel,
11
+ useEscalationReason,
12
+ useFailureReason,
13
+ useGlobalEscData,
14
+ useGlobalStateHitAuditLog,
15
+ useGlobalStateHitOrder,
16
+ useNewStatus,
17
+ useOrderCancelReason,
18
+ useOrderCustomersList,
19
+ useOrderDetails,
20
+ useOrderHoldReason,
21
+ usePrevOrderDetails,
22
+ useProductDetails,
23
+ } from '../../../store';
24
+ import OrderCharges from './charges/order-charges';
25
+ import CollectionAddOns from './charges/collection-add-ons';
26
+ import DisposalCharge from './charges/disposal-charges';
27
+ import styled from 'styled-components';
28
+ import BaseCharges from './charges/base-charge';
29
+ import DeliveryAddOns from './charges/delivery-add-ons';
30
+ import AdhocSection from './charges/adhoc';
31
+ import OrderInfo from './order-info';
32
+ import ForceDebriefSelector from './Selector';
33
+ import {
34
+ Checkbox,
35
+ Label,
36
+ useApiHook,
37
+ useAxios,
38
+ } from '@bjsdistribution/dms-component-library';
39
+ import Escalation from './escalation';
40
+ import FDNotification from './notifications';
41
+
42
+ import { compareOrderDetailsStates, filterObject } from '../../../utils';
43
+ import { AdhocCharge, ApiResponse, OrdersType } from '../../../types';
44
+ import { notification } from 'antd';
45
+ import BaseChargeConfirmationModal from './BaseChargeConfirmationModal';
46
+ import { v4 as uuidv4 } from 'uuid';
47
+
48
+ interface IProps {
49
+ callOrdersApi: any;
50
+ callOrderStatusApi: any;
51
+ callOrderAlertsApi: any;
52
+ }
53
+
54
+ function ForceDebriefModal(props: IProps) {
55
+ const [customerInfo, setCustomerInfo] = useCustomerInfo();
56
+ const [allCustomers, setAllCustomers] = useOrderCustomersList();
57
+ const infoText = `${customerInfo?.recipient_name}, ${customerInfo?.postcode}`;
58
+ const [, setCurrentAction] = useCurrentAction();
59
+
60
+ const [activeTab, setActiveTab] = useActiveTab();
61
+ const handleSwitchChange = (newValue: any) => setActiveTab(newValue);
62
+ const [chargesState, setCharges] = useChargesState();
63
+ const [inputValue, setInputValue] = useState<Record<string, string>>({}); // only for UI purpose
64
+ const [staticData, setDebriefStaticData] = useState([]);
65
+ const [orderDetails, setOrderDetails] = useOrderDetails();
66
+ const [prevOrderDetails, setPrevOrderDetails] = usePrevOrderDetails();
67
+ const [isEscalationEnabled, setIsEscalationEnabled] = useState<boolean>(true);
68
+ const [newStatus, setNewStatus] = useNewStatus();
69
+ const [cancellationReason, setCancellationReason] = useOrderCancelReason();
70
+ const [orderHold, setOrderHold] = useOrderHoldReason();
71
+ const [failureReason, setFailureReason] = useFailureReason();
72
+ const [escalationCategory, setEscalationCategory] = useEscalationCategory();
73
+ const [escalationLevel, setEscalationLevel] = useEscalationLevel();
74
+ const [escalationReason, setEscalationReason] = useEscalationReason();
75
+ const [, setRecallOrders] = useGlobalStateHitOrder();
76
+ const [, setRecallAuditLog] = useGlobalStateHitAuditLog();
77
+ const [, setGlobalEscData] = useGlobalEscData();
78
+
79
+ const [showAmountConfirmModal, setShowAmountConfirmModal] = useState<boolean>(
80
+ false
81
+ );
82
+
83
+ const [productdata] = useProductDetails();
84
+ const sortedProductData = productdata?.sort((a: any, b: any) => {
85
+ return a?.status === b?.status ? 0 : a?.status ? -1 : 1;
86
+ });
87
+
88
+ const isDeleted = Array.isArray(sortedProductData)
89
+ ? sortedProductData?.filter(item => item?.status === true)
90
+ : [];
91
+
92
+ //customers API
93
+ const [orderData] = useOrderDetails();
94
+ const customersData = orderData;
95
+ const id = customersData?.customer_id;
96
+
97
+ //Customers list API call
98
+ const {
99
+ data: fetchCustomerData,
100
+ loading: customerLoading,
101
+ fetchData,
102
+ } = useAxios<{
103
+ data: ApiResponse[];
104
+ }>({
105
+ endpoint: `/v1/customer/list`,
106
+ method: 'GET',
107
+ pagination: { is_pagination: false },
108
+ filters: [{ field: 'status', op: '=', value: '1' }],
109
+ });
110
+
111
+ useEffect(() => {
112
+ if (fetchCustomerData && fetchCustomerData?.data) {
113
+ const res = fetchCustomerData?.data;
114
+ setAllCustomers(res);
115
+ }
116
+ }, [fetchCustomerData, customerLoading]);
117
+
118
+ useEffect(() => {
119
+ fetchData();
120
+ }, []);
121
+
122
+ // For API Call
123
+ const [customerData, setCustomerData] = useCustomerDetails();
124
+ const { data: fetchedData, loading, setShouldPerformAction } = useApiHook<{
125
+ data: ApiResponse[];
126
+ }>({
127
+ endpoint: `customers/${id}`,
128
+ method: 'GET',
129
+ performAction: false,
130
+ });
131
+
132
+ useEffect(() => {
133
+ if (id) {
134
+ setShouldPerformAction(true);
135
+ }
136
+ }, [id]);
137
+
138
+ useEffect(() => {
139
+ if (fetchedData && fetchedData?.data) {
140
+ const requiredData = fetchedData?.data;
141
+ setCustomerData(requiredData);
142
+ }
143
+ }, [fetchedData, loading]);
144
+ const selectedCustomer = allCustomers?.find(
145
+ (customer: any) => customer?.id === customerData?.id
146
+ );
147
+
148
+ const adhocChargesFields: AdhocCharge[] = Array.from({ length: 9 }, () => ({
149
+ id: uuidv4(),
150
+ adhoc_charges_description: '',
151
+ adhoc_charges: 0,
152
+ }));
153
+
154
+ const {
155
+ fetchData: fetchAllDebriefStaticData,
156
+ data: debriefStaticData,
157
+ loading: debriefLoading,
158
+ } = useAxios<{
159
+ data: any;
160
+ }>({
161
+ endpoint: `/finance/debrief/getData/all/`,
162
+ method: 'GET',
163
+ });
164
+
165
+ useEffect(() => {
166
+ setCharges(prev => ({
167
+ ...prev,
168
+ adhoc_charges: adhocChargesFields,
169
+ }));
170
+
171
+ // call debrief static api for getting base charges type
172
+ fetchAllDebriefStaticData();
173
+ }, []);
174
+
175
+ useEffect(() => {
176
+ if (debriefStaticData?.data) {
177
+ setDebriefStaticData(debriefStaticData?.data[0]);
178
+ }
179
+ }, [debriefLoading]);
180
+
181
+ const { fetchData: callUpdateOrderAPI } = useAxios<{
182
+ data: ApiResponse[];
183
+ }>({
184
+ endpoint: `/orders/update/`,
185
+ method: 'PUT',
186
+ });
187
+
188
+ const { fetchData: callForceDebriefApi } = useAxios<{
189
+ data: ApiResponse[];
190
+ }>({
191
+ endpoint: `/invoices/force-debrief/`,
192
+ method: 'POST',
193
+ });
194
+
195
+ const { fetchData: createEscalation } = useAxios<{
196
+ data: any;
197
+ }>({
198
+ endpoint: `/orders/escalations/create/`,
199
+ method: 'POST',
200
+ });
201
+
202
+ const initialValues = () => {
203
+ setOrderDetails(prevOrderDetails);
204
+ setNewStatus('');
205
+ setCancellationReason('');
206
+ setOrderHold('');
207
+ setFailureReason('');
208
+ setEscalationCategory('');
209
+ setEscalationLevel('');
210
+ setEscalationReason('');
211
+ setActiveTab('success');
212
+ };
213
+
214
+ const closeModal = () => {
215
+ initialValues();
216
+ setCurrentAction(undefined);
217
+ };
218
+
219
+ const isDifferent = () => {
220
+ const keysToRemovefromOrders = [
221
+ 'order_locked',
222
+ 'order_communications',
223
+ 'updated_at',
224
+ 'updated_by',
225
+ ];
226
+ const filteredOrderDetails = filterObject(
227
+ orderDetails,
228
+ keysToRemovefromOrders
229
+ );
230
+ const filteredPrevOrderDetails = filterObject(
231
+ prevOrderDetails,
232
+ keysToRemovefromOrders
233
+ );
234
+
235
+ const orderDetailsSorted = JSON.stringify(filteredOrderDetails);
236
+ const prevOrderDetailsSorted = JSON.stringify(filteredPrevOrderDetails);
237
+ const isSame = orderDetailsSorted === prevOrderDetailsSorted;
238
+ return !isSame;
239
+ };
240
+
241
+ const debriefchargesApi = async (finalPayload: any, failurePayload: any) => {
242
+ try {
243
+ const responseForceDebrief = (await callForceDebriefApi({
244
+ payload: {
245
+ debrief_data: finalPayload,
246
+ ...(activeTab === 'failure'
247
+ ? { failure_data: failurePayload }
248
+ : { failure_data: {} }),
249
+ },
250
+ })) as {
251
+ code: number | null;
252
+ error?: string | null | undefined;
253
+ [key: string]: any;
254
+ };
255
+ if (responseForceDebrief.code === 200) {
256
+ notification.success({
257
+ message: 'Success',
258
+ description: `${responseForceDebrief?.message}`,
259
+ });
260
+ }
261
+ } catch (err) {}
262
+ };
263
+
264
+ const ordersUpdateApi = async () => {
265
+ const ordersApiPayload = compareOrderDetailsStates(
266
+ prevOrderDetails,
267
+ orderDetails
268
+ );
269
+
270
+ const serviceKeys = [
271
+ 'assemble',
272
+ 'disassemble',
273
+ 'unpack_items',
274
+ 'collect_disposal',
275
+ 'take_packaging_away',
276
+ 'assembly_type',
277
+ ];
278
+
279
+ let orderServicesPayload: Record<string, any> = {};
280
+
281
+ const includesKey = serviceKeys.some(key => key in ordersApiPayload);
282
+
283
+ if (includesKey) {
284
+ for (const key of serviceKeys) {
285
+ orderServicesPayload[key as keyof typeof ordersApiPayload] =
286
+ key in ordersApiPayload
287
+ ? ordersApiPayload[key as keyof typeof ordersApiPayload]
288
+ : orderDetails[key as keyof OrdersType];
289
+ delete ordersApiPayload[key as keyof typeof ordersApiPayload];
290
+ if (
291
+ orderServicesPayload?.assemble === false &&
292
+ orderServicesPayload?.disassemble === false
293
+ ) {
294
+ orderServicesPayload.assembly_type = null;
295
+ }
296
+ }
297
+ }
298
+
299
+ if (Object.keys(orderServicesPayload).length > 0) {
300
+ ordersApiPayload.order_services = [orderServicesPayload];
301
+ }
302
+
303
+ try {
304
+ let response = (await callUpdateOrderAPI({
305
+ payload: [ordersApiPayload],
306
+ })) as {
307
+ code: number | null;
308
+ error?: string | null | undefined;
309
+ [key: string]: any;
310
+ };
311
+ if (response.code === 200 && response?.data?.length > 0) {
312
+ notification.success({
313
+ message: 'Success',
314
+ description: `${response?.message}`,
315
+ });
316
+ setOrderDetails(response?.data[0]);
317
+ setPrevOrderDetails(response?.data[0]);
318
+ setCustomerInfo({
319
+ recipient_name: response?.data[0]?.order_recipient?.recipient_name,
320
+ postcode: response?.data[0]?.order_recipient?.postcode,
321
+ });
322
+ await setRecallOrders(true);
323
+ }
324
+ } catch (err) {
325
+ setOrderDetails(prevOrderDetails);
326
+ }
327
+ };
328
+
329
+ const escalationCreateApi = async (escalationPayload: any) => {
330
+ try {
331
+ const apiResponse = (await createEscalation({
332
+ payload: escalationPayload,
333
+ })) as {
334
+ code: number | null;
335
+ error?: string | null | undefined;
336
+ [key: string]: any;
337
+ };
338
+ if (apiResponse?.code === 200) {
339
+ notification.success({
340
+ message: 'Success',
341
+ description: `${apiResponse?.message}`,
342
+ });
343
+
344
+ setGlobalEscData(apiResponse?.data);
345
+ }
346
+ } catch (err) {}
347
+ };
348
+
349
+ const onSubmit = async () => {
350
+ setRecallOrders(false);
351
+ const ordersPayload = {
352
+ consignment: orderDetails?.consignment,
353
+ order_number: orderDetails?.order_number,
354
+ customer_id: customerData?.id,
355
+ customer_name: customerData?.customer_name,
356
+ client_name: selectedCustomer?.client_name,
357
+ recipient_name: orderDetails?.order_recipient?.recipient_name,
358
+ order_id: orderDetails?.id,
359
+ order_type: orderDetails?.order_type?.type,
360
+ legacy_order_id: orderDetails?.gsit_order_id,
361
+ postcode: orderDetails?.order_recipient?.postcode,
362
+ ...(activeTab === 'failure' && { failure_new_status: newStatus }),
363
+ };
364
+ const adhocCharges = chargesState?.adhoc_charges
365
+ ?.filter(
366
+ item =>
367
+ !(item.adhoc_charges === 0 && item.adhoc_charges_description === '')
368
+ )
369
+ .map(({ adhoc_charges_description, adhoc_charges }) => ({
370
+ adhoc_charges_description,
371
+ adhoc_charges,
372
+ }));
373
+ const chargesPayload: any = { ...chargesState };
374
+ chargesPayload.adhoc_charges = adhocCharges;
375
+ chargesPayload.debrief_status = activeTab;
376
+ if (activeTab === 'success') {
377
+ delete chargesPayload.new_order_status;
378
+ }
379
+
380
+ const failurePayload = {
381
+ failure_reason_id: failureReason?.id,
382
+ ...(newStatus === 'Cancelled' && {
383
+ cancelled_reason_id: cancellationReason?.value,
384
+ }),
385
+ ...(newStatus === 'On Hold' && { hold_reason_id: orderHold?.value }),
386
+ failure_order_status: newStatus,
387
+ status: activeTab,
388
+ };
389
+
390
+ const finalPayload = {
391
+ ...ordersPayload,
392
+ status: activeTab,
393
+ charges: [chargesPayload],
394
+ ...(activeTab === 'failure' && { failureData: failurePayload }),
395
+ }; // check adhoc charges if 0 and description is empty then
396
+
397
+ // APPLY ALL VALIDATIONS HERE BEFORE CALLING ANY API
398
+
399
+ if (activeTab === 'failure') {
400
+ if (!failureReason?.id) {
401
+ notification.error({
402
+ message: 'Error',
403
+ description: 'Failure reason is mandatory',
404
+ });
405
+ return;
406
+ }
407
+
408
+ if (newStatus?.length === 0) {
409
+ notification.error({
410
+ message: 'Error',
411
+ description: 'New status is mandatory',
412
+ });
413
+ return;
414
+ }
415
+
416
+ if (newStatus === 'On Hold' && orderHold?.length === 0) {
417
+ notification.error({
418
+ message: 'Error',
419
+ description: 'Hold reason is mandatory',
420
+ });
421
+ return;
422
+ }
423
+
424
+ if (newStatus === 'Cancelled' && cancellationReason?.length === 0) {
425
+ notification.error({
426
+ message: 'Error',
427
+ description: 'Cancel reason is mandatory',
428
+ });
429
+ return;
430
+ }
431
+ }
432
+
433
+ if (isDifferent()) {
434
+ await ordersUpdateApi();
435
+ }
436
+
437
+ if (activeTab === 'failure' && isEscalationEnabled) {
438
+ const escalationPayload = [
439
+ {
440
+ order_id: orderDetails?.id,
441
+ escalation_reason_id: escalationReason?.value,
442
+ escalation_category_id: escalationCategory?.value,
443
+ escalation_level_id: escalationLevel?.value,
444
+ is_deleted: false,
445
+ route_id: orderDetails?.order_routes?.route_id,
446
+ },
447
+ ];
448
+
449
+ await escalationCreateApi(escalationPayload);
450
+ }
451
+
452
+ await debriefchargesApi(finalPayload, failurePayload);
453
+ await setRecallAuditLog(true);
454
+ // call status api and alerts api
455
+ initialValues();
456
+ await props?.callOrderStatusApi();
457
+ await props?.callOrderAlertsApi();
458
+ await props?.callOrdersApi();
459
+ // closeModal();
460
+ };
461
+
462
+ const onForceDebrief = () => {
463
+ if (chargesState?.base_charge > 200) {
464
+ setShowAmountConfirmModal(true);
465
+ } else {
466
+ onSubmit();
467
+ }
468
+ };
469
+
470
+ return (
471
+ <OrderActionModal
472
+ headerTitle="Order Debrief"
473
+ onCloseHeader={closeModal}
474
+ infoText={infoText}
475
+ onSubmit={onForceDebrief}
476
+ submitBtnTitle={'Complete Order'}
477
+ // isSubmitDisabled={true}
478
+ maxWidth="95vw"
479
+ headerActions={
480
+ <ForceDebriefSelector onSwitchChange={handleSwitchChange} />
481
+ }
482
+ >
483
+ <MainContainer>
484
+ <FDNotification />
485
+ <ContentContainer>
486
+ <OrderInfo />
487
+ </ContentContainer>
488
+ <ContentContainer>
489
+ <Container>
490
+ <Label
491
+ label="Delivery Instructions"
492
+ htmlFor="deliveryInstruction"
493
+ />
494
+ <Text>{orderDetails?.delivery_instructions || 'N/A'}</Text>
495
+ </Container>
496
+
497
+ <Container>
498
+ <Label label="Other Instructions" htmlFor="otherInstruction" />
499
+ <Text>{orderDetails?.other_instructions || 'N/A'}</Text>
500
+ </Container>
501
+ </ContentContainer>
502
+ {/* ORDER-PRODUCT SECTION */}
503
+ {isDeleted?.length > 0 && (
504
+ <ProductDiv>
505
+ <Container>
506
+ {isDeleted?.map((item, index) => (
507
+ <ProductContainer key={index}>
508
+ <Status>{'*'}</Status>
509
+ <Status>{item?.status_value || 'N/A'}</Status>
510
+ <Status>{item?.order_product_type?.type || 'N/A'}</Status>
511
+ <Status>{item?.sku || 'N/A'}</Status>
512
+ <Status>{`Part 1 of 1`}</Status>
513
+ <Status>{'Weight' + ':' + item?.weight || 'N/A'}</Status>
514
+ <Status>{'Cube' + ':' + item?.cube || 'N/A'}</Status>
515
+ </ProductContainer>
516
+ ))}
517
+ </Container>
518
+ </ProductDiv>
519
+ )}
520
+
521
+ {/* CHARGES SECTION */}
522
+ <ContentContainer>
523
+ <ContainerInner>
524
+ <BaseCharges
525
+ inputValue={inputValue}
526
+ setInputValue={setInputValue}
527
+ staticData={staticData}
528
+ />
529
+ <DeliveryAddOns
530
+ inputValue={inputValue}
531
+ setInputValue={setInputValue}
532
+ />
533
+ </ContainerInner>
534
+ <ContainerInner>
535
+ <CollectionAddOns
536
+ inputValue={inputValue}
537
+ setInputValue={setInputValue}
538
+ />
539
+ <DisposalCharge
540
+ inputValue={inputValue}
541
+ setInputValue={setInputValue}
542
+ />
543
+ </ContainerInner>
544
+ <OrderCharges inputValue={inputValue} setInputValue={setInputValue} />
545
+ <AdhocSection />
546
+ </ContentContainer>
547
+ {activeTab === 'failure' && (
548
+ <ContentContainer style={{ flexDirection: 'column', gap: '10px' }}>
549
+ <div style={{ display: 'flex', gap: '10px' }}>
550
+ Escalation
551
+ <Checkbox
552
+ checked={isEscalationEnabled}
553
+ onChange={event => setIsEscalationEnabled(event.target.checked)}
554
+ />
555
+ </div>
556
+ <Escalation />
557
+ </ContentContainer>
558
+ )}
559
+ </MainContainer>
560
+ {showAmountConfirmModal && (
561
+ <BaseChargeConfirmationModal
562
+ setConfirmationModal={setShowAmountConfirmModal}
563
+ onProceed={onSubmit}
564
+ />
565
+ )}
566
+ </OrderActionModal>
567
+ );
568
+ }
569
+
570
+ const Status = styled.span`
571
+ font-family: 'Roboto', sans-serif;
572
+ font-size: 14px;
573
+ font-weight: 400;
574
+ text-transform: capitalize;
575
+ color: #3a3630;
576
+ `;
577
+
578
+ const ProductContainer = styled.div`
579
+ display: flex;
580
+ flex-wrap: wrap;
581
+ gap: 16px;
582
+ `;
583
+
584
+ const MainContainer = styled.div`
585
+ padding: 10px;
586
+ display: flex;
587
+ flex-direction: column;
588
+ gap: 10px;
589
+ `;
590
+
591
+ const ContainerInner = styled.div`
592
+ display: flex;
593
+ flex-direction: column;
594
+ gap: 16px;
595
+ `;
596
+
597
+ const Container = styled.div`
598
+ width: 100%;
599
+ `;
600
+
601
+ const Text = styled.div`
602
+ color: #363a30;
603
+ font-size: 14px;
604
+ white-space: break-spaces;
605
+ `;
606
+
607
+ export const ContentContainer = styled.div`
608
+ display: flex;
609
+ padding: 12px;
610
+ flex-direction: row;
611
+ align-items: flex-start;
612
+ gap: 40px;
613
+ flex: 1 0 0;
614
+ border-radius: 15px;
615
+ background: #f8fafc;
616
+ width: 100%;
617
+ white-space: nowrap;
618
+ `;
619
+
620
+ export const ProductDiv = styled.div`
621
+ display: flex;
622
+ padding: 12px;
623
+ flex-direction: row;
624
+ align-items: flex-start;
625
+ gap: 40px;
626
+ flex: 1 0 0;
627
+ border-radius: 15px;
628
+ background: #f8fafc;
629
+ width: 100%;
630
+ white-space: nowrap;
631
+ min-height: 60px;
632
+ overflow: scroll;
633
+ max-height: 150px;
634
+ `;
635
+ export default React.memo(ForceDebriefModal);
@@ -0,0 +1,65 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import SwitchSelector from 'react-switch-selector';
4
+ import { notification } from 'antd';
5
+
6
+ interface ForceDebriefSelectorProps {
7
+ onSwitchChange: (newValue: string) => void;
8
+ }
9
+
10
+ export const Options = [
11
+ {
12
+ label: 'Success',
13
+ value: 'success',
14
+ selectedBackgroundColor: '#57DB7A',
15
+ },
16
+ {
17
+ label: 'Failure',
18
+ value: 'failure',
19
+ selectedBackgroundColor: '#E95252',
20
+ },
21
+ ];
22
+
23
+ const ForceDebriefSelector: React.FC<ForceDebriefSelectorProps> = ({
24
+ onSwitchChange,
25
+ }) => {
26
+ const initialSelectedIndex = Options?.findIndex(
27
+ ({ value }) => value === 'success'
28
+ );
29
+
30
+ const handleSwitchChange = (selectedOptionValue: unknown) => {
31
+ if (typeof selectedOptionValue === 'string') {
32
+ onSwitchChange(selectedOptionValue);
33
+ } else {
34
+ notification.error({
35
+ message: 'Error',
36
+ description:
37
+ typeof selectedOptionValue ||
38
+ 'Unexpected type for selectedOptionValue:',
39
+ });
40
+ }
41
+ };
42
+
43
+ return (
44
+ <StyledSwitch>
45
+ <SwitchSelector
46
+ onChange={handleSwitchChange}
47
+ options={Options}
48
+ initialSelectedIndex={initialSelectedIndex}
49
+ backgroundColor={'#cbc8c2'}
50
+ fontColor={'#f5f6fa'}
51
+ optionBorderRadius={30}
52
+ />
53
+ </StyledSwitch>
54
+ );
55
+ };
56
+
57
+ const StyledSwitch = styled.div`
58
+ width: 25%;
59
+ height: 40px;
60
+ .react-switch-selector-wrapper {
61
+ background: #777777;
62
+ }
63
+ `;
64
+
65
+ export default ForceDebriefSelector;