@bjsdistribution/dms-client-return 0.0.18 → 0.0.20

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 (80) hide show
  1. package/dist/assets/icons/DustbinIcon.d.ts +3 -0
  2. package/dist/common/date-picker/header/ClearDate.d.ts +1 -1
  3. package/dist/components/order-daily-overview/header-filters/overViewFilter.d.ts +16 -0
  4. package/dist/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.d.ts +1 -1
  5. package/dist/components/order-daily-overview/store/store.d.ts +2 -0
  6. package/dist/components/order-daily-overview/table-view/ReturnPagination.d.ts +3 -0
  7. package/dist/components/order-daily-overview/table-view/TableStyle.d.ts +4 -4
  8. package/dist/components/order-view/fakedata.d.ts +1 -1
  9. package/dist/components/order-view/order-actions/Dropdown.d.ts +6 -2
  10. package/dist/components/order-view/order-actions/actions/confirm-order/customer-info/ContactWith.d.ts +3 -0
  11. package/dist/components/order-view/order-actions/actions/confirm-order/tables/NotesTable.d.ts +1 -1
  12. package/dist/components/order-view/order-actions/actions/confirm-order/tables/ProductTable.d.ts +1 -1
  13. package/dist/components/order-view/order-actions/actions/confirm-order/tables/ReminderStyles.d.ts +9 -0
  14. package/dist/components/order-view/order-actions/store.d.ts +34 -1
  15. package/dist/components/order-view/order-actions/types.d.ts +5 -0
  16. package/dist/components/order-view/store.d.ts +1 -0
  17. package/dist/components/order-view/types.d.ts +5 -2
  18. package/dist/dms-client-return.cjs.development.js +2395 -1670
  19. package/dist/dms-client-return.cjs.development.js.map +1 -1
  20. package/dist/dms-client-return.cjs.production.min.js +1 -1
  21. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  22. package/dist/dms-client-return.esm.js +2398 -1673
  23. package/dist/dms-client-return.esm.js.map +1 -1
  24. package/package.json +2 -2
  25. package/src/assets/icons/DustbinIcon.tsx +20 -0
  26. package/src/common/modals/order-action-modal/OrderActionModal.tsx +4 -2
  27. package/src/components/order-daily-overview/header-filters/filterStore.ts +19 -18
  28. package/src/components/order-daily-overview/header-filters/overViewFilter.ts +80 -0
  29. package/src/components/order-daily-overview/index.tsx +27 -33
  30. package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +47 -5
  31. package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +9 -5
  32. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +1 -1
  33. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +2 -2
  34. package/src/components/order-daily-overview/return-order-table/ReturnTable.tsx +25 -1
  35. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +29 -11
  36. package/src/components/order-daily-overview/store/store.ts +11 -1
  37. package/src/components/order-daily-overview/table-view/Pagination.tsx +2 -1
  38. package/src/components/order-daily-overview/table-view/ReturnPagination.tsx +136 -0
  39. package/src/components/order-view/details-filters/left-side-filters/dropdowns/OptionsDropDown.tsx +26 -12
  40. package/src/components/order-view/details-filters/right-side-filters/Details.tsx +8 -1
  41. package/src/components/order-view/fakedata.ts +5 -9
  42. package/src/components/order-view/general-information/dropdowns/BjsMenu.tsx +15 -4
  43. package/src/components/order-view/general-information/dropdowns/Print.tsx +79 -39
  44. package/src/components/order-view/general-information/dropdowns/index.tsx +0 -13
  45. package/src/components/order-view/general-information/index.tsx +3 -19
  46. package/src/components/order-view/generic-table/AuditLogs.tsx +7 -5
  47. package/src/components/order-view/index.tsx +1 -2
  48. package/src/components/order-view/modalsPopup/ModalManager.tsx +69 -196
  49. package/src/components/order-view/notes/AddNote.tsx +4 -14
  50. package/src/components/order-view/notes/index.tsx +8 -13
  51. package/src/components/order-view/order-actions/Dropdown.tsx +8 -3
  52. package/src/components/order-view/order-actions/actions/cancel-order/index.tsx +146 -12
  53. package/src/components/order-view/order-actions/actions/charge-log/index.tsx +126 -79
  54. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ActionDropdown.tsx +21 -9
  55. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactMobile.tsx +64 -1
  56. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactPhone.tsx +67 -1
  57. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactTypeDropdown.tsx +19 -7
  58. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactWith.tsx +28 -0
  59. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactWork.tsx +65 -1
  60. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/DeliveryDate.tsx +40 -3
  61. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/EmailAddress.tsx +47 -2
  62. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/TimedServiceDropdown.tsx +38 -9
  63. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/index.tsx +4 -1
  64. package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +196 -6
  65. package/src/components/order-view/order-actions/actions/confirm-order/slot-and-instructions/index.tsx +5 -1
  66. package/src/components/order-view/order-actions/actions/confirm-order/tables/NotesTable.tsx +121 -20
  67. package/src/components/order-view/order-actions/actions/confirm-order/tables/ProductTable.tsx +54 -32
  68. package/src/components/order-view/order-actions/actions/confirm-order/tables/ReminderStyles.tsx +289 -0
  69. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.tsx +41 -8
  70. package/src/components/order-view/order-actions/actions/create-task-reminder/index.tsx +11 -83
  71. package/src/components/order-view/order-actions/actions/hold-order/HoldOrderModal.tsx +61 -14
  72. package/src/components/order-view/order-actions/actions/release-order/ReleaseOrder.tsx +93 -25
  73. package/src/components/order-view/order-actions/actions/split-order/SplitOrderTable.tsx +102 -247
  74. package/src/components/order-view/order-actions/actions/split-order/index.tsx +57 -9
  75. package/src/components/order-view/order-actions/index.tsx +7 -2
  76. package/src/components/order-view/order-actions/store.ts +45 -0
  77. package/src/components/order-view/order-actions/types.ts +5 -0
  78. package/src/components/order-view/order-details/expanded-content/footer/index.tsx +15 -12
  79. package/src/components/order-view/store.ts +7 -0
  80. package/src/components/order-view/types.ts +5 -2
@@ -7,6 +7,8 @@ import {
7
7
  selectedTabKeyAtom,
8
8
  useCreateOrderProducts,
9
9
  useDeleteProdsID,
10
+ usefetchAgain,
11
+ // usefetchAgain,
10
12
  useOrderId,
11
13
  useProductDetails,
12
14
  useRecieveOrderProducts,
@@ -23,13 +25,14 @@ import { ApiResponse } from '../types';
23
25
  import CreateReturnModal from './CreateReturnModal';
24
26
  import {
25
27
  useFinalPayload,
26
- useGroupedPayload,
28
+ // useGroupedPayload,
27
29
  useNewReturnPayload,
28
30
  usePostLoading,
29
31
  useSelectAll,
30
32
  useSelectedConfirmLoc,
31
33
  useSelectedOrders,
32
34
  } from '../../store';
35
+ import { notification } from 'antd';
33
36
 
34
37
  const ModalManager = () => {
35
38
  const [popupName, dispatch] = useAtom(countReducerAtom);
@@ -42,14 +45,14 @@ const ModalManager = () => {
42
45
  const [selectedProductId] = useAtom(letselectedProductIdAtom);
43
46
  const [selectedTab] = useAtom(selectedTabKeyAtom);
44
47
  const [, setIsFormValid] = useState(false);
45
- const [newGrouped, setNewGrouped] = useFinalPayload();
48
+ const [newGrouped] = useFinalPayload();
46
49
  const [, SetPostLoading] = usePostLoading();
47
50
  const [, setSelectedReturnOrder] = useSelectedOrders();
48
- const [, setCheck] = useSelectedConfirmLoc();
51
+ const [forDisabledCheck, setCheck] = useSelectedConfirmLoc();
49
52
  const [, setNewPayload] = useNewReturnPayload();
50
- const [, setGrouped] = useGroupedPayload();
53
+ // const [, setGrouped] = useGroupedPayload();
51
54
  const [, setSelectAll] = useSelectAll();
52
- // const [forCheck, setStateCheck] = useState(false);
55
+ const [, setCallForFetch] = usefetchAgain();
53
56
 
54
57
  console.log(orderProduct, 'abcabcabcabcabcabcabcabcabcabcabc');
55
58
 
@@ -66,113 +69,6 @@ const ModalManager = () => {
66
69
  setIsFormValid(validateForm());
67
70
  }, [selectedRows]);
68
71
 
69
- // const payloads: DeleteProds[] = selectedRows?.map(row => ({
70
- // id: row.id,
71
- // order_id: row.order_id,
72
- // }));
73
-
74
- // const { data: isresponse, setShouldPerformAction: setaction } = useApiHook<{
75
- // data: ApiResponse[];
76
- // }>({
77
- // endpoint: `order/order_products/delete/`,
78
- // method: 'DELETE',
79
- // body: payloads,
80
- // performAction: false,
81
- // });
82
-
83
- // Effect to handle API response
84
- // useEffect(() => {
85
- // if (isresponse && isresponse?.data) {
86
- // handleRemoveRow();
87
- // dispatch({ type: 'close' });
88
- // }
89
- // }, [isresponse]);
90
- // const onDeleteProducts = () => {
91
- // if (isFormValid) {
92
- // setaction(true);
93
- // } else {
94
- // console.log('Please fill in all required fields before proceeding.');
95
- // }
96
- // };
97
-
98
- // const handleRemoveRow = () => {
99
- // if (selectedRows.length > 0) {
100
- // setProductData((prevProductData: any) =>
101
- // prevProductData.filter(
102
- // (item: any) => !selectedRows.some(row => row.id === item.id)
103
- // )
104
- // );
105
- // setSelectedRows([]);
106
- // }
107
- // };
108
-
109
- // API block for creating product order
110
- // const {
111
- // data: response,
112
- // setShouldPerformAction: setOrderAction,
113
- // } = useApiHook<{
114
- // data: ApiResponse[];
115
- // }>({
116
- // endpoint: `order/order_products/create/`,
117
- // method: 'POST',
118
- // body: [orderProduct],
119
- // performAction: false,
120
- // });
121
-
122
- // const validateAddForm = () => {
123
- // if (!Array.isArray(orderProduct)) return false;
124
-
125
- // return orderProduct.every(
126
- // (product: any) =>
127
- // product.code !== '' &&
128
- // product.description !== '' &&
129
- // product.weight !== 0 &&
130
- // product.cube !== 0 &&
131
- // product.order_product_type_id !== 0 &&
132
- // product.sku !== ''
133
- // );
134
- // };
135
-
136
- // useEffect(() => {
137
- // setAddIsFormValid(validateAddForm());
138
- // }, [orderProduct]);
139
-
140
- // const onAddOrderProduct = () => {
141
- // if (isAddFormValid) {
142
- // setOrderProduct((prev: any) =>
143
- // prev.map((product: any) => ({
144
- // ...product,
145
- // order_id: orderId,
146
- // }))
147
- // );
148
- // setOrderAction(true);
149
- // } else {
150
- // console.log('Please fill in all required fields before proceeding.');
151
- // }
152
- // };
153
-
154
- // useEffect(() => {
155
- // if (response && response?.data) {
156
- // dispatch({ type: 'close' });
157
- // }
158
- // }, [response]);
159
-
160
- // const [isAddFormValid, setAddIsFormValid] = useState(false);
161
-
162
- // const AddMore = () => {
163
- // setOrderProduct((prevProducts: any) => [
164
- // ...prevProducts,
165
- // {
166
- // code: '',
167
- // description: '',
168
- // sku: '',
169
- // weight: '',
170
- // cube: '',
171
- // order_product_type_id: '',
172
- // },
173
- // ]);
174
- // };
175
-
176
72
  // api block for the create product order
177
73
  const {
178
74
  data: actionResponse,
@@ -205,15 +101,6 @@ const ModalManager = () => {
205
101
  performAction: false,
206
102
  });
207
103
 
208
- // const onUnrecieveProductOrder = () => {
209
- // setUnRecieve((prev: any) => ({
210
- // ...prev,
211
- // order_id: orderId,
212
- // id: selectedProductId,
213
- // }));
214
- // setUnrecieveaction(true);
215
- // };
216
-
217
104
  const onSubmit = () => {
218
105
  if (selectedTab === '1') {
219
106
  setUpdateOrderProduct((prev: any) => ({
@@ -242,12 +129,13 @@ const ModalManager = () => {
242
129
  }
243
130
  }, [updateResponse]);
244
131
 
245
- //Confirm return popup
246
132
  // Confirm return popup
247
133
  const {
248
134
  data: response,
249
135
  setShouldPerformAction,
250
136
  loading: confirmLoading,
137
+ error: apiError,
138
+ setError,
251
139
  } = useApiHook<{
252
140
  data: ApiResponse[];
253
141
  }>({
@@ -256,36 +144,78 @@ const ModalManager = () => {
256
144
  body: newGrouped,
257
145
  performAction: false,
258
146
  });
259
-
260
- useEffect(() => {
261
- SetPostLoading(confirmLoading);
262
- }, [confirmLoading]);
263
-
264
- console.log(response, 'response');
265
- console.log(newGrouped, 'newGrouped');
147
+ console.log(response, 'data'),
148
+ useEffect(() => {
149
+ SetPostLoading(confirmLoading);
150
+ }, [confirmLoading]);
266
151
 
267
152
  const handleConfirmReturn = () => {
268
- setShouldPerformAction(false);
269
-
270
- if (newGrouped?.length > 0) {
153
+ // setStateCheck(!forCheck);
154
+ if (newGrouped.length > 0) {
271
155
  setShouldPerformAction(true);
272
- } else {
273
- setShouldPerformAction(false);
156
+ setCallForFetch(true);
274
157
  }
275
-
276
158
  dispatch({ type: 'close' });
277
159
  };
278
160
 
161
+ // useEffect(() => {
162
+ // console.log(error, 'error');
163
+ // //@ts-ignore
164
+ // if (!confirmLoading) {
165
+ // // if (error && error.errorStatus !== 200) {
166
+ // // console.log(error, 'errorINsodeofIFFFFFF');
167
+ // // notification.error({
168
+ // // message: error.errorStatus || 'Error',
169
+ // // description: error.errorMessage || 'Something went wrong',
170
+ // // });
171
+ // // setError(null);
172
+ // // }
173
+
174
+ // //@ts-ignore
175
+ // if (error === null && response && response?.code === 200) {
176
+ // notification.success({
177
+ // message: 'Success',
178
+ // // @ts-ignore
179
+ // description: `${response?.message}`,
180
+ // });
181
+ // dispatch({ type: 'close' });
182
+ // setSelectedReturnOrder([]);
183
+ // setCheck([]);
184
+ // setNewPayload([]);
185
+ // setSelectAll(false);
186
+ // }
187
+ // }
188
+ // }, [confirmLoading]); //forCheck
189
+
279
190
  useEffect(() => {
280
- if (response && !response) {
191
+ // @ts-ignore
192
+ if (apiError && apiError?.code !== 200) {
193
+ dispatch({ type: 'close' });
194
+ // setSelectedReturnOrder([]);
195
+ // setCheck([]);
196
+ // setNewPayload([]);
197
+ // setShouldPerformAction(false);
198
+ // setSelectAll(false);
199
+ notification.error({
200
+ message: 'Failure',
201
+ // @ts-ignore
202
+ description: `Failed`,
203
+ });
204
+ setError(null);
205
+ // @ts-ignore
206
+ } else if (response?.code === 200) {
207
+ notification.success({
208
+ message: 'Success',
209
+ // @ts-ignore
210
+ description: `${response?.message}`,
211
+ });
281
212
  dispatch({ type: 'close' });
282
- setNewGrouped([]);
283
213
  setSelectedReturnOrder([]);
284
214
  setCheck([]);
285
215
  setNewPayload([]);
286
- setGrouped([]);
287
216
  setShouldPerformAction(false);
288
217
  setSelectAll(false);
218
+ setError(null);
289
219
  }
290
220
  }, [response]);
291
221
 
@@ -306,7 +236,7 @@ const ModalManager = () => {
306
236
  btnStyle: 'rounded',
307
237
  onClick: handleConfirmReturn,
308
238
  type: 'button',
309
- // disabled: forDisabledCheck.length === 0,
239
+ disabled: forDisabledCheck.length === 0,
310
240
  },
311
241
  ],
312
242
 
@@ -317,63 +247,6 @@ const ModalManager = () => {
317
247
  classNameAdd={'globalPopup'}
318
248
  />
319
249
  )}
320
-
321
- {/* {popupName?.state === 'deleteProduct' && (
322
- <AntModal
323
- openStatus={popupName?.state === 'deleteProduct'}
324
- closeModal={closeModal}
325
- PopupHeader={{
326
- heading: 'Delete Product(s) From Order',
327
- subHeading: 'TOM LEWIS, CW11 4ZP',
328
- }}
329
- PopupFooter={{
330
- btns: [
331
- {
332
- name: 'CONFIRM DELETE',
333
- type: 'button',
334
- btnStyle: 'rounded',
335
- onClick: onDeleteProducts,
336
- disabled: !isFormValid,
337
- },
338
- ],
339
- btnAlign: 'justifyEnd',
340
- }}
341
- BodyComponent={DeleteProduct}
342
- width={1104}
343
- classNameAdd={'globalPopup'}
344
- />
345
- )} */}
346
-
347
- {/* {popupName?.state === 'addProduct' && (
348
- <AntModal
349
- openStatus={popupName?.state === 'addProduct'}
350
- closeModal={closeModal}
351
- PopupHeader={{
352
- heading: 'Add Product(s) to Order',
353
- subHeading: 'Full Stock Control',
354
- }}
355
- PopupFooter={{
356
- btns: [
357
- {
358
- name: 'Add More Product',
359
- btnStyle: 'normalLink',
360
- icon: 'addIcon',
361
- onClick: AddMore,
362
- },
363
- {
364
- name: 'Save Details',
365
- btnStyle: 'rounded',
366
- onClick: onAddOrderProduct,
367
- disabled: !isAddFormValid,
368
- },
369
- ],
370
- btnAlign: 'justifySpaceBetween',
371
- }}
372
- BodyComponent={AddProduct}
373
- width={1104}
374
- classNameAdd={'globalPopup'}
375
- />
376
- )} */}
377
250
  {popupName?.state === 'qclog' && (
378
251
  <AntModal
379
252
  openStatus={popupName?.state === 'qclog'}
@@ -9,16 +9,10 @@ import styled from 'styled-components';
9
9
  import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
10
10
  import { getCookie } from '../utils';
11
11
  import { useLocation } from 'react-router-dom';
12
- import {
13
- useCallAPi,
14
- usemoduleIds,
15
- UseNotesLoading,
16
- useOrderId,
17
- } from '../store';
12
+ import { usemoduleIds, UseNotesLoading, useOrderId } from '../store';
18
13
  import { notification } from 'antd';
19
14
 
20
15
  function AddNote() {
21
- const [, setNoteLoadingStore] = UseNotesLoading();
22
16
  const [noteText, setNoteText] = useState('');
23
17
  const [orderId] = useOrderId();
24
18
 
@@ -26,10 +20,11 @@ function AddNote() {
26
20
  const pathname = location.pathname;
27
21
  const orderIdLocaation = pathname.split('/')[1];
28
22
 
29
- const [, CallAPi] = useCallAPi();
30
23
  const ssoToken = getCookie('id_token');
31
24
  const [moduleIds] = usemoduleIds();
32
25
 
26
+ const [NoteLoadingStore, setNoteLoadingStore] = UseNotesLoading();
27
+
33
28
  // Save New Note
34
29
 
35
30
  const [notificationData, setNotificationData] = useState<{
@@ -39,9 +34,6 @@ function AddNote() {
39
34
  } | null>(null);
40
35
 
41
36
  const saveNote = async () => {
42
- setNoteLoadingStore(true);
43
- CallAPi(false);
44
-
45
37
  if (!noteText) return;
46
38
  const endpoint = `${getBaseEndpoint()}/audit_logs/orders/`;
47
39
  const payload = {
@@ -78,10 +70,8 @@ function AddNote() {
78
70
  message: 'Success',
79
71
  description: message || 'Successfully Created Note.',
80
72
  });
81
- setNoteLoadingStore(true);
73
+ setNoteLoadingStore(!NoteLoadingStore);
82
74
  setNoteText('');
83
- // setNoteLoadingStore(false);
84
- CallAPi(true);
85
75
  } else if (error) {
86
76
  // Error: Set error notification
87
77
  setNotificationData({
@@ -5,7 +5,7 @@ import AuditLogs from './logs';
5
5
  import { useApiHook } from '@bjsdistribution/dms-component-library';
6
6
  import {
7
7
  SeteauditLogToggle,
8
- useCallAPi,
8
+ // useCallAPi,
9
9
  usegetNotes,
10
10
  usemoduleIds,
11
11
  UseNotesLoading,
@@ -18,9 +18,9 @@ function Notes() {
18
18
  const location = useLocation();
19
19
  const pathname = location.pathname;
20
20
  const orderIdLocaation = pathname.split('/')[1];
21
- const [, setNoteLoadingStore] = UseNotesLoading();
21
+ const [apiBaseLoading] = UseNotesLoading();
22
22
  const [, setNotes] = usegetNotes();
23
- const [loderStatus] = useCallAPi();
23
+ // const [loderStatus] = useCallAPi();
24
24
  const [auditState] = SeteauditLogToggle();
25
25
 
26
26
  // Fetch module IDs
@@ -64,10 +64,10 @@ function Notes() {
64
64
  });
65
65
 
66
66
  useEffect(() => {
67
- setNoteLoadingStore(true);
67
+ let combinedArray = [];
68
68
 
69
69
  if (moduleIds) {
70
- setShouldPerformAction(auditState);
70
+ setShouldPerformAction(true);
71
71
  }
72
72
  if (!NotesLoading && NotesData?.data) {
73
73
  const updatedData = NotesData?.data
@@ -75,19 +75,14 @@ function Notes() {
75
75
  .map((item: any) => [item['ORDER-NOTE'], item['ORDER']])
76
76
  .flat()
77
77
  .filter(Boolean);
78
- const combinedArray = updatedData.flat();
78
+ combinedArray = updatedData.flat();
79
79
  combinedArray.sort(
80
80
  (a: any, b: any) =>
81
81
  new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
82
82
  );
83
- setNotes(combinedArray);
84
- setNotes(combinedArray);
85
- setNoteLoadingStore(NotesLoading);
86
- loderStatus
87
- ? setShouldPerformAction(true)
88
- : setShouldPerformAction(false);
89
83
  }
90
- }, [moduleIds, NotesLoading, auditState]);
84
+ setNotes({ data: combinedArray, loading: NotesLoading });
85
+ }, [moduleIds, NotesLoading, auditState, apiBaseLoading]);
91
86
 
92
87
  return (
93
88
  <Container>
@@ -9,9 +9,13 @@ interface ActionsDropdownProps {
9
9
  label: string;
10
10
  placeholder: string;
11
11
  options: StandardOptionsType[];
12
- onSelect: () => void;
13
- onSearch: () => void;
12
+ onSelect: (value: string) => void;
13
+ onSearch?: () => void;
14
14
  className?: string;
15
+ value?: string;
16
+ disabled?: boolean;
17
+ defaultValue?: any;
18
+ onChange?: any;
15
19
  }
16
20
 
17
21
  function OrderActionsDropdown(props: ActionsDropdownProps) {
@@ -22,12 +26,13 @@ function OrderActionsDropdown(props: ActionsDropdownProps) {
22
26
  options={props.options}
23
27
  placeholder={props.placeholder}
24
28
  onChange={props.onSelect}
25
- disabled={false}
29
+ disabled={props.disabled}
26
30
  style={{ width: '100%' }}
27
31
  onSearch={props.onSearch}
28
32
  showSearch={true}
29
33
  popupClassName={'dropDownStyle'}
30
34
  selectWrapperClass={'rounded'}
35
+ defaultValue={props.value}
31
36
  />
32
37
  </Container>
33
38
  );
@@ -1,48 +1,182 @@
1
1
  import styled from 'styled-components';
2
- import React from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import OrderActionModal from '../../../../../common/modals/order-action-modal/OrderActionModal';
4
- import CancelationNote from './CancelationNote';
5
- import CancelationReason from './CancelationReason';
6
4
  import ReturnAction from './ReturnAction';
7
5
  import ReturnReason from './ReturnReason';
8
- import CancelOrderTable from './CancelOrderTable';
9
- import { useCurrentAction } from '../../../store';
6
+ // import CancelOrderTable from './CancelOrderTable';
7
+ import {
8
+ useCurrentAction,
9
+ useCustomerInfo,
10
+ useOrderDetails,
11
+ useOrderId,
12
+ useOrderStaticData,
13
+ usePrevOrderDetails,
14
+ } from '../../../store';
15
+ import OrderActionsDropdown from '../../Dropdown';
16
+ import { TextArea, useApiHook } from '@bjsdistribution/dms-component-library';
17
+ import { ApiResponse, OrdersType } from '../../../types';
18
+ import { useLoading } from '../../../../order-daily-overview/store/store';
19
+ import { notification } from 'antd';
10
20
 
11
21
  function CancelOrder() {
22
+ const [orderId] = useOrderId();
23
+ const [, setOrderDetails] = useOrderDetails();
24
+ const [, setPrevOrderDetails] = usePrevOrderDetails();
25
+ const [, setLoading] = useLoading();
12
26
  const [, setCurrentAction] = useCurrentAction();
27
+ const [customerInfo] = useCustomerInfo();
28
+ const infoText = `${customerInfo?.recipient_name}, ${customerInfo?.postcode}`;
29
+
30
+ const [orderStaticData] = useOrderStaticData();
31
+
32
+ const [cancelReason, setCancelReason] = useState<string | undefined>(
33
+ undefined
34
+ );
35
+
36
+ const [cancelNotes, setCancelNotes] = useState<string>('');
37
+
38
+ const cancelReasonOptions = orderStaticData?.cancellation_reasons?.map(
39
+ (item: any) => {
40
+ return {
41
+ label: item?.reason,
42
+ value: item?.reason,
43
+ };
44
+ }
45
+ );
46
+
47
+ const {
48
+ data: response,
49
+ setShouldPerformAction: setPerformAction,
50
+ } = useApiHook<{
51
+ data: ApiResponse[];
52
+ }>({
53
+ endpoint: `orders/${orderId}/cancel/?cancelled_reason=${cancelReason}&cancelled_notes=${cancelNotes}`,
54
+ method: 'POST',
55
+ performAction: false,
56
+ });
57
+
58
+ const { data: fetchedData, loading, setShouldPerformAction } = useApiHook<{
59
+ data: OrdersType[];
60
+ }>({
61
+ endpoint: `orders/${orderId}`,
62
+ method: 'GET',
63
+ performAction: false,
64
+ });
65
+
66
+ useEffect(() => {
67
+ setLoading(loading);
68
+ if (fetchedData && fetchedData.data) {
69
+ const requiredData = fetchedData?.data;
70
+ setOrderDetails(requiredData[0]);
71
+ setPrevOrderDetails(requiredData[0]);
72
+ setCurrentAction(undefined);
73
+ }
74
+ if (
75
+ (fetchedData && fetchedData?.data === null) ||
76
+ fetchedData?.data?.length === 0
77
+ ) {
78
+ setCurrentAction(undefined);
79
+ }
80
+ }, [loading]);
81
+
82
+ useEffect(() => {
83
+ if (response) {
84
+ //@ts-ignore
85
+ if (response?.data && response?.code === 200) {
86
+ setShouldPerformAction(true);
87
+ } else {
88
+ // alert(response?.error_traceback);
89
+ notification.error({
90
+ message: 'Error',
91
+ description:
92
+ //@ts-ignore
93
+ response?.error_traceback ||
94
+ 'An error has occurred. Please try again later.',
95
+ });
96
+ setCurrentAction(undefined);
97
+ }
98
+ }
99
+ }, [response]);
13
100
 
14
101
  const onClose = () => {
15
102
  setCurrentAction(undefined);
16
103
  };
104
+
105
+ const onSelectCancelReason = (value: string) => {
106
+ setCancelReason(value);
107
+ };
108
+
109
+ const onChangeNotes = (event: any) => {
110
+ setCancelNotes(event.target.value);
111
+ };
112
+
113
+ const onSubmitCancel = () => {
114
+ if (orderId) {
115
+ setPerformAction(true);
116
+ }
117
+ };
118
+
119
+ const showSubmitBtn = cancelReason !== undefined && cancelNotes?.length > 0;
120
+
17
121
  return (
18
122
  <OrderActionModal
19
123
  headerTitle="Cancel Order"
20
124
  showAdditionalInfo
21
- infoText="Gemma Harris, LE12 6AW"
125
+ infoText={infoText}
22
126
  onCloseHeader={onClose}
23
- onSubmit={() => {}}
127
+ onSubmit={onSubmitCancel}
128
+ submitBtnTitle="Save Details"
129
+ isSubmitDisabled={!showSubmitBtn}
24
130
  >
25
131
  <ContentContainer>
26
132
  <Top>
27
133
  <TopLeft>
28
- <CancelationReason />
134
+ <OrderActionsDropdown
135
+ label="Cancelation Reason"
136
+ placeholder="Select Cancelation Reason"
137
+ options={cancelReasonOptions || []}
138
+ onSelect={onSelectCancelReason}
139
+ value={cancelReason}
140
+ />
29
141
  <Wrapper>
30
142
  <ReturnAction />
31
143
  <ReturnReason />
32
144
  </Wrapper>
33
145
  </TopLeft>
34
146
  <TopRight>
35
- <CancelationNote />
147
+ <Container>
148
+ <Label>Cancelation Note</Label>
149
+ <TextArea
150
+ rows={5}
151
+ onChange={onChangeNotes}
152
+ value={cancelNotes}
153
+ placeholder="Reason for Cancel Order"
154
+ />
155
+ </Container>
36
156
  </TopRight>
37
157
  </Top>
38
- <Bottom>
158
+ {/* <Bottom>
39
159
  <CancelOrderTable />
40
- </Bottom>
160
+ </Bottom> */}
41
161
  </ContentContainer>
42
162
  </OrderActionModal>
43
163
  );
44
164
  }
45
165
 
166
+ const Label = styled.label`
167
+ color: #6a7378;
168
+ font-family: 'Lato', sans-serif;
169
+ font-size: 14px;
170
+ font-style: normal;
171
+ font-weight: 500;
172
+ `;
173
+
174
+ const Container = styled.div`
175
+ display: flex;
176
+ flex-direction: column;
177
+ gap: 6px;
178
+ `;
179
+
46
180
  const Wrapper = styled.div`
47
181
  display: flex;
48
182
  gap: 15px;
@@ -69,7 +203,7 @@ const Top = styled.div`
69
203
  width: 100%;
70
204
  `;
71
205
 
72
- const Bottom = styled.div``;
206
+ // const Bottom = styled.div``;
73
207
 
74
208
  const ContentContainer = styled.div`
75
209
  display: flex;