@bjsdistribution/dms-client-return 0.0.43 → 0.0.44

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.43",
2
+ "version": "0.0.44",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -347,7 +347,7 @@ function SelectionFilter() {
347
347
  value={selectedLocationValue}
348
348
  placeholder="Select Location"
349
349
  onChange={handleLocationChange}
350
- style={{ minWidth: '14vw' }}
350
+ style={{ minWidth: '150px' }}
351
351
  allowClear
352
352
  mode="multiple"
353
353
  />
@@ -1,5 +1,5 @@
1
1
  import { Empty, notification, Select } from 'antd';
2
- import React, { useEffect, useRef, useState } from 'react';
2
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Skeleton } from 'antd';
4
4
  // import { useSelectedOrders } from '../../../store';
5
5
  import { useOrderId, useReturnAfterOrderData } from '../../../order-view/store';
@@ -25,6 +25,8 @@ import styled from 'styled-components';
25
25
  import { useApiHook } from '@bjsdistribution/dms-component-library';
26
26
  import { ApiResponse } from '../../common/interface';
27
27
  import Loader from '../../header/loader/Loader';
28
+ import CaretDownFilledIcon from '../../../../common/CaretDownFilledIcon';
29
+ import SortIcon from '../../../../common/SortIcon';
28
30
 
29
31
  const OrderTable = ({ loadingskeleton }: any) => {
30
32
  // const [, setSelectedReturnOrder] = useSelectedOrders();
@@ -39,6 +41,52 @@ const OrderTable = ({ loadingskeleton }: any) => {
39
41
  const [, setAssign] = useState<boolean>(false);
40
42
  const [, setCallAPi] = useCallApiAgain();
41
43
 
44
+ //sorting
45
+ const [sortConfig, setSortConfig] = useState<{
46
+ key: string;
47
+ direction: 'asc' | 'desc';
48
+ } | null>(null);
49
+
50
+ const handleSort = (key: string) => {
51
+ setSortConfig((prev: any) => {
52
+ if (prev?.key === key && prev.direction === 'asc') {
53
+ return { key, direction: 'desc' };
54
+ }
55
+ return { key, direction: 'asc' };
56
+ });
57
+ };
58
+
59
+ const sortedData = useMemo(() => {
60
+ if (!returnAfterOrder || !sortConfig) return returnAfterOrder;
61
+
62
+ const { key, direction } = sortConfig;
63
+ return [...returnAfterOrder].sort((a, b) => {
64
+ const valueA = a[key];
65
+ const valueB = b[key];
66
+
67
+ if (typeof valueA === 'number' && typeof valueB === 'number') {
68
+ return direction === 'asc' ? valueA - valueB : valueB - valueA;
69
+ }
70
+ if (typeof valueA === 'string' && typeof valueB === 'string') {
71
+ return direction === 'asc'
72
+ ? valueA.localeCompare(valueB)
73
+ : valueB.localeCompare(valueA);
74
+ }
75
+ return 0;
76
+ });
77
+ }, [returnAfterOrder, sortConfig]);
78
+
79
+ const renderSortIcon = (columnKey: string) => {
80
+ if (!sortConfig || sortConfig.key !== columnKey) {
81
+ return <SortIcon />;
82
+ }
83
+ return sortConfig.direction === 'asc' ? (
84
+ <CaretDownFilledIcon />
85
+ ) : (
86
+ <CaretDownFilledIcon />
87
+ );
88
+ };
89
+
42
90
  const OpenDropDown = (index: number) => {
43
91
  setPrintToggle(prevIndex => (prevIndex === index ? null : index));
44
92
  };
@@ -169,16 +217,37 @@ const OrderTable = ({ loadingskeleton }: any) => {
169
217
  {/* <th className="emailInvoiceCheckbox">
170
218
  <Checkbox checked={false} />
171
219
  </th> */}
172
- <th>Created</th>
173
- <th>Return Location</th>
220
+ <th onClick={() => handleSort('created_at')}>
221
+ <div className="sortIconClass">
222
+ Created {renderSortIcon('created_at')}
223
+ </div>
224
+ </th>
225
+ <th onClick={() => handleSort('return_locations.location_name')}>
226
+ <div className="sortIconClass">
227
+ Return Location{' '}
228
+ {renderSortIcon('return_locations.location_name')}
229
+ </div>
230
+ </th>
174
231
  <th>Pick Up Location</th>
175
- <th>Recipient</th>
232
+ <th onClick={() => handleSort('order_recipient.recipient_name')}>
233
+ <div className="sortIconClass">
234
+ Recipient {renderSortIcon('order_recipient.recipient_name')}
235
+ </div>
236
+ </th>
176
237
  <th> Client</th>
177
238
  <th>Consignment</th>
178
239
  <th>Return Order No</th>
179
240
  <th> Total Parts</th>
180
- <th>Total Weight</th>
181
- <th>Total CBM</th>
241
+ <th onClick={() => handleSort('weight')}>
242
+ <div className="sortIconClass">
243
+ Total Weight {renderSortIcon('weight')}
244
+ </div>
245
+ </th>
246
+ <th onClick={() => handleSort('cube')}>
247
+ <div className="sortIconClass">
248
+ Total CBM {renderSortIcon('cube')}
249
+ </div>
250
+ </th>
182
251
  <th>Assign</th>
183
252
  <th>Status</th>
184
253
  <th className="emailInvoiceShare">Labels</th>
@@ -192,7 +261,7 @@ const OrderTable = ({ loadingskeleton }: any) => {
192
261
  </td>
193
262
  <td colSpan={16}></td>
194
263
  </tr>
195
- ) : returnAfterOrder?.length === 0 ? (
264
+ ) : sortedData?.length === 0 ? (
196
265
  <tr>
197
266
  <td colSpan={16}>
198
267
  <EmptyDataContainer>
@@ -201,7 +270,7 @@ const OrderTable = ({ loadingskeleton }: any) => {
201
270
  </td>
202
271
  </tr>
203
272
  ) : (
204
- returnAfterOrder?.map((item: any, index: any) => {
273
+ sortedData?.map((item: any, index: any) => {
205
274
  const statusMapping: any = {
206
275
  cancelled: 'Cancelled',
207
276
  OO: 'On Hold',