@bjsdistribution/dms-client-return 0.1.9-prod → 0.1.10-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.
Files changed (135) hide show
  1. package/dist/components/client-portal/OutstandingTable.d.ts +3 -0
  2. package/dist/components/client-portal/ReturnAfterSearchBar.d.ts +4 -0
  3. package/dist/components/client-portal/ReturnOverview.d.ts +3 -0
  4. package/dist/components/client-portal/ReturnRTFilters.d.ts +5 -0
  5. package/dist/components/client-portal/ReturnSearchBar.d.ts +4 -0
  6. package/dist/components/client-portal/ReturnStatus.d.ts +8 -0
  7. package/dist/components/client-portal/return-confirm/ConfirmedMain.d.ts +3 -0
  8. package/dist/components/client-portal/return-confirm/ReturnConfirmedTable.d.ts +3 -0
  9. package/dist/components/order-daily-overview/common/fakedata.d.ts +1 -0
  10. package/dist/components/order-daily-overview/header/route-header/RouterHeader.d.ts +1 -0
  11. package/dist/components/order-view/notes/AddNote.d.ts +1 -0
  12. package/dist/components/order-view/notes/order-dropdown/NewReturnDropdown.d.ts +3 -0
  13. package/dist/components/order-view/order-actions/actions/clear-booking-status/ClearBookingStatus.d.ts +4 -1
  14. package/dist/components/order-view/order-actions/actions/confirm-order/index.d.ts +4 -1
  15. package/dist/components/order-view/order-actions/actions/force-debrief/BaseChargeConfirmationModal.d.ts +7 -0
  16. package/dist/components/order-view/order-actions/actions/force-debrief/ForceDebriefModal.d.ts +11 -0
  17. package/dist/components/order-view/order-actions/actions/force-debrief/Selector.d.ts +11 -0
  18. package/dist/components/order-view/order-actions/actions/force-debrief/charges/adhoc/index.d.ts +3 -0
  19. package/dist/components/order-view/order-actions/actions/force-debrief/charges/base-charge/index.d.ts +8 -0
  20. package/dist/components/order-view/order-actions/actions/force-debrief/charges/collection-add-ons/index.d.ts +7 -0
  21. package/dist/components/order-view/order-actions/actions/force-debrief/charges/delivery-add-ons/index.d.ts +7 -0
  22. package/dist/components/order-view/order-actions/actions/force-debrief/charges/disposal-charges/index.d.ts +7 -0
  23. package/dist/components/order-view/order-actions/actions/force-debrief/charges/order-charges/index.d.ts +7 -0
  24. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/EscalationCategory.d.ts +3 -0
  25. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/EscalationLevel.d.ts +3 -0
  26. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/EscalationReason.d.ts +3 -0
  27. package/dist/components/order-view/order-actions/actions/force-debrief/escalation/index.d.ts +3 -0
  28. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/FlagsTemplate.d.ts +3 -0
  29. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/OrderTemplate.d.ts +3 -0
  30. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/Tabs.d.ts +3 -0
  31. package/dist/components/order-view/order-actions/actions/force-debrief/notifications/index.d.ts +3 -0
  32. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/RadioButtons.d.ts +7 -0
  33. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/CancellationReasonDropdown.d.ts +3 -0
  34. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/FailureReasonDropdown.d.ts +3 -0
  35. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/OrderHoldReasonDropdown.d.ts +3 -0
  36. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/StatusDropdown.d.ts +3 -0
  37. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/ZoneDropdown.d.ts +3 -0
  38. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/failure-content/index.d.ts +3 -0
  39. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/index.d.ts +4 -0
  40. package/dist/components/order-view/order-actions/actions/force-debrief/order-info/success-content/index.d.ts +3 -0
  41. package/dist/components/order-view/order-actions/actions/force-debrief/styles.d.ts +8 -0
  42. package/dist/components/order-view/order-actions/actions/hold-order/HoldOrderModal.d.ts +1 -0
  43. package/dist/components/order-view/order-actions/actions/remove-from-route/RemoveFromRoute.d.ts +1 -1
  44. package/dist/components/order-view/order-actions/actions/unhold-order/UnholdOrder.d.ts +1 -0
  45. package/dist/components/order-view/products-info/expanded-content/index.d.ts +4 -1
  46. package/dist/components/order-view/return-client-products/ProductTable.d.ts +4 -1
  47. package/dist/components/order-view/return-client-products/product-table/ReturnProductTable.d.ts +4 -1
  48. package/dist/components/order-view/store.d.ts +14 -2
  49. package/dist/components/order-view/types.d.ts +49 -1
  50. package/dist/components/order-view/utils.d.ts +3 -0
  51. package/dist/components/store.d.ts +12 -1
  52. package/dist/components/utils.d.ts +1 -0
  53. package/dist/dms-client-return.cjs.development.js +7053 -2711
  54. package/dist/dms-client-return.cjs.development.js.map +1 -1
  55. package/dist/dms-client-return.cjs.production.min.js +1 -1
  56. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  57. package/dist/dms-client-return.esm.js +7111 -2769
  58. package/dist/dms-client-return.esm.js.map +1 -1
  59. package/package.json +6 -4
  60. package/src/assets/icons/ActionIcon.tsx +1 -1
  61. package/src/assets/icons/ArrowDownIcon.tsx +2 -2
  62. package/src/components/client-portal/OutstandingTable.tsx +412 -0
  63. package/src/components/client-portal/ReturnAfterSearchBar.tsx +242 -0
  64. package/src/components/client-portal/ReturnOverview.tsx +185 -0
  65. package/src/components/client-portal/ReturnRTFilters.tsx +228 -0
  66. package/src/components/client-portal/ReturnSearchBar.tsx +294 -0
  67. package/src/components/client-portal/ReturnStatus.tsx +252 -0
  68. package/src/components/client-portal/return-confirm/ConfirmedMain.tsx +235 -0
  69. package/src/components/client-portal/return-confirm/ReturnConfirmedTable.tsx +404 -0
  70. package/src/components/order-daily-overview/common/fakedata.tsx +18 -0
  71. package/src/components/order-daily-overview/header/route-header/RouterHeader.tsx +130 -1
  72. package/src/components/order-daily-overview/header-filters/HeaderFilter.tsx +15 -3
  73. package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +100 -70
  74. package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +4 -0
  75. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +86 -0
  76. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +12 -2
  77. package/src/components/order-daily-overview/return-after-table/table-filters/TableFilters.tsx +22 -1
  78. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnFilter.tsx +34 -6
  79. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +24 -11
  80. package/src/components/order-daily-overview/return-order-table/return-orders-filters/RightFilters.tsx +26 -6
  81. package/src/components/order-daily-overview/shared/elements/PrintDropDown.tsx +5 -3
  82. package/src/components/order-view/details-filters/left-side-filters/dropdowns/OptionsDropDown.tsx +5 -0
  83. package/src/components/order-view/details-filters/right-side-filters/Details.tsx +28 -3
  84. package/src/components/order-view/generic-table/AuditLogs.tsx +39 -12
  85. package/src/components/order-view/index.tsx +45 -0
  86. package/src/components/order-view/notes/AddNote.tsx +94 -65
  87. package/src/components/order-view/notes/order-dropdown/NewReturnDropdown.tsx +8 -10
  88. package/src/components/order-view/notification/OrderTemplate.tsx +192 -41
  89. package/src/components/order-view/order-actions/actions/cancel-order/ReturnAction.tsx +25 -4
  90. package/src/components/order-view/order-actions/actions/cancel-order/ReturnReason.tsx +24 -4
  91. package/src/components/order-view/order-actions/actions/clear-booking-status/ClearBookingStatus.tsx +9 -2
  92. package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +12 -6
  93. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.tsx +2 -2
  94. package/src/components/order-view/order-actions/actions/force-debrief/BaseChargeConfirmationModal.tsx +94 -0
  95. package/src/components/order-view/order-actions/actions/force-debrief/ForceDebriefModal.tsx +620 -0
  96. package/src/components/order-view/order-actions/actions/force-debrief/Selector.tsx +65 -0
  97. package/src/components/order-view/order-actions/actions/force-debrief/charges/adhoc/index.tsx +94 -0
  98. package/src/components/order-view/order-actions/actions/force-debrief/charges/base-charge/index.tsx +106 -0
  99. package/src/components/order-view/order-actions/actions/force-debrief/charges/collection-add-ons/index.tsx +77 -0
  100. package/src/components/order-view/order-actions/actions/force-debrief/charges/delivery-add-ons/index.tsx +78 -0
  101. package/src/components/order-view/order-actions/actions/force-debrief/charges/disposal-charges/index.tsx +77 -0
  102. package/src/components/order-view/order-actions/actions/force-debrief/charges/order-charges/index.tsx +124 -0
  103. package/src/components/order-view/order-actions/actions/force-debrief/escalation/EscalationCategory.tsx +92 -0
  104. package/src/components/order-view/order-actions/actions/force-debrief/escalation/EscalationLevel.tsx +90 -0
  105. package/src/components/order-view/order-actions/actions/force-debrief/escalation/EscalationReason.tsx +122 -0
  106. package/src/components/order-view/order-actions/actions/force-debrief/escalation/index.tsx +16 -0
  107. package/src/components/order-view/order-actions/actions/force-debrief/notifications/FlagsTemplate.tsx +46 -0
  108. package/src/components/order-view/order-actions/actions/force-debrief/notifications/OrderTemplate.tsx +117 -0
  109. package/src/components/order-view/order-actions/actions/force-debrief/notifications/Tabs.tsx +32 -0
  110. package/src/components/order-view/order-actions/actions/force-debrief/notifications/index.tsx +180 -0
  111. package/src/components/order-view/order-actions/actions/force-debrief/order-info/RadioButtons.tsx +201 -0
  112. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/CancellationReasonDropdown.tsx +40 -0
  113. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/FailureReasonDropdown.tsx +108 -0
  114. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/OrderHoldReasonDropdown.tsx +37 -0
  115. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/StatusDropdown.tsx +48 -0
  116. package/src/components/order-view/order-actions/actions/force-debrief/order-info/dropdowns/ZoneDropdown.tsx +27 -0
  117. package/src/components/order-view/order-actions/actions/force-debrief/order-info/failure-content/index.tsx +187 -0
  118. package/src/components/order-view/order-actions/actions/force-debrief/order-info/index.tsx +55 -0
  119. package/src/components/order-view/order-actions/actions/force-debrief/order-info/success-content/index.tsx +221 -0
  120. package/src/components/order-view/order-actions/actions/force-debrief/styles.tsx +51 -0
  121. package/src/components/order-view/order-actions/actions/hold-order/HoldOrderModal.tsx +2 -0
  122. package/src/components/order-view/order-actions/actions/remove-from-route/RemoveFromRoute.tsx +7 -2
  123. package/src/components/order-view/order-actions/actions/unhold-order/UnholdOrder.tsx +2 -0
  124. package/src/components/order-view/order-actions/index.tsx +15 -3
  125. package/src/components/order-view/order-details/expanded-content/instruction-section/index.tsx +1 -1
  126. package/src/components/order-view/products-info/expanded-content/index.tsx +27 -11
  127. package/src/components/order-view/products-info/index.tsx +4 -4
  128. package/src/components/order-view/return-client-products/ProductTable.tsx +6 -2
  129. package/src/components/order-view/return-client-products/product-table/ReturnProductTable.tsx +54 -15
  130. package/src/components/order-view/store.ts +106 -0
  131. package/src/components/order-view/types.ts +54 -1
  132. package/src/components/order-view/utils.ts +37 -0
  133. package/src/components/store.ts +62 -1
  134. package/src/components/utils.ts +13 -3
  135. package/src/index.tsx +26 -16
@@ -0,0 +1,294 @@
1
+ import {
2
+ CrossIcon,
3
+ SearchIcon,
4
+ useAxios,
5
+ } from '@bjsdistribution/dms-component-library';
6
+ import React, { useEffect, useState } from 'react';
7
+ import styled from 'styled-components';
8
+ import {
9
+ useAtom,
10
+ useClientOutstandingReturnData,
11
+ useClientPortal,
12
+ useEndDate,
13
+ useSearchText,
14
+ useStartDate,
15
+ useStatsCPCount,
16
+ } from '../store';
17
+ import dayjs from 'dayjs';
18
+ import { filtersReducerAtom } from '../order-daily-overview/header-filters/filterStore';
19
+ import { ApiResponse } from '../types';
20
+ import { javascriptStringDumpToJSON } from '../utils';
21
+ import { UsePaginationData } from '../order-daily-overview/store/store';
22
+ import { notification } from 'antd';
23
+ import { useParams } from 'react-router-dom';
24
+ import { returnCountType } from './ReturnStatus';
25
+
26
+ function ReturnSearchBar() {
27
+ const [searchText, setSearchText] = useState('');
28
+ const [debouncedSearchText, setDebouncedSearchText] = useSearchText();
29
+ const [modifiedFilters, setModifiedFilters] = useState<any[]>([]);
30
+ const [, setOutstandingData] = useClientOutstandingReturnData();
31
+ const { status } = useParams();
32
+ //condition on client view
33
+ const [clientPortal] = useClientPortal();
34
+ const [, setPaginationObject] = UsePaginationData();
35
+ const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
36
+ setSearchText(event.target.value);
37
+ };
38
+ //CP
39
+ const [startDate] = useStartDate();
40
+ const [endDate] = useEndDate();
41
+ const [state] = useAtom(filtersReducerAtom);
42
+ const [, setCount] = useStatsCPCount();
43
+ const [modifiedStatsFilters, setModifiedStatsFilters] = useState<any[]>([]);
44
+
45
+ const { 'x-pagination': pagination } = state;
46
+
47
+ useEffect(() => {
48
+ const isClientOutstanding = clientPortal && status === 'outstanding_return';
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>({
158
+ endpoint: '/v1/return/product/pending/',
159
+ method: 'GET',
160
+ filters: modifiedFilters,
161
+ pagination: pagination,
162
+ });
163
+
164
+ useEffect(() => {
165
+ if (debouncedSearchText?.length > 1) {
166
+ getPendingData({
167
+ endPointQuery: `?search_term=${debouncedSearchText}`,
168
+ }).then((response: any) => {
169
+ if (paginationData) {
170
+ const formattedPagination = javascriptStringDumpToJSON(
171
+ paginationData
172
+ );
173
+ const { ...rest } = formattedPagination;
174
+ setPaginationObject(rest);
175
+ }
176
+
177
+ if (response?.data?.length > 0) {
178
+ setOutstandingData(response?.data);
179
+ } else {
180
+ setOutstandingData([]);
181
+ }
182
+ });
183
+ } else if (
184
+ debouncedSearchText?.length > 0 &&
185
+ debouncedSearchText?.length <= 2
186
+ ) {
187
+ notification.warning({
188
+ message: 'Search Phrase cannot be less than 3 characters',
189
+ });
190
+ }
191
+ }, [debouncedSearchText]);
192
+
193
+ // Debouncing effect
194
+ useEffect(() => {
195
+ const handler = setTimeout(() => {
196
+ setDebouncedSearchText(searchText);
197
+ }, 1000);
198
+ return () => {
199
+ clearTimeout(handler);
200
+ };
201
+ }, [searchText]);
202
+
203
+ useEffect(() => {
204
+ if (debouncedSearchText?.length === 0) {
205
+ setSearchText('');
206
+ }
207
+ }, [debouncedSearchText]);
208
+
209
+ //
210
+ const { fetchData: fetchStatsData } = useAxios<{
211
+ data: returnCountType[];
212
+ }>({
213
+ endpoint: `v1/portal/return/stats/`,
214
+ method: 'GET',
215
+ pagination: { is_pagination: false },
216
+ filters: modifiedStatsFilters,
217
+ });
218
+
219
+ useEffect(() => {
220
+ const isClientOutstanding = clientPortal && status === 'outstanding_return';
221
+ if (!isClientOutstanding || debouncedSearchText?.length < 3) return;
222
+
223
+ const fetchStats = async () => {
224
+ const response = await fetchStatsData({
225
+ endPointQuery: `?search_term=${debouncedSearchText}&type=outstanding`,
226
+ });
227
+ //@ts-ignore
228
+ if (response?.data) {
229
+ //@ts-ignore
230
+ setCount(response?.data); // Set the count here
231
+ } else {
232
+ setCount(null); // fallback if no data
233
+ }
234
+ };
235
+
236
+ fetchStats();
237
+ }, [debouncedSearchText, status, clientPortal]);
238
+
239
+ const handleClear = () => {
240
+ setSearchText('');
241
+ };
242
+ return (
243
+ <Search>
244
+ <SearchIcon />
245
+
246
+ <SearchInput
247
+ type="text"
248
+ placeholder="Search"
249
+ value={searchText}
250
+ onChange={handleInputChange}
251
+ />
252
+ {searchText ? (
253
+ <ClearButton className="clear" onClick={handleClear}>
254
+ <CrossIcon />
255
+ </ClearButton>
256
+ ) : null}
257
+ </Search>
258
+ );
259
+ }
260
+
261
+ const ClearButton = styled.button`
262
+ border: none;
263
+ background: none;
264
+ position: relative;
265
+ border: none;
266
+ cursor: pointer;
267
+ padding: 0 4px;
268
+ font-size: 0;
269
+ &:hover {
270
+ color: #000;
271
+ }
272
+ `;
273
+
274
+ const Search = styled.div`
275
+ display: flex;
276
+ padding: 4px 12px;
277
+ align-items: center;
278
+ gap: 8px;
279
+ align-self: stretch;
280
+ border-radius: 20px;
281
+ border: 1px solid var(--Neutral-Gray-Gray-100, #e0e2e7);
282
+ background-color: var(--Flowkit-White, #fff);
283
+ height: 35px;
284
+ box-shadow: 0px 1px 2px 0px rgba(16, 24, 40, 0.05);
285
+ `;
286
+ const SearchInput = styled.input`
287
+ border: none;
288
+ outline: none;
289
+ flex-grow: 1;
290
+ width: 100%;
291
+ background: transparent;
292
+ `;
293
+
294
+ export default React.memo(ReturnSearchBar);
@@ -0,0 +1,252 @@
1
+ import {
2
+ CountItem,
3
+ device,
4
+ useAxios,
5
+ } from '@bjsdistribution/dms-component-library';
6
+ import React, { useEffect, useRef, useState } from 'react';
7
+ import styled from 'styled-components';
8
+ import {
9
+ useActiveCardId,
10
+ useAtom,
11
+ useClientPortal,
12
+ useEndDate,
13
+ useSearchAfterText,
14
+ useSearchText,
15
+ useStartDate,
16
+ useStatsCPCount,
17
+ } from '../store';
18
+ import { useNavigate, useParams } from 'react-router-dom';
19
+ import { filtersReducerReturnAtom } from '../order-daily-overview/return-after-table/table-filters/ReturnFilterStore';
20
+ import dayjs from 'dayjs';
21
+ export type returnCountType = {
22
+ outstanding_count: number | null;
23
+ scheduled_count: number;
24
+ completed_count: number;
25
+ };
26
+ const ReturnStatus = () => {
27
+ //CP
28
+ type returnCountType = {
29
+ outstanding_count: number | null;
30
+ scheduled_count: number;
31
+ completed_count: number;
32
+ };
33
+
34
+ // const [count, setCount] = useState<returnCountType[] | undefined>();
35
+ const [activeCardId, setActiveCardId] = useActiveCardId();
36
+ const [, dispatch] = useAtom(filtersReducerReturnAtom);
37
+ const { status } = useParams();
38
+ const [count, setCount] = useStatsCPCount();
39
+ const [startDate] = useStartDate();
40
+ const [endDate] = useEndDate();
41
+ const [clientPortal] = useClientPortal();
42
+ const [modifiedFilters, setModifiedFilters] = useState<any[]>([]);
43
+ const [debouncedSearchText] = useSearchText();
44
+ const [debouncedSearchAfterText] = useSearchAfterText();
45
+
46
+ const getDateFilters = (
47
+ startDate: dayjs.Dayjs | null,
48
+ endDate: dayjs.Dayjs | null
49
+ ) => {
50
+ const stored = JSON.parse(localStorage.getItem('returnDate') || '{}');
51
+
52
+ const sDate = startDate?.isValid?.() ? startDate : dayjs(stored?.startDate);
53
+ const eDate = endDate?.isValid?.()
54
+ ? endDate
55
+ : stored?.endDate
56
+ ? dayjs(stored?.endDate)
57
+ : null;
58
+
59
+ if (!sDate?.isValid?.()) return [];
60
+
61
+ let dateFilters = [];
62
+
63
+ if (eDate && eDate.isValid()) {
64
+ dateFilters = [
65
+ { field: 'created_at', op: '>=', value: sDate.format('YYYY-MM-DD') },
66
+ {
67
+ field: 'created_at',
68
+ op: '<=',
69
+ value: eDate.add(1, 'day').format('YYYY-MM-DD'),
70
+ },
71
+ ];
72
+ } else {
73
+ dateFilters = [
74
+ {
75
+ field: 'created_at',
76
+ op: '=',
77
+ value: sDate.format('YYYY-MM-DD'),
78
+ },
79
+ ];
80
+ }
81
+
82
+ return dateFilters;
83
+ };
84
+
85
+ useEffect(() => {
86
+ if (!clientPortal) return;
87
+
88
+ const dateFilters = getDateFilters(startDate, endDate);
89
+ setModifiedFilters(dateFilters);
90
+ }, [startDate, endDate]);
91
+
92
+ //stats API
93
+
94
+ const { data: statsData, loading: apiLoading, fetchData } = useAxios<{
95
+ data: returnCountType[];
96
+ }>({
97
+ endpoint: `v1/portal/return/stats/`,
98
+ method: 'GET',
99
+ //@ts-ignore
100
+ pagination: { is_pagination: false },
101
+ filters: modifiedFilters,
102
+ });
103
+
104
+ const prevSearchTextRef = useRef('');
105
+ const prevSearchAfterTextRef = useRef('');
106
+
107
+ useEffect(() => {
108
+ const prev = prevSearchTextRef.current;
109
+ if (clientPortal && prev && debouncedSearchText === '') {
110
+ fetchData();
111
+ }
112
+ prevSearchTextRef.current = debouncedSearchText;
113
+ }, [debouncedSearchText, startDate, endDate]);
114
+
115
+ useEffect(() => {
116
+ const prev = prevSearchAfterTextRef.current;
117
+ if (clientPortal && prev && debouncedSearchAfterText === '') {
118
+ fetchData();
119
+ }
120
+ prevSearchAfterTextRef.current = debouncedSearchAfterText;
121
+ }, [debouncedSearchAfterText, startDate, endDate]);
122
+
123
+ console.log(debouncedSearchText, 'debouncedSearchText');
124
+ console.log(debouncedSearchAfterText, 'debouncedSearchAfterText');
125
+ useEffect(() => {
126
+ fetchData();
127
+ }, [startDate, endDate]);
128
+
129
+ useEffect(() => {
130
+ if (statsData && statsData?.data) {
131
+ const data = statsData?.data;
132
+ setCount(data);
133
+ }
134
+ }, [apiLoading]);
135
+
136
+ const returnCounts = [
137
+ {
138
+ id: 1,
139
+ icon: 'outstanding_return',
140
+ status: 'outstanding_return',
141
+ count: count?.outstanding_count || 0,
142
+ label: 'Outstanding Return',
143
+ },
144
+ {
145
+ id: 2,
146
+ icon: 'scheduled_for_return',
147
+ status: 'scheduled_for_return',
148
+ count: count?.scheduled_count || 0,
149
+ label: 'Scheduled For Return',
150
+ },
151
+ {
152
+ id: 3,
153
+ icon: 'return_completed',
154
+ status: 'return_completed',
155
+ count: count?.completed_count || 0,
156
+ label: 'Return Completed',
157
+ },
158
+ ];
159
+ const navigate = useNavigate();
160
+ const [, setDebouncedSearchText] = useSearchAfterText();
161
+
162
+ const handleCardClick = (item: any) => {
163
+ if (activeCardId === item?.id) {
164
+ return;
165
+ }
166
+ setActiveCardId(item?.id);
167
+ navigate(`/return/${item?.status}`);
168
+ setDebouncedSearchText('');
169
+ if (item?.status == 'scheduled_for_return') {
170
+ dispatch({
171
+ type: 'SET_SCHEDULED_RETURN_FILTER',
172
+ payload:
173
+ 'awaiting confirmation,awaiting route,routed,confirmed,on hold,subcontracted',
174
+ });
175
+ dispatch({
176
+ type: 'SET_PAGE',
177
+ payload: 1,
178
+ });
179
+ }
180
+ if (item?.status == 'return_completed') {
181
+ dispatch({
182
+ type: 'SET_RETURN_COMPLETED_FILTER',
183
+ payload: 'complete',
184
+ });
185
+ dispatch({
186
+ type: 'SET_PAGE',
187
+ payload: 1,
188
+ });
189
+ }
190
+ };
191
+
192
+ useEffect(() => {
193
+ const matchedItem = returnCounts.find(item => item?.status === status);
194
+
195
+ if (!matchedItem) return;
196
+
197
+ setActiveCardId(matchedItem.id);
198
+ if (status == 'scheduled_for_return') {
199
+ dispatch({
200
+ type: 'SET_SCHEDULED_RETURN_FILTER',
201
+ payload:
202
+ 'awaiting confirmation,awaiting route,routed,confirmed,on hold,subcontracted',
203
+ });
204
+ }
205
+ if (status == 'return_completed') {
206
+ dispatch({
207
+ type: 'SET_RETURN_COMPLETED_FILTER',
208
+ payload: 'complete',
209
+ });
210
+ }
211
+ dispatch({ type: 'SET_PAGE', payload: 1 });
212
+ }, []);
213
+
214
+ return (
215
+ <div>
216
+ {' '}
217
+ <OrderStatusWrapper>
218
+ <StyledListCover className="listAlignment styleCovered">
219
+ {returnCounts?.map(item => (
220
+ <CountItem
221
+ key={item.id}
222
+ countDetails={item}
223
+ //@ts-ignore
224
+ isActive={item.id === activeCardId}
225
+ onClick={() => handleCardClick(item)}
226
+ />
227
+ ))}
228
+ </StyledListCover>
229
+ </OrderStatusWrapper>
230
+ </div>
231
+ );
232
+ };
233
+ const OrderStatusWrapper = styled.div`
234
+ margin-bottom: 30px;
235
+ @media ${device.smallScreen} {
236
+ padding: 0 0px;
237
+ }
238
+ `;
239
+
240
+ const StyledListCover = styled.ul`
241
+ margin: 0;
242
+ padding: 0;
243
+ list-style: none;
244
+ box-sizing: border-box;
245
+ display: flex;
246
+ gap: 25px;
247
+ /* aligns-items: center; */
248
+ margin-top: -40px;
249
+ padding: 0 20px;
250
+ flex-wrap: wrap;
251
+ `;
252
+ export default ReturnStatus;