@bjsdistribution/dms-client-return 0.0.9 → 0.0.11

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 (48) hide show
  1. package/dist/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.d.ts +16 -0
  2. package/dist/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.d.ts +1 -0
  3. package/dist/components/store.d.ts +12 -2
  4. package/dist/components/types.d.ts +7 -0
  5. package/dist/dms-client-return.cjs.development.js +657 -478
  6. package/dist/dms-client-return.cjs.development.js.map +1 -1
  7. package/dist/dms-client-return.cjs.production.min.js +1 -1
  8. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  9. package/dist/dms-client-return.esm.js +663 -484
  10. package/dist/dms-client-return.esm.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/common/custom-switch/index.tsx +12 -4
  13. package/src/components/order-daily-overview/filters/FilterStyle.tsx +2 -13
  14. package/src/components/order-daily-overview/filters/Filters.tsx +7 -1
  15. package/src/components/order-daily-overview/header-filters/HeaderFilter.tsx +1 -1
  16. package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +46 -1
  17. package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +6 -5
  18. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +130 -0
  19. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +152 -69
  20. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnFilter.tsx +3 -2
  21. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +131 -23
  22. package/src/components/order-daily-overview/return-order-table/return-orders-filters/returnstyles.ts +15 -1
  23. package/src/components/order-daily-overview/shared/utlis.ts +7 -1
  24. package/src/components/order-daily-overview/table/ReturnTable.tsx +12 -0
  25. package/src/components/order-view/hooks/useGetEventNotes.tsx +15 -2
  26. package/src/components/order-view/hooks/useGetSystemLogs.tsx +14 -2
  27. package/src/components/order-view/hooks/useUpdateOrder.ts +13 -2
  28. package/src/components/order-view/modalsPopup/CreateReturnModal.tsx +14 -17
  29. package/src/components/order-view/modalsPopup/ModalManager.tsx +90 -62
  30. package/src/components/order-view/notes/AddNote.tsx +7 -2
  31. package/src/components/order-view/order-actions/actions/change-customer-account/ChangeCustomerAccModal.tsx +6 -2
  32. package/src/components/order-view/order-actions/actions/escalation/Dropdowns.tsx +5 -0
  33. package/src/components/order-view/order-actions/actions/escalation/upgrade/index.tsx +7 -1
  34. package/src/components/order-view/order-actions/hooks/useAllReminderData.ts +13 -2
  35. package/src/components/order-view/order-actions/hooks/useAllTaskData.ts +15 -5
  36. package/src/components/order-view/order-actions/hooks/useCreateReminder.ts +20 -4
  37. package/src/components/order-view/order-actions/hooks/useCreateTask.ts +14 -3
  38. package/src/components/order-view/order-actions/hooks/useFetchSingleFlagData.ts +15 -3
  39. package/src/components/order-view/order-actions/hooks/useFetchSingleReminder.ts +13 -2
  40. package/src/components/order-view/order-actions/hooks/useUpdateFlag.ts +12 -2
  41. package/src/components/order-view/order-actions/hooks/useUpdateReminder.ts +12 -2
  42. package/src/components/order-view/products-info/expanded-content/index.tsx +6 -1
  43. package/src/components/order-view/return-client-products/product-table-footer/ProductDetailsFooter.tsx +6 -1
  44. package/src/components/order-view/system-event-logs/expanded-content/index.tsx +7 -1
  45. package/src/components/order-view/view-reminder/AssigneeDropdown.tsx +6 -1
  46. package/src/components/store.ts +30 -1
  47. package/src/components/types.ts +8 -0
  48. package/src/index.tsx +8 -4
@@ -1,13 +1,14 @@
1
- import {
2
- Checkbox,
3
- displayValueOrNA,
4
- useApiHook,
5
- } from '@bjsdistribution/dms-component-library';
1
+ import { Checkbox, useApiHook } from '@bjsdistribution/dms-component-library';
6
2
  import { Empty } from 'antd';
7
3
  import { useAtom } from 'jotai';
8
4
  import React, { useEffect, useRef, useState } from 'react';
9
5
  import { Skeleton } from 'antd';
10
- import { useSelectedOrders } from '../../../store';
6
+ import {
7
+ useGroupedPayload,
8
+ useNewReturnPayload,
9
+ useReturnPayload,
10
+ useSelectedOrders,
11
+ } from '../../../store';
11
12
  import { useReturnData } from '../../../order-view/store';
12
13
  import { EmptyDataContainer } from '../../table/table-data/styles';
13
14
  import { CustomDrop, StyledTable, StyledTableWrapper } from './returnstyles';
@@ -17,7 +18,7 @@ import { useLoading, usePrintOptionTOggle } from '../../store/store';
17
18
  import { ApiResponse } from '../../../types';
18
19
  import { filtersReducerAtom } from '../../header-filters/filterStore';
19
20
  import PrintDropDown from '../../../order-view/details-filters/left-side-filters/dropdowns/PrintDropDown';
20
-
21
+ import { displayValueOrNA } from '../../shared/utlis';
21
22
  const ReturnOrderTable = ({ loadingskeleton }: any) => {
22
23
  const [state] = useAtom(filtersReducerAtom);
23
24
 
@@ -29,6 +30,9 @@ const ReturnOrderTable = ({ loadingskeleton }: any) => {
29
30
  const dropdownRefParent = useRef<HTMLDivElement>(null);
30
31
  const dropdownRef = useRef<HTMLDivElement>(null);
31
32
  const [printToogle, setPrintToggle] = usePrintOptionTOggle();
33
+ const [createReturn, setReturnPayload] = useReturnPayload();
34
+ const [newpayload, setNewPayload] = useNewReturnPayload();
35
+ const [, setGrouped] = useGroupedPayload();
32
36
 
33
37
  const OpenDropDown = (index: number) => {
34
38
  setPrintToggle(prevIndex => (prevIndex === index ? null : index));
@@ -70,9 +74,23 @@ const ReturnOrderTable = ({ loadingskeleton }: any) => {
70
74
  setSelectAll(e.target.checked);
71
75
  if (e.target.checked) {
72
76
  setSelectedReturnOrder(
73
- returnData.map((invoice: any) => ({
74
- id: invoice.id,
75
- status_id: 3,
77
+ returnData?.map((loc: any) => ({
78
+ id: loc.id,
79
+ return_locations: loc?.return_locations,
80
+ return_location: loc?.return_location,
81
+ products: loc.id,
82
+ order_product_return_action: loc?.order_product_return_action,
83
+ return_location_token: loc?.return_locations?.token,
84
+ }))
85
+ );
86
+ setNewPayload(
87
+ returnData?.map((loc: any) => ({
88
+ id: loc.id,
89
+ account_number: createReturn?.account_number,
90
+ customer_id: createReturn?.customer_id,
91
+ products: loc.id,
92
+ return_action: loc?.order_product_return_action?.type || null,
93
+ return_location_token: loc?.return_locations?.token,
76
94
  }))
77
95
  );
78
96
  } else {
@@ -80,37 +98,118 @@ const ReturnOrderTable = ({ loadingskeleton }: any) => {
80
98
  }
81
99
  };
82
100
 
83
- const handleSelectInvoice = (id: any) => {
84
- setSelectedReturnOrder((prevSelectedInvoices: any) => {
85
- const isSelected = prevSelectedInvoices?.some(
86
- (invoice: any) => invoice.id === id
101
+ const handleSelectOrderReturn = (
102
+ id: any,
103
+ return_location: any,
104
+ return_locations: any,
105
+ order_product_return_action: any
106
+ ) => {
107
+ setSelectedReturnOrder((prevSelectedLocations: any) => {
108
+ const isSelected = prevSelectedLocations?.some(
109
+ (loc: any) => loc.id === id
87
110
  );
88
111
 
89
112
  if (isSelected) {
90
- return prevSelectedInvoices.filter((invoice: any) => invoice.id !== id);
113
+ const updatedSelectedLocations = prevSelectedLocations.filter(
114
+ (loc: any) => loc.id !== id
115
+ );
116
+
117
+ setReturnPayload(prevState => ({
118
+ ...prevState,
119
+ products: id,
120
+ return_action: order_product_return_action?.type || null,
121
+ return_location_token: return_locations?.token || null,
122
+ }));
123
+
124
+ setNewPayload((prevPayload: any) =>
125
+ prevPayload.filter((item: any) => item.id !== id)
126
+ );
127
+
128
+ return updatedSelectedLocations;
91
129
  } else {
92
- return [...prevSelectedInvoices, { id, status_id: 3 }];
130
+ const newReturnPayload = {
131
+ id,
132
+ account_number: createReturn?.account_number,
133
+ customer_id: createReturn?.customer_id,
134
+ products: id,
135
+ return_action: order_product_return_action?.type || null,
136
+ return_location_token: return_locations?.token || null,
137
+ };
138
+
139
+ setNewPayload((prevPayload: any) => [...prevPayload, newReturnPayload]);
140
+
141
+ setReturnPayload(prevState => ({
142
+ ...prevState,
143
+ products: id,
144
+ return_action: order_product_return_action?.type || null,
145
+ return_location_token: return_locations?.token || null,
146
+ }));
147
+
148
+ return [
149
+ ...prevSelectedLocations,
150
+ {
151
+ id,
152
+ return_location,
153
+ return_locations,
154
+ order_product_return_action,
155
+ },
156
+ ];
93
157
  }
94
158
  });
95
159
  };
160
+
161
+ useEffect(() => {
162
+ if (newpayload?.length === 0) return;
163
+
164
+ const groupedPayload = newpayload?.reduce((acc: any, item: any) => {
165
+ const { return_location_token } = item;
166
+
167
+ if (!return_location_token) {
168
+ acc.push(item);
169
+ } else {
170
+ if (!acc[return_location_token]) {
171
+ acc[return_location_token] = {
172
+ ...item,
173
+ products: [],
174
+ return_action: [],
175
+ };
176
+ }
177
+
178
+ acc[return_location_token].products = [
179
+ ...acc[return_location_token].products,
180
+ ...item.products,
181
+ ];
182
+
183
+ acc[return_location_token].return_action = [
184
+ ...acc[return_location_token].return_action,
185
+ ...item.return_action,
186
+ ];
187
+ }
188
+
189
+ return acc;
190
+ }, []);
191
+
192
+ const mergedPayload = Object.values(groupedPayload);
193
+ setGrouped(mergedPayload);
194
+ }, [newpayload]);
195
+
96
196
  return (
97
197
  <>
98
- <StyledTableWrapper id="tableScrolling">
198
+ <StyledTableWrapper>
99
199
  <StyledTable>
100
200
  <thead>
101
201
  <tr>
102
202
  <th className="emailInvoiceCheckbox">
103
203
  <Checkbox checked={selectAll} onChange={handleSelectAll} />
104
204
  </th>
105
- {/* <th className="emailInvoiceNo">Invoice No.</th> */}
106
205
  <th>Product Location</th>
107
206
  <th>Return Location</th>
108
207
  <th>Recipient</th>
109
208
  <th>Code</th>
110
- <th> Description</th>
209
+ <th>Description</th>
111
210
  <th>Part</th>
112
211
  <th>Weight</th>
113
- <th> CBM</th>
212
+ <th>CBM</th>
114
213
  <th>Return Reason</th>
115
214
  <th>Collected</th>
116
215
  <th>Collection Reason</th>
@@ -142,12 +241,21 @@ const ReturnOrderTable = ({ loadingskeleton }: any) => {
142
241
  (selectedInvoice: any) =>
143
242
  selectedInvoice?.id === item.id
144
243
  )}
145
- onChange={() => handleSelectInvoice(item.id)}
244
+ onChange={() =>
245
+ handleSelectOrderReturn(
246
+ item.id,
247
+ item.return_location,
248
+ item.return_locations,
249
+ item.order_product_return_action
250
+ )
251
+ }
146
252
  />
147
253
  </td>
148
254
 
149
255
  <td>
150
- {displayValueOrNA(item?.orders_products_stock?.location)}
256
+ {item?.orders_products_stock?.location ? null : (
257
+ <div className="awaiting">Awating</div>
258
+ )}
151
259
  </td>
152
260
 
153
261
  <td> {displayValueOrNA(item?.return_location)}</td>
@@ -174,7 +282,7 @@ const ReturnOrderTable = ({ loadingskeleton }: any) => {
174
282
  </td>
175
283
  <td>{displayValueOrNA(item?.code)}</td>
176
284
  <td>{displayValueOrNA(item?.description)}</td>
177
- <td>N/A</td>
285
+ <td>{displayValueOrNA(item?.parts_count)}</td>
178
286
  <td>{displayValueOrNA(item?.weight)}KG</td>
179
287
  <td>{displayValueOrNA(item?.cube)}</td>
180
288
  <td>{displayValueOrNA(item?.return_reasons?.reason)}</td>
@@ -386,6 +386,20 @@ export const StyledTable = styled.table`
386
386
  border-radius: 22px;
387
387
  background: rgba(41, 204, 106, 0.15);
388
388
  }
389
+ .awaiting {
390
+ display: flex;
391
+ min-width: 85px;
392
+ padding: 6px 10px;
393
+ justify-content: center;
394
+ align-items: center;
395
+ gap: 5px;
396
+ border-radius: 22px;
397
+ background: rgba(233, 82, 82, 0.15);
398
+ color: #e95252;
399
+ font-family: 'Open Sans';
400
+ font-size: 12px;
401
+ font-weight: 600;
402
+ }
389
403
  ul > li > a {
390
404
  text-decoration: none !important;
391
405
  color: #0099ff;
@@ -498,7 +512,7 @@ export const StyledTableWrapper = styled.div`
498
512
  overflow-x: auto;
499
513
  max-height: calc(100vh - 396px);
500
514
  scrollbar-width: none;
501
- height: 400px;
515
+ height: 600px;
502
516
  /* box-shadow: 0px 0px 30px 6px rgba(46, 45, 116, 0.05); */
503
517
  &::-webkit-scrollbar {
504
518
  width: 5px;
@@ -74,5 +74,11 @@ export const formatDate = (date: any) => {
74
74
 
75
75
  export const displayValueOrNA = (value: any) => {
76
76
  const isBlankArray = Array.isArray(value) && value.length === 0;
77
- return value && !isBlankArray ? value : '--';
77
+ if (value === 0) {
78
+ return 0;
79
+ }
80
+ if (value === 'NA' || value === undefined || value === null || isBlankArray) {
81
+ return 'NA';
82
+ }
83
+ return value;
78
84
  };
@@ -49,6 +49,8 @@ const ReturnTable: React.FC = ({ loadingskeleton }: any) => {
49
49
  <th>Client</th>
50
50
  <th>Orders</th>
51
51
  <th>Products</th>
52
+ <th>RTS</th>
53
+ <th>Pending</th>
52
54
  <th>Dispose</th>
53
55
  <th>Re-allocate</th>
54
56
  <th>Re-Del</th>
@@ -105,6 +107,16 @@ const ReturnTable: React.FC = ({ loadingskeleton }: any) => {
105
107
  <GreyBox>{key?.return_order_products}</GreyBox>
106
108
  </ColumStyle>
107
109
  </td>
110
+ <td>
111
+ <ColumStyle>
112
+ <GreyBox>{key?.RTS}</GreyBox>
113
+ </ColumStyle>
114
+ </td>
115
+ <td>
116
+ <ColumStyle>
117
+ <GreyBox>{key?.PENDING}</GreyBox>
118
+ </ColumStyle>
119
+ </td>
108
120
  <td>
109
121
  <ColumStyle>
110
122
  <GreyBox>{key?.DISPOSE}</GreyBox>
@@ -1,5 +1,6 @@
1
1
  import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
2
2
  import { getCookie } from '../utils';
3
+ import { notification } from 'antd';
3
4
  // import { useOrderDetails, useOrderProductSystemLogs } from '../store';
4
5
 
5
6
  function useGetEventNotes() {
@@ -25,7 +26,13 @@ function useGetEventNotes() {
25
26
  const json = await response.json();
26
27
  const detail = json?.detail;
27
28
  const msg = detail[0]?.msg;
28
- console.error('Error response:', msg);
29
+ // console.error('Error response:', msg);
30
+
31
+ notification.error({
32
+ message: 'Error',
33
+ description:
34
+ `${msg}` || 'An error has occurred. Please try again later.',
35
+ });
29
36
  // setLoading(false);
30
37
  return [];
31
38
  }
@@ -35,7 +42,13 @@ function useGetEventNotes() {
35
42
  }
36
43
  return [];
37
44
  } catch (err) {
38
- console.error('Error fetching data:', err);
45
+ // console.error('Error fetching data:', err);
46
+ notification.error({
47
+ message: 'Error',
48
+ description:
49
+ `${err}` || 'An error has occurred. Please try again later.',
50
+ });
51
+
39
52
  return [];
40
53
  } finally {
41
54
  // setLoading(false);
@@ -1,6 +1,7 @@
1
1
  import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
2
2
  import { getCookie } from '../utils';
3
3
  import { useOrderDetails, useOrderProductSystemLogs } from '../store';
4
+ import { notification } from 'antd';
4
5
 
5
6
  function useSystemLogs() {
6
7
  const ssoToken = getCookie('id_token');
@@ -36,7 +37,13 @@ function useSystemLogs() {
36
37
  const json = await response.json();
37
38
  const detail = json?.detail;
38
39
  const msg = detail[0]?.msg;
39
- console.error('Error response:', msg);
40
+ // console.error('Error response:', msg);
41
+
42
+ notification.error({
43
+ message: 'Error',
44
+ description:
45
+ `${msg}` || 'An error has occurred. Please try again later.',
46
+ });
40
47
  // setLoading(false);
41
48
  return [];
42
49
  }
@@ -48,7 +55,12 @@ function useSystemLogs() {
48
55
  }
49
56
  return [];
50
57
  } catch (err) {
51
- console.error('Error fetching data:', err);
58
+ // console.error('Error fetching data:', err);
59
+ notification.error({
60
+ message: 'Error',
61
+ description:
62
+ `${err}` || 'An error has occurred. Please try again later.',
63
+ });
52
64
  return [];
53
65
  } finally {
54
66
  // setLoading(false);
@@ -1,5 +1,6 @@
1
1
  import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
2
2
  import { getCookie } from '../utils';
3
+ import { notification } from 'antd';
3
4
 
4
5
  function useUpdateOrder() {
5
6
  let controller: AbortController;
@@ -32,11 +33,21 @@ function useUpdateOrder() {
32
33
  throw new Error('response is not ok');
33
34
  }
34
35
  const json = await response.json();
35
- alert('Order has been updated');
36
+ // alert('Order has been updated');
37
+ notification.success({
38
+ message: 'Success',
39
+ description: 'Order has been updated.',
40
+ });
36
41
  return json;
37
42
  } catch (err) {
38
43
  // setLoading(false);
39
- console.log(err, 'error');
44
+ // console.log(err, 'error');
45
+
46
+ notification.error({
47
+ message: 'Error',
48
+ description:
49
+ `${err}` || 'An error has occurred. Please try again later.',
50
+ });
40
51
  } finally {
41
52
  // setLoading(false); // Set loading to false after fetching
42
53
  }
@@ -1,27 +1,24 @@
1
1
  import { Alert, Checkbox } from '@bjsdistribution/dms-component-library';
2
2
  import React, { useState } from 'react';
3
3
  import styled from 'styled-components';
4
- import { useLocationData } from '../../store';
4
+ import { useSelectedOrders } from '../../store';
5
5
 
6
6
  const CreateReturnModal = () => {
7
- const [, setSelectedLocations] = useState<any[]>();
8
- const [locationData] = useLocationData();
7
+ const [selectedlocation, setSelectedLocations] = useState<any[]>([]);
8
+ const [selectedReturnOrder] = useSelectedOrders();
9
9
 
10
- const handleSelectLocations = (id: any) => {
11
- setSelectedLocations((prevSelectedLocations: any) => {
12
- const isSelected = prevSelectedLocations?.some(
13
- (location: any) => location.id === id
14
- );
10
+ const handleSelectLocations = (id: number) => {
11
+ setSelectedLocations((prevSelectedLocations: number[]) => {
12
+ const isSelected = prevSelectedLocations.includes(id);
15
13
 
16
14
  if (isSelected) {
17
- return prevSelectedLocations.filter(
18
- (invoice: any) => invoice.id !== id
19
- );
15
+ return prevSelectedLocations.filter(selectedId => selectedId !== id);
20
16
  } else {
21
- return [...prevSelectedLocations, { id, status_id: 3 }];
17
+ return [...prevSelectedLocations, id];
22
18
  }
23
19
  });
24
20
  };
21
+
25
22
  return (
26
23
  <Wrapper>
27
24
  <Alert
@@ -33,9 +30,9 @@ const CreateReturnModal = () => {
33
30
  />
34
31
  <Container>
35
32
  <ul style={{ listStyle: 'none', padding: 0 }}>
36
- {locationData?.map((invoice: any) => (
33
+ {selectedReturnOrder?.map((returnLoc: any) => (
37
34
  <li
38
- key={invoice.id}
35
+ key={returnLoc.id}
39
36
  style={{
40
37
  marginBottom: '8px',
41
38
  display: 'flex',
@@ -43,11 +40,11 @@ const CreateReturnModal = () => {
43
40
  }}
44
41
  >
45
42
  <Checkbox
46
- checked={true}
47
- onChange={() => handleSelectLocations(invoice.id)}
43
+ checked={selectedlocation.includes(returnLoc.id)}
44
+ onChange={() => handleSelectLocations(returnLoc.id)}
48
45
  />
49
46
  <StyledText style={{ marginLeft: '8px' }}>
50
- {invoice.location_name}
47
+ {returnLoc?.return_location}
51
48
  </StyledText>
52
49
  </li>
53
50
  ))}
@@ -15,16 +15,17 @@ import {
15
15
 
16
16
  import ProductAction from './ProductAction';
17
17
  // import DeleteProduct from './DeleteProduct';
18
- import AddProduct from './AddProduct';
18
+ // import AddProduct from './AddProduct';
19
19
  import logsTable from './qclogs/logsTable';
20
20
  import DefectsModal from './DefectsModal';
21
21
  import repackModal from './RepackModal';
22
22
  import { ApiResponse } from '../types';
23
23
  import CreateReturnModal from './CreateReturnModal';
24
+ import { useNewReturnPayload } from '../../store';
24
25
  const ModalManager = () => {
25
26
  const [popupName, dispatch] = useAtom(countReducerAtom);
26
27
  const [,] = useProductDetails();
27
- const [orderProduct, setOrderProduct] = useCreateOrderProducts();
28
+ const [orderProduct] = useCreateOrderProducts();
28
29
  const [orderId] = useOrderId();
29
30
  const [selectedRows] = useDeleteProdsID();
30
31
  const [unRecieve, setUnRecieve] = useRecieveOrderProducts();
@@ -32,6 +33,7 @@ const ModalManager = () => {
32
33
  const [selectedProductId] = useAtom(selectedProductIdAtom);
33
34
  const [selectedTab] = useAtom(selectedTabKeyAtom);
34
35
  const [, setIsFormValid] = useState(false);
36
+ const [newPayload, setNewPayload] = useNewReturnPayload();
35
37
 
36
38
  console.log(orderProduct, 'abcabcabcabcabcabcabcabcabcabcabc');
37
39
 
@@ -89,71 +91,71 @@ const ModalManager = () => {
89
91
  // };
90
92
 
91
93
  // API block for creating product order
92
- const {
93
- data: response,
94
- setShouldPerformAction: setOrderAction,
95
- } = useApiHook<{
96
- data: ApiResponse[];
97
- }>({
98
- endpoint: `order/order_products/create/`,
99
- method: 'POST',
100
- body: [orderProduct],
101
- performAction: false,
102
- });
94
+ // const {
95
+ // data: response,
96
+ // setShouldPerformAction: setOrderAction,
97
+ // } = useApiHook<{
98
+ // data: ApiResponse[];
99
+ // }>({
100
+ // endpoint: `order/order_products/create/`,
101
+ // method: 'POST',
102
+ // body: [orderProduct],
103
+ // performAction: false,
104
+ // });
103
105
 
104
- const validateAddForm = () => {
105
- if (!Array.isArray(orderProduct)) return false;
106
+ // const validateAddForm = () => {
107
+ // if (!Array.isArray(orderProduct)) return false;
106
108
 
107
- return orderProduct.every(
108
- (product: any) =>
109
- product.code !== '' &&
110
- product.description !== '' &&
111
- product.weight !== 0 &&
112
- product.cube !== 0 &&
113
- product.order_product_type_id !== 0 &&
114
- product.sku !== ''
115
- );
116
- };
109
+ // return orderProduct.every(
110
+ // (product: any) =>
111
+ // product.code !== '' &&
112
+ // product.description !== '' &&
113
+ // product.weight !== 0 &&
114
+ // product.cube !== 0 &&
115
+ // product.order_product_type_id !== 0 &&
116
+ // product.sku !== ''
117
+ // );
118
+ // };
117
119
 
118
- useEffect(() => {
119
- setAddIsFormValid(validateAddForm());
120
- }, [orderProduct]);
120
+ // useEffect(() => {
121
+ // setAddIsFormValid(validateAddForm());
122
+ // }, [orderProduct]);
121
123
 
122
- const onAddOrderProduct = () => {
123
- if (isAddFormValid) {
124
- setOrderProduct((prev: any) =>
125
- prev.map((product: any) => ({
126
- ...product,
127
- order_id: orderId,
128
- }))
129
- );
130
- setOrderAction(true);
131
- } else {
132
- console.log('Please fill in all required fields before proceeding.');
133
- }
134
- };
124
+ // const onAddOrderProduct = () => {
125
+ // if (isAddFormValid) {
126
+ // setOrderProduct((prev: any) =>
127
+ // prev.map((product: any) => ({
128
+ // ...product,
129
+ // order_id: orderId,
130
+ // }))
131
+ // );
132
+ // setOrderAction(true);
133
+ // } else {
134
+ // console.log('Please fill in all required fields before proceeding.');
135
+ // }
136
+ // };
135
137
 
136
- useEffect(() => {
137
- if (response && response?.data) {
138
- dispatch({ type: 'close' });
139
- }
140
- }, [response]);
138
+ // useEffect(() => {
139
+ // if (response && response?.data) {
140
+ // dispatch({ type: 'close' });
141
+ // }
142
+ // }, [response]);
141
143
 
142
- const [isAddFormValid, setAddIsFormValid] = useState(false);
144
+ // const [isAddFormValid, setAddIsFormValid] = useState(false);
143
145
 
144
- const AddMore = () => {
145
- setOrderProduct((prevProducts: any) => [
146
- ...prevProducts,
147
- {
148
- code: '',
149
- description: '',
150
- sku: '',
151
- weight: '',
152
- cube: '',
153
- order_product_type_id: '',
154
- },
155
- ]);
156
- };
146
+ // const AddMore = () => {
147
+ // setOrderProduct((prevProducts: any) => [
148
+ // ...prevProducts,
149
+ // {
150
+ // code: '',
151
+ // description: '',
152
+ // sku: '',
153
+ // weight: '',
154
+ // cube: '',
155
+ // order_product_type_id: '',
156
+ // },
157
+ // ]);
158
+ // };
157
159
 
158
160
  // api block for the create product order
159
161
  const {
@@ -224,6 +226,30 @@ const ModalManager = () => {
224
226
  }
225
227
  }, [updateResponse]);
226
228
 
229
+ //Confirm return popup
230
+ const { data: response, setShouldPerformAction } = useApiHook<{
231
+ data: ApiResponse[];
232
+ }>({
233
+ endpoint: `return_orders/`,
234
+ method: 'POST',
235
+ body: [newPayload],
236
+ performAction: false,
237
+ });
238
+ const handleConfirmReturn = () => {
239
+ const payloadWithoutId = newPayload?.map(({ id, ...rest }: any) => ({
240
+ ...rest,
241
+ }));
242
+
243
+ console.log(response);
244
+
245
+ if (payloadWithoutId) {
246
+ setNewPayload(payloadWithoutId);
247
+ setShouldPerformAction(true);
248
+ } else {
249
+ setShouldPerformAction(false);
250
+ }
251
+ };
252
+
227
253
  return (
228
254
  <>
229
255
  {popupName?.state == 'create-return' && (
@@ -239,7 +265,9 @@ const ModalManager = () => {
239
265
  {
240
266
  name: 'Submit',
241
267
  btnStyle: 'rounded',
268
+ onClick: handleConfirmReturn,
242
269
  type: 'button',
270
+ disabled: !newPayload,
243
271
  },
244
272
  ],
245
273
 
@@ -277,7 +305,7 @@ const ModalManager = () => {
277
305
  />
278
306
  )} */}
279
307
 
280
- {popupName?.state === 'addProduct' && (
308
+ {/* {popupName?.state === 'addProduct' && (
281
309
  <AntModal
282
310
  openStatus={popupName?.state === 'addProduct'}
283
311
  closeModal={closeModal}
@@ -306,7 +334,7 @@ const ModalManager = () => {
306
334
  width={1104}
307
335
  classNameAdd={'globalPopup'}
308
336
  />
309
- )}
337
+ )} */}
310
338
  {popupName?.state === 'qclog' && (
311
339
  <AntModal
312
340
  openStatus={popupName?.state === 'qclog'}