@bjsdistribution/dms-client-return 0.1.60-prod → 0.1.61-prod
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/store.d.ts +2 -1
- package/dist/dms-client-return.cjs.development.js +223 -60
- 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 +223 -60
- package/dist/dms-client-return.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/order-daily-overview/header/route-header/search/SearchType.tsx +11 -1
- package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +81 -56
- package/src/components/order-daily-overview/header-filters/filterStore.ts +1 -1
- package/src/components/order-daily-overview/index.tsx +1 -1
- package/src/components/order-daily-overview/table/ReturnTable.tsx +188 -104
- package/src/components/store.ts +7 -0
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import { ClientData } from '../../../common/interface';
|
|
|
11
11
|
import { notification } from 'antd';
|
|
12
12
|
import { overviewfiltersReducerAtom } from '../../../header-filters/overViewFilter';
|
|
13
13
|
import { UsePaginationOverviewData } from '../../../store/store';
|
|
14
|
+
import { useStatsLoading } from '../../../store/store';
|
|
14
15
|
|
|
15
16
|
const SearchType = () => {
|
|
16
17
|
const [searchText, setSearchText] = useState('');
|
|
@@ -18,6 +19,7 @@ const SearchType = () => {
|
|
|
18
19
|
const [debouncedSearchText, setDebouncedSearchText] = useInternalSearchText();
|
|
19
20
|
const [state] = useAtom(overviewfiltersReducerAtom);
|
|
20
21
|
const [, setPaginationObject] = UsePaginationOverviewData();
|
|
22
|
+
const [, setStatsLoading] = useStatsLoading();
|
|
21
23
|
const didMountRef = useRef(false);
|
|
22
24
|
const { 'x-filters': filters, 'x-pagination': pagination } = state;
|
|
23
25
|
|
|
@@ -54,7 +56,7 @@ const SearchType = () => {
|
|
|
54
56
|
if (searchData && Array.isArray(searchData?.data)) {
|
|
55
57
|
setClientData(searchData?.data);
|
|
56
58
|
}
|
|
57
|
-
}, [searchData
|
|
59
|
+
}, [searchData]);
|
|
58
60
|
|
|
59
61
|
const handleClear = () => {
|
|
60
62
|
setSearchText('');
|
|
@@ -76,6 +78,14 @@ const SearchType = () => {
|
|
|
76
78
|
filters: filters,
|
|
77
79
|
});
|
|
78
80
|
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (debouncedSearchText && debouncedSearchText?.length > 0) {
|
|
83
|
+
setStatsLoading(loading);
|
|
84
|
+
} else {
|
|
85
|
+
setStatsLoading(statsDataLoading);
|
|
86
|
+
}
|
|
87
|
+
}, [loading, statsDataLoading, debouncedSearchText]);
|
|
88
|
+
|
|
79
89
|
useEffect(() => {
|
|
80
90
|
if (fetchedClientData && fetchedClientData.data) {
|
|
81
91
|
const result = fetchedClientData?.data;
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
useClientPortal,
|
|
17
17
|
useCustomerData,
|
|
18
18
|
useReturnPayload,
|
|
19
|
+
useFlatCustomerData,
|
|
19
20
|
} from '../../store';
|
|
20
21
|
import { filtersReducerAtom } from './filterStore';
|
|
21
22
|
import {
|
|
@@ -31,10 +32,11 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
|
31
32
|
import { useAxios } from '@bjsdistribution/dms-component-library';
|
|
32
33
|
import { ApiResponse } from '../common/interface';
|
|
33
34
|
|
|
35
|
+
|
|
34
36
|
export const clickedState = atom<boolean>(false);
|
|
35
37
|
|
|
36
38
|
function SelectionFilter() {
|
|
37
|
-
const [customers
|
|
39
|
+
const [customers] = useCustomerData();
|
|
38
40
|
const [selectedFilterValue, setSelectedFilterValue] = useSelectedAction();
|
|
39
41
|
const [, dispatch] = useAtom(filtersReducerAtom);
|
|
40
42
|
const [
|
|
@@ -49,9 +51,10 @@ function SelectionFilter() {
|
|
|
49
51
|
const [actionTypeOptions, setActionTypeOptions] = useActionTypeOptions();
|
|
50
52
|
const [locationOptions, setLocationOptions] = useLocationOptions();
|
|
51
53
|
const [searchParams] = useSearchParams();
|
|
52
|
-
const [clientPortal] = useClientPortal();
|
|
53
54
|
const navigate = useNavigate();
|
|
55
|
+
const [clientPortal] = useClientPortal();
|
|
54
56
|
const [clientLoading] = useClientLoading();
|
|
57
|
+
|
|
55
58
|
//API for client data
|
|
56
59
|
const { data: fetchedCustomerData, loading: loading, fetchData } = useAxios<
|
|
57
60
|
ApiResponse
|
|
@@ -61,41 +64,63 @@ function SelectionFilter() {
|
|
|
61
64
|
//@ts-ignore
|
|
62
65
|
pagination: { is_pagination: false },
|
|
63
66
|
});
|
|
64
|
-
|
|
67
|
+
|
|
68
|
+
const [flatCustomers, setFlatCustomers] = useFlatCustomerData();
|
|
69
|
+
|
|
65
70
|
useEffect(() => {
|
|
66
71
|
if (!clientPortal && !clientLoading) {
|
|
67
|
-
|
|
72
|
+
if (!flatCustomers || flatCustomers.length === 0) {
|
|
73
|
+
fetchData();
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
}, [clientLoading]);
|
|
70
77
|
|
|
71
78
|
useEffect(() => {
|
|
72
79
|
if (fetchedCustomerData && fetchedCustomerData?.data) {
|
|
73
|
-
|
|
80
|
+
setFlatCustomers(fetchedCustomerData?.data);
|
|
74
81
|
}
|
|
75
82
|
}, [loading]);
|
|
83
|
+
|
|
76
84
|
//new codee
|
|
77
85
|
const urlCustomerId = searchParams.get('customerId');
|
|
78
86
|
const urlActiontype = searchParams.get('type');
|
|
79
87
|
|
|
80
|
-
|
|
88
|
+
// Used strictly for getting the account number for the API payload (works for both parent and children)
|
|
89
|
+
const selectedFlatCustomer = flatCustomers?.find(
|
|
81
90
|
(customer: any) => customer?.customer_id?.toString() === urlCustomerId
|
|
82
91
|
);
|
|
83
|
-
const accountNumber =
|
|
92
|
+
const accountNumber = selectedFlatCustomer?.account_number;
|
|
93
|
+
|
|
94
|
+
// Used strictly for retrieving children bundling IDs (only populates if it's a parent)
|
|
95
|
+
const selectedGroupedCustomer = customers?.find(
|
|
96
|
+
(customer: any) => customer?.customer_id?.toString() === urlCustomerId
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const getFilterPayload = () => {
|
|
100
|
+
let payload: any = urlCustomerId;
|
|
101
|
+
if (selectedGroupedCustomer?.children && selectedGroupedCustomer?.children?.length > 0) {
|
|
102
|
+
payload = [
|
|
103
|
+
urlCustomerId,
|
|
104
|
+
...selectedGroupedCustomer?.children?.map((child: any) => child?.customer_id?.toString())
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
return payload;
|
|
108
|
+
};
|
|
84
109
|
|
|
85
110
|
//customer name
|
|
86
|
-
const clientOptions = customers
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
option?.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})
|
|
111
|
+
const clientOptions = [...(flatCustomers || []), ...(customers || [])]
|
|
112
|
+
.filter((v, i, a) => a?.findIndex((t: any) => t?.customer_id?.toString() === v?.customer_id?.toString()) === i)
|
|
113
|
+
.filter((option: any) => option?.customer_id != null)
|
|
114
|
+
.map((option: any) => {
|
|
115
|
+
const name = String(option?.customer_name || option?.trading_as || '');
|
|
116
|
+
return {
|
|
117
|
+
label: name.charAt(0)?.toUpperCase() + name?.slice(1),
|
|
118
|
+
value: Number(option?.customer_id),
|
|
119
|
+
actions: option?.actions,
|
|
120
|
+
return_locations: option?.return_locations,
|
|
121
|
+
account_number: option?.account_number,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
99
124
|
|
|
100
125
|
//client change
|
|
101
126
|
const handleClientChange = (value: any, option: any) => {
|
|
@@ -108,22 +133,22 @@ function SelectionFilter() {
|
|
|
108
133
|
if (filteredClient) {
|
|
109
134
|
const mappedActions = Array.isArray(filteredClient?.actions)
|
|
110
135
|
? filteredClient?.actions?.map((action: any) => ({
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
136
|
+
label: action,
|
|
137
|
+
value: action,
|
|
138
|
+
}))
|
|
114
139
|
: [];
|
|
115
140
|
|
|
116
141
|
setActionTypeOptions(mappedActions);
|
|
117
142
|
|
|
118
143
|
const mappedLocations = Array.isArray(filteredClient?.return_locations)
|
|
119
144
|
? filteredClient.return_locations
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
.filter(
|
|
146
|
+
(location: any) => location?.location_name && location?.token
|
|
147
|
+
)
|
|
148
|
+
.map((location: any) => ({
|
|
149
|
+
label: location.location_name,
|
|
150
|
+
value: location.token,
|
|
151
|
+
}))
|
|
127
152
|
: [];
|
|
128
153
|
|
|
129
154
|
setLocationOptions(mappedLocations);
|
|
@@ -156,24 +181,24 @@ function SelectionFilter() {
|
|
|
156
181
|
if (filteredClient) {
|
|
157
182
|
const mappedActions = Array.isArray(filteredClient?.actions)
|
|
158
183
|
? filteredClient?.actions?.map((action: any) => ({
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
label: action,
|
|
185
|
+
value: action,
|
|
186
|
+
}))
|
|
162
187
|
: [];
|
|
163
188
|
|
|
164
189
|
setActionTypeOptions(mappedActions);
|
|
165
190
|
|
|
166
191
|
const mappedLocations = Array.isArray(filteredClient?.return_locations)
|
|
167
192
|
? filteredClient.return_locations
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
193
|
+
.filter((location: any) => {
|
|
194
|
+
const name = location?.location_name;
|
|
195
|
+
const token = location?.token;
|
|
196
|
+
return name && name !== 'null' && token && token !== 'null';
|
|
197
|
+
})
|
|
198
|
+
.map((location: any) => ({
|
|
199
|
+
label: location?.location_name,
|
|
200
|
+
value: location?.token,
|
|
201
|
+
}))
|
|
177
202
|
: [];
|
|
178
203
|
|
|
179
204
|
setLocationOptions(mappedLocations);
|
|
@@ -219,18 +244,18 @@ function SelectionFilter() {
|
|
|
219
244
|
setActionTypeOptions(
|
|
220
245
|
Array.isArray(clientActions)
|
|
221
246
|
? clientActions?.map(action => ({
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
247
|
+
label: action,
|
|
248
|
+
value: action,
|
|
249
|
+
}))
|
|
225
250
|
: []
|
|
226
251
|
);
|
|
227
252
|
|
|
228
253
|
setLocationOptions(
|
|
229
254
|
Array.isArray(clientLocations)
|
|
230
255
|
? clientLocations?.map(location => ({
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
256
|
+
label: location?.location_name,
|
|
257
|
+
value: location?.token,
|
|
258
|
+
}))
|
|
234
259
|
: []
|
|
235
260
|
);
|
|
236
261
|
|
|
@@ -238,7 +263,7 @@ function SelectionFilter() {
|
|
|
238
263
|
if (urlCustomerId) {
|
|
239
264
|
dispatch({
|
|
240
265
|
type: 'SET_CLIENT_FILTER',
|
|
241
|
-
payload:
|
|
266
|
+
payload: getFilterPayload(),
|
|
242
267
|
});
|
|
243
268
|
dispatch({
|
|
244
269
|
type: 'SET_PAGE',
|
|
@@ -282,7 +307,7 @@ function SelectionFilter() {
|
|
|
282
307
|
}
|
|
283
308
|
}, [selectedClient, selectedFilterValue, selectedLocationValue]);
|
|
284
309
|
|
|
285
|
-
useEffect(() => {}, [location.pathname]);
|
|
310
|
+
useEffect(() => { }, [location.pathname]);
|
|
286
311
|
|
|
287
312
|
useEffect(() => {
|
|
288
313
|
if (!selectedFilterValue || selectedFilterValue === null) {
|
|
@@ -314,7 +339,7 @@ function SelectionFilter() {
|
|
|
314
339
|
if (urlCustomerId && urlActiontype) {
|
|
315
340
|
dispatch({
|
|
316
341
|
type: 'SET_CLIENT_FILTER',
|
|
317
|
-
payload:
|
|
342
|
+
payload: getFilterPayload(),
|
|
318
343
|
});
|
|
319
344
|
setSelectedClient(+urlCustomerId);
|
|
320
345
|
|
|
@@ -331,7 +356,7 @@ function SelectionFilter() {
|
|
|
331
356
|
} else if (urlCustomerId) {
|
|
332
357
|
dispatch({
|
|
333
358
|
type: 'SET_CLIENT_FILTER',
|
|
334
|
-
payload:
|
|
359
|
+
payload: getFilterPayload(),
|
|
335
360
|
});
|
|
336
361
|
setSelectedClient(+urlCustomerId);
|
|
337
362
|
dispatch({
|
|
@@ -339,7 +364,7 @@ function SelectionFilter() {
|
|
|
339
364
|
payload: 1,
|
|
340
365
|
});
|
|
341
366
|
}
|
|
342
|
-
}, [urlCustomerId]);
|
|
367
|
+
}, [urlCustomerId, customers]);
|
|
343
368
|
|
|
344
369
|
const handleClearAction = () => {
|
|
345
370
|
dispatch({ type: 'CLEAR_ACTION' });
|
|
@@ -362,7 +387,7 @@ function SelectionFilter() {
|
|
|
362
387
|
placeholder="Select Client Name"
|
|
363
388
|
onChange={handleClientChange}
|
|
364
389
|
style={{ minWidth: '250px' }}
|
|
365
|
-
value={selectedClient}
|
|
390
|
+
value={clientOptions?.length > 0 ? selectedClient || undefined : undefined}
|
|
366
391
|
allowClear
|
|
367
392
|
onClear={handleClear}
|
|
368
393
|
filterOption={(input: any, option: any) =>
|
|
@@ -380,7 +405,7 @@ function SelectionFilter() {
|
|
|
380
405
|
<StyledAntSelect
|
|
381
406
|
options={actionTypeOptions}
|
|
382
407
|
placeholder="Select Action Type"
|
|
383
|
-
value={selectedFilterValue}
|
|
408
|
+
value={actionTypeOptions?.length > 0 ? selectedFilterValue || undefined : undefined}
|
|
384
409
|
onChange={handleActionClick}
|
|
385
410
|
style={{ minWidth: '200px' }}
|
|
386
411
|
allowClear
|
|
@@ -392,7 +417,7 @@ function SelectionFilter() {
|
|
|
392
417
|
<Label>Location </Label>
|
|
393
418
|
<StyledAntSelect
|
|
394
419
|
options={locationOptions}
|
|
395
|
-
value={selectedLocationValue}
|
|
420
|
+
value={locationOptions?.length > 0 ? selectedLocationValue || undefined : undefined}
|
|
396
421
|
placeholder="Select Location"
|
|
397
422
|
onChange={handleLocationChange}
|
|
398
423
|
style={{ minWidth: '200px' }}
|
|
@@ -64,7 +64,7 @@ const filterReducer = (state: FilterState, action: any): FilterState => {
|
|
|
64
64
|
...state['x-filters'].filter(f => f.field !== 'customer_id'),
|
|
65
65
|
{
|
|
66
66
|
field: 'customer_id',
|
|
67
|
-
op: '=',
|
|
67
|
+
op: Array?.isArray(action?.payload) ? 'in' : '=',
|
|
68
68
|
value: action.payload,
|
|
69
69
|
},
|
|
70
70
|
],
|
|
@@ -57,7 +57,7 @@ function ReturnMainTable() {
|
|
|
57
57
|
const { data: fetchedCustomerData, loading: loading, fetchData } = useAxios<
|
|
58
58
|
ApiResponse
|
|
59
59
|
>({
|
|
60
|
-
endpoint: `/v1/return/product/customers
|
|
60
|
+
endpoint: `/v1/return/product/customers/?grouped=true`,
|
|
61
61
|
method: 'GET',
|
|
62
62
|
//@ts-ignore
|
|
63
63
|
pagination: { is_pagination: false },
|