@bjsdistribution/dms-client-return 0.0.79 → 0.0.81

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.79",
2
+ "version": "0.0.81",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -1,14 +1,45 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  //common
3
3
  import styled from 'styled-components';
4
4
  import { SearchIcon } from '../../../../../assets/icons';
5
+ import { useAtom } from 'jotai';
6
+ import { overviewfiltersReducerAtom } from '../../../header-filters/overViewFilter';
7
+ import { CrossIcon } from '@bjsdistribution/dms-component-library';
5
8
 
6
9
  const SearchType = () => {
7
10
  const [searchText, setSearchText] = useState('');
11
+ const [debouncedSearchText, setDebouncedSearchText] = useState('');
12
+ const [, dispatch] = useAtom(overviewfiltersReducerAtom);
13
+
8
14
  const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
9
15
  setSearchText(event.target.value);
10
16
  };
11
17
 
18
+ // Debouncing effect
19
+ useEffect(() => {
20
+ const handler = setTimeout(() => {
21
+ setDebouncedSearchText(searchText);
22
+ }, 1000);
23
+ return () => {
24
+ clearTimeout(handler);
25
+ };
26
+ }, [searchText]);
27
+ useEffect(() => {
28
+ if (debouncedSearchText) {
29
+ dispatch({
30
+ type: 'SET_COMP_RETURN_FILTERS',
31
+ payload: debouncedSearchText,
32
+ });
33
+ }
34
+ }, [debouncedSearchText, dispatch]);
35
+
36
+ const handleClear = () => {
37
+ setSearchText('');
38
+ dispatch({
39
+ type: 'CLEAR_SEARCH',
40
+ });
41
+ };
42
+
12
43
  return (
13
44
  <Search>
14
45
  <SearchIcon />
@@ -18,6 +49,11 @@ const SearchType = () => {
18
49
  value={searchText}
19
50
  onChange={handleInputChange}
20
51
  />
52
+ {searchText && (
53
+ <ClearButton className="clear" onClick={handleClear}>
54
+ <CrossIcon />
55
+ </ClearButton>
56
+ )}
21
57
  </Search>
22
58
  );
23
59
  };
@@ -29,8 +65,23 @@ const Search = styled.div`
29
65
  top: 50%;
30
66
  transform: translateY(-50%);
31
67
  }
68
+ .clear {
69
+ position: absolute;
70
+ right: 32px;
71
+ top: 50%;
72
+ }
73
+ `;
74
+ const ClearButton = styled.button`
75
+ position: relative;
76
+ border: none;
77
+ color: rgba(0, 0, 0, 0.25);
78
+ cursor: pointer;
79
+ padding: 0 8px;
80
+ font-size: 14px;
81
+ &:hover {
82
+ color: #000;
83
+ }
32
84
  `;
33
- Search;
34
85
  const SearchInput = styled.input`
35
86
  border-radius: 20px;
36
87
  border: 1px solid #e0e2e7;
@@ -42,5 +93,10 @@ const SearchInput = styled.input`
42
93
  gap: 8px;
43
94
  align-self: stretch;
44
95
  padding-left: 39px;
96
+ &:focus {
97
+ outline: none;
98
+ border-color: gray;
99
+ box-shadow: 0px 1px 2px 0px rgba(16, 24, 40, 0.05);
100
+ }
45
101
  `;
46
102
  export default SearchType;
@@ -9,6 +9,7 @@ interface Filter {
9
9
  field: string;
10
10
  op: string;
11
11
  value: any;
12
+ join?: any;
12
13
  }
13
14
 
14
15
  interface Pagination {
@@ -20,26 +21,48 @@ interface FilterState {
20
21
  'x-filters': Filter[];
21
22
  'x-pagination': Pagination;
22
23
  }
23
- // let todayDate = new Date();
24
24
  const initialState: FilterState = {
25
- 'x-filters': [
26
- // {
27
- // field: 'action_date',
28
- // op: '>=',
29
- // value: `${format(new Date(todayDate), 'yyyy-MM-dd')}T00:00:00+00:00`,
30
- // },
31
- // {
32
- // field: 'action_date',
33
- // op: '<=',
34
- // value: `${format(new Date(todayDate), 'yyyy-MM-dd')}T23:59:59+00:00`,
35
- // },
36
- // { field: 'status', op: 'count', value: '' },
37
- ],
25
+ 'x-filters': [],
38
26
  'x-pagination': { page: 1, per_page: 50 },
39
27
  };
40
28
 
41
29
  const filterReducer = (state: FilterState, action: any): FilterState => {
42
30
  switch (action.type) {
31
+ case 'SET_COMP_RETURN_FILTERS':
32
+ return {
33
+ ...state,
34
+ 'x-filters': [
35
+ ...state['x-filters'].filter(
36
+ f => f.field !== 'customer_name' && f.field !== 'trading_as'
37
+ ),
38
+ {
39
+ field: 'customer_name',
40
+ op: 'like',
41
+ value: `%${action.payload}%`,
42
+ join: 'or',
43
+ },
44
+ {
45
+ field: 'trading_as',
46
+ op: 'like',
47
+ value: `%${action.payload}%`,
48
+ join: 'or',
49
+ },
50
+ ],
51
+ 'x-pagination': { ...state['x-pagination'], page: 1 },
52
+ };
53
+
54
+ case 'CLEAR_SEARCH':
55
+ return {
56
+ ...state,
57
+ 'x-filters': [...initialState['x-filters']],
58
+ 'x-pagination': { ...initialState['x-pagination'], page: 1 },
59
+ };
60
+
61
+ case 'CLEAR_ALL_FILTER':
62
+ return {
63
+ ...state,
64
+ };
65
+
43
66
  case 'SET_PAGE':
44
67
  return {
45
68
  ...state,
@@ -23,7 +23,7 @@ function ReturnMainTable() {
23
23
  const [paginationObj, setPaginationObject] = UsePaginationOverviewData();
24
24
  const [, setCurrentPage] = useState(1);
25
25
  const [itemsPerPage, setItemsPerPage] = useItemsPerOverviewPage();
26
- const { 'x-pagination': pagination } = state;
26
+ const { 'x-filters': filters, 'x-pagination': pagination } = state;
27
27
  const { page, total } = paginationObj;
28
28
  // const [selectedClient] = useTableName();
29
29
  const [isScrolled] = useStickyStatus();
@@ -52,6 +52,7 @@ function ReturnMainTable() {
52
52
  method: 'GET',
53
53
  //@ts-ignore
54
54
  pagination: pagination,
55
+ filters: filters,
55
56
  });
56
57
 
57
58
  useEffect(() => {