@bjsdistribution/dms-client-return 0.0.91 → 0.0.92

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.91",
2
+ "version": "0.0.92",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -88,11 +88,13 @@
88
88
  "@emotion/react": "^11.11.3",
89
89
  "@emotion/styled": "^11.11.0",
90
90
  "@mui/material": "^5.15.10",
91
+ "@reduxjs/toolkit": "^2.5.0",
91
92
  "@tanstack/react-table": "^8.11.8",
92
93
  "antd": "^5.18.3",
93
94
  "dayjs": "^1.11.11",
94
95
  "jotai": "^2.6.3",
95
96
  "react-custom-scrollbars-2": "^4.5.0",
97
+ "react-redux": "^9.2.0",
96
98
  "react-switch-selector": "^2.2.1"
97
99
  }
98
100
  }
@@ -1,8 +1,14 @@
1
1
  import { Checkbox, useApiHook } from '@bjsdistribution/dms-component-library';
2
- import { Empty, notification } from 'antd';
2
+ import { Empty, notification, Skeleton } from 'antd';
3
+ import { format } from 'date-fns';
3
4
  import { useAtom } from 'jotai';
4
5
  import React, { useEffect, useMemo, useRef, useState } from 'react';
5
- import { Skeleton } from 'antd';
6
+ import DownIcon from '../../../../assets/icons/DownIcon';
7
+ import PrinterIcon from '../../../../assets/icons/PrinterIcon';
8
+ import CaretDownFilledIcon from '../../../../common/CaretDownFilledIcon';
9
+ import SortIcon from '../../../../common/SortIcon';
10
+ import PrintDropDownReturn from '../../../order-view/details-filters/left-side-filters/dropdowns/PrintDropDownReturn';
11
+ import { usefetchAgain, useReturnData } from '../../../order-view/store';
6
12
  import {
7
13
  useGroupedPayload,
8
14
  useLocationData,
@@ -11,32 +17,24 @@ import {
11
17
  useSelectAll,
12
18
  useSelectedOrders,
13
19
  } from '../../../store';
14
- import { usefetchAgain, useReturnData } from '../../../order-view/store';
15
- import { EmptyDataContainer } from '../../table/table-data/styles';
16
- import { CustomDrop, StyledTable, StyledTableWrapper } from './returnstyles';
17
- import PrinterIcon from '../../../../assets/icons/PrinterIcon';
18
- import DownIcon from '../../../../assets/icons/DownIcon';
20
+ import { ApiResponse } from '../../../types';
21
+ import { filtersReducerAtom } from '../../header-filters/filterStore';
22
+ import { displayValueOrNA } from '../../shared/utlis';
19
23
  import {
20
24
  useLoading,
21
25
  UsePaginationData,
22
26
  usePrintOptionTOggle,
23
27
  } from '../../store/store';
24
- import { ApiResponse } from '../../../types';
25
- import { filtersReducerAtom } from '../../header-filters/filterStore';
26
- import { displayValueOrNA } from '../../shared/utlis';
27
- import PrintDropDownReturn from '../../../order-view/details-filters/left-side-filters/dropdowns/PrintDropDownReturn';
28
- import { format } from 'date-fns';
29
- import CaretDownFilledIcon from '../../../../common/CaretDownFilledIcon';
30
- import SortIcon from '../../../../common/SortIcon';
28
+ import { EmptyDataContainer } from '../../table/table-data/styles';
29
+ import { CustomDrop, StyledTable, StyledTableWrapper } from './returnstyles';
30
+
31
31
  const ReturnOrderTable = () => {
32
32
  const [state] = useAtom(filtersReducerAtom);
33
-
34
33
  const [selectedReturnOrder, setSelectedReturnOrder] = useSelectedOrders();
35
34
  const [selectAll, setSelectAll] = useSelectAll();
36
35
  const { 'x-filters': filters, 'x-pagination': pagination } = state;
37
36
  const [returnData, setReturnData] = useReturnData();
38
37
  const [load, setLoading] = useLoading();
39
- // const [postLoading] = usePostLoading();
40
38
  const dropdownRefParent = useRef<HTMLDivElement>(null);
41
39
  const dropdownRef = useRef<HTMLDivElement>(null);
42
40
  const [printToogle, setPrintToggle] = usePrintOptionTOggle();
@@ -171,40 +169,32 @@ const ReturnOrderTable = () => {
171
169
  }, [fetchedOrderData, returnDataLoad, locationData, state, callForFetch]);
172
170
 
173
171
  const handleSelectAll = (e: any) => {
174
- setSelectAll(e.target.checked);
175
-
176
- if (e.target.checked) {
177
- setSelectedReturnOrder(
178
- returnData
179
- ?.filter(
180
- (loc: any) => loc?.order_product_return_action?.type === 'RTS'
181
- )
182
- .map((loc: any) => ({
183
- id: loc.id,
184
- return_locations: loc?.return_locations,
185
- return_location: loc?.return_location,
186
- products: loc?.legacy_product_id,
187
- order_product_return_action: loc?.order_product_return_action,
188
- return_location_token: loc?.return_location,
189
- // new_location: loc?.new_location,
190
- }))
191
- );
172
+ const isChecked = e.target.checked;
173
+ setSelectAll(isChecked);
192
174
 
193
- setNewPayload(
194
- returnData
195
- ?.filter(
196
- (loc: any) => loc?.order_product_return_action?.type === 'RTS'
197
- )
198
- .map((loc: any) => ({
199
- id: loc.id,
200
- account_number: createReturn?.account_number,
201
- customer_id: +createReturn?.customer_id,
202
- products: [loc?.legacy_product_id],
203
- return_action: loc?.order_product_return_action?.type,
204
- return_location_token: loc?.return_location || null,
205
- // new_location: loc?.new_location,
206
- }))
175
+ if (isChecked) {
176
+ const filteredData = returnData?.filter(
177
+ (loc: any) => loc?.order_product_return_action?.type === 'RTS'
207
178
  );
179
+ const selectedOrders = filteredData.map((loc: any) => ({
180
+ id: loc.id,
181
+ return_locations: loc?.return_locations,
182
+ return_location: loc?.return_location,
183
+ products: loc?.legacy_product_id,
184
+ order_product_return_action: loc?.order_product_return_action,
185
+ return_location_token: loc?.return_location,
186
+ }));
187
+ const newPayload = filteredData.map((loc: any) => ({
188
+ id: loc.id,
189
+ account_number: createReturn?.account_number,
190
+ customer_id: +createReturn?.customer_id,
191
+ products: [loc?.legacy_product_id],
192
+ return_action: loc?.order_product_return_action?.type,
193
+ return_location_token: loc?.return_location || null,
194
+ }));
195
+
196
+ setSelectedReturnOrder(selectedOrders);
197
+ setNewPayload(newPayload);
208
198
  } else {
209
199
  setSelectedReturnOrder([]);
210
200
  setNewPayload([]);
@@ -217,7 +207,6 @@ const ReturnOrderTable = () => {
217
207
  return_location: any,
218
208
  return_locations: any,
219
209
  order_product_return_action: any,
220
- // new_location: any,
221
210
  legacy_product_id: any
222
211
  ) => {
223
212
  setSelectedReturnOrder((prevSelectedLocations: any) => {
@@ -242,6 +231,7 @@ const ReturnOrderTable = () => {
242
231
  prevPayload.filter((item: any) => item.id !== id)
243
232
  );
244
233
 
234
+ setSelectAll(false); // Ensure "select all" is false if one is deselected
245
235
  return updatedSelectedLocations;
246
236
  } else {
247
237
  const newReturnPayload = {
@@ -249,32 +239,28 @@ const ReturnOrderTable = () => {
249
239
  account_number: createReturn?.account_number,
250
240
  customer_id: +createReturn?.customer_id,
251
241
  products: [legacy_product_id],
252
- return_action: order_product_return_action?.type
253
- ? [order_product_return_action.type]
254
- : null,
242
+ return_action: order_product_return_action?.type || null,
255
243
  return_location_token: return_location || null,
256
244
  };
257
245
 
258
246
  setNewPayload((prevPayload: any) => [...prevPayload, newReturnPayload]);
259
247
 
260
- setReturnPayload(prevState => ({
261
- ...prevState,
262
- products: legacy_product_id,
263
- return_action: order_product_return_action?.type || null,
264
- return_location_token: return_location || null,
265
- // new_location: new_location,
266
- }));
267
-
268
- return [
248
+ const updatedSelectedLocations = [
269
249
  ...prevSelectedLocations,
270
250
  {
271
251
  id,
272
252
  return_location,
273
253
  return_locations,
274
254
  order_product_return_action,
275
- // new_location,
276
255
  },
277
256
  ];
257
+ setSelectAll(
258
+ updatedSelectedLocations?.length ===
259
+ returnData?.filter(
260
+ (loc: any) => loc?.order_product_return_action?.type === 'RTS'
261
+ )?.length
262
+ );
263
+ return updatedSelectedLocations;
278
264
  }
279
265
  });
280
266
  };
@@ -397,33 +383,26 @@ const ReturnOrderTable = () => {
397
383
  sortedData?.map((item: any, index: any) => (
398
384
  <tr key={item.id}>
399
385
  <td>
400
- {item?.order_product_return_action?.type == 'RTS' ? (
401
- <>
402
- <Checkbox
403
- className="custom-check"
404
- checked={selectedReturnOrder?.some(
405
- (selectedInvoice: any) =>
406
- selectedInvoice?.id === item.id
407
- )}
408
- onChange={() =>
409
- handleSelectOrderReturn(
410
- item.id,
411
- item.return_location,
412
- item.return_locations,
413
- item.order_product_return_action,
414
- // item.new_location,
415
- item.legacy_product_id
416
- )
417
- }
418
- />
419
- </>
386
+ {item?.order_product_return_action?.type === 'RTS' ? (
387
+ <Checkbox
388
+ className="custom-check"
389
+ checked={selectedReturnOrder.some(
390
+ (selectedInvoice: any) =>
391
+ selectedInvoice?.id === item?.id
392
+ )}
393
+ onChange={() =>
394
+ handleSelectOrderReturn(
395
+ item?.id,
396
+ item?.return_location,
397
+ item?.return_locations,
398
+ item?.order_product_return_action,
399
+ item?.legacy_product_id
400
+ )
401
+ }
402
+ />
420
403
  ) : null}
421
404
  </td>
422
405
 
423
- {/* <>
424
- <Checkbox disabled onChange={() => {}} checked={false} />
425
- </> */}
426
-
427
406
  <td>
428
407
  {item?.orders_products_stock?.location !== null &&
429
408
  item?.orders_products_stock?.location !== undefined ? (