Skip to content

Commit bf42e8b

Browse files
Diego Dariodiegodario88
authored andcommitted
feat: add multi option for priority queryParam
1 parent ba55a4b commit bf42e8b

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

src/pages/Home/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IFilterFormProps } from './components/Filter/types';
1111

1212
const initialFilterData: IFilterFormProps = {
1313
search: '',
14-
priority: null,
14+
priority: [],
1515
supplyCategoryIds: [],
1616
supplyIds: [],
1717
shelterStatus: [],

src/pages/Home/components/Filter/Filter.tsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import {
2020
IFilterFormikProps,
2121
IFilterProps,
22-
ISelectField,
2322
ShelterAvailabilityStatus,
2423
} from './types';
2524
import { priorityOptions } from '@/lib/utils';
@@ -66,12 +65,10 @@ const Filter = (props: IFilterProps) => {
6665
{
6766
initialValues: {
6867
cities: data.cities ?? [],
69-
priority: data.priority
70-
? {
71-
label: priorityOpts[data.priority],
72-
value: data.priority,
73-
}
74-
: null,
68+
priority: data.priority.map((p: string) => ({
69+
label: priorityOpts[Number(p) as SupplyPriority],
70+
value: p,
71+
})),
7572
search: data.search,
7673
shelterStatus: data.shelterStatus.map((s) => ({
7774
label: ShelterAvailabilityStatusMapped[s],
@@ -103,16 +100,15 @@ const Filter = (props: IFilterProps) => {
103100
cities,
104101
} = values;
105102
onSubmit({
106-
priority: priority?.value ? +priority.value : null,
103+
priority: priority.map((p) => p.value).join(),
107104
search,
108105
shelterStatus: shelterStatus.map((s) => s.value),
109106
supplyCategoryIds: supplyCategories.map((s) => s.value),
110107
supplyIds: supplies.map((s) => s.value),
111108
cities,
112109
});
113110
},
114-
}
115-
);
111+
});
116112

117113
const supplyOptions = useMemo(() => {
118114
return supplies
@@ -187,20 +183,14 @@ const Filter = (props: IFilterProps) => {
187183
<Select
188184
placeholder="Selecione"
189185
value={values.priority}
186+
isMulti
190187
options={Object.entries(priorityOpts).map(
191-
([priority, label]) =>
192-
({
193-
label,
194-
value: +priority,
195-
} as ISelectField<SupplyPriority>)
188+
([priority, label]) => ({
189+
label,
190+
value: priority,
191+
}),
196192
)}
197-
onChange={(v) => {
198-
const newValue = {
199-
...v,
200-
value: v ? +v.value : SupplyPriority.Urgent,
201-
};
202-
setFieldValue('priority', newValue);
203-
}}
193+
onChange={(v) => setFieldValue('priority', v)}
204194
/>
205195
</div>
206196
<div className="flex flex-col gap-1 w-full">

src/pages/Home/components/Filter/types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { SupplyPriority } from '@/service/supply/types';
2-
31
export type ShelterAvailabilityStatus = 'available' | 'unavailable' | 'waiting';
42

53
export interface ISelectField<T = string> {
@@ -9,24 +7,28 @@ export interface ISelectField<T = string> {
97

108
export interface IFilterFormProps {
119
search: string;
12-
priority: SupplyPriority | null;
10+
priority: string[];
1311
supplyCategoryIds: string[];
1412
supplyIds: string[];
1513
shelterStatus: ShelterAvailabilityStatus[];
1614
cities: string[];
1715
}
1816

17+
export interface IFilterSubmittionForm
18+
extends Omit<IFilterFormProps, 'priority'> {
19+
priority: string;
20+
}
1921
export interface IFilterFormikProps {
2022
search: string;
21-
priority: ISelectField<SupplyPriority> | null;
23+
priority: ISelectField[];
2224
supplyCategories: ISelectField[];
2325
supplies: ISelectField[];
2426
shelterStatus: ISelectField<ShelterAvailabilityStatus>[];
2527
cities: string[];
2628
}
2729

2830
export interface IFilterProps {
29-
onSubmit: (values: IFilterFormProps) => void;
31+
onSubmit: (values: IFilterSubmittionForm) => void;
3032
data: IFilterFormProps;
3133
open: boolean;
3234
onClose: () => void;

0 commit comments

Comments
 (0)