@bjsdistribution/dms-client-return 0.0.2 → 0.0.3

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 (75) hide show
  1. package/dist/components/order-daily-overview/common/interface.d.ts +22 -0
  2. package/dist/components/order-daily-overview/header-filters/Styledfilters.d.ts +1 -2
  3. package/dist/components/order-daily-overview/header-filters/filterStore.d.ts +16 -0
  4. package/dist/components/order-daily-overview/return-order-table/return-orders-filters/returnstyles.d.ts +1 -0
  5. package/dist/components/order-daily-overview/shared/utlis.d.ts +2 -2
  6. package/dist/components/order-daily-overview/store/store.d.ts +4 -0
  7. package/dist/components/order-view/details-filters/left-side-filters/dropdowns/PrintDropDown.d.ts +3 -1
  8. package/dist/components/order-view/store.d.ts +5 -1
  9. package/dist/components/store.d.ts +5 -2
  10. package/dist/components/types.d.ts +1 -1
  11. package/dist/dms-client-return.cjs.development.js +1065 -964
  12. package/dist/dms-client-return.cjs.development.js.map +1 -1
  13. package/dist/dms-client-return.cjs.production.min.js +1 -1
  14. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  15. package/dist/dms-client-return.esm.js +1067 -966
  16. package/dist/dms-client-return.esm.js.map +1 -1
  17. package/package.json +2 -2
  18. package/src/components/order-daily-overview/common/fakedata.tsx +5 -6
  19. package/src/components/order-daily-overview/common/interface.ts +120 -97
  20. package/src/components/order-daily-overview/filters/Filters.tsx +1 -8
  21. package/src/components/order-daily-overview/header-filters/HeaderFilter.tsx +56 -67
  22. package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +160 -223
  23. package/src/components/order-daily-overview/header-filters/Styledfilters.tsx +19 -7
  24. package/src/components/order-daily-overview/header-filters/filterStore.ts +145 -0
  25. package/src/components/order-daily-overview/index.tsx +59 -6
  26. package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +24 -1
  27. package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +177 -234
  28. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +63 -6
  29. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnFilter.tsx +5 -47
  30. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +51 -185
  31. package/src/components/order-daily-overview/return-order-table/return-orders-filters/returnstyles.ts +62 -0
  32. package/src/components/order-daily-overview/store/store.ts +23 -12
  33. package/src/components/order-daily-overview/table/ReturnTable.tsx +193 -205
  34. package/src/components/order-view/details-filters/DetailsFilters.tsx +3 -2
  35. package/src/components/order-view/details-filters/left-side-filters/dropdowns/PrintDropDown.tsx +57 -46
  36. package/src/components/order-view/general-information/Status.tsx +1 -1
  37. package/src/components/order-view/index.tsx +6 -4
  38. package/src/components/order-view/modalsPopup/UnReceiveProduct.tsx +1 -1
  39. package/src/components/order-view/order-actions/actions/escalation/EscalationModal.tsx +1 -1
  40. package/src/components/order-view/order-details/expanded-content/customer-section/RecipientName.tsx +1 -0
  41. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactEmail.tsx +1 -0
  42. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactHome.tsx +1 -0
  43. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactMobile.tsx +1 -1
  44. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactWork.tsx +1 -0
  45. package/src/components/order-view/order-details/expanded-content/customer-section/location-info/Address.tsx +1 -0
  46. package/src/components/order-view/order-details/expanded-content/customer-section/location-info/Latitude.tsx +1 -0
  47. package/src/components/order-view/order-details/expanded-content/customer-section/location-info/Longitude.tsx +1 -0
  48. package/src/components/order-view/order-details/expanded-content/customer-section/location-info/Postcode.tsx +1 -0
  49. package/src/components/order-view/order-details/expanded-content/customer-section/location-info/What3words.tsx +1 -0
  50. package/src/components/order-view/order-details/expanded-content/footer/index.tsx +3 -2
  51. package/src/components/order-view/order-details/expanded-content/index.tsx +1 -1
  52. package/src/components/order-view/order-details/expanded-content/instruction-section/index.tsx +2 -1
  53. package/src/components/order-view/order-details/expanded-content/orders-section/Carrier.tsx +7 -1
  54. package/src/components/order-view/order-details/expanded-content/orders-section/DeliveryDate.tsx +1 -0
  55. package/src/components/order-view/order-details/expanded-content/orders-section/Depot.tsx +14 -1
  56. package/src/components/order-view/order-details/expanded-content/orders-section/Droptime.tsx +2 -1
  57. package/src/components/order-view/order-details/expanded-content/orders-section/OrderNumber.tsx +2 -1
  58. package/src/components/order-view/order-details/expanded-content/orders-section/RecipientReference.tsx +2 -1
  59. package/src/components/order-view/order-details/expanded-content/orders-section/ScheduleAfter.tsx +1 -0
  60. package/src/components/order-view/order-details/expanded-content/orders-section/VehicleType.tsx +13 -1
  61. package/src/components/order-view/order-details/expanded-content/services-section/DeliveryPoint.tsx +13 -1
  62. package/src/components/order-view/order-details/expanded-content/services-section/ServiceType.tsx +13 -1
  63. package/src/components/order-view/order-details/expanded-content/services-section/TimedService.tsx +14 -1
  64. package/src/components/order-view/return-client-products/product-table/ReturnProductTable.tsx +2 -2
  65. package/src/components/order-view/store.ts +40 -12
  66. package/src/components/store.ts +26 -4
  67. package/src/components/types.ts +2 -6
  68. package/dist/components/order-daily-overview/table/InfiniteScrolling.d.ts +0 -5
  69. package/dist/components/order-daily-overview/table/Return.d.ts +0 -3
  70. package/dist/components/order-daily-overview/table/table-data/MyTable.d.ts +0 -18
  71. package/dist/components/order-daily-overview/table/table-data/Table.d.ts +0 -18
  72. package/src/components/order-daily-overview/table/InfiniteScrolling.tsx +0 -54
  73. package/src/components/order-daily-overview/table/Return.tsx +0 -156
  74. package/src/components/order-daily-overview/table/table-data/MyTable.tsx +0 -433
  75. package/src/components/order-daily-overview/table/table-data/Table.tsx +0 -445
@@ -1,215 +1,149 @@
1
- import React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import {
3
3
  ApplyButton,
4
- // DatePickerWrap,
5
4
  FilterColumn,
6
5
  FilterRow,
7
6
  Label,
8
7
  LeftColumn,
9
- // RangeSelect,
10
8
  RightColumn,
11
- StyledAntSelect,
12
9
  Wrapper,
13
10
  } from './Styledfilters';
14
- // import {
15
- // displayFormattedDate,
16
- // // overviewFiltersReducerAtom,
17
- // lastSundayDate,
18
- // filtersReducerAtom,
19
- // usefilterApplied,
20
- // } from './FilterStore';
21
- import { atom } from 'jotai';
22
- // import {
23
- // allCustomerData,
24
- // usePrevSelectedClients,
25
- // useSelectedClients,
26
- // useSelectedFilter,
27
- // useSelectedSubClients,
28
- // } from '../store';
29
- // import { useApiHook } from '@bjsdistribution/dms-component-library';
30
- // import { ApiResponse } from '../../readyforinvoice/types';
31
- // import { DatePicker, Tooltip } from 'antd';
32
- // import dayjs from 'dayjs';
33
- // import { compareArrays, prepareData } from '../utils';
34
- // import { useReadyForInvoiceView } from '../../readyforinvoice/store';
35
- // import { emailFiltersReducerAtom } from '../../emailInvoice/EmailFilterStore';
11
+ import { atom, useAtom } from 'jotai';
12
+ import { useActionType, useCustomerData, useLocationData } from '../../store';
13
+ import { filtersReducerAtom } from './filterStore';
14
+ import {
15
+ useSelectedAction,
16
+ useSelectedClient,
17
+ useSelectedLocation,
18
+ useTableName,
19
+ } from '../store/store';
20
+ import styled from 'styled-components';
21
+ import { Select } from 'antd';
22
+ import { DefaultOptionType } from 'antd/es/select';
23
+
36
24
  export const clickedState = atom<boolean>(false);
37
25
 
38
26
  function SelectionFilter() {
39
- // const [, setFilterAplied] = usefilterApplied();
40
- // const [selectedFilter] = useSelectedFilter();
41
- // const [, dispatchEmailFilters] = useAtom(emailFiltersReducerAtom);
42
-
43
- // const [, dispatchOverviewFilters] = useAtom(overviewFiltersReducerAtom);
44
- // const [, dispatchFilters] = useAtom(filtersReducerAtom);
45
- // const [
46
- // readyForInvoiceView,
47
- // setReadyForInvoiceView,
48
- // ] = useReadyForInvoiceView();
49
- // const [prevSelectedDate, setPrevSelectedDate] = useState<
50
- // Date | string | null
51
- // >(lastSundayDate); // for comparison
52
- // const [selectedDate, setDate] = useState<Date | string | null>(
53
- // lastSundayDate
54
- // );
55
- // const [customerData, setCustomerData] = allCustomerData();
56
-
57
- // const [
58
- // prevSelectedClients,
59
- // setPrevSelectedClients,
60
- // ] = usePrevSelectedClients();
61
-
62
- // const [selectedClients, setClients] = useSelectedClients();
63
-
64
- // const [subAccounts, setSubaccounts] = useState<any>([]);
65
-
66
- // const [selectedSubClients, setSelectedSubClients] = useSelectedSubClients();
67
-
68
- // const [, setIsClicked] = useAtom(clickedState);
69
-
70
- //API
71
- // const { data: fetchedStaticData, loading: loading } = useApiHook<ApiResponse>(
72
- // {
73
- // endpoint: `/customer/`,
74
- // method: 'GET',
75
- // pagination: { page: 1, per_page: 50 },
76
- // }
77
- // );
78
-
79
- // useEffect(() => {
80
- // if (!loading) {
81
- // setCustomerData(fetchedStaticData?.data);
82
- // }
83
- // }, [loading]);
84
-
85
- // const clientOptions = customerData
86
- // ?.filter((x: any) => x.id === x?.parent_id || x?.parent_id === null)
87
- // ?.map((option: any) => ({
88
- // label: option?.name?.charAt(0)?.toUpperCase() + option?.name?.slice(1),
89
- // value: option?.id,
90
- // }));
91
-
92
- // const selectedClientValues = selectedClients?.map(item => item?.value);
93
- // const prevSelectedClientValues = prevSelectedClients?.map(
94
- // item => item?.value
95
- // );
96
-
97
- // const subAccountData = customerData
98
- // ?.filter(item => selectedClientValues?.includes(item?.parent_id))
99
- // ?.filter(x => x.id !== x.parent_id);
100
-
101
- // const preparedData = prepareData(clientOptions, subAccountData);
102
-
103
- // const subAccountOptions = preparedData?.filter(
104
- // (item: any) => item?.options?.length > 0
105
- // );
106
-
107
- // const handleDateChange: DatePickerProps['onChange'] = (date, _dateString) => {
108
- // setFilterAplied(true);
109
- // const newDate = date?.format('YYYY-MM-DDTHH:mm:ss');
110
- // if (newDate !== undefined) {
111
- // setDate(newDate);
112
- // } else {
113
- // setDate(null);
114
- // }
115
- // };
116
-
117
- // const handleCustomerChange = (_label: any, value: any) => {
118
- // if (value.length === 0) {
119
- // setReadyForInvoiceView(undefined);
120
- // setPrevSelectedClients(value);
121
- // dispatchOverviewFilters({
122
- // type: 'SET_DATE_FILTER',
123
- // payload: selectedDate,
124
- // });
125
- // }
126
- // setClients(value);
127
- // };
128
-
129
- // const onChangeSubAccount = (value: any) => {
130
- // setSubaccounts(value);
131
- // };
132
-
133
- // const ApplyFilters = () => {
134
- // setIsClicked(true);
135
- // if (
136
- // readyForInvoiceView !== 'client' &&
137
- // selectedClientValues?.length === 0
138
- // ) {
139
- // console.log('inside if rfiview');
140
- // dispatchOverviewFilters({
141
- // type: 'SET_DATE_FILTER',
142
- // payload: selectedDate,
143
- // });
144
- // }
145
- // if (selectedClientValues?.length > 0) {
146
- // console.log('inside if rfiview asdfasdf');
147
- // dispatchFilters({
148
- // type: 'SET_CUSTOMER_FILTER',
149
- // payload: selectedClientValues,
150
- // });
151
- // dispatchFilters({
152
- // type: 'SET_DATE_FILTER',
153
- // payload: selectedDate,
154
- // });
155
- // if (readyForInvoiceView !== 'client') {
156
- // setReadyForInvoiceView('client');
157
- // }
158
- // }
159
- // dispatchEmailFilters({
160
- // type: 'SET_CUSTOMER_FILTER',
161
- // payload: selectedClientValues,
162
- // });
163
- // dispatchEmailFilters({
164
- // type: 'SET_DATE_FILTERS',
165
- // payload: selectedDate,
166
- // });
167
-
168
- // // need to update prev selected clients state for comparison
169
- // setPrevSelectedClients(selectedClients);
170
- // setPrevSelectedDate(selectedDate);
171
- // setSelectedSubClients(subAccounts);
172
- // if (selectedClients?.length === 0) {
173
- // setIsClicked(false);
174
- // }
175
- // };
176
-
177
- // const isDifferent = () => {
178
- // let actualDate = null;
179
- // let isDateDiff;
180
- // if (selectedDate !== null) {
181
- // actualDate = new Date(selectedDate);
182
- // }
183
- // if (prevSelectedDate !== null && actualDate !== null) {
184
- // isDateDiff =
185
- // actualDate.getTime() !== new Date(prevSelectedDate).getTime();
186
- // }
187
- // if (prevSelectedDate !== null && actualDate === null) {
188
- // isDateDiff = false;
189
- // }
190
- // const isClientDiff = compareArrays(
191
- // selectedClientValues,
192
- // prevSelectedClientValues
193
- // );
194
- // const isSubAccountDiff = compareArrays(subAccounts, selectedSubClients);
195
- // const isSame = isDateDiff || isClientDiff || isSubAccountDiff;
196
- // return !isSame;
197
- // };
198
- const ActionOptions = [
199
- { label: 'RTS', value: 'rt' },
200
- { label: 'Dispose', value: 'dispose' },
201
- { label: 'Pending', value: 'pending' },
202
- { label: 'Re-allocated', value: 're-allocate' },
203
- { label: 'Re-Del', value: 're-del' },
204
- { label: 'Re-Recycle', value: 're-recycle' },
205
- { label: 'Unknown', value: 'unknown' },
206
- ];
207
-
208
- const ReturnLocationOptions = [
209
- { label: 'bedkingdom wf14 0dq ', value: 'bedkingdom' },
210
- { label: 'cotswold returns', value: 'cotswold-returns' },
211
- { label: 'appliance house c/o hdl', value: 'appliance' },
212
- ];
27
+ const [customers] = useCustomerData();
28
+ const [actionType] = useActionType();
29
+ const [locationData] = useLocationData();
30
+ const [filteredLocationOptions, setFilteredLocationOptions] = useState([]);
31
+ const [getUuid, setUuid] = useState<any>();
32
+ const [selectedFilterValue, setSelectedFilterValue] = useSelectedAction();
33
+ const [, dispatch] = useAtom(filtersReducerAtom);
34
+ const [
35
+ selectedLocationValue,
36
+ setSelectedLocationValue,
37
+ ] = useSelectedLocation();
38
+ const [selectedClientId, setSelectedClient] = useSelectedClient();
39
+ const [, setClientLabel] = useTableName();
40
+ const [name, setName] = useState<string>();
41
+ const [isButtonEnabled, setIsButtonEnabled] = useState(false);
42
+
43
+ //client options
44
+ const clientOptions = customers?.map((option: any) => ({
45
+ label:
46
+ option?.customer_name?.charAt(0)?.toUpperCase() +
47
+ option?.customer_name?.slice(1),
48
+ value: `${option?.id}_${option?.uuid}`,
49
+ id: option?.id,
50
+ uuid: option?.uuid,
51
+ }));
52
+
53
+ const actionTypeOptions = actionType?.map((option: any) => ({
54
+ label: option?.type?.charAt(0)?.toUpperCase() + option?.type?.slice(1),
55
+ value: option?.id,
56
+ }));
57
+
58
+ const LocationOptions = locationData?.map((option: any) => ({
59
+ label: option?.location_name,
60
+ value: option?.customer_id,
61
+ }));
62
+
63
+ //client change
64
+ const handleSelectChange = (value: unknown, option: DefaultOptionType) => {
65
+ console.log(value, 'value');
66
+ const selectedLabel = option?.label as string;
67
+ const selectedValue = option?.id as number;
68
+ const selectedUuids = option?.uuid as string;
69
+ setSelectedClient(selectedValue);
70
+ setName(selectedLabel);
71
+ localStorage.setItem('clientName', selectedLabel);
72
+
73
+ const filteredSubLocations = locationData
74
+ ?.filter((subCat: any) => subCat?.customer_id === selectedUuids)
75
+ .map((subCat: any) => ({
76
+ label: subCat?.location_name,
77
+ value: subCat?.customer_id,
78
+ }));
79
+
80
+ setFilteredLocationOptions(filteredSubLocations);
81
+ setUuid('');
82
+ };
83
+
84
+ useEffect(() => {}, [getUuid, filteredLocationOptions]);
85
+
86
+ //location change
87
+ const handleLocationChange = (value: unknown, option: DefaultOptionType) => {
88
+ const selectedLabel = option?.label as string;
89
+ console.log(value, 'value');
90
+ setSelectedLocationValue(selectedLabel);
91
+
92
+ if (selectedLocationValue === selectedLabel) {
93
+ dispatch({
94
+ type: 'CLEAR_ALL_FILTERS',
95
+ payload: null,
96
+ });
97
+ }
98
+ };
99
+
100
+ //action type
101
+ const handleActionClick = (value: any) => {
102
+ setSelectedFilterValue(value);
103
+ if (selectedFilterValue === value) {
104
+ dispatch({
105
+ type: 'CLEAR_ALL_FILTERS',
106
+ payload: null,
107
+ });
108
+ }
109
+ };
110
+
111
+ //Apply filters
112
+ const applyFilters = () => {
113
+ if (storedName) {
114
+ setClientLabel(storedName);
115
+ }
116
+ if (selectedClientId) {
117
+ dispatch({
118
+ type: 'SET_CLIENT_FILTER',
119
+ payload: selectedClientId,
120
+ });
121
+ }
122
+ if (selectedFilterValue) {
123
+ dispatch({
124
+ type: 'SET_ACTIONS_FILTER',
125
+ payload: selectedFilterValue,
126
+ });
127
+ }
128
+
129
+ if (selectedLocationValue) {
130
+ dispatch({
131
+ type: 'SET_LOCATION_FILTER',
132
+ payload: selectedLocationValue,
133
+ });
134
+ }
135
+ };
136
+
137
+ const storedName = localStorage.getItem('clientName');
138
+ useEffect(() => {
139
+ if (selectedClientId || selectedFilterValue || selectedLocationValue) {
140
+ setIsButtonEnabled(true);
141
+ } else {
142
+ setIsButtonEnabled(false);
143
+ }
144
+ }, [storedName, selectedFilterValue, selectedLocationValue]);
145
+
146
+ console.log('check', storedName, selectedFilterValue, selectedLocationValue);
213
147
 
214
148
  return (
215
149
  <Wrapper>
@@ -218,55 +152,58 @@ function SelectionFilter() {
218
152
  <FilterColumn>
219
153
  <Label>Clients</Label>
220
154
  <StyledAntSelect
221
- options={[]}
155
+ options={clientOptions}
222
156
  placeholder="Select Client Name"
223
- onChange={() => {}}
224
- mode="multiple"
157
+ onChange={handleSelectChange}
225
158
  style={{ minWidth: '14vw' }}
159
+ allowClear
160
+ value={name}
226
161
  />
227
162
  </FilterColumn>
228
163
 
229
164
  <FilterColumn>
230
165
  <Label>Action Type</Label>
231
166
  <StyledAntSelect
232
- options={ActionOptions}
167
+ options={actionTypeOptions}
233
168
  placeholder="Select Action Type"
234
- // value={""}
235
- onChange={() => {}}
169
+ value={selectedFilterValue}
170
+ onChange={handleActionClick}
236
171
  style={{ minWidth: '14vw' }}
237
- // style={{ width: '18vw', overflow: 'hidden' }}
238
- mode="multiple"
239
- // maxTagCount={0}
240
- // maxTagPlaceholder={(omittedValues: any) => (
241
- // <Tooltip
242
- // overlayStyle={{ pointerEvents: 'none' }}
243
- // title={omittedValues
244
- // .map(({ label }: any) => label)
245
- // .join(', ')}
246
- // >
247
- // <span>{`${omittedValues.length} selected`}</span>
248
- // </Tooltip>
249
- // )}
172
+ allowClear
250
173
  />
251
174
  </FilterColumn>
252
175
 
253
176
  <FilterColumn>
254
177
  <Label>Location </Label>
255
178
  <StyledAntSelect
256
- options={ReturnLocationOptions}
179
+ options={
180
+ filteredLocationOptions?.length > 0
181
+ ? filteredLocationOptions
182
+ : LocationOptions
183
+ }
184
+ value={selectedLocationValue}
257
185
  placeholder="Select Location"
258
- onChange={() => {}}
259
- mode="multiple"
186
+ onChange={handleLocationChange}
260
187
  style={{ minWidth: '14vw' }}
188
+ allowClear
261
189
  />
262
190
  </FilterColumn>
263
191
  </LeftColumn>
264
192
  <RightColumn>
265
- <ApplyButton colors="secondary">Apply</ApplyButton>
193
+ <ApplyButton onClick={applyFilters} disabled={!isButtonEnabled}>
194
+ Apply
195
+ </ApplyButton>
266
196
  </RightColumn>
267
197
  </FilterRow>
268
198
  </Wrapper>
269
199
  );
270
200
  }
271
201
 
202
+ const StyledAntSelect = styled(Select)`
203
+ .ant-select-selector {
204
+ /* width: 22vw; */
205
+ border-radius: 22px;
206
+ }
207
+ `;
208
+
272
209
  export default SelectionFilter;
@@ -1,4 +1,4 @@
1
- import { Button } from '@bjsdistribution/dms-component-library';
1
+ // import { Button } from '@bjsdistribution/dms-component-library';
2
2
  import { Select } from 'antd';
3
3
  import styled from 'styled-components';
4
4
 
@@ -26,7 +26,7 @@ export const CoverPage = styled.div`
26
26
  border: 1px solid #e3e3e3;
27
27
  background: #fff;
28
28
  box-shadow: 0px 4px 30px 0px rgba(46, 45, 116, 0.05);
29
- padding: 20px 20px 20px 20px;
29
+ padding: 20px 20px 20px 20px;
30
30
  top: -60px;
31
31
  `;
32
32
  export const StatusPanel = styled.div`
@@ -92,7 +92,7 @@ export const Wrapper = styled.div`
92
92
  gap: 15px;
93
93
  flex: 1 0 0;
94
94
  border-radius: 15px;
95
- background: #F8FAFC;
95
+ background: #f8fafc;
96
96
  `;
97
97
 
98
98
  export const StyledAntSelect = styled(Select)`
@@ -190,13 +190,25 @@ export const RangeSelect = styled.div`
190
190
  color: #8e8a85;
191
191
  `;
192
192
 
193
- export const ApplyButton = styled(Button)`
194
- border-radius: 15px !important;
193
+ export const ApplyButton = styled.button`
194
+ border-radius: 15px;
195
195
  display: flex;
196
- padding: 7px 12px !important;
196
+ padding: 7px 12px;
197
197
  justify-content: center;
198
198
  align-items: center;
199
- font-size: 14px !important;
199
+ font-size: 14px;
200
200
  font-family: 'Lato', sans-serif;
201
201
  background: transparent;
202
+ color: #3a3620;
203
+ border: 1px solid #3a3630;
204
+
205
+ &:not(:disabled):hover {
206
+ background: #feba30;
207
+ }
208
+
209
+ &:disabled {
210
+ background: #ccc;
211
+ cursor: not-allowed;
212
+ opacity: 0.6;
213
+ }
202
214
  `;
@@ -0,0 +1,145 @@
1
+ import { atom, useAtom } from 'jotai';
2
+ // import { formatDate } from '../shared/utlis';
3
+ import { format } from 'date-fns';
4
+
5
+ const date = atom(new Date());
6
+ export const usedate = () => {
7
+ return useAtom(date);
8
+ };
9
+
10
+ interface Filter {
11
+ field: string;
12
+ op: string;
13
+ value: any;
14
+ }
15
+
16
+ interface Pagination {
17
+ page: number;
18
+ per_page: number;
19
+ }
20
+
21
+ interface FilterState {
22
+ 'x-filters': Filter[];
23
+ 'x-pagination': Pagination;
24
+ }
25
+ // let todayDate = new Date();
26
+ const initialState: FilterState = {
27
+ 'x-filters': [
28
+ // {
29
+ // field: 'action_date',
30
+ // op: '>=',
31
+ // value: `${format(new Date(todayDate), 'yyyy-MM-dd')}T00:00:00+00:00`,
32
+ // },
33
+ // {
34
+ // field: 'action_date',
35
+ // op: '<=',
36
+ // value: `${format(new Date(todayDate), 'yyyy-MM-dd')}T23:59:59+00:00`,
37
+ // },
38
+ // { field: 'status', op: 'count', value: '' },
39
+ ],
40
+ 'x-pagination': { page: 1, per_page: 50 },
41
+ };
42
+
43
+ const filterReducer = (state: FilterState, action: any): FilterState => {
44
+ switch (action.type) {
45
+ case 'SET_DATE_FILTER':
46
+ return {
47
+ ...state,
48
+ 'x-filters': [
49
+ ...state['x-filters'].filter(
50
+ f => f.field !== 'action_date' && f.field !== 'status'
51
+ ),
52
+ {
53
+ field: 'action_date',
54
+ op: '>=',
55
+ value: `${format(
56
+ new Date(action.payload),
57
+ 'yyyy-MM-dd'
58
+ )}T00:00:00+00:00`,
59
+ },
60
+ {
61
+ field: 'action_date',
62
+ op: '<=',
63
+ value: `${format(
64
+ new Date(action.payload),
65
+ 'yyyy-MM-dd'
66
+ )}T23:59:59+00:00`,
67
+ },
68
+ { field: 'status', op: 'count', value: '' },
69
+ ],
70
+ };
71
+
72
+ case 'SET_CLIENT_FILTER':
73
+ return {
74
+ ...state,
75
+ 'x-filters': [
76
+ ...state['x-filters'].filter(f => f.field !== 'order.customer_id'),
77
+ {
78
+ field: 'order.customer_id',
79
+ op: '=',
80
+ value: action.payload,
81
+ },
82
+ ],
83
+ };
84
+
85
+ case 'SET_ACTIONS_FILTER':
86
+ return {
87
+ ...state,
88
+ 'x-filters': [
89
+ ...state['x-filters'].filter(
90
+ f => f.field !== 'product_return_action_id'
91
+ ),
92
+ {
93
+ field: 'product_return_action_id',
94
+ op: '=',
95
+ value: action.payload,
96
+ },
97
+ ],
98
+ };
99
+
100
+ case 'SET_LOCATION_FILTER':
101
+ return {
102
+ ...state,
103
+ 'x-filters': [
104
+ ...state['x-filters'].filter(f => f.field !== 'return_location'),
105
+ {
106
+ field: 'return_location',
107
+ op: '=',
108
+ value: action.payload,
109
+ },
110
+ ],
111
+ };
112
+
113
+ case 'SET_PAGE':
114
+ return {
115
+ ...state,
116
+ 'x-pagination': {
117
+ ...state['x-pagination'],
118
+ page: action.payload,
119
+ },
120
+ };
121
+
122
+ case 'SET_PERPAGE':
123
+ return {
124
+ ...state,
125
+ 'x-pagination': {
126
+ ...state['x-pagination'],
127
+ per_page: action.payload,
128
+ },
129
+ };
130
+ case 'CLEAR_FILTERS':
131
+ return {
132
+ ...state,
133
+ };
134
+ default:
135
+ return state;
136
+ }
137
+ };
138
+
139
+ const filtersStateAtom = atom(initialState);
140
+
141
+ export const filtersReducerAtom = atom(
142
+ get => get(filtersStateAtom),
143
+ (get, set, action) =>
144
+ set(filtersStateAtom, filterReducer(get(filtersStateAtom), action))
145
+ );