Skip to content

Commit

Permalink
feat: add multi option for priority queryParam
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Dario authored and diegodario88 committed May 28, 2024
1 parent ba55a4b commit bf42e8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IFilterFormProps } from './components/Filter/types';

const initialFilterData: IFilterFormProps = {
search: '',
priority: null,
priority: [],
supplyCategoryIds: [],
supplyIds: [],
shelterStatus: [],
Expand Down
34 changes: 12 additions & 22 deletions src/pages/Home/components/Filter/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import {
IFilterFormikProps,
IFilterProps,
ISelectField,
ShelterAvailabilityStatus,
} from './types';
import { priorityOptions } from '@/lib/utils';
Expand Down Expand Up @@ -66,12 +65,10 @@ const Filter = (props: IFilterProps) => {
{
initialValues: {
cities: data.cities ?? [],
priority: data.priority
? {
label: priorityOpts[data.priority],
value: data.priority,
}
: null,
priority: data.priority.map((p: string) => ({
label: priorityOpts[Number(p) as SupplyPriority],
value: p,
})),
search: data.search,
shelterStatus: data.shelterStatus.map((s) => ({
label: ShelterAvailabilityStatusMapped[s],
Expand Down Expand Up @@ -103,16 +100,15 @@ const Filter = (props: IFilterProps) => {
cities,
} = values;
onSubmit({
priority: priority?.value ? +priority.value : null,
priority: priority.map((p) => p.value).join(),
search,
shelterStatus: shelterStatus.map((s) => s.value),
supplyCategoryIds: supplyCategories.map((s) => s.value),
supplyIds: supplies.map((s) => s.value),
cities,
});
},
}
);
});

const supplyOptions = useMemo(() => {
return supplies
Expand Down Expand Up @@ -187,20 +183,14 @@ const Filter = (props: IFilterProps) => {
<Select
placeholder="Selecione"
value={values.priority}
isMulti
options={Object.entries(priorityOpts).map(
([priority, label]) =>
({
label,
value: +priority,
} as ISelectField<SupplyPriority>)
([priority, label]) => ({
label,
value: priority,
}),
)}
onChange={(v) => {
const newValue = {
...v,
value: v ? +v.value : SupplyPriority.Urgent,
};
setFieldValue('priority', newValue);
}}
onChange={(v) => setFieldValue('priority', v)}
/>
</div>
<div className="flex flex-col gap-1 w-full">
Expand Down
12 changes: 7 additions & 5 deletions src/pages/Home/components/Filter/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { SupplyPriority } from '@/service/supply/types';

export type ShelterAvailabilityStatus = 'available' | 'unavailable' | 'waiting';

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

export interface IFilterFormProps {
search: string;
priority: SupplyPriority | null;
priority: string[];
supplyCategoryIds: string[];
supplyIds: string[];
shelterStatus: ShelterAvailabilityStatus[];
cities: string[];
}

export interface IFilterSubmittionForm
extends Omit<IFilterFormProps, 'priority'> {
priority: string;
}
export interface IFilterFormikProps {
search: string;
priority: ISelectField<SupplyPriority> | null;
priority: ISelectField[];
supplyCategories: ISelectField[];
supplies: ISelectField[];
shelterStatus: ISelectField<ShelterAvailabilityStatus>[];
cities: string[];
}

export interface IFilterProps {
onSubmit: (values: IFilterFormProps) => void;
onSubmit: (values: IFilterSubmittionForm) => void;
data: IFilterFormProps;
open: boolean;
onClose: () => void;
Expand Down

0 comments on commit bf42e8b

Please sign in to comment.