@bjsdistribution/dms-client-return 0.1.18-dev → 0.1.20-dev
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/dist/components/client-portal/OutstandingTable.d.ts +3 -0
- package/dist/components/client-portal/ReturnStatus.d.ts +5 -0
- package/dist/components/client-portal/return-confirm/ConfirmedMain.d.ts +3 -0
- package/dist/components/client-portal/return-confirm/ReturnConfirmedTable.d.ts +3 -0
- package/dist/components/store.d.ts +5 -1
- package/dist/dms-client-return.cjs.development.js +1105 -298
- package/dist/dms-client-return.cjs.development.js.map +1 -1
- package/dist/dms-client-return.cjs.production.min.js +1 -1
- package/dist/dms-client-return.cjs.production.min.js.map +1 -1
- package/dist/dms-client-return.esm.js +1106 -299
- package/dist/dms-client-return.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/client-portal/OutstandingTable.tsx +412 -0
- package/src/components/client-portal/ReturnAfterSearchBar.tsx +116 -11
- package/src/components/client-portal/ReturnOverview.tsx +4 -4
- package/src/components/client-portal/ReturnRTFilters.tsx +59 -40
- package/src/components/client-portal/ReturnSearchBar.tsx +93 -12
- package/src/components/client-portal/ReturnStatus.tsx +36 -3
- package/src/components/client-portal/return-confirm/ConfirmedMain.tsx +235 -0
- package/src/components/client-portal/return-confirm/ReturnConfirmedTable.tsx +404 -0
- package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +18 -38
- package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +18 -24
- package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +35 -146
- package/src/components/store.ts +23 -0
package/package.json
CHANGED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Checkbox,
|
|
3
|
+
displayValueOrNA,
|
|
4
|
+
useAxios,
|
|
5
|
+
} from '@bjsdistribution/dms-component-library';
|
|
6
|
+
import { Empty, notification, Skeleton } from 'antd';
|
|
7
|
+
import { format } from 'date-fns';
|
|
8
|
+
import { useAtom } from 'jotai';
|
|
9
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import { NavLink, useParams } from 'react-router-dom';
|
|
11
|
+
import dayjs from 'dayjs';
|
|
12
|
+
import { filtersReducerAtom } from '../order-daily-overview/header-filters/filterStore';
|
|
13
|
+
import {
|
|
14
|
+
useClientOutstandingReturnData,
|
|
15
|
+
useClientPortal,
|
|
16
|
+
useEndDate,
|
|
17
|
+
useLocationData,
|
|
18
|
+
useSearchText,
|
|
19
|
+
useSelectedClientPortOrders,
|
|
20
|
+
useStartDate,
|
|
21
|
+
} from '../store';
|
|
22
|
+
import { usefetchAgain } from '../order-view/store';
|
|
23
|
+
import {
|
|
24
|
+
useLoading,
|
|
25
|
+
UsePaginationData,
|
|
26
|
+
usePrintOptionTOggle,
|
|
27
|
+
} from '../order-daily-overview/store/store';
|
|
28
|
+
import SortIcon from '../../common/SortIcon';
|
|
29
|
+
import CaretDownFilledIcon from '../../common/CaretDownFilledIcon';
|
|
30
|
+
import { ApiResponse } from '../types';
|
|
31
|
+
import {
|
|
32
|
+
CustomDrop,
|
|
33
|
+
EmptyDataContainer,
|
|
34
|
+
StyledTable,
|
|
35
|
+
StyledTableWrapper,
|
|
36
|
+
} from '../order-daily-overview/return-order-table/return-orders-filters/returnstyles';
|
|
37
|
+
import PrinterIcon from '../../assets/icons/PrinterIcon';
|
|
38
|
+
import DownIcon from '../../assets/icons/DownIcon';
|
|
39
|
+
import PrintDropDownReturn from '../order-view/details-filters/left-side-filters/dropdowns/PrintDropDownReturn';
|
|
40
|
+
|
|
41
|
+
const OutstandingTable = () => {
|
|
42
|
+
const [state] = useAtom(filtersReducerAtom);
|
|
43
|
+
const { 'x-pagination': pagination } = state;
|
|
44
|
+
const [
|
|
45
|
+
outstandingReturnData,
|
|
46
|
+
setOutstandingReturnData,
|
|
47
|
+
] = useClientOutstandingReturnData();
|
|
48
|
+
const [load, setLoading] = useLoading();
|
|
49
|
+
const dropdownRefParent = useRef<HTMLDivElement>(null);
|
|
50
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
51
|
+
const [printToogle, setPrintToggle] = usePrintOptionTOggle();
|
|
52
|
+
const [locationData] = useLocationData();
|
|
53
|
+
const [, setPaginationObject] = UsePaginationData();
|
|
54
|
+
const [callForFetch] = usefetchAgain();
|
|
55
|
+
const [clientPortal] = useClientPortal();
|
|
56
|
+
const { status } = useParams();
|
|
57
|
+
const [selectedOrderIds, setSelectedOrderIds] = useSelectedClientPortOrders();
|
|
58
|
+
const [selectClientAll, setSelectClientAll] = useState(false);
|
|
59
|
+
const [debouncedSearchText] = useSearchText();
|
|
60
|
+
|
|
61
|
+
//sorting
|
|
62
|
+
const [sortConfig, setSortConfig] = useState<{
|
|
63
|
+
key: string;
|
|
64
|
+
direction: 'asc' | 'desc';
|
|
65
|
+
} | null>(null);
|
|
66
|
+
|
|
67
|
+
const handleSort = (key: string) => {
|
|
68
|
+
setSortConfig((prev: any) => {
|
|
69
|
+
if (prev?.key === key && prev.direction === 'asc') {
|
|
70
|
+
return { key, direction: 'desc' };
|
|
71
|
+
}
|
|
72
|
+
return { key, direction: 'asc' };
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const sortedData = useMemo(() => {
|
|
77
|
+
if (!outstandingReturnData || !sortConfig) return outstandingReturnData;
|
|
78
|
+
|
|
79
|
+
const { key, direction } = sortConfig;
|
|
80
|
+
return [...outstandingReturnData].sort((a, b) => {
|
|
81
|
+
const valueA = a[key];
|
|
82
|
+
const valueB = b[key];
|
|
83
|
+
|
|
84
|
+
if (typeof valueA === 'number' && typeof valueB === 'number') {
|
|
85
|
+
return direction === 'asc' ? valueA - valueB : valueB - valueA;
|
|
86
|
+
}
|
|
87
|
+
if (typeof valueA === 'string' && typeof valueB === 'string') {
|
|
88
|
+
return direction === 'asc'
|
|
89
|
+
? valueA.localeCompare(valueB)
|
|
90
|
+
: valueB.localeCompare(valueA);
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
});
|
|
94
|
+
}, [outstandingReturnData, sortConfig]);
|
|
95
|
+
|
|
96
|
+
const renderSortIcon = (columnKey: string) => {
|
|
97
|
+
if (!sortConfig || sortConfig.key !== columnKey) {
|
|
98
|
+
return <SortIcon />;
|
|
99
|
+
}
|
|
100
|
+
return sortConfig.direction === 'asc' ? (
|
|
101
|
+
<CaretDownFilledIcon />
|
|
102
|
+
) : (
|
|
103
|
+
<CaretDownFilledIcon />
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const OpenDropDown = (index: number) => {
|
|
108
|
+
setPrintToggle(prevIndex => (prevIndex === index ? null : index));
|
|
109
|
+
};
|
|
110
|
+
// Close dropdown outside click
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
113
|
+
return () => {
|
|
114
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
115
|
+
};
|
|
116
|
+
}, []);
|
|
117
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
118
|
+
if (
|
|
119
|
+
dropdownRef.current &&
|
|
120
|
+
!dropdownRef.current.contains(event.target as Node)
|
|
121
|
+
) {
|
|
122
|
+
setPrintToggle(null);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
//CP
|
|
127
|
+
const [startDate] = useStartDate();
|
|
128
|
+
const [endDate] = useEndDate();
|
|
129
|
+
|
|
130
|
+
const filters = useMemo(() => {
|
|
131
|
+
if (!clientPortal) return [];
|
|
132
|
+
|
|
133
|
+
const stored = JSON.parse(localStorage.getItem('returnDate') || '{}');
|
|
134
|
+
|
|
135
|
+
const sDate = startDate?.isValid?.() ? startDate : dayjs(stored?.startDate);
|
|
136
|
+
const eDate = endDate?.isValid?.()
|
|
137
|
+
? endDate
|
|
138
|
+
: stored?.endDate
|
|
139
|
+
? dayjs(stored?.endDate)
|
|
140
|
+
: null;
|
|
141
|
+
|
|
142
|
+
if (!sDate?.isValid?.()) return [];
|
|
143
|
+
|
|
144
|
+
let dateFilters: any[] = [];
|
|
145
|
+
|
|
146
|
+
if (eDate && eDate.isValid()) {
|
|
147
|
+
dateFilters = [
|
|
148
|
+
{ field: 'created_at', op: '>=', value: sDate.format('YYYY-MM-DD') },
|
|
149
|
+
{
|
|
150
|
+
field: 'created_at',
|
|
151
|
+
op: '<=',
|
|
152
|
+
value: eDate.add(1, 'day').format('YYYY-MM-DD'),
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
} else {
|
|
156
|
+
dateFilters = [
|
|
157
|
+
{
|
|
158
|
+
field: 'created_at',
|
|
159
|
+
op: '=',
|
|
160
|
+
value: sDate.format('YYYY-MM-DD'),
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const baseFilters: any[] =
|
|
166
|
+
status === 'outstanding_return'
|
|
167
|
+
? [
|
|
168
|
+
{ field: 'isdeleted', op: '=', value: 0 },
|
|
169
|
+
{ field: 'product_return_action_id', op: '=', value: 'RTS' },
|
|
170
|
+
]
|
|
171
|
+
: [];
|
|
172
|
+
|
|
173
|
+
return [...baseFilters, ...dateFilters];
|
|
174
|
+
}, [startDate, endDate, status]);
|
|
175
|
+
|
|
176
|
+
const {
|
|
177
|
+
data: fetchedOrderData,
|
|
178
|
+
loading: returnDataLoad,
|
|
179
|
+
paginationData,
|
|
180
|
+
fetchData,
|
|
181
|
+
} = useAxios<ApiResponse>({
|
|
182
|
+
endpoint: '/v1/return/product/pending/',
|
|
183
|
+
method: 'GET',
|
|
184
|
+
filters: filters,
|
|
185
|
+
pagination: pagination,
|
|
186
|
+
});
|
|
187
|
+
console.log(filters, 'outstanding filters');
|
|
188
|
+
const hasFetchedRef = useRef(false);
|
|
189
|
+
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const shouldFetch =
|
|
192
|
+
clientPortal &&
|
|
193
|
+
debouncedSearchText === '' &&
|
|
194
|
+
filters?.length > 0 &&
|
|
195
|
+
!hasFetchedRef.current;
|
|
196
|
+
|
|
197
|
+
if (shouldFetch) {
|
|
198
|
+
fetchData();
|
|
199
|
+
hasFetchedRef.current = true;
|
|
200
|
+
}
|
|
201
|
+
}, [debouncedSearchText, filters, clientPortal]);
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
hasFetchedRef.current = false;
|
|
204
|
+
}, [debouncedSearchText, filters]);
|
|
205
|
+
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
setLoading(returnDataLoad);
|
|
208
|
+
if (fetchedOrderData && fetchedOrderData?.data) {
|
|
209
|
+
setOutstandingReturnData(fetchedOrderData?.data);
|
|
210
|
+
if (paginationData) {
|
|
211
|
+
try {
|
|
212
|
+
const { count, ...rest } = JSON.parse(paginationData);
|
|
213
|
+
setPaginationObject(rest);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.error('Error parsing paginationData:', error);
|
|
216
|
+
notification.error({
|
|
217
|
+
message: 'Error',
|
|
218
|
+
description: 'Failed to parse pagination data',
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
notification.error({
|
|
223
|
+
message: 'Error',
|
|
224
|
+
description: 'Pagination data is null or undefined',
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}, [fetchedOrderData, returnDataLoad]);
|
|
229
|
+
|
|
230
|
+
// console.log(modifiedFilters, 'modifiedFilters');
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
setLoading(returnDataLoad);
|
|
233
|
+
if (fetchedOrderData && fetchedOrderData?.data && locationData) {
|
|
234
|
+
const updatedReturnData = fetchedOrderData.data.map(returnItem => {
|
|
235
|
+
const matchingLocation = locationData.find(
|
|
236
|
+
(location: any) => location?.token === returnItem?.return_location
|
|
237
|
+
);
|
|
238
|
+
return {
|
|
239
|
+
...returnItem,
|
|
240
|
+
new_location: matchingLocation
|
|
241
|
+
? matchingLocation?.location_name
|
|
242
|
+
: null,
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
setOutstandingReturnData(updatedReturnData);
|
|
247
|
+
}
|
|
248
|
+
}, [fetchedOrderData, returnDataLoad, locationData, state, callForFetch]);
|
|
249
|
+
|
|
250
|
+
//Client Portal
|
|
251
|
+
const handleSelectOrderId = (id: string | number) => {
|
|
252
|
+
setSelectedOrderIds(prev =>
|
|
253
|
+
prev.includes(id) ? prev.filter(orderId => orderId !== id) : [...prev, id]
|
|
254
|
+
);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const handleClientSelectAll = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
258
|
+
const isChecked = e.target.checked;
|
|
259
|
+
setSelectClientAll(isChecked);
|
|
260
|
+
|
|
261
|
+
if (isChecked) {
|
|
262
|
+
setSelectedOrderIds(
|
|
263
|
+
outstandingReturnData?.map((item: any) => item?.order_id) || []
|
|
264
|
+
);
|
|
265
|
+
} else {
|
|
266
|
+
setSelectedOrderIds([]);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
return (
|
|
270
|
+
<>
|
|
271
|
+
<StyledTableWrapper className="fortables">
|
|
272
|
+
<StyledTable>
|
|
273
|
+
<thead>
|
|
274
|
+
<tr>
|
|
275
|
+
{/* <th className="emailInvoiceCheckbox">
|
|
276
|
+
<Checkbox checked={selectAll} onChange={handleSelectAll} />
|
|
277
|
+
</th> */}
|
|
278
|
+
<th className="emailInvoiceCheckbox">
|
|
279
|
+
<Checkbox
|
|
280
|
+
checked={selectClientAll}
|
|
281
|
+
onChange={handleClientSelectAll}
|
|
282
|
+
/>
|
|
283
|
+
</th>
|
|
284
|
+
<th onClick={() => handleSort('return_location_name')}>
|
|
285
|
+
<div className="sortIconClass">
|
|
286
|
+
Return Location {renderSortIcon('return_location_name')}
|
|
287
|
+
</div>
|
|
288
|
+
</th>
|
|
289
|
+
<th onClick={() => handleSort('recipient_name')}>
|
|
290
|
+
<div className="sortIconClass">
|
|
291
|
+
Recipient {renderSortIcon('recipient_name')}
|
|
292
|
+
</div>
|
|
293
|
+
</th>
|
|
294
|
+
<th>Return Action</th>
|
|
295
|
+
<th>Code</th>
|
|
296
|
+
<th>Description</th>
|
|
297
|
+
<th>Part</th>
|
|
298
|
+
<th onClick={() => handleSort('weight')}>
|
|
299
|
+
<div className="sortIconClass">
|
|
300
|
+
Weight {renderSortIcon('weight')}
|
|
301
|
+
</div>
|
|
302
|
+
</th>
|
|
303
|
+
<th>CBM</th>
|
|
304
|
+
<th onClick={() => handleSort('return_reason')}>
|
|
305
|
+
<div className="sortIconClass">
|
|
306
|
+
Return Reason {renderSortIcon('return_reason')}
|
|
307
|
+
</div>
|
|
308
|
+
</th>
|
|
309
|
+
<th>Collected</th>
|
|
310
|
+
<th onClick={() => handleSort('collection_reason')}>
|
|
311
|
+
<div className="sortIconClass">
|
|
312
|
+
Collection Reason {renderSortIcon('collection_reason')}
|
|
313
|
+
</div>
|
|
314
|
+
</th>
|
|
315
|
+
<th className="emailInvoiceShare">Labels</th>
|
|
316
|
+
</tr>
|
|
317
|
+
</thead>
|
|
318
|
+
<tbody>
|
|
319
|
+
{load ? (
|
|
320
|
+
<tr>
|
|
321
|
+
<td colSpan={14}>
|
|
322
|
+
<Skeleton active />
|
|
323
|
+
</td>
|
|
324
|
+
</tr>
|
|
325
|
+
) : sortedData?.length === 0 ? (
|
|
326
|
+
<tr>
|
|
327
|
+
<td colSpan={14}>
|
|
328
|
+
<EmptyDataContainer>
|
|
329
|
+
<Empty />
|
|
330
|
+
</EmptyDataContainer>
|
|
331
|
+
</td>
|
|
332
|
+
</tr>
|
|
333
|
+
) : (
|
|
334
|
+
sortedData?.map((item: any, index: any) => (
|
|
335
|
+
<tr key={item.id}>
|
|
336
|
+
<td>
|
|
337
|
+
<Checkbox
|
|
338
|
+
checked={selectedOrderIds.includes(item?.order_id)}
|
|
339
|
+
onChange={() => handleSelectOrderId(item?.order_id)}
|
|
340
|
+
/>
|
|
341
|
+
</td>
|
|
342
|
+
<td> {displayValueOrNA(item?.return_location_name)}</td>
|
|
343
|
+
<td>
|
|
344
|
+
<ul style={{ listStyleType: 'none', padding: 0 }}>
|
|
345
|
+
<li
|
|
346
|
+
style={{
|
|
347
|
+
color: '#0099ff',
|
|
348
|
+
fontWeight: 600,
|
|
349
|
+
paddingLeft: 0,
|
|
350
|
+
}}
|
|
351
|
+
>
|
|
352
|
+
<NavLink to={`/orders/view/${item?.order_id}`}>
|
|
353
|
+
{displayValueOrNA(item?.recipient_name)}
|
|
354
|
+
</NavLink>
|
|
355
|
+
</li>
|
|
356
|
+
<li style={{ color: '#888075' }}>
|
|
357
|
+
{displayValueOrNA(item?.postcode)}
|
|
358
|
+
</li>
|
|
359
|
+
</ul>
|
|
360
|
+
</td>
|
|
361
|
+
<td>{displayValueOrNA(item?.product_return_action)}</td>
|
|
362
|
+
<td>{displayValueOrNA(item?.code)}</td>
|
|
363
|
+
<td>{displayValueOrNA(item?.description)}</td>
|
|
364
|
+
<td>{displayValueOrNA(item?.part)}</td>
|
|
365
|
+
<td>
|
|
366
|
+
{displayValueOrNA(item?.weight)}{' '}
|
|
367
|
+
{item?.weight && item?.weight !== null ? 'KG' : ''}
|
|
368
|
+
</td>
|
|
369
|
+
<td>{displayValueOrNA(item?.cube)}</td>
|
|
370
|
+
<td>{displayValueOrNA(item?.return_reason)}</td>
|
|
371
|
+
<td>
|
|
372
|
+
{item?.collected_at
|
|
373
|
+
? format(new Date(item?.collected_at), 'dd/MM/yyyy')
|
|
374
|
+
: 'UNKNOWN'}
|
|
375
|
+
</td>
|
|
376
|
+
|
|
377
|
+
<td>{displayValueOrNA(item?.collection_reason)}</td>
|
|
378
|
+
<td>
|
|
379
|
+
<ul className="actionbox">
|
|
380
|
+
<CustomDrop
|
|
381
|
+
ref={dropdownRefParent}
|
|
382
|
+
className={printToogle === index ? 'active' : ''}
|
|
383
|
+
>
|
|
384
|
+
<li
|
|
385
|
+
className="shareIconContainer"
|
|
386
|
+
onClick={() => OpenDropDown(index)}
|
|
387
|
+
>
|
|
388
|
+
<PrinterIcon />
|
|
389
|
+
<DownIcon />
|
|
390
|
+
{printToogle === index && (
|
|
391
|
+
<div ref={dropdownRef}>
|
|
392
|
+
<PrintDropDownReturn
|
|
393
|
+
legacyURL={item?.return_order_product_label}
|
|
394
|
+
legacyProductID={item?.legacy_product_id}
|
|
395
|
+
/>
|
|
396
|
+
</div>
|
|
397
|
+
)}
|
|
398
|
+
</li>
|
|
399
|
+
</CustomDrop>
|
|
400
|
+
</ul>
|
|
401
|
+
</td>
|
|
402
|
+
</tr>
|
|
403
|
+
))
|
|
404
|
+
)}
|
|
405
|
+
</tbody>
|
|
406
|
+
</StyledTable>
|
|
407
|
+
</StyledTableWrapper>
|
|
408
|
+
</>
|
|
409
|
+
);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
export default OutstandingTable;
|
|
@@ -5,28 +5,43 @@ import {
|
|
|
5
5
|
} from '@bjsdistribution/dms-component-library';
|
|
6
6
|
import React, { useEffect, useState } from 'react';
|
|
7
7
|
import styled from 'styled-components';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
useAtom,
|
|
10
|
+
useClientPortal,
|
|
11
|
+
useEndDate,
|
|
12
|
+
useReturnConfirmedOrderData,
|
|
13
|
+
useSearchAfterText,
|
|
14
|
+
useStartDate,
|
|
15
|
+
useStatsCPCount,
|
|
16
|
+
} from '../store';
|
|
9
17
|
|
|
10
18
|
import { ApiResponse } from '../types';
|
|
11
19
|
import { javascriptStringDumpToJSON } from '../utils';
|
|
12
20
|
import { UsePaginationData } from '../order-daily-overview/store/store';
|
|
13
21
|
import { notification } from 'antd';
|
|
14
|
-
import { useReturnAfterOrderData } from '../order-view/store';
|
|
15
22
|
import { filtersReducerReturnAtom } from '../order-daily-overview/return-after-table/table-filters/ReturnFilterStore';
|
|
23
|
+
import dayjs from 'dayjs';
|
|
24
|
+
import { returnCountType } from './ReturnStatus';
|
|
25
|
+
import { useParams } from 'react-router-dom';
|
|
16
26
|
|
|
17
27
|
function ReturnAfterSearchBar() {
|
|
18
28
|
const [searchText, setSearchText] = useState('');
|
|
19
29
|
const [debouncedSearchText, setDebouncedSearchText] = useSearchAfterText();
|
|
20
|
-
const [,
|
|
30
|
+
const [, setReturnConfirmedData] = useReturnConfirmedOrderData();
|
|
21
31
|
//condition on client view
|
|
22
32
|
const [, setPaginationObject] = UsePaginationData();
|
|
23
33
|
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
24
34
|
setSearchText(event.target.value);
|
|
25
35
|
};
|
|
26
36
|
//CP
|
|
27
|
-
|
|
37
|
+
const [modifiedStatsFilters, setModifiedStatsFilters] = useState<any[]>([]);
|
|
38
|
+
const [startDate] = useStartDate();
|
|
39
|
+
const [endDate] = useEndDate();
|
|
28
40
|
const [state] = useAtom(filtersReducerReturnAtom);
|
|
29
41
|
const { 'x-filters': filters, 'x-pagination': pagination } = state;
|
|
42
|
+
const [count, setCount] = useStatsCPCount();
|
|
43
|
+
const [clientPortal] = useClientPortal();
|
|
44
|
+
const { status } = useParams();
|
|
30
45
|
|
|
31
46
|
const { paginationData, fetchData: returnAfterCall } = useAxios<ApiResponse>({
|
|
32
47
|
endpoint: '/v1/return/orders/',
|
|
@@ -36,7 +51,7 @@ function ReturnAfterSearchBar() {
|
|
|
36
51
|
});
|
|
37
52
|
|
|
38
53
|
useEffect(() => {
|
|
39
|
-
if (debouncedSearchText
|
|
54
|
+
if (debouncedSearchText?.length > 1) {
|
|
40
55
|
returnAfterCall({
|
|
41
56
|
endPointQuery: `?search_term=${debouncedSearchText}`,
|
|
42
57
|
}).then((response: any) => {
|
|
@@ -48,14 +63,14 @@ function ReturnAfterSearchBar() {
|
|
|
48
63
|
setPaginationObject(rest);
|
|
49
64
|
}
|
|
50
65
|
if (response?.data) {
|
|
51
|
-
|
|
66
|
+
setReturnConfirmedData(response?.data);
|
|
52
67
|
} else {
|
|
53
|
-
|
|
68
|
+
setReturnConfirmedData([]);
|
|
54
69
|
}
|
|
55
70
|
});
|
|
56
71
|
} else if (
|
|
57
|
-
debouncedSearchText
|
|
58
|
-
debouncedSearchText
|
|
72
|
+
debouncedSearchText?.length > 0 &&
|
|
73
|
+
debouncedSearchText?.length <= 2
|
|
59
74
|
) {
|
|
60
75
|
notification.warning({
|
|
61
76
|
message: 'Search Phrase cannot be less than 3 characters',
|
|
@@ -73,14 +88,104 @@ function ReturnAfterSearchBar() {
|
|
|
73
88
|
}, [searchText]);
|
|
74
89
|
|
|
75
90
|
useEffect(() => {
|
|
76
|
-
if (debouncedSearchText
|
|
91
|
+
if (debouncedSearchText?.length === 0) {
|
|
77
92
|
setSearchText('');
|
|
78
93
|
}
|
|
79
94
|
}, [debouncedSearchText]);
|
|
80
95
|
|
|
96
|
+
//
|
|
97
|
+
|
|
98
|
+
const getDateFilters = (
|
|
99
|
+
startDate: dayjs.Dayjs | null,
|
|
100
|
+
endDate: dayjs.Dayjs | null
|
|
101
|
+
) => {
|
|
102
|
+
const stored = JSON.parse(localStorage.getItem('returnDate') || '{}');
|
|
103
|
+
|
|
104
|
+
const sDate = startDate?.isValid?.() ? startDate : dayjs(stored?.startDate);
|
|
105
|
+
const eDate = endDate?.isValid?.()
|
|
106
|
+
? endDate
|
|
107
|
+
: stored?.endDate
|
|
108
|
+
? dayjs(stored?.endDate)
|
|
109
|
+
: null;
|
|
110
|
+
|
|
111
|
+
if (!sDate?.isValid?.()) return [];
|
|
112
|
+
|
|
113
|
+
let dateFilters = [];
|
|
114
|
+
|
|
115
|
+
if (eDate && eDate.isValid()) {
|
|
116
|
+
dateFilters = [
|
|
117
|
+
{ field: 'created_at', op: '>=', value: sDate.format('YYYY-MM-DD') },
|
|
118
|
+
{
|
|
119
|
+
field: 'created_at',
|
|
120
|
+
op: '<=',
|
|
121
|
+
value: eDate.add(1, 'day').format('YYYY-MM-DD'),
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
} else {
|
|
125
|
+
dateFilters = [
|
|
126
|
+
{
|
|
127
|
+
field: 'created_at',
|
|
128
|
+
op: '=',
|
|
129
|
+
value: sDate.format('YYYY-MM-DD'),
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return dateFilters;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!clientPortal) return;
|
|
139
|
+
|
|
140
|
+
const dateFilters = getDateFilters(startDate, endDate);
|
|
141
|
+
setModifiedStatsFilters(dateFilters);
|
|
142
|
+
}, [startDate, endDate]);
|
|
143
|
+
|
|
144
|
+
const { data: statsData, fetchData: fetchStatsData } = useAxios<{
|
|
145
|
+
data: returnCountType[];
|
|
146
|
+
}>({
|
|
147
|
+
endpoint: `v1/portal/return/stats/`,
|
|
148
|
+
method: 'GET',
|
|
149
|
+
pagination: { is_pagination: false },
|
|
150
|
+
filters: modifiedStatsFilters,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
const validStatuses = ['scheduled_for_return', 'return_completed'];
|
|
155
|
+
const isClientView = clientPortal && validStatuses.includes(status || '');
|
|
156
|
+
|
|
157
|
+
if (!isClientView || debouncedSearchText?.length < 3) return;
|
|
158
|
+
console.log('IN after view entered');
|
|
159
|
+
const statusTypeMap: Record<string, string> = {
|
|
160
|
+
scheduled_for_return: 'scheduled',
|
|
161
|
+
return_completed: 'complete',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const type = statusTypeMap[status as keyof typeof statusTypeMap];
|
|
165
|
+
|
|
166
|
+
const fetchStats = async () => {
|
|
167
|
+
const response = await fetchStatsData({
|
|
168
|
+
endPointQuery: `?search_term=${debouncedSearchText}&type=${type}`,
|
|
169
|
+
});
|
|
170
|
+
//@ts-ignore
|
|
171
|
+
if (response?.data) {
|
|
172
|
+
console.log('inside response', response);
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
setCount(response?.data);
|
|
175
|
+
} else {
|
|
176
|
+
setCount(null);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
fetchStats();
|
|
181
|
+
}, [debouncedSearchText, status, clientPortal]);
|
|
182
|
+
|
|
183
|
+
console.log(statsData, 'statsData');
|
|
184
|
+
|
|
185
|
+
console.log(count, 'new count');
|
|
186
|
+
|
|
81
187
|
const handleClear = () => {
|
|
82
188
|
setSearchText('');
|
|
83
|
-
setDebouncedSearchText('');
|
|
84
189
|
};
|
|
85
190
|
return (
|
|
86
191
|
<Search>
|
|
@@ -2,8 +2,6 @@ import React, { useState } from 'react';
|
|
|
2
2
|
import HeaderFilter from '../order-daily-overview/header-filters/HeaderFilter';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import ReturnFilter from '../order-daily-overview/return-order-table/return-orders-filters/ReturnFilter';
|
|
5
|
-
import ReturnOrderTable from '../order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable';
|
|
6
|
-
import ReturnAfterTable from '../order-daily-overview/return-after-table/ReturnAfterTable';
|
|
7
5
|
import Pagination from '../order-daily-overview/table-view/Pagination';
|
|
8
6
|
import {
|
|
9
7
|
useItemsPerPage,
|
|
@@ -12,6 +10,8 @@ import {
|
|
|
12
10
|
import { useClientPortal } from '../store';
|
|
13
11
|
import { useParams } from 'react-router-dom';
|
|
14
12
|
import RouterHeader from '../order-daily-overview/header/route-header/RouterHeader';
|
|
13
|
+
import OutstandingTable from './OutstandingTable';
|
|
14
|
+
import ConfirmedMain from './return-confirm/ConfirmedMain';
|
|
15
15
|
|
|
16
16
|
const ReturnOverview = () => {
|
|
17
17
|
const [paginationObj] = UsePaginationData();
|
|
@@ -43,7 +43,7 @@ const ReturnOverview = () => {
|
|
|
43
43
|
<ReturnFilter />
|
|
44
44
|
{clientPortal && status === 'outstanding_return' && (
|
|
45
45
|
<>
|
|
46
|
-
<
|
|
46
|
+
<OutstandingTable />
|
|
47
47
|
{total > 0 && (
|
|
48
48
|
<Pagination
|
|
49
49
|
currentPage={page}
|
|
@@ -57,7 +57,7 @@ const ReturnOverview = () => {
|
|
|
57
57
|
)}
|
|
58
58
|
{shouldShowReturnAfterTable && (
|
|
59
59
|
<>
|
|
60
|
-
<
|
|
60
|
+
<ConfirmedMain />
|
|
61
61
|
</>
|
|
62
62
|
)}
|
|
63
63
|
</Container>
|