@bjsdistribution/dms-client-return 0.0.37 → 0.0.38

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.37",
2
+ "version": "0.0.38",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -59,7 +59,7 @@
59
59
  "testEnvironment": "jest-environment-jsdom-sixteen"
60
60
  },
61
61
  "devDependencies": {
62
- "@bjsdistribution/dms-component-library": "0.1.4",
62
+ "@bjsdistribution/dms-component-library": "0.1.10",
63
63
  "@size-limit/preset-small-lib": "^11.0.1",
64
64
  "@tippyjs/react": "^4.2.6",
65
65
  "@types/react": "^18.2.47",
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ function CaretDownFilledIcon(props: any) {
3
+ return (
4
+ <svg
5
+ width="16"
6
+ height="16"
7
+ viewBox="0 0 18 18"
8
+ fill="none"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ {...props}
11
+ >
12
+ <g clip-path="url(#clip0_2034_435)">
13
+ <path
14
+ d="M13.5 6.75C14.139 6.75 14.4727 7.4895 14.0872 7.96725L14.0302 8.03025L9.53021 12.5303C9.40107 12.6594 9.22924 12.737 9.04698 12.7484C8.86471 12.7599 8.68452 12.7044 8.54021 12.5925L8.46971 12.5303L3.96972 8.03025L3.90746 7.95975L3.86697 7.902L3.82647 7.83L3.81371 7.803L3.79347 7.75275L3.76946 7.67175L3.76196 7.632L3.75446 7.587L3.75146 7.54425V7.45575L3.75521 7.41225L3.76196 7.36725L3.76946 7.32825L3.79347 7.24725L3.81371 7.197L3.86622 7.098L3.91496 7.0305L3.96972 6.96975L4.04021 6.9075L4.09797 6.867L4.16996 6.8265L4.19697 6.81375L4.24721 6.7935L4.32821 6.7695L4.36796 6.762L4.41296 6.7545L4.45571 6.7515L13.5 6.75Z"
15
+ fill="#9E9E9E"
16
+ />
17
+ </g>
18
+ <defs>
19
+ <clipPath id="clip0_2034_435">
20
+ <rect width="16" height="16" fill="white" />
21
+ </clipPath>
22
+ </defs>
23
+ </svg>
24
+ );
25
+ }
26
+
27
+ export default CaretDownFilledIcon;
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ function CaretDownFilledIcon(props: any) {
3
+ return (
4
+ <svg
5
+ width="16"
6
+ height="16"
7
+ viewBox="0 0 18 18"
8
+ fill="none"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ {...props}
11
+ >
12
+ <g clip-path="url(#clip0_2034_435)">
13
+ <path
14
+ d="M13.5 6.75C14.139 6.75 14.4727 7.4895 14.0872 7.96725L14.0302 8.03025L9.53021 12.5303C9.40107 12.6594 9.22924 12.737 9.04698 12.7484C8.86471 12.7599 8.68452 12.7044 8.54021 12.5925L8.46971 12.5303L3.96972 8.03025L3.90746 7.95975L3.86697 7.902L3.82647 7.83L3.81371 7.803L3.79347 7.75275L3.76946 7.67175L3.76196 7.632L3.75446 7.587L3.75146 7.54425V7.45575L3.75521 7.41225L3.76196 7.36725L3.76946 7.32825L3.79347 7.24725L3.81371 7.197L3.86622 7.098L3.91496 7.0305L3.96972 6.96975L4.04021 6.9075L4.09797 6.867L4.16996 6.8265L4.19697 6.81375L4.24721 6.7935L4.32821 6.7695L4.36796 6.762L4.41296 6.7545L4.45571 6.7515L13.5 6.75Z"
15
+ fill="#9E9E9E"
16
+ />
17
+ </g>
18
+ <defs>
19
+ <clipPath id="clip0_2034_435">
20
+ <rect width="16" height="16" fill="white" />
21
+ </clipPath>
22
+ </defs>
23
+ </svg>
24
+ );
25
+ }
26
+
27
+ export default CaretDownFilledIcon;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+
3
+ const SortIcon = () => {
4
+ return (
5
+ <svg
6
+ width="16"
7
+ height="17"
8
+ viewBox="0 0 16 17"
9
+ fill="none"
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ >
12
+ <g id="bxs:sort-alt">
13
+ <path
14
+ id="Vector"
15
+ d="M4.15138 7.83335H11.8494C12.424 7.83335 12.7294 7.15335 12.3474 6.72335L8.49871 2.39335C8.43628 2.32288 8.35961 2.26647 8.27377 2.22783C8.18792 2.1892 8.09485 2.16922 8.00071 2.16922C7.90657 2.16922 7.8135 2.1892 7.72766 2.22783C7.64181 2.26647 7.56514 2.32288 7.50271 2.39335L3.65271 6.72335C3.27071 7.15335 3.57604 7.83335 4.15138 7.83335ZM7.50204 14.606C7.56447 14.6765 7.64114 14.7329 7.72699 14.7715C7.81284 14.8102 7.9059 14.8301 8.00004 14.8301C8.09418 14.8301 8.18725 14.8102 8.2731 14.7715C8.35895 14.7329 8.43562 14.6765 8.49804 14.606L12.3467 10.276C12.7294 9.84668 12.424 9.16668 11.8487 9.16668H4.15138C3.57671 9.16668 3.27138 9.84668 3.65338 10.2767L7.50204 14.606Z"
16
+ fill="#9E9E9E"
17
+ />
18
+ </g>
19
+ </svg>
20
+ );
21
+ };
22
+
23
+ export default SortIcon;
@@ -117,8 +117,8 @@ function SelectionFilter() {
117
117
 
118
118
  const mappedLocations = Array.isArray(filteredClient?.return_locations)
119
119
  ? filteredClient?.return_locations?.map((location: any) => ({
120
- label: location,
121
- value: location,
120
+ label: location?.location_name,
121
+ value: location?.token,
122
122
  }))
123
123
  : [];
124
124
 
@@ -302,7 +302,6 @@ function SelectionFilter() {
302
302
  />
303
303
  </FilterColumn>
304
304
  </>
305
- {/* ) : null} */}
306
305
  </LeftColumn>
307
306
  <RightColumn>
308
307
  <ApplyButton onClick={applyFilters} disabled={!isButtonEnabled}>
@@ -1,11 +1,9 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import {
3
- // useItemsPerOverviewPage,
4
- //useItemsPerPage,
5
- useLoading,
6
- // UsePaginationOverviewData,
3
+ useItemsPerOverviewPage,
4
+ useStatsLoading,
5
+ UsePaginationOverviewData,
7
6
  useTableName,
8
- //UsePaginationData,
9
7
  } from './store/store';
10
8
  import Filters from './filters/Filters';
11
9
  import styled from 'styled-components';
@@ -17,36 +15,34 @@ import { ClientData } from './common/interface';
17
15
  import ReturnFilter from './return-order-table/return-orders-filters/ReturnFilter';
18
16
  import { Text } from './filters/FilterStyle';
19
17
  import ReturnTable from './table/ReturnTable';
18
+ import { notification } from 'antd';
20
19
  import { overviewfiltersReducerAtom } from './header-filters/overViewFilter';
21
- // import { notification } from 'antd';
22
- // import Pagination from './table-view/Pagination';
23
- // import Pagination from './table-view/Pagination';
24
- // import { overviewfiltersReducerAtom } from './header-filters/overViewFilter';
20
+ import Pagination from './table-view/Pagination';
25
21
 
26
22
  function ReturnMainTable() {
27
23
  const [state] = useAtom(overviewfiltersReducerAtom);
28
- // const [paginationObj] = UsePaginationOverviewData();
29
- // const [, setCurrentPage] = useState(1);
30
- // const [itemsPerPage, setItemsPerPage] = useItemsPerOverviewPage();
24
+ const [paginationObj, setPaginationObject] = UsePaginationOverviewData();
25
+ const [, setCurrentPage] = useState(1);
26
+ const [itemsPerPage, setItemsPerPage] = useItemsPerOverviewPage();
31
27
  const { 'x-pagination': pagination } = state;
32
- // const { page, total } = paginationObj;
28
+ const { page, total } = paginationObj;
33
29
  // const [selectedClient] = useTableName();
34
30
  const [isScrolled] = useStickyStatus();
35
- const [, setLoading] = useLoading();
31
+ const [, setLoading] = useStatsLoading();
36
32
  const [, setClientData] = useClientData();
37
33
  const [tableName] = useTableName();
38
34
 
39
- // const handlePageChange = (page: number) => {
40
- // setCurrentPage(page);
41
- // };
42
- // const handleItemsPerPageChange = (itemsPerPage: number) => {
43
- // setItemsPerPage(itemsPerPage);
44
- // };
35
+ const handlePageChange = (page: number) => {
36
+ setCurrentPage(page);
37
+ };
38
+ const handleItemsPerPageChange = (itemsPerPage: number) => {
39
+ setItemsPerPage(itemsPerPage);
40
+ };
45
41
 
46
42
  const {
47
43
  data: fetchedClientData,
48
44
  loading: statsDataLoading,
49
- // paginationData,
45
+ paginationData,
50
46
  } = useApiHook<{
51
47
  data: ClientData[];
52
48
  }>({
@@ -61,15 +57,15 @@ function ReturnMainTable() {
61
57
  if (fetchedClientData && fetchedClientData.data) {
62
58
  const result = fetchedClientData?.data;
63
59
  setClientData(result);
64
- // if (paginationData !== null) {
65
- // const { count, ...rest } = JSON.parse(paginationData);
66
- // setPaginationObject(rest);
67
- // } else {
68
- // notification.error({
69
- // message: 'Error',
70
- // description: 'Pagination data is null',
71
- // });
72
- // }
60
+ if (paginationData !== null) {
61
+ const { count, ...rest } = JSON.parse(paginationData);
62
+ setPaginationObject(rest);
63
+ } else {
64
+ notification.error({
65
+ message: 'Error',
66
+ description: 'Pagination data is null',
67
+ });
68
+ }
73
69
  }
74
70
  }, [statsDataLoading]);
75
71
 
@@ -86,7 +82,7 @@ function ReturnMainTable() {
86
82
  </Row>
87
83
  <ReturnTable />
88
84
  </Container>
89
- {/* {total > 0 && (
85
+ {total > 0 && (
90
86
  <Pagination
91
87
  currentPage={page}
92
88
  totalItems={total}
@@ -94,7 +90,7 @@ function ReturnMainTable() {
94
90
  onPageChange={handlePageChange}
95
91
  onItemsPerPageChange={handleItemsPerPageChange}
96
92
  ></Pagination>
97
- )} */}
93
+ )}
98
94
  </div>
99
95
  </DashBoardWrapper>
100
96
  </>
@@ -1,7 +1,7 @@
1
1
  import { Checkbox, useApiHook } from '@bjsdistribution/dms-component-library';
2
2
  import { Empty, notification } from 'antd';
3
3
  import { useAtom } from 'jotai';
4
- import React, { useEffect, useRef } from 'react';
4
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { Skeleton } from 'antd';
6
6
  import {
7
7
  useGroupedPayload,
@@ -28,6 +28,8 @@ import { displayValueOrNA } from '../../shared/utlis';
28
28
  import PrintDropDownReturn from '../../../order-view/details-filters/left-side-filters/dropdowns/PrintDropDownReturn';
29
29
  import { format } from 'date-fns';
30
30
  import Loader from '../../header/loader/Loader';
31
+ import CaretDownFilledIcon from '../../../../common/CaretDownFilledIcon';
32
+ import SortIcon from '../../../../common/SortIcon';
31
33
  const ReturnOrderTable = () => {
32
34
  const [state] = useAtom(filtersReducerAtom);
33
35
 
@@ -46,6 +48,53 @@ const ReturnOrderTable = () => {
46
48
  const [locationData] = useLocationData();
47
49
  const [, setPaginationObject] = UsePaginationData();
48
50
  const [callForFetch] = usefetchAgain();
51
+
52
+ //sorting
53
+ const [sortConfig, setSortConfig] = useState<{
54
+ key: string;
55
+ direction: 'asc' | 'desc';
56
+ } | null>(null);
57
+
58
+ const handleSort = (key: string) => {
59
+ setSortConfig((prev: any) => {
60
+ if (prev?.key === key && prev.direction === 'asc') {
61
+ return { key, direction: 'desc' };
62
+ }
63
+ return { key, direction: 'asc' };
64
+ });
65
+ };
66
+
67
+ const sortedData = useMemo(() => {
68
+ if (!returnData || !sortConfig) return returnData;
69
+
70
+ const { key, direction } = sortConfig;
71
+ return [...returnData].sort((a, b) => {
72
+ const valueA = a[key];
73
+ const valueB = b[key];
74
+
75
+ if (typeof valueA === 'number' && typeof valueB === 'number') {
76
+ return direction === 'asc' ? valueA - valueB : valueB - valueA;
77
+ }
78
+ if (typeof valueA === 'string' && typeof valueB === 'string') {
79
+ return direction === 'asc'
80
+ ? valueA.localeCompare(valueB)
81
+ : valueB.localeCompare(valueA);
82
+ }
83
+ return 0;
84
+ });
85
+ }, [returnData, sortConfig]);
86
+
87
+ const renderSortIcon = (columnKey: string) => {
88
+ if (!sortConfig || sortConfig.key !== columnKey) {
89
+ return <SortIcon />;
90
+ }
91
+ return sortConfig.direction === 'asc' ? (
92
+ <CaretDownFilledIcon />
93
+ ) : (
94
+ <CaretDownFilledIcon />
95
+ );
96
+ };
97
+
49
98
  const OpenDropDown = (index: number) => {
50
99
  setPrintToggle(prevIndex => (prevIndex === index ? null : index));
51
100
  };
@@ -105,7 +154,7 @@ const ReturnOrderTable = () => {
105
154
  return {
106
155
  ...returnItem,
107
156
  new_location: matchingLocation
108
- ? matchingLocation.location_name
157
+ ? matchingLocation?.location_name
109
158
  : null,
110
159
  };
111
160
  });
@@ -131,7 +180,7 @@ const ReturnOrderTable = () => {
131
180
  products: loc?.legacy_product_id,
132
181
  order_product_return_action: loc?.order_product_return_action,
133
182
  return_location_token: loc?.return_location,
134
- new_location: loc?.new_location,
183
+ // new_location: loc?.new_location,
135
184
  }))
136
185
  );
137
186
 
@@ -147,7 +196,7 @@ const ReturnOrderTable = () => {
147
196
  products: [loc?.legacy_product_id],
148
197
  return_action: loc?.order_product_return_action?.type,
149
198
  return_location_token: loc?.return_location || null,
150
- new_location: loc?.new_location,
199
+ // new_location: loc?.new_location,
151
200
  }))
152
201
  );
153
202
  } else {
@@ -162,7 +211,7 @@ const ReturnOrderTable = () => {
162
211
  return_location: any,
163
212
  return_locations: any,
164
213
  order_product_return_action: any,
165
- new_location: any,
214
+ // new_location: any,
166
215
  legacy_product_id: any
167
216
  ) => {
168
217
  setSelectedReturnOrder((prevSelectedLocations: any) => {
@@ -180,7 +229,7 @@ const ReturnOrderTable = () => {
180
229
  products: legacy_product_id,
181
230
  return_action: order_product_return_action?.type || null,
182
231
  return_location_token: return_location || null,
183
- new_location: new_location,
232
+ // new_location: new_location,
184
233
  }));
185
234
 
186
235
  setNewPayload((prevPayload: any) =>
@@ -207,7 +256,7 @@ const ReturnOrderTable = () => {
207
256
  products: legacy_product_id,
208
257
  return_action: order_product_return_action?.type || null,
209
258
  return_location_token: return_location || null,
210
- new_location: new_location,
259
+ // new_location: new_location,
211
260
  }));
212
261
 
213
262
  return [
@@ -217,7 +266,7 @@ const ReturnOrderTable = () => {
217
266
  return_location,
218
267
  return_locations,
219
268
  order_product_return_action,
220
- new_location,
269
+ // new_location,
221
270
  },
222
271
  ];
223
272
  }
@@ -257,6 +306,7 @@ const ReturnOrderTable = () => {
257
306
 
258
307
  const mergedPayload = Object.values(groupedPayload);
259
308
  setGrouped(mergedPayload);
309
+ console.log(mergedPayload, 'mergedPayload');
260
310
  }, [newpayload]);
261
311
 
262
312
  return (
@@ -278,29 +328,60 @@ const ReturnOrderTable = () => {
278
328
  ) : (
279
329
  <th></th>
280
330
  )}
281
- <th>Product Location</th>
282
- <th>Return Location</th>
283
- <th>Recipient</th>
331
+ <th onClick={() => handleSort('orders_products_stock.location')}>
332
+ <div className="sortIconClass">
333
+ Product Location{' '}
334
+ {renderSortIcon('orders_products_stock.location')}
335
+ </div>
336
+ </th>
337
+ <th onClick={() => handleSort('new_location')}>
338
+ <div className="sortIconClass">
339
+ Return Location {renderSortIcon('new_location')}
340
+ </div>
341
+ </th>
342
+ <th
343
+ onClick={() =>
344
+ handleSort('order_data.order_recipient.recipient_name')
345
+ }
346
+ >
347
+ <div className="sortIconClass">
348
+ Recipient{' '}
349
+ {renderSortIcon('order_data.order_recipient.recipient_name')}
350
+ </div>
351
+ </th>
284
352
  <th>Return Action</th>
285
353
  <th>Code</th>
286
354
  <th>Description</th>
287
355
  <th>Part</th>
288
- <th>Weight</th>
356
+ <th onClick={() => handleSort('weight')}>
357
+ <div className="sortIconClass">
358
+ Weight {renderSortIcon('weight')}
359
+ </div>
360
+ </th>
289
361
  <th>CBM</th>
290
- <th>Return Reason</th>
362
+ <th onClick={() => handleSort('return_reasons.reason')}>
363
+ <div className="sortIconClass">
364
+ Return Reason {renderSortIcon('return_reasons.reason')}
365
+ </div>
366
+ </th>
291
367
  <th>Collected</th>
292
- <th>Collection Reason</th>
368
+ <th onClick={() => handleSort('collection_reasons.reason')}>
369
+ <div className="sortIconClass">
370
+ Collection Reason{' '}
371
+ {renderSortIcon('collection_reasons.reason')}
372
+ </div>
373
+ </th>
293
374
  <th className="emailInvoiceShare">Labels</th>
294
375
  </tr>
295
376
  </thead>
296
377
  <tbody>
297
378
  {load ? (
298
379
  <tr>
299
- <td colSpan={13}>
380
+ <td colSpan={14}>
300
381
  <Skeleton active />
301
382
  </td>
302
383
  </tr>
303
- ) : returnData?.length === 0 ? (
384
+ ) : sortedData?.length === 0 ? (
304
385
  <tr>
305
386
  <td colSpan={14}>
306
387
  <EmptyDataContainer>
@@ -309,7 +390,7 @@ const ReturnOrderTable = () => {
309
390
  </td>
310
391
  </tr>
311
392
  ) : (
312
- returnData?.map((item: any, index: any) => (
393
+ sortedData?.map((item: any, index: any) => (
313
394
  <tr key={item.id}>
314
395
  <td>
315
396
  {item?.order_product_return_action?.type == 'RTS' ? (
@@ -326,7 +407,7 @@ const ReturnOrderTable = () => {
326
407
  item.return_location,
327
408
  item.return_locations,
328
409
  item.order_product_return_action,
329
- item.new_location,
410
+ // item.new_location,
330
411
  item.legacy_product_id
331
412
  )
332
413
  }
@@ -382,9 +463,9 @@ const ReturnOrderTable = () => {
382
463
  <td>{displayValueOrNA(item?.return_reasons?.reason)}</td>
383
464
  <td>
384
465
  {item?.order_product_returns?.length > 0
385
- ? item.order_product_returns.map((ret: any) =>
466
+ ? item?.order_product_returns?.map((ret: any) =>
386
467
  ret?.collected_at
387
- ? format(new Date(ret.collected_at), 'dd/MM/yyyy')
468
+ ? format(new Date(ret?.collected_at), 'dd/MM/yyyy')
388
469
  : 'UNKNOWN'
389
470
  )
390
471
  : 'UNKNOWN'}
@@ -405,7 +486,7 @@ const ReturnOrderTable = () => {
405
486
  {printToogle == index && (
406
487
  <div ref={dropdownRef}>
407
488
  <PrintDropDownReturn
408
- legacyProductId={item.legacy_product_id}
489
+ legacyProductId={item?.legacy_product_id}
409
490
  />
410
491
  </div>
411
492
  )}
@@ -277,6 +277,10 @@ export const StyledTable = styled.table`
277
277
  border-radius: 0px 100px 100px 0;
278
278
  border-right: 1px solid rgba(0, 0, 0, 0.08);
279
279
  }
280
+ .sortIconClass {
281
+ cursor: pointer;
282
+ display: flex;
283
+ }
280
284
  }
281
285
  }
282
286
  }
@@ -35,12 +35,18 @@ const atomRoutesTable = atom<TableRowType[]>([]);
35
35
  export const useRoutesTable = () => {
36
36
  return useAtom(atomRoutesTable);
37
37
  };
38
-
38
+ //this
39
39
  const loading = atom<boolean>(false);
40
- export const useLoading = () => {
40
+ export const useStatsLoading = () => {
41
41
  return useAtom(loading);
42
42
  };
43
43
 
44
+ //this
45
+ const loadingState = atom<boolean>(false);
46
+ export const useLoading = () => {
47
+ return useAtom(loadingState);
48
+ };
49
+
44
50
  const selectedAction = atom<number | null>(null);
45
51
  export function useSelectedAction() {
46
52
  return useAtom(selectedAction);
@@ -1,10 +1,10 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import {
3
3
  useAtom,
4
4
  useClientData,
5
5
  useOrderStaticData,
6
6
  } from '../../order-view/store';
7
- import { useLoading } from '../store/store';
7
+ import { useStatsLoading } from '../store/store';
8
8
  import { useApiHook } from '@bjsdistribution/dms-component-library';
9
9
  import {
10
10
  ColumStyle,
@@ -17,6 +17,9 @@ import { Empty, Skeleton } from 'antd';
17
17
  import { useNavigate } from 'react-router-dom';
18
18
  import { filtersReducerAtom } from '../header-filters/filterStore';
19
19
  import { useCustomerData } from '../../store';
20
+ import SortIcon from '../../../common/SortIcon';
21
+ import CaretDownFilledIcon from '../../../common/CaretDownFilledIcon';
22
+ import Loader from '../header/loader/Loader';
20
23
 
21
24
  interface ApiResponse {
22
25
  message: string;
@@ -29,12 +32,59 @@ interface ApiResponse {
29
32
  const ReturnTable: React.FC = () => {
30
33
  const [clientData] = useClientData();
31
34
  const [updatedData, setUpdatedData] = useState<any>([]);
32
- const [statsLoading, setLoading] = useLoading();
35
+ const [statsLoading, setLoading] = useStatsLoading();
33
36
  const [, setOrderStaticData] = useOrderStaticData();
34
37
  const [, dispatch] = useAtom(filtersReducerAtom);
35
38
  const navigate = useNavigate();
36
39
  const [customers] = useCustomerData();
37
40
 
41
+ //sorting
42
+ const [sortConfig, setSortConfig] = useState<{
43
+ key: string;
44
+ direction: 'asc' | 'desc';
45
+ } | null>(null);
46
+
47
+ const handleSort = (key: string) => {
48
+ setSortConfig(prev => {
49
+ if (prev?.key === key && prev.direction === 'asc') {
50
+ return { key, direction: 'desc' };
51
+ }
52
+ return { key, direction: 'asc' };
53
+ });
54
+ };
55
+
56
+ const sortedData = useMemo(() => {
57
+ if (!updatedData || !sortConfig) return updatedData;
58
+
59
+ const { key, direction } = sortConfig;
60
+ return [...updatedData].sort((a, b) => {
61
+ const valueA = a[key];
62
+ const valueB = b[key];
63
+
64
+ if (typeof valueA === 'number' && typeof valueB === 'number') {
65
+ return direction === 'asc' ? valueA - valueB : valueB - valueA;
66
+ }
67
+ if (typeof valueA === 'string' && typeof valueB === 'string') {
68
+ return direction === 'asc'
69
+ ? valueA.localeCompare(valueB)
70
+ : valueB.localeCompare(valueA);
71
+ }
72
+ return 0;
73
+ });
74
+ }, [updatedData, sortConfig]);
75
+
76
+ const renderSortIcon = (columnKey: string) => {
77
+ if (!sortConfig || sortConfig.key !== columnKey) {
78
+ return <SortIcon />;
79
+ }
80
+ return sortConfig.direction === 'asc' ? (
81
+ <CaretDownFilledIcon />
82
+ ) : (
83
+ <CaretDownFilledIcon />
84
+ );
85
+ };
86
+
87
+ //API call
38
88
  const { data: fetchedStaticData, loading: staticDataLoading } = useApiHook<{
39
89
  data: ApiResponse[];
40
90
  }>({
@@ -91,29 +141,38 @@ const ReturnTable: React.FC = () => {
91
141
  payload: [],
92
142
  });
93
143
  }
94
- navigate(`filter/${customerId}`);
144
+ //navigate(`filter/${customerId}`);
95
145
 
96
146
  //forlocal
97
- // navigate(`/filter/${customerId}`);
147
+ navigate(`/filter/${customerId}`);
98
148
  };
99
149
 
100
150
  return (
101
151
  <>
152
+ {statsLoading && <Loader />}
102
153
  <StyledTableWrapper id="tableScrolling">
103
154
  <StyledTable>
104
155
  <thead>
105
156
  <tr>
106
- <th>Trading Name</th>
107
- <th>Client</th>
108
- <th>Orders</th>
109
- <th>Products</th>
110
- <th>RTS</th>
111
- <th>Pending</th>
112
- <th>Dispose</th>
113
- <th>Re-allocate</th>
114
- <th>Re-Del</th>
115
- <th>Recycle</th>
116
- <th>Unknown</th>
157
+ {[
158
+ { label: 'Trading Name', key: 'trading_as' },
159
+ { label: 'Client', key: 'customer_name' },
160
+ { label: 'Orders', key: 'orders' },
161
+ { label: 'Products', key: 'return_order_products' },
162
+ { label: 'RTS', key: 'RTS' },
163
+ { label: 'Pending', key: 'PENDING' },
164
+ { label: 'Dispose', key: 'DISPOSE' },
165
+ { label: 'Re-allocate', key: 'RE-ALLOCATE' },
166
+ { label: 'Re-Del', key: 'RE-DEL' },
167
+ { label: 'Recycle', key: 'RECYCLE' },
168
+ { label: 'Unknown', key: 'UNKNOWN' },
169
+ ].map(({ label, key }) => (
170
+ <th key={key} onClick={() => handleSort(key)}>
171
+ <div style={{ display: 'flex', cursor: 'pointer' }}>
172
+ {label} <span>{renderSortIcon(key)}</span>
173
+ </div>
174
+ </th>
175
+ ))}
117
176
  </tr>
118
177
  </thead>
119
178
  <tbody>
@@ -123,7 +182,7 @@ const ReturnTable: React.FC = () => {
123
182
  <Skeleton active />
124
183
  </td>
125
184
  </tr>
126
- ) : updatedData?.length === 0 ? (
185
+ ) : sortedData?.length === 0 ? (
127
186
  <tr>
128
187
  <td colSpan={11}>
129
188
  <EmptyDataContainer>
@@ -132,7 +191,7 @@ const ReturnTable: React.FC = () => {
132
191
  </td>
133
192
  </tr>
134
193
  ) : (
135
- updatedData?.map((key: any, index: any) => {
194
+ sortedData?.map((key: any, index: number) => {
136
195
  return (
137
196
  <tr key={index}>
138
197
  <td>{key?.trading_as}</td>