Skip to content

Commit 39f8d05

Browse files
committed
just Filter now
1 parent 0308a32 commit 39f8d05

File tree

1 file changed

+32
-53
lines changed

1 file changed

+32
-53
lines changed

frontend/src/components/common/Filter.tsx

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,17 @@ import {
99
} from "@chakra-ui/react";
1010
import FilterOpenIcon from "../assets/filter-open.svg";
1111

12-
import { filterConfigs, FilterSection } from "../../constants/filterConfig";
12+
import { filterConfigs } from "../../constants/filterConfig";
1313

1414
export type FilterType = "petList" | "userManagement";
1515

16-
type FilterProviderProps = {
16+
type FilterProps = {
1717
type: FilterType;
1818
onFilterChange: (selectedFilters: Record<string, string[]>) => void;
1919
selected?: Record<string, string[]>;
2020
};
2121

22-
type FilterProps = {
23-
onChange: (value: string) => void;
24-
data: FilterSection;
25-
selectedOptions?: string[];
26-
};
27-
28-
const Filter: React.FC<FilterProps> = ({
29-
onChange,
30-
data,
31-
selectedOptions = [],
32-
}) => {
33-
return (
34-
<Popover>
35-
<PopoverTrigger>
36-
<Button>
37-
<img src={FilterOpenIcon} alt="open" />
38-
{data.name}
39-
</Button>
40-
</PopoverTrigger>
41-
<PopoverContent>
42-
<PopoverBody className="filter">
43-
<h4>Filter by: {data.name}</h4>
44-
{data.options.map((option) => (
45-
<div key={option.value}>
46-
<input
47-
type="checkbox"
48-
onClick={() => onChange(option.value)}
49-
checked={selectedOptions.includes(option.value)}
50-
readOnly
51-
/>
52-
<p>{option.label}</p>
53-
</div>
54-
))}
55-
</PopoverBody>
56-
</PopoverContent>
57-
</Popover>
58-
);
59-
};
60-
61-
const FilterProvider: React.FC<FilterProviderProps> = ({
62-
type,
63-
onFilterChange,
64-
selected,
65-
}) => {
22+
const Filter: React.FC<FilterProps> = ({ type, onFilterChange, selected }) => {
6623
const filters = filterConfigs[type];
6724
const [selectedFilters, setSelectedFilters] = useState<
6825
Record<string, string[]>
@@ -86,15 +43,37 @@ const FilterProvider: React.FC<FilterProviderProps> = ({
8643
return (
8744
<div>
8845
{filters.map((filter) => (
89-
<Filter
90-
key={filter.name}
91-
data={filter}
92-
selectedOptions={selectedFilters[filter.name] || []}
93-
onChange={(value) => handleOptionChange(filter.name, value)}
94-
/>
46+
<Popover key={filter.name}>
47+
<PopoverTrigger>
48+
<Button>
49+
<img src={FilterOpenIcon} alt="open" /> {filter.name}
50+
</Button>
51+
</PopoverTrigger>
52+
<PopoverContent>
53+
<PopoverBody className="filter">
54+
<h4>Filter by: {filter.name}</h4>
55+
{filter.options.map((option) => (
56+
<div key={option.value}>
57+
<input
58+
type="checkbox"
59+
onClick={() =>
60+
handleOptionChange(filter.name, option.value)
61+
}
62+
checked={
63+
selectedFilters[filter.name]?.includes(option.value) ||
64+
false
65+
}
66+
readOnly
67+
/>
68+
<p>{option.label}</p>
69+
</div>
70+
))}
71+
</PopoverBody>
72+
</PopoverContent>
73+
</Popover>
9574
))}
9675
</div>
9776
);
9877
};
9978

100-
export default FilterProvider;
79+
export default Filter;

0 commit comments

Comments
 (0)