@bjsdistribution/dms-client-return 0.1.16-prod → 0.1.17-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/common/date-picker/header/ClearDate.d.ts +1 -1
- package/dist/components/client-portal/DateFilterStore.d.ts +15 -0
- package/dist/components/client-portal/ReturnRTFilters.d.ts +3 -0
- package/dist/components/order-daily-overview/header/route-header/ClientRouterHeader.d.ts +11 -0
- package/dist/components/order-daily-overview/table-view/TableStyle.d.ts +4 -4
- package/dist/components/order-view/order-actions/types.d.ts +2 -2
- package/dist/components/order-view/types.d.ts +6 -0
- package/dist/components/order-view/utils.d.ts +8 -2
- package/dist/components/order-view/view-reminder/ViewReminder.d.ts +2 -0
- package/dist/dms-client-return.cjs.development.js +1780 -2272
- 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 +1838 -2330
- package/dist/dms-client-return.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/client-portal/DateFilterStore.ts +139 -0
- package/src/components/client-portal/OutstandingTable.tsx +16 -72
- package/src/components/client-portal/ReturnAfterSearchBar.tsx +42 -87
- package/src/components/client-portal/ReturnOverview.tsx +11 -2
- package/src/components/client-portal/ReturnRTFilters.tsx +140 -43
- package/src/components/client-portal/ReturnSearchBar.tsx +42 -153
- package/src/components/client-portal/ReturnStatus.tsx +30 -66
- package/src/components/client-portal/return-confirm/ConfirmedMain.tsx +12 -23
- package/src/components/client-portal/return-confirm/ReturnConfirmedTable.tsx +9 -86
- package/src/components/order-daily-overview/header/route-header/ClientRouterHeader.tsx +166 -0
- package/src/components/order-daily-overview/header/route-header/RouterHeader.tsx +2 -86
- package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +5 -2
- package/src/components/order-daily-overview/index.tsx +16 -4
- package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +36 -36
- package/src/components/order-view/notification/ReminderTemplate.tsx +13 -5
- package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +0 -29
- package/src/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.tsx +86 -28
- package/src/components/order-view/order-actions/actions/force-debrief/ForceDebriefModal.tsx +35 -20
- package/src/components/order-view/order-actions/actions/force-debrief/order-info/RadioButtons.tsx +11 -62
- package/src/components/order-view/order-actions/index.tsx +1 -5
- package/src/components/order-view/order-actions/types.ts +2 -2
- package/src/components/order-view/order-details/expanded-content/footer/index.tsx +55 -80
- package/src/components/order-view/order-details/expanded-content/services-section/AssemblyType.tsx +9 -91
- package/src/components/order-view/order-details/expanded-content/services-section/OrderServices.tsx +10 -182
- package/src/components/order-view/store.ts +6 -0
- package/src/components/order-view/types.ts +6 -0
- package/src/components/order-view/utils.ts +0 -33
- package/src/components/order-view/view-reminder/AssigneeDropdown.tsx +85 -26
- package/src/components/order-view/view-reminder/ViewReminder.tsx +33 -14
- package/src/components/store.ts +1 -1
- package/src/index.tsx +17 -2
- package/dist/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.d.ts +0 -7
- package/dist/components/order-view/order-actions/actions/log-service-refusal/Notes.d.ts +0 -7
- package/dist/components/order-view/order-actions/actions/log-service-refusal/OrderServices.d.ts +0 -7
- package/dist/components/order-view/order-actions/actions/log-service-refusal/helper.d.ts +0 -3
- package/dist/components/order-view/order-actions/actions/log-service-refusal/index.d.ts +0 -3
- package/src/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.tsx +0 -50
- package/src/components/order-view/order-actions/actions/log-service-refusal/Notes.tsx +0 -50
- package/src/components/order-view/order-actions/actions/log-service-refusal/OrderServices.tsx +0 -57
- package/src/components/order-view/order-actions/actions/log-service-refusal/helper.ts +0 -26
- package/src/components/order-view/order-actions/actions/log-service-refusal/index.tsx +0 -130
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useReturnAfterOrderData,
|
|
6
|
-
useReturnData,
|
|
7
|
-
} from '../order-view/store';
|
|
8
|
-
import { filtersReducerAtom } from '../order-daily-overview/header-filters/filterStore';
|
|
9
|
-
import { ExportButton, useAxios } from '@bjsdistribution/dms-component-library';
|
|
3
|
+
import { useAtom } from '../order-view/store';
|
|
4
|
+
import { useAxios } from '@bjsdistribution/dms-component-library';
|
|
10
5
|
import { useParams } from 'react-router-dom';
|
|
11
|
-
import { filtersReducerReturnAtom } from '../order-daily-overview/return-after-table/table-filters/ReturnFilterStore';
|
|
12
|
-
import { notification } from 'antd';
|
|
6
|
+
// import { filtersReducerReturnAtom } from '../order-daily-overview/return-after-table/table-filters/ReturnFilterStore';
|
|
7
|
+
import { notification, Spin } from 'antd';
|
|
13
8
|
import {
|
|
9
|
+
useClientOutstandingReturnData,
|
|
10
|
+
useReturnConfirmedOrderData,
|
|
14
11
|
useSelectedClientAfterOrders,
|
|
15
12
|
useSelectedClientPortOrders,
|
|
16
|
-
// useSelectedClientPortOrders,
|
|
17
13
|
} from '../store';
|
|
14
|
+
import { dateFilterCPReducer } from './DateFilterStore';
|
|
18
15
|
|
|
19
16
|
const ReturnRTFilters = () => {
|
|
20
|
-
const [
|
|
21
|
-
const [
|
|
22
|
-
const [state] = useAtom(filtersReducerReturnAtom);
|
|
23
|
-
const [returnAfterOrder] = useReturnAfterOrderData();
|
|
24
|
-
// const [selectedReturnOrder] = useSelectedClientPortOrders();
|
|
17
|
+
const [outstandingReturnData] = useClientOutstandingReturnData();
|
|
18
|
+
const [returnConfirmedData] = useReturnConfirmedOrderData();
|
|
25
19
|
const [
|
|
26
20
|
selectedOrderIds,
|
|
27
21
|
setSelectedOrderIds,
|
|
@@ -31,32 +25,102 @@ const ReturnRTFilters = () => {
|
|
|
31
25
|
setSelectedPendingOrderIds,
|
|
32
26
|
] = useSelectedClientPortOrders();
|
|
33
27
|
const { status } = useParams<{ status: any }>();
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
28
|
+
const [spinLoading, setSpinLoading] = useState<boolean>(false);
|
|
29
|
+
const [state] = useAtom(dateFilterCPReducer);
|
|
30
|
+
const { 'x-filters': filters } = state;
|
|
31
|
+
|
|
32
|
+
//export csv
|
|
33
|
+
const { fetchData: callExportCSV } = useAxios<{
|
|
34
|
+
data: any[];
|
|
35
|
+
message: string;
|
|
36
|
+
}>({
|
|
37
|
+
endpoint: `/v1/export/generate/`,
|
|
38
|
+
method: 'POST',
|
|
39
|
+
});
|
|
40
|
+
const { fetchData: downloadFile } = useAxios({
|
|
41
|
+
endpoint: '/v1/export/download/',
|
|
42
|
+
method: 'POST',
|
|
43
|
+
});
|
|
44
|
+
const download: any = (response: any) => {
|
|
45
|
+
downloadFile({
|
|
46
|
+
endPointQuery: `${response?.data?.file_reference}`,
|
|
47
|
+
})
|
|
48
|
+
.then((response: any) => {
|
|
49
|
+
if (response?.data?.url) {
|
|
50
|
+
window.open(response?.data?.url, '_blank');
|
|
51
|
+
}
|
|
52
|
+
setSpinLoading(false);
|
|
53
|
+
})
|
|
54
|
+
.catch((err: any) => {
|
|
55
|
+
notification.error({
|
|
56
|
+
message: 'Failed to download file',
|
|
57
|
+
description: err,
|
|
58
|
+
});
|
|
59
|
+
setSpinLoading(false);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleExportCSV = () => {
|
|
64
|
+
let moduleInfo: any | null = null;
|
|
65
|
+
const url =
|
|
66
|
+
process.env.REACT_APP_API_PATH ||
|
|
67
|
+
'https://development.dmsbackend.bjshomedelivery.com';
|
|
68
|
+
if (status === 'outstanding_return') {
|
|
69
|
+
moduleInfo = {
|
|
70
|
+
isExportedData: outstandingReturnData?.length > 0,
|
|
71
|
+
file_type: 'csv',
|
|
72
|
+
moduleName: 'return',
|
|
73
|
+
filter: [
|
|
74
|
+
{ field: 'isdeleted', op: '=', value: 0 },
|
|
75
|
+
{ field: 'product_return_action_id', op: '=', value: 'RTS' },
|
|
76
|
+
],
|
|
77
|
+
url: `${url}/v1/return/product/pending/`,
|
|
78
|
+
reference: 'return_outstanding_export',
|
|
79
|
+
feature_name: 'return',
|
|
80
|
+
};
|
|
81
|
+
} else if (['scheduled_for_return', 'return_completed'].includes(status)) {
|
|
82
|
+
moduleInfo = {
|
|
83
|
+
isExportedData: returnConfirmedData?.length > 0,
|
|
84
|
+
file_type: 'csv',
|
|
85
|
+
moduleName: 'return',
|
|
86
|
+
url: `${url}/v1/return/orders/`,
|
|
87
|
+
|
|
88
|
+
reference:
|
|
89
|
+
status === 'scheduled_for_return'
|
|
90
|
+
? 'return_scheduled_export'
|
|
91
|
+
: 'return_completed_export',
|
|
92
|
+
feature_name: 'return',
|
|
93
|
+
filter: filters,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (moduleInfo?.isExportedData) {
|
|
98
|
+
setSpinLoading(true);
|
|
99
|
+
|
|
100
|
+
callExportCSV({
|
|
101
|
+
payload: {
|
|
102
|
+
file_type: moduleInfo?.file_type,
|
|
103
|
+
url: moduleInfo?.url,
|
|
104
|
+
reference: moduleInfo?.reference,
|
|
105
|
+
feature_name: moduleInfo?.feature_name,
|
|
106
|
+
filter: moduleInfo?.filter,
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
.then((res: any) => {
|
|
110
|
+
setTimeout(() => download(res), 10000);
|
|
111
|
+
})
|
|
112
|
+
.catch(err => {
|
|
113
|
+
notification.error({
|
|
114
|
+
message: 'Failed to export csv',
|
|
115
|
+
description: err,
|
|
116
|
+
});
|
|
117
|
+
setSpinLoading(false);
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
notification.warning({ message: 'No data to Export' });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
60
124
|
//Export Manifest
|
|
61
125
|
const isExportEnabled =
|
|
62
126
|
status === 'outstanding_return'
|
|
@@ -135,7 +199,12 @@ const ReturnRTFilters = () => {
|
|
|
135
199
|
|
|
136
200
|
return (
|
|
137
201
|
<StyledBulkFilterCover className="dmsBulkFilter">
|
|
138
|
-
<ExportButton moduleInfoModule={moduleInfo} />
|
|
202
|
+
{/* <ExportButton moduleInfoModule={moduleInfo} /> */}
|
|
203
|
+
<ExportCSVButton type="left" onClick={handleExportCSV}>
|
|
204
|
+
<div className="label">
|
|
205
|
+
Export CSV <Spin spinning={spinLoading} />
|
|
206
|
+
</div>
|
|
207
|
+
</ExportCSVButton>
|
|
139
208
|
<StyledBulkItem
|
|
140
209
|
onClick={handleExportManifest}
|
|
141
210
|
style={{
|
|
@@ -225,4 +294,32 @@ export const StyledBulkItem = styled.div`
|
|
|
225
294
|
padding: 0;
|
|
226
295
|
}
|
|
227
296
|
`;
|
|
297
|
+
|
|
298
|
+
export const ExportCSVButton = styled.div<{
|
|
299
|
+
type: 'left' | 'right' | 'middle';
|
|
300
|
+
}>`
|
|
301
|
+
display: flex;
|
|
302
|
+
background: #fff;
|
|
303
|
+
min-height: 40px;
|
|
304
|
+
padding: 8px 12px;
|
|
305
|
+
align-items: center;
|
|
306
|
+
gap: 8px;
|
|
307
|
+
cursor: pointer;
|
|
308
|
+
border-radius: ${props =>
|
|
309
|
+
props?.type === 'left'
|
|
310
|
+
? '50px 0px 0px 50px'
|
|
311
|
+
: props?.type === 'right'
|
|
312
|
+
? ' 0px 50px 50px 0px'
|
|
313
|
+
: ''};
|
|
314
|
+
border-right: ${props => (props.type === 'right' ? '' : '1px solid #d0d5dd')};
|
|
315
|
+
.label {
|
|
316
|
+
color: #6a7378;
|
|
317
|
+
text-align: center;
|
|
318
|
+
font-family: Lato;
|
|
319
|
+
font-size: 14px;
|
|
320
|
+
font-style: normal;
|
|
321
|
+
font-weight: 500;
|
|
322
|
+
line-height: 18px;
|
|
323
|
+
}
|
|
324
|
+
`;
|
|
228
325
|
export default ReturnRTFilters;
|
|
@@ -8,163 +8,52 @@ import styled from 'styled-components';
|
|
|
8
8
|
import {
|
|
9
9
|
useAtom,
|
|
10
10
|
useClientOutstandingReturnData,
|
|
11
|
-
useClientPortal,
|
|
12
|
-
useEndDate,
|
|
13
11
|
useSearchText,
|
|
14
|
-
useStartDate,
|
|
15
12
|
useStatsCPCount,
|
|
16
13
|
} from '../store';
|
|
17
|
-
import dayjs from 'dayjs';
|
|
18
14
|
import { filtersReducerAtom } from '../order-daily-overview/header-filters/filterStore';
|
|
19
15
|
import { ApiResponse } from '../types';
|
|
20
16
|
import { javascriptStringDumpToJSON } from '../utils';
|
|
21
17
|
import { UsePaginationData } from '../order-daily-overview/store/store';
|
|
22
18
|
import { notification } from 'antd';
|
|
23
|
-
import { useParams } from 'react-router-dom';
|
|
24
19
|
import { returnCountType } from './ReturnStatus';
|
|
20
|
+
import { dateFilterCPReducer } from './DateFilterStore';
|
|
25
21
|
|
|
26
22
|
function ReturnSearchBar() {
|
|
27
23
|
const [searchText, setSearchText] = useState('');
|
|
28
24
|
const [debouncedSearchText, setDebouncedSearchText] = useSearchText();
|
|
29
|
-
const [modifiedFilters, setModifiedFilters] = useState<any[]>([]);
|
|
30
25
|
const [, setOutstandingData] = useClientOutstandingReturnData();
|
|
31
|
-
const { status } = useParams();
|
|
32
|
-
//condition on client view
|
|
33
|
-
const [clientPortal] = useClientPortal();
|
|
34
26
|
const [, setPaginationObject] = UsePaginationData();
|
|
35
27
|
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
36
28
|
setSearchText(event.target.value);
|
|
37
29
|
};
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const [
|
|
41
|
-
const [state] = useAtom(filtersReducerAtom);
|
|
30
|
+
const [state] = useAtom(dateFilterCPReducer);
|
|
31
|
+
const { 'x-filters': filters } = state;
|
|
32
|
+
const [statePagination] = useAtom(filtersReducerAtom);
|
|
42
33
|
const [, setCount] = useStatsCPCount();
|
|
43
|
-
const
|
|
34
|
+
const { 'x-pagination': pagination } = statePagination;
|
|
44
35
|
|
|
45
|
-
const
|
|
36
|
+
const baseFilters = [
|
|
37
|
+
{ field: 'isdeleted', op: '=', value: 0 },
|
|
38
|
+
{ field: 'product_return_action_id', op: '=', value: 'RTS' },
|
|
39
|
+
];
|
|
40
|
+
const cleanedFilters = filters.filter(f => f.field !== 'order_status');
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!isClientOutstanding) return;
|
|
50
|
-
|
|
51
|
-
setModifiedFilters([
|
|
52
|
-
{ field: 'isdeleted', op: '=', value: 0 },
|
|
53
|
-
{ field: 'product_return_action_id', op: '=', value: 'RTS' },
|
|
54
|
-
]);
|
|
55
|
-
}, []);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (!clientPortal) return;
|
|
59
|
-
|
|
60
|
-
const stored = JSON.parse(localStorage.getItem('returnDate') || '{}');
|
|
61
|
-
|
|
62
|
-
const sDate = startDate?.isValid?.() ? startDate : dayjs(stored?.startDate);
|
|
63
|
-
const eDate = endDate?.isValid?.()
|
|
64
|
-
? endDate
|
|
65
|
-
: stored?.endDate
|
|
66
|
-
? dayjs(stored?.endDate)
|
|
67
|
-
: null;
|
|
68
|
-
|
|
69
|
-
if (!sDate?.isValid?.()) return;
|
|
70
|
-
|
|
71
|
-
let dateFilters = [];
|
|
72
|
-
|
|
73
|
-
if (eDate && eDate.isValid()) {
|
|
74
|
-
dateFilters = [
|
|
75
|
-
{ field: 'created_at', op: '>=', value: sDate.format('YYYY-MM-DD') },
|
|
76
|
-
{
|
|
77
|
-
field: 'created_at',
|
|
78
|
-
op: '<=',
|
|
79
|
-
value: eDate.add(1, 'day').format('YYYY-MM-DD'),
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
} else {
|
|
83
|
-
dateFilters = [
|
|
84
|
-
{
|
|
85
|
-
field: 'created_at',
|
|
86
|
-
op: '=',
|
|
87
|
-
value: sDate.format('YYYY-MM-DD'),
|
|
88
|
-
},
|
|
89
|
-
];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const updatedFilters =
|
|
93
|
-
status === 'outstanding_return'
|
|
94
|
-
? [
|
|
95
|
-
{ field: 'isdeleted', op: '=', value: 0 },
|
|
96
|
-
{ field: 'product_return_action_id', op: '=', value: 'RTS' },
|
|
97
|
-
...dateFilters,
|
|
98
|
-
]
|
|
99
|
-
: dateFilters;
|
|
100
|
-
|
|
101
|
-
setModifiedFilters(updatedFilters);
|
|
102
|
-
}, [startDate, endDate, status]);
|
|
103
|
-
|
|
104
|
-
//For stats
|
|
105
|
-
|
|
106
|
-
const getDateFilters = (
|
|
107
|
-
startDate: dayjs.Dayjs | null,
|
|
108
|
-
endDate: dayjs.Dayjs | null
|
|
109
|
-
) => {
|
|
110
|
-
const stored = JSON.parse(localStorage.getItem('returnDate') || '{}');
|
|
111
|
-
|
|
112
|
-
const sDate = startDate?.isValid?.() ? startDate : dayjs(stored?.startDate);
|
|
113
|
-
const eDate = endDate?.isValid?.()
|
|
114
|
-
? endDate
|
|
115
|
-
: stored?.endDate
|
|
116
|
-
? dayjs(stored?.endDate)
|
|
117
|
-
: null;
|
|
118
|
-
|
|
119
|
-
if (!sDate?.isValid?.()) return [];
|
|
120
|
-
|
|
121
|
-
let dateFilters = [];
|
|
122
|
-
|
|
123
|
-
if (eDate && eDate.isValid()) {
|
|
124
|
-
dateFilters = [
|
|
125
|
-
{ field: 'created_at', op: '>=', value: sDate.format('YYYY-MM-DD') },
|
|
126
|
-
{
|
|
127
|
-
field: 'created_at',
|
|
128
|
-
op: '<=',
|
|
129
|
-
value: eDate.add(1, 'day').format('YYYY-MM-DD'),
|
|
130
|
-
},
|
|
131
|
-
];
|
|
132
|
-
} else {
|
|
133
|
-
dateFilters = [
|
|
134
|
-
{
|
|
135
|
-
field: 'created_at',
|
|
136
|
-
op: '=',
|
|
137
|
-
value: sDate.format('YYYY-MM-DD'),
|
|
138
|
-
},
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return dateFilters;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
if (!clientPortal) return;
|
|
147
|
-
|
|
148
|
-
const dateFilters = getDateFilters(startDate, endDate);
|
|
149
|
-
setModifiedStatsFilters(dateFilters);
|
|
150
|
-
}, [startDate, endDate]);
|
|
151
|
-
|
|
152
|
-
const {
|
|
153
|
-
// loading,
|
|
154
|
-
paginationData,
|
|
155
|
-
fetchData: getPendingData,
|
|
156
|
-
// data: fetchedReturnOrderData,
|
|
157
|
-
} = useAxios<ApiResponse>({
|
|
42
|
+
const modifiedFilters = [...baseFilters, ...cleanedFilters];
|
|
43
|
+
const { paginationData, fetchData: getPendingData } = useAxios<ApiResponse>({
|
|
158
44
|
endpoint: '/v1/return/product/pending/',
|
|
159
45
|
method: 'GET',
|
|
160
46
|
filters: modifiedFilters,
|
|
161
47
|
pagination: pagination,
|
|
162
48
|
});
|
|
163
49
|
|
|
50
|
+
// Debouncing effect
|
|
164
51
|
useEffect(() => {
|
|
165
|
-
|
|
52
|
+
const trimmedText = debouncedSearchText?.trim() || '';
|
|
53
|
+
|
|
54
|
+
if (trimmedText.length > 2) {
|
|
166
55
|
getPendingData({
|
|
167
|
-
endPointQuery: `?search_term=${
|
|
56
|
+
endPointQuery: `?search_term=${trimmedText}`,
|
|
168
57
|
}).then((response: any) => {
|
|
169
58
|
if (paginationData) {
|
|
170
59
|
const formattedPagination = javascriptStringDumpToJSON(
|
|
@@ -175,22 +64,18 @@ function ReturnSearchBar() {
|
|
|
175
64
|
}
|
|
176
65
|
|
|
177
66
|
if (response?.data?.length > 0) {
|
|
178
|
-
setOutstandingData(response
|
|
67
|
+
setOutstandingData(response.data);
|
|
179
68
|
} else {
|
|
180
69
|
setOutstandingData([]);
|
|
181
70
|
}
|
|
182
71
|
});
|
|
183
|
-
} else if (
|
|
184
|
-
debouncedSearchText?.length > 0 &&
|
|
185
|
-
debouncedSearchText?.length <= 2
|
|
186
|
-
) {
|
|
72
|
+
} else if (trimmedText.length > 0 && trimmedText.length <= 2) {
|
|
187
73
|
notification.warning({
|
|
188
|
-
message: 'Search
|
|
74
|
+
message: 'Search phrase cannot be less than 2 characters',
|
|
189
75
|
});
|
|
190
76
|
}
|
|
191
|
-
}, [debouncedSearchText]);
|
|
77
|
+
}, [debouncedSearchText, JSON.stringify(modifiedFilters)]);
|
|
192
78
|
|
|
193
|
-
// Debouncing effect
|
|
194
79
|
useEffect(() => {
|
|
195
80
|
const handler = setTimeout(() => {
|
|
196
81
|
setDebouncedSearchText(searchText);
|
|
@@ -205,7 +90,6 @@ function ReturnSearchBar() {
|
|
|
205
90
|
setSearchText('');
|
|
206
91
|
}
|
|
207
92
|
}, [debouncedSearchText]);
|
|
208
|
-
|
|
209
93
|
//
|
|
210
94
|
const { fetchData: fetchStatsData } = useAxios<{
|
|
211
95
|
data: returnCountType[];
|
|
@@ -213,28 +97,33 @@ function ReturnSearchBar() {
|
|
|
213
97
|
endpoint: `v1/portal/return/stats/`,
|
|
214
98
|
method: 'GET',
|
|
215
99
|
pagination: { is_pagination: false },
|
|
216
|
-
filters:
|
|
100
|
+
filters: [...cleanedFilters],
|
|
217
101
|
});
|
|
218
102
|
|
|
219
103
|
useEffect(() => {
|
|
220
|
-
const
|
|
221
|
-
if (!isClientOutstanding || debouncedSearchText?.length < 3) return;
|
|
104
|
+
const trimmedText = debouncedSearchText?.trim() || '';
|
|
222
105
|
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (response?.data) {
|
|
106
|
+
if (trimmedText.length > 2) {
|
|
107
|
+
const fetchStats = async () => {
|
|
108
|
+
const response = await fetchStatsData({
|
|
109
|
+
endPointQuery: `?search_term=${trimmedText}&type=outstanding`,
|
|
110
|
+
});
|
|
229
111
|
//@ts-ignore
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
112
|
+
if (response?.data) {
|
|
113
|
+
//@ts-ignore
|
|
114
|
+
setCount(response?.data);
|
|
115
|
+
} else {
|
|
116
|
+
setCount(null);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
235
119
|
|
|
236
|
-
|
|
237
|
-
|
|
120
|
+
fetchStats();
|
|
121
|
+
} else if (trimmedText.length > 0 && trimmedText.length <= 2) {
|
|
122
|
+
notification.warning({
|
|
123
|
+
message: 'Search phrase cannot be less than 3 characters',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, [debouncedSearchText, JSON.stringify(modifiedFilters)]);
|
|
238
127
|
|
|
239
128
|
const handleClear = () => {
|
|
240
129
|
setSearchText('');
|
|
@@ -3,21 +3,19 @@ import {
|
|
|
3
3
|
device,
|
|
4
4
|
useAxios,
|
|
5
5
|
} from '@bjsdistribution/dms-component-library';
|
|
6
|
-
import React, { useEffect
|
|
6
|
+
import React, { useEffect } from 'react';
|
|
7
7
|
import styled from 'styled-components';
|
|
8
8
|
import {
|
|
9
9
|
useActiveCardId,
|
|
10
10
|
useAtom,
|
|
11
11
|
useClientPortal,
|
|
12
|
-
useEndDate,
|
|
13
12
|
useSearchAfterText,
|
|
14
13
|
useSearchText,
|
|
15
|
-
useStartDate,
|
|
16
14
|
useStatsCPCount,
|
|
17
15
|
} from '../store';
|
|
18
16
|
import { useNavigate, useParams } from 'react-router-dom';
|
|
19
|
-
import {
|
|
20
|
-
import dayjs from 'dayjs';
|
|
17
|
+
import { dateFilterCPReducer } from './DateFilterStore';
|
|
18
|
+
// import dayjs from 'dayjs';
|
|
21
19
|
export type returnCountType = {
|
|
22
20
|
outstanding_count: number | null;
|
|
23
21
|
scheduled_count: number;
|
|
@@ -31,55 +29,21 @@ const ReturnStatus = () => {
|
|
|
31
29
|
completed_count: number;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
// const [count, setCount] = useState<returnCountType[] | undefined>();
|
|
35
32
|
const [activeCardId, setActiveCardId] = useActiveCardId();
|
|
36
|
-
const [, dispatch] = useAtom(
|
|
33
|
+
const [state, dispatch] = useAtom(dateFilterCPReducer);
|
|
34
|
+
const { 'x-filters': filters } = state;
|
|
37
35
|
const { status } = useParams();
|
|
36
|
+
const navigate = useNavigate();
|
|
38
37
|
const [count, setCount] = useStatsCPCount();
|
|
39
|
-
const [startDate] = useStartDate();
|
|
40
|
-
const [endDate] = useEndDate();
|
|
41
38
|
const [clientPortal] = useClientPortal();
|
|
42
|
-
const [debouncedSearchText] = useSearchText();
|
|
43
|
-
const [debouncedSearchAfterText] = useSearchAfterText();
|
|
44
|
-
|
|
45
|
-
//stats API
|
|
46
|
-
const filters = useMemo(() => {
|
|
47
|
-
if (!clientPortal) return [];
|
|
48
|
-
|
|
49
|
-
const stored = JSON.parse(localStorage.getItem('returnDate') || '{}');
|
|
39
|
+
const [debouncedSearchText, setOutstandingSearch] = useSearchText();
|
|
50
40
|
|
|
51
|
-
|
|
52
|
-
const eDate = endDate?.isValid?.()
|
|
53
|
-
? endDate
|
|
54
|
-
: stored?.endDate
|
|
55
|
-
? dayjs(stored?.endDate)
|
|
56
|
-
: null;
|
|
41
|
+
const cleanedFilters = filters.filter(f => f.field !== 'order_status');
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (eDate && eDate.isValid()) {
|
|
63
|
-
dateFilters = [
|
|
64
|
-
{ field: 'created_at', op: '>=', value: sDate.format('YYYY-MM-DD') },
|
|
65
|
-
{
|
|
66
|
-
field: 'created_at',
|
|
67
|
-
op: '<=',
|
|
68
|
-
value: eDate.add(1, 'day').format('YYYY-MM-DD'),
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
} else {
|
|
72
|
-
dateFilters = [
|
|
73
|
-
{
|
|
74
|
-
field: 'created_at',
|
|
75
|
-
op: '=',
|
|
76
|
-
value: sDate.format('YYYY-MM-DD'),
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return [...dateFilters];
|
|
82
|
-
}, [startDate, endDate, status]);
|
|
43
|
+
const [
|
|
44
|
+
debouncedSearchAfterText,
|
|
45
|
+
setDebouncedSearchText,
|
|
46
|
+
] = useSearchAfterText();
|
|
83
47
|
const { data: statsData, loading: apiLoading, fetchData } = useAxios<{
|
|
84
48
|
data: returnCountType[];
|
|
85
49
|
}>({
|
|
@@ -87,31 +51,29 @@ const ReturnStatus = () => {
|
|
|
87
51
|
method: 'GET',
|
|
88
52
|
//@ts-ignore
|
|
89
53
|
pagination: { is_pagination: false },
|
|
90
|
-
filters:
|
|
54
|
+
filters: cleanedFilters,
|
|
91
55
|
});
|
|
92
56
|
|
|
93
|
-
const prevSearchTextRef = useRef('');
|
|
94
|
-
const prevSearchAfterTextRef = useRef('');
|
|
95
|
-
|
|
96
57
|
useEffect(() => {
|
|
97
|
-
|
|
98
|
-
|
|
58
|
+
if (
|
|
59
|
+
clientPortal &&
|
|
60
|
+
debouncedSearchText === '' &&
|
|
61
|
+
status == 'outstanding_return'
|
|
62
|
+
) {
|
|
99
63
|
fetchData();
|
|
100
64
|
}
|
|
101
|
-
|
|
102
|
-
}, [debouncedSearchText, startDate, endDate]);
|
|
65
|
+
}, [debouncedSearchText, debouncedSearchAfterText, JSON.stringify(filters)]);
|
|
103
66
|
|
|
104
67
|
useEffect(() => {
|
|
105
|
-
|
|
106
|
-
|
|
68
|
+
if (
|
|
69
|
+
(clientPortal &&
|
|
70
|
+
debouncedSearchAfterText === '' &&
|
|
71
|
+
status == 'scheduled_for_return') ||
|
|
72
|
+
status == 'return_completed'
|
|
73
|
+
) {
|
|
107
74
|
fetchData();
|
|
108
75
|
}
|
|
109
|
-
|
|
110
|
-
}, [debouncedSearchAfterText, startDate, endDate]);
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
fetchData();
|
|
114
|
-
}, [startDate, endDate]);
|
|
76
|
+
}, [debouncedSearchAfterText, debouncedSearchText, JSON.stringify(filters)]);
|
|
115
77
|
|
|
116
78
|
useEffect(() => {
|
|
117
79
|
if (statsData && statsData?.data) {
|
|
@@ -143,15 +105,17 @@ const ReturnStatus = () => {
|
|
|
143
105
|
label: 'Return Completed',
|
|
144
106
|
},
|
|
145
107
|
];
|
|
146
|
-
const navigate = useNavigate();
|
|
147
|
-
const [, setDebouncedSearchText] = useSearchAfterText();
|
|
148
108
|
|
|
149
109
|
const handleCardClick = (item: any) => {
|
|
150
110
|
if (activeCardId === item?.id) {
|
|
151
111
|
return;
|
|
152
112
|
}
|
|
153
113
|
setActiveCardId(item?.id);
|
|
114
|
+
//for dev
|
|
154
115
|
navigate(`/return/${item?.status}`);
|
|
116
|
+
//for local
|
|
117
|
+
//navigate(`/${item?.status}`);
|
|
118
|
+
setOutstandingSearch('');
|
|
155
119
|
setDebouncedSearchText('');
|
|
156
120
|
if (item?.status == 'scheduled_for_return') {
|
|
157
121
|
dispatch({
|