@bjsdistribution/dms-client-return 0.0.94-prod → 0.0.95-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 (138) hide show
  1. package/dist/assets/icons/ArrowDownIcon.d.ts +6 -0
  2. package/dist/assets/icons/DeliverProductIcon.d.ts +3 -0
  3. package/dist/assets/icons/ReturnProductIcon.d.ts +3 -0
  4. package/dist/common/checkbox/index.d.ts +2 -0
  5. package/dist/common/modals/order-action-modal/OrderActionModal.d.ts +3 -1
  6. package/dist/components/order-view/details-filters/left-side-filters/dropdowns/DropDowns.d.ts +1 -0
  7. package/dist/components/order-view/details-filters/left-side-filters/dropdowns/MenuDropDown.d.ts +2 -2
  8. package/dist/components/order-view/flags-action-modal/Actions.d.ts +6 -2
  9. package/dist/components/order-view/flags-action-modal/Dropdowns.d.ts +1 -0
  10. package/dist/components/order-view/flags-action-modal/Header.d.ts +1 -1
  11. package/dist/components/order-view/notification/FlagTemplate.d.ts +1 -1
  12. package/dist/components/order-view/notification/OrderTemplate.d.ts +1 -1
  13. package/dist/components/order-view/notification/Tabs.d.ts +1 -1
  14. package/dist/components/order-view/order-actions/actions/cancel-order/CancelOrderTable.d.ts +5 -0
  15. package/dist/components/order-view/order-actions/actions/cancel-order/index.d.ts +7 -1
  16. package/dist/components/order-view/order-actions/actions/change-customer-account/ChangeCustomerAccModal.d.ts +4 -1
  17. package/dist/components/order-view/order-actions/actions/charge-log/index.d.ts +11 -0
  18. package/dist/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.d.ts +1 -13
  19. package/dist/components/order-view/order-actions/actions/create-task-reminder/TaskModal.d.ts +5 -1
  20. package/dist/components/order-view/order-actions/actions/create-task-reminder/index.d.ts +6 -2
  21. package/dist/components/order-view/order-actions/actions/hold-order/HoldOrderModal.d.ts +6 -1
  22. package/dist/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.d.ts +5 -1
  23. package/dist/components/order-view/order-actions/actions/log-service-refusal/Notes.d.ts +5 -3
  24. package/dist/components/order-view/order-actions/actions/log-service-refusal/OrderServices.d.ts +5 -1
  25. package/dist/components/order-view/order-actions/actions/log-service-refusal/index.d.ts +1 -1
  26. package/dist/components/order-view/order-actions/actions/uncancel-order/UncancelOrder.d.ts +7 -1
  27. package/dist/components/order-view/order-actions/actions/uncancel-order/UncancelOrderTable.d.ts +5 -0
  28. package/dist/components/order-view/order-actions/actions/unhold-order/UnholdOrder.d.ts +6 -1
  29. package/dist/components/order-view/order-actions/store.d.ts +10 -8
  30. package/dist/components/order-view/order-actions/types.d.ts +38 -60
  31. package/dist/components/order-view/order-actions/utils.d.ts +2 -1
  32. package/dist/components/order-view/store.d.ts +48 -3
  33. package/dist/components/order-view/types.d.ts +11 -0
  34. package/dist/components/order-view/utils.d.ts +1 -0
  35. package/dist/components/order-view/view-reminder/ViewReminder.d.ts +5 -1
  36. package/dist/components/order-view/view-reminder/reminder-styles.d.ts +3 -1
  37. package/dist/components/store.d.ts +2 -1
  38. package/dist/dms-client-return.cjs.development.js +4812 -3095
  39. package/dist/dms-client-return.cjs.development.js.map +1 -1
  40. package/dist/dms-client-return.cjs.production.min.js +1 -1
  41. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  42. package/dist/dms-client-return.esm.js +4815 -3098
  43. package/dist/dms-client-return.esm.js.map +1 -1
  44. package/package.json +2 -2
  45. package/src/assets/icons/ArrowDownIcon.tsx +28 -0
  46. package/src/assets/icons/DeliverProductIcon.tsx +42 -0
  47. package/src/assets/icons/ReturnProductIcon.tsx +23 -0
  48. package/src/common/checkbox/index.tsx +60 -17
  49. package/src/common/modals/order-action-modal/OrderActionModal.tsx +13 -7
  50. package/src/common/radio-group/RadioButtonGroup.tsx +3 -4
  51. package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +29 -26
  52. package/src/components/order-daily-overview/header-filters/filterStore.ts +6 -8
  53. package/src/components/order-daily-overview/index.tsx +20 -7
  54. package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +2 -2
  55. package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +19 -19
  56. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +11 -9
  57. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +19 -4
  58. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +41 -59
  59. package/src/components/order-daily-overview/table/ReturnTable.tsx +1 -30
  60. package/src/components/order-view/details-filters/left-side-filters/dropdowns/DropDowns.tsx +52 -2
  61. package/src/components/order-view/details-filters/left-side-filters/dropdowns/MenuDropDown.tsx +37 -43
  62. package/src/components/order-view/details-filters/left-side-filters/dropdowns/OptionsDropDown.tsx +75 -44
  63. package/src/components/order-view/fakedata.ts +7 -6
  64. package/src/components/order-view/flags-action-modal/Actions.tsx +51 -25
  65. package/src/components/order-view/flags-action-modal/DetailSection.tsx +5 -5
  66. package/src/components/order-view/flags-action-modal/Dropdowns.tsx +75 -89
  67. package/src/components/order-view/flags-action-modal/Header.tsx +32 -23
  68. package/src/components/order-view/flags-action-modal/TextSection.tsx +9 -6
  69. package/src/components/order-view/flags-action-modal/index.tsx +54 -67
  70. package/src/components/order-view/general-information/dropdowns/Print.tsx +136 -70
  71. package/src/components/order-view/generic-table/AuditLogs.tsx +5 -4
  72. package/src/components/order-view/index.tsx +9 -42
  73. package/src/components/order-view/modalsPopup/CreateReturnModal.tsx +20 -18
  74. package/src/components/order-view/modalsPopup/ModalManager.tsx +4 -10
  75. package/src/components/order-view/notes/logs/index.tsx +1 -1
  76. package/src/components/order-view/notes/order-dropdown/NewReturnDropdown.tsx +5 -7
  77. package/src/components/order-view/notification/FlagTemplate.tsx +8 -8
  78. package/src/components/order-view/notification/OrderTemplate.tsx +169 -175
  79. package/src/components/order-view/notification/ReminderTemplate.tsx +23 -14
  80. package/src/components/order-view/notification/Tabs.tsx +15 -14
  81. package/src/components/order-view/notification/index.tsx +164 -92
  82. package/src/components/order-view/order-actions/actions/add-resources/index.tsx +19 -29
  83. package/src/components/order-view/order-actions/actions/cancel-order/CancelOrderTable.tsx +345 -0
  84. package/src/components/order-view/order-actions/actions/cancel-order/index.tsx +146 -71
  85. package/src/components/order-view/order-actions/actions/change-customer-account/ChangeCustomerAccModal.tsx +95 -32
  86. package/src/components/order-view/order-actions/actions/charge-log/index.tsx +395 -0
  87. package/src/components/order-view/order-actions/actions/clear-booking-status/ClearBookingStatus.tsx +1 -1
  88. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ActionDropdown.tsx +34 -17
  89. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactMobile.tsx +2 -3
  90. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactPhone.tsx +2 -3
  91. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactWork.tsx +2 -3
  92. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/DeliveryDate.tsx +39 -25
  93. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/EmailAddress.tsx +1 -1
  94. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/TimedServiceDropdown.tsx +4 -2
  95. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/index.tsx +1 -1
  96. package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +254 -66
  97. package/src/components/order-view/order-actions/actions/confirm-order/slot-and-instructions/index.tsx +1 -1
  98. package/src/components/order-view/order-actions/actions/confirm-order/tables/NotesTable.tsx +13 -9
  99. package/src/components/order-view/order-actions/actions/confirm-order/tables/ProductTable.tsx +1 -1
  100. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.tsx +213 -117
  101. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateTaskModal.tsx +97 -152
  102. package/src/components/order-view/order-actions/actions/create-task-reminder/TaskModal.tsx +30 -87
  103. package/src/components/order-view/order-actions/actions/create-task-reminder/index.tsx +77 -83
  104. package/src/components/order-view/order-actions/actions/hold-order/HoldOrderModal.tsx +57 -65
  105. package/src/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.tsx +10 -16
  106. package/src/components/order-view/order-actions/actions/log-service-refusal/Notes.tsx +21 -4
  107. package/src/components/order-view/order-actions/actions/log-service-refusal/OrderServices.tsx +39 -11
  108. package/src/components/order-view/order-actions/actions/log-service-refusal/index.tsx +79 -8
  109. package/src/components/order-view/order-actions/actions/send-email/SendEmailModal.tsx +114 -17
  110. package/src/components/order-view/order-actions/actions/send-sms/SendSmsModal.tsx +115 -7
  111. package/src/components/order-view/order-actions/actions/split-order/index.tsx +14 -4
  112. package/src/components/order-view/order-actions/actions/uncancel-order/UncancelOrder.tsx +176 -87
  113. package/src/components/order-view/order-actions/actions/uncancel-order/UncancelOrderTable.tsx +352 -0
  114. package/src/components/order-view/order-actions/actions/unhold-order/UnholdOrder.tsx +35 -59
  115. package/src/components/order-view/order-actions/index.tsx +237 -22
  116. package/src/components/order-view/order-actions/store.ts +50 -48
  117. package/src/components/order-view/order-actions/types.ts +40 -65
  118. package/src/components/order-view/order-actions/utils.ts +15 -8
  119. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactEmail.tsx +2 -1
  120. package/src/components/order-view/order-details/expanded-content/footer/index.tsx +80 -39
  121. package/src/components/order-view/order-details/expanded-content/orders-section/Carrier.tsx +10 -14
  122. package/src/components/order-view/order-details/expanded-content/orders-section/DeliveryDate.tsx +10 -1
  123. package/src/components/order-view/order-details/expanded-content/orders-section/ScheduleAfter.tsx +2 -1
  124. package/src/components/order-view/products-info/expanded-content/index.tsx +3 -2
  125. package/src/components/order-view/products-info/index.tsx +14 -11
  126. package/src/components/order-view/return-client-products/product-table/ReturnProductTable.tsx +26 -24
  127. package/src/components/order-view/store.ts +59 -2
  128. package/src/components/order-view/system-event-logs/columns/Date.tsx +4 -2
  129. package/src/components/order-view/system-event-logs/columns/Event.tsx +9 -9
  130. package/src/components/order-view/system-event-logs/columns/Note.tsx +1 -1
  131. package/src/components/order-view/system-event-logs/expanded-content/index.tsx +25 -25
  132. package/src/components/order-view/types.ts +13 -0
  133. package/src/components/order-view/utils.ts +4 -0
  134. package/src/components/order-view/view-reminder/AssigneeDropdown.tsx +183 -12
  135. package/src/components/order-view/view-reminder/ViewReminder.tsx +234 -143
  136. package/src/components/order-view/view-reminder/reminder-styles.tsx +14 -8
  137. package/src/components/store.ts +6 -0
  138. package/src/index.tsx +28 -18
@@ -0,0 +1,345 @@
1
+ import React from 'react';
2
+ import { useCancelOrderProducts, useOrderStaticData } from '../../../store';
3
+ import { useLoading } from '../../../../order-daily-overview/store/store';
4
+ import { Empty, Select, Skeleton } from 'antd';
5
+ // import { AntSelect } from '@bjsdistribution/dms-component-library';
6
+ import { CancelOrderProductsType } from '../../../types';
7
+ import OrderActionsDropdown from '../../Dropdown';
8
+ import styled from 'styled-components';
9
+ import DeliverProductIcon from '../../../../../assets/icons/DeliverProductIcon';
10
+ import ReturnProductIcon from '../../../../../assets/icons/ReturnProductIcon';
11
+ import { EmptyDataContainer } from '../charge-log';
12
+
13
+ const deliverTypeOptions = [
14
+ {
15
+ label: 'Deliver',
16
+ value: 'deliver',
17
+ icon: <DeliverProductIcon />,
18
+ },
19
+ {
20
+ label: 'Return',
21
+ value: 'return',
22
+ icon: <ReturnProductIcon />,
23
+ },
24
+ ];
25
+
26
+ const collectTypeOptions = [
27
+ {
28
+ label: 'Return',
29
+ value: 'return',
30
+ icon: <ReturnProductIcon />,
31
+ },
32
+ ];
33
+
34
+ const CancelOrderTable = () => {
35
+ const [
36
+ cancelOrderProducts,
37
+ setCancelOrderProducts,
38
+ ] = useCancelOrderProducts();
39
+
40
+ const [loading] = useLoading();
41
+ const [orderStaticData] = useOrderStaticData();
42
+
43
+ if (!cancelOrderProducts?.length) {
44
+ return null;
45
+ }
46
+
47
+ const returnReasonsOptions = orderStaticData?.return_reasons?.map(
48
+ (option: any) => ({
49
+ label: option?.reason,
50
+ value: option?.reason,
51
+ })
52
+ );
53
+
54
+ const returnActionOptions = orderStaticData?.order_product_return_action?.map(
55
+ (option: any) => ({
56
+ label: option?.value,
57
+ value: option?.value,
58
+ })
59
+ );
60
+
61
+ const onChange = (
62
+ selectedVal: string,
63
+ id: number,
64
+ type: keyof CancelOrderProductsType
65
+ ) => {
66
+ console.log(selectedVal, id, type);
67
+ const updatedList = cancelOrderProducts?.map(
68
+ (item: CancelOrderProductsType) => {
69
+ const newItem =
70
+ item.order_product_id === id
71
+ ? {
72
+ ...item,
73
+ [type]: selectedVal,
74
+ }
75
+ : item;
76
+ return newItem;
77
+ }
78
+ );
79
+ setCancelOrderProducts(updatedList);
80
+ };
81
+
82
+ return (
83
+ <div>
84
+ <StyledTableWrapper>
85
+ <StyledTable className="scrollClass">
86
+ <thead>
87
+ <tr>
88
+ <th>Status</th>
89
+ <th>Code</th>
90
+ <th>Description</th>
91
+ <th>SKU</th>
92
+ </tr>
93
+ </thead>
94
+ <tbody>
95
+ {loading ? (
96
+ <tr>
97
+ <td colSpan={4}>
98
+ <Skeleton active />
99
+ </td>
100
+ </tr>
101
+ ) : cancelOrderProducts?.length === 0 ? (
102
+ <tr>
103
+ <td className="emptyTd" colSpan={4}>
104
+ <EmptyDataContainer>
105
+ <Empty />
106
+ </EmptyDataContainer>
107
+ </td>
108
+ </tr>
109
+ ) : (
110
+ cancelOrderProducts?.map((product: CancelOrderProductsType) => {
111
+ const dropdownOptions =
112
+ product?.product_type === 'deliver'
113
+ ? deliverTypeOptions
114
+ : collectTypeOptions;
115
+
116
+ const isReturn = product?.action === 'return';
117
+
118
+ return (
119
+ <tr
120
+ key={product?.order_product_id}
121
+ style={{
122
+ boxShadow: '0px 1px 3px 0px rgba(16, 24, 40, 0.1)',
123
+ }}
124
+ >
125
+ <td colSpan={4}>
126
+ <table style={{ width: '100%' }}>
127
+ <tbody>
128
+ <tr>
129
+ <td style={{ width: '25%' }}>
130
+ <CustomSelectDropdown
131
+ options={dropdownOptions}
132
+ placeholder="Select"
133
+ onChange={(val: any) =>
134
+ onChange(
135
+ val,
136
+ product?.order_product_id!,
137
+ 'action'
138
+ )
139
+ }
140
+ prefix={
141
+ product?.action === 'deliver' ? (
142
+ <DeliverProductIcon />
143
+ ) : product?.action === 'return' ? (
144
+ <ReturnProductIcon />
145
+ ) : (
146
+ <></>
147
+ )
148
+ }
149
+ style={{ width: '100%' }}
150
+ value={dropdownOptions?.filter(
151
+ (item: any) => item?.value === product?.action
152
+ )}
153
+ optionRender={(option: any) => (
154
+ <div
155
+ style={{
156
+ display: 'flex',
157
+ gap: '8px',
158
+ alignItems: 'center',
159
+ }}
160
+ >
161
+ <span
162
+ style={{ display: 'flex' }}
163
+ aria-label={option.data.label}
164
+ >
165
+ {option.data.icon}
166
+ </span>
167
+ <span style={{ color: '#8D8F90' }}>
168
+ {option.data.label}
169
+ </span>
170
+ </div>
171
+ )}
172
+ />
173
+ </td>
174
+ <td style={{ width: '25%' }}>{product?.code}</td>
175
+ <td style={{ width: '25%' }}>
176
+ {product?.description}
177
+ </td>
178
+ <td style={{ width: '25%' }}>{product?.sku}</td>
179
+ </tr>
180
+
181
+ {isReturn && (
182
+ <tr>
183
+ <td colSpan={4}>
184
+ <ReturnRowWrapper>
185
+ <StyledDropdown
186
+ label="Return Action"
187
+ required
188
+ placeholder="Select action"
189
+ options={returnActionOptions}
190
+ onSelect={(val: any) =>
191
+ onChange(
192
+ val,
193
+ product?.order_product_id!,
194
+ 'return_action'
195
+ )
196
+ }
197
+ value={returnActionOptions?.filter(
198
+ (option: any) =>
199
+ option.value === product?.return_action
200
+ )}
201
+ />
202
+ <StyledDropdown
203
+ label="Return Reason"
204
+ required
205
+ placeholder="Select reason"
206
+ options={returnReasonsOptions}
207
+ onSelect={(val: any) =>
208
+ onChange(
209
+ val,
210
+ product?.order_product_id!,
211
+ 'return_reason'
212
+ )
213
+ }
214
+ value={returnReasonsOptions?.filter(
215
+ (option: any) =>
216
+ option.value === product?.return_reason
217
+ )}
218
+ />
219
+ </ReturnRowWrapper>
220
+ </td>
221
+ </tr>
222
+ )}
223
+ </tbody>
224
+ </table>
225
+ </td>
226
+ </tr>
227
+ );
228
+ })
229
+ )}
230
+ </tbody>
231
+ </StyledTable>
232
+ </StyledTableWrapper>
233
+ </div>
234
+ );
235
+ };
236
+
237
+ const CustomSelectDropdown: any = styled(Select)`
238
+ .ant-select-selector {
239
+ border-radius: 25px !important;
240
+ /* border: none !important; */
241
+ min-width: 100px;
242
+ padding: 0 10px;
243
+ display: flex;
244
+ gap: 10px;
245
+ align-items: center;
246
+
247
+ .ant-select-prefix {
248
+ margin-top: 3px;
249
+ }
250
+ }
251
+ .ant-select-selection-item {
252
+ font-weight: 400;
253
+ font-size: 13px;
254
+ }
255
+ `;
256
+
257
+ export const StyledTableWrapper = styled.div`
258
+ width: 100%;
259
+ overflow-x: auto;
260
+ background-color: #fff;
261
+ border-radius: 12px;
262
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
263
+ padding: 16px;
264
+ `;
265
+
266
+ const StyledDropdown = styled(OrderActionsDropdown)`
267
+ flex: 1;
268
+ `;
269
+
270
+ export const StyledTable = styled.table`
271
+ width: 100%;
272
+ font-size: 14px;
273
+ color: #333;
274
+ border-spacing: 0 10px;
275
+
276
+ th,
277
+ td {
278
+ padding: 12px 16px;
279
+ background: #fff;
280
+ }
281
+
282
+ th {
283
+ background: #f0f2f2;
284
+
285
+ &:first-child {
286
+ border-top-left-radius: 40px;
287
+ border-bottom-left-radius: 40px;
288
+ }
289
+
290
+ &:last-child {
291
+ border-top-right-radius: 40px;
292
+ border-bottom-right-radius: 40px;
293
+ }
294
+ }
295
+
296
+ // This affects ONLY top-level rows
297
+ > tbody > tr {
298
+ background: #fff;
299
+ border-radius: 40px;
300
+ box-shadow: 0px 1px 3px rgba(16, 24, 40, 0.1);
301
+ }
302
+
303
+ // Round the outer row's corners only on first/last td
304
+ > tbody > tr > td:first-child {
305
+ border-top-left-radius: 40px;
306
+ border-bottom-left-radius: 40px;
307
+ }
308
+
309
+ > tbody > tr > td:last-child {
310
+ border-top-right-radius: 40px;
311
+ border-bottom-right-radius: 40px;
312
+ }
313
+
314
+ .scrollClass {
315
+ overflow-x: auto;
316
+ }
317
+
318
+ .emptyTd {
319
+ text-align: center;
320
+ padding: 40px 0;
321
+ color: #999;
322
+ background: transparent;
323
+ box-shadow: none;
324
+ }
325
+
326
+ td table {
327
+ border-spacing: 0;
328
+ width: 100%;
329
+ }
330
+
331
+ td table td {
332
+ background: transparent;
333
+ padding: 8px 12px;
334
+ }
335
+ `;
336
+
337
+ const ReturnRowWrapper = styled.div`
338
+ display: flex;
339
+ flex-direction: row;
340
+ gap: 12px;
341
+ padding: 0 12px;
342
+ width: 100%;
343
+ `;
344
+
345
+ export default CancelOrderTable;
@@ -4,25 +4,34 @@ import OrderActionModal from '../../../../../common/modals/order-action-modal/Or
4
4
  import ReturnAction from './ReturnAction';
5
5
  import ReturnReason from './ReturnReason';
6
6
  import {
7
+ useCancelOrderProducts,
7
8
  useCurrentAction,
8
9
  useCustomerInfo,
9
- useOrderDetails,
10
10
  useOrderId,
11
11
  useOrderStaticData,
12
- usePrevOrderDetails,
12
+ useProductDetails,
13
13
  } from '../../../store';
14
14
  import OrderActionsDropdown from '../../Dropdown';
15
- import { TextArea, useApiHook } from '@bjsdistribution/dms-component-library';
16
- import { ApiResponse, OrdersType } from '../../../types';
17
- import { useLoading } from '../../../../order-daily-overview/store/store';
15
+ import { TextArea, useAxios } from '@bjsdistribution/dms-component-library';
16
+ import { ApiResponse, CancelOrderProductsType } from '../../../types';
18
17
  import { notification } from 'antd';
18
+ import CancelOrderTable from './CancelOrderTable';
19
19
 
20
- function CancelOrder() {
20
+ interface IProps {
21
+ callOrdersApi: any;
22
+ callOrderStatusApi: any;
23
+ callOrderAlertsApi: any;
24
+ callOrderProductsApi: any;
25
+ }
26
+
27
+ function CancelOrder(props: IProps) {
21
28
  const [orderId] = useOrderId();
22
- const [, setOrderDetails] = useOrderDetails();
23
- const [, setPrevOrderDetails] = usePrevOrderDetails();
24
- const [, setLoading] = useLoading();
25
29
  const [, setCurrentAction] = useCurrentAction();
30
+ const [orderProductDetails] = useProductDetails();
31
+ const [
32
+ cancelOrderProducts,
33
+ setCancelOrderProducts,
34
+ ] = useCancelOrderProducts();
26
35
  const [customerInfo] = useCustomerInfo();
27
36
  const infoText = `${customerInfo?.recipient_name}, ${customerInfo?.postcode}`;
28
37
 
@@ -43,68 +52,40 @@ function CancelOrder() {
43
52
  }
44
53
  );
45
54
 
46
- const {
47
- data: response,
48
- setShouldPerformAction: setPerformAction,
49
- } = useApiHook<{
55
+ const { fetchData: callCancelApi } = useAxios<{
50
56
  data: ApiResponse[];
51
57
  }>({
52
- endpoint: `orders/${orderId}/cancel/?cancelled_reason=${cancelReason}&cancelled_notes=${cancelNotes}`,
58
+ endpoint: `v1/orders/cancel/?order_id=${orderId}`,
53
59
  method: 'POST',
54
- performAction: false,
55
- });
56
-
57
- const { data: fetchedData, loading, setShouldPerformAction } = useApiHook<{
58
- data: OrdersType[];
59
- }>({
60
- endpoint: `orders/${orderId}`,
61
- method: 'GET',
62
- performAction: false,
63
60
  });
64
61
 
65
62
  useEffect(() => {
66
- setLoading(loading);
67
- if (fetchedData && fetchedData.data) {
68
- const requiredData = fetchedData?.data;
69
- setOrderDetails(requiredData[0]);
70
- setPrevOrderDetails(requiredData[0]);
71
- setCurrentAction(undefined);
72
- }
73
- if (
74
- (fetchedData && fetchedData?.data === null) ||
75
- fetchedData?.data?.length === 0
76
- ) {
77
- setCurrentAction(undefined);
78
- }
79
- }, [loading]);
80
-
81
- useEffect(() => {
82
- if (response) {
83
- //@ts-ignore
84
- if (response?.data && response?.code === 200) {
85
- setShouldPerformAction(true);
86
- notification.success({
87
- message: 'Success',
88
- description:
89
- //@ts-ignore
90
- response?.message || 'Sucess',
91
- });
92
- } else {
93
- // alert(response?.error_traceback);
94
- notification.error({
95
- message: 'Error',
96
- description:
97
- //@ts-ignore
98
- response?.error_traceback ||
99
- 'An error has occurred. Please try again later.',
100
- });
101
- setCurrentAction(undefined);
102
- }
103
- }
104
- }, [response]);
63
+ const receivedProducts = orderProductDetails?.filter(
64
+ (product: any) =>
65
+ product?.status_value === 'received' &&
66
+ product?.order_product_type?.type !== 'return'
67
+ );
68
+ const modifiedReceivedProducts =
69
+ receivedProducts?.length > 0
70
+ ? receivedProducts?.map((product: any) => {
71
+ return {
72
+ order_product_id: product?.id,
73
+ action: '',
74
+ return_action: '',
75
+ return_reason: '',
76
+ code: product?.code,
77
+ description: product?.description,
78
+ sku: product?.sku,
79
+ product_type: product?.order_product_type?.type,
80
+ };
81
+ })
82
+ : [];
83
+ setCancelOrderProducts(modifiedReceivedProducts);
84
+ }, [orderProductDetails]);
105
85
 
106
86
  const onClose = () => {
107
87
  setCurrentAction(undefined);
88
+ setCancelOrderProducts([]);
108
89
  };
109
90
 
110
91
  const onSelectCancelReason = (value: string) => {
@@ -115,9 +96,94 @@ function CancelOrder() {
115
96
  setCancelNotes(event.target.value);
116
97
  };
117
98
 
118
- const onSubmitCancel = () => {
99
+ const onSubmitCancel = async () => {
100
+ const productsPayload = cancelOrderProducts?.map(
101
+ (product: CancelOrderProductsType) => {
102
+ if (product?.action === 'deliver') {
103
+ return {
104
+ order_product_id: product?.order_product_id,
105
+ action: product?.action,
106
+ };
107
+ }
108
+ return {
109
+ order_product_id: product?.order_product_id,
110
+ action: product?.action,
111
+ return_action: product?.return_action,
112
+ return_reason: product?.return_reason,
113
+ };
114
+ }
115
+ );
116
+
117
+ // VALIDATIONS START
118
+
119
+ const productsPayloadActions = productsPayload?.map(
120
+ (product: CancelOrderProductsType) => {
121
+ if (product?.action !== '') {
122
+ return true;
123
+ }
124
+ return false;
125
+ }
126
+ );
127
+
128
+ if (productsPayloadActions?.includes(false)) {
129
+ notification.error({
130
+ message: 'Error',
131
+ description: `please fill product status field`,
132
+ });
133
+ return;
134
+ }
135
+
136
+ const productsPayloadValidate = productsPayload?.map(
137
+ (product: CancelOrderProductsType) => {
138
+ if (product?.action === 'return') {
139
+ return product?.return_action !== '' && product?.return_reason !== '';
140
+ }
141
+ return true;
142
+ }
143
+ );
144
+
145
+ if (productsPayloadValidate?.includes(false)) {
146
+ notification.error({
147
+ message: 'Error',
148
+ description: `please fill all the mandatory fields`,
149
+ });
150
+ return;
151
+ }
152
+
153
+ // VALIDATIONS END
154
+
155
+ const apiPayload = {
156
+ cancelled_reason: cancelReason,
157
+ cancelled_notes: cancelNotes,
158
+ products: productsPayload,
159
+ };
160
+
119
161
  if (orderId) {
120
- setPerformAction(true);
162
+ const response = (await callCancelApi({
163
+ payload: apiPayload,
164
+ })) as {
165
+ code: number | null;
166
+ error?: string | null | undefined;
167
+ [key: string]: any;
168
+ };
169
+ if (response?.code === 200) {
170
+ notification.success({
171
+ message: 'Success',
172
+ description: `${response.message}`,
173
+ });
174
+ // call orders api to update status
175
+ await props?.callOrderProductsApi();
176
+ await props?.callOrderAlertsApi();
177
+ await props?.callOrderStatusApi();
178
+ await props?.callOrdersApi();
179
+ }
180
+ if (response?.code !== 200) {
181
+ notification.error({
182
+ message: 'Error',
183
+ description: `${response.error}`,
184
+ });
185
+ setCurrentAction(undefined);
186
+ }
121
187
  }
122
188
  };
123
189
 
@@ -138,8 +204,8 @@ function CancelOrder() {
138
204
  <TopLeft>
139
205
  <OrderActionsDropdown
140
206
  required
141
- label="Cancelation Reason"
142
- placeholder="Select Cancelation Reason"
207
+ label="Cancellation Reason"
208
+ placeholder="Select Cancellation Reason"
143
209
  options={cancelReasonOptions || []}
144
210
  onSelect={onSelectCancelReason}
145
211
  value={cancelReason}
@@ -152,7 +218,7 @@ function CancelOrder() {
152
218
  <TopRight>
153
219
  <Container>
154
220
  <div style={{ display: 'flex', flexDirection: 'row' }}>
155
- <Label>Cancelation Note</Label>{' '}
221
+ <Label>Cancellation Note</Label>{' '}
156
222
  <RequiredAsterisk>*</RequiredAsterisk>
157
223
  </div>
158
224
  <TArea
@@ -164,6 +230,9 @@ function CancelOrder() {
164
230
  </Container>
165
231
  </TopRight>
166
232
  </Top>
233
+ <Bottom>
234
+ <CancelOrderTable />
235
+ </Bottom>
167
236
  </ContentContainer>
168
237
  </OrderActionModal>
169
238
  );
@@ -213,19 +282,25 @@ const TopRight = styled.div`
213
282
  `;
214
283
 
215
284
  const Top = styled.div`
285
+ width: 100%;
286
+ border-radius: 16px;
287
+ border: 1px solid #edebe8;
288
+ background: #f8fafc;
216
289
  display: flex;
290
+ padding: 15px;
291
+ align-items: flex-start;
217
292
  gap: 30px;
218
- width: 100%;
293
+ align-self: stretch;
219
294
  `;
220
295
 
221
- // const Bottom = styled.div``;
296
+ const Bottom = styled.div``;
222
297
 
223
298
  const ContentContainer = styled.div`
224
299
  display: flex;
225
- padding: 0px 15px;
300
+ padding: 15px;
226
301
  align-items: flex-start;
227
- gap: 10px;
228
302
  flex-direction: column;
303
+ width: 100%;
229
304
  `;
230
305
 
231
306
  export default CancelOrder;