Skip to content

Commit 063850f

Browse files
committed
fix: priority
1 parent 9f7a08b commit 063850f

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/pages/Home/Home.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useCallback, useContext, useMemo, useState } from 'react';
2-
import { useNavigate } from 'react-router-dom';
1+
import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
2+
import { useNavigate, useSearchParams } from 'react-router-dom';
33
import { RotateCw, LogOutIcon } from 'lucide-react';
44
import qs from 'query-string';
55

@@ -21,6 +21,7 @@ const initialFilterData: IFilterFormProps = {
2121

2222
const Home = () => {
2323
const { data: shelters, loading, refresh } = useShelters();
24+
const [searchParams, setSearchParams] = useSearchParams();
2425
const {
2526
loading: loadingSession,
2627
refreshSession,
@@ -37,7 +38,6 @@ const Home = () => {
3738
const params = {
3839
search: v ? qs.stringify(filterData, { arrayFormat: 'bracket' }) : '',
3940
};
40-
4141
refresh({
4242
params: params,
4343
});
@@ -58,11 +58,21 @@ const Home = () => {
5858
[shelters.page, shelters.perPage, shelters.count]
5959
);
6060

61-
const onSubmitFilterForm = useCallback((values: IFilterFormProps) => {
62-
setOpenModal(false);
63-
setFilterData(values);
64-
//TODO: logica de buscar no filtro
65-
}, []);
61+
const onSubmitFilterForm = useCallback(
62+
(values: IFilterFormProps) => {
63+
setOpenModal(false);
64+
setFilterData(values);
65+
console.log(values);
66+
const search = qs.stringify(values, { arrayFormat: 'bracket' });
67+
setSearchParams(search);
68+
refresh({
69+
params: {
70+
search,
71+
},
72+
});
73+
},
74+
[refresh, setSearchParams]
75+
);
6676

6777
const handleFetchMore = useCallback(() => {
6878
const params = {
@@ -80,6 +90,10 @@ const Home = () => {
8090
);
8191
}, [refresh, searchValue, shelters.filters, shelters.page, shelters.perPage]);
8292

93+
useEffect(() => {
94+
console.log(searchParams.toString());
95+
}, [searchParams]);
96+
8397
return (
8498
<div className="flex flex-col h-screen items-center">
8599
{isModalOpen && (

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
ShelterAvailabilityStatus,
2121
} from './types';
2222
import { priorityOptions } from '@/lib/utils';
23-
import { ISupply } from '@/service/supply/types';
23+
import { ISupply, SupplyPriority } from '@/service/supply/types';
2424
import { useCallback } from 'react';
2525

2626
const Filter = (props: IFilterProps) => {
@@ -37,7 +37,12 @@ const Filter = (props: IFilterProps) => {
3737
validationSchema: Yup.object().shape({
3838
search: Yup.string(),
3939
}),
40-
onSubmit,
40+
onSubmit: (values) => {
41+
onSubmit({
42+
...values,
43+
priority: values.priority ? +values.priority : null,
44+
});
45+
},
4146
});
4247

4348
const handleToggleShelterStatus = useCallback(
@@ -88,11 +93,12 @@ const Filter = (props: IFilterProps) => {
8893
</label>
8994
<Select
9095
placeholder="Selecione"
91-
defaultValue={values.priority}
9296
options={Object.entries(priorityOptions).map(
9397
([priority, label]) => ({ label, value: priority } as any)
9498
)}
95-
onChange={(v) => setFieldValue('priority', v)}
99+
onChange={(
100+
v: { label: string; value: SupplyPriority } | null
101+
) => setFieldValue('priority', v?.value)}
96102
/>
97103
</div>
98104
<div className="flex flex-col gap-1 w-full">

0 commit comments

Comments
 (0)