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