From 7772252bab30a8b1385cb88ab7faa31f8985e6dd Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Mon, 17 Mar 2025 16:59:56 +0700 Subject: [PATCH] fix filter --- .../aldeias/hooks/ManageAldeiasContext.tsx | 6 +++-- .../master/postoadms/blocks/ListToolbar.tsx | 4 ++-- .../master/postoadms/blocks/SearchDialog.tsx | 12 +++++----- .../hooks/ManagePostoAdmsContext.tsx | 22 ++++++++++--------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/pages/master/aldeias/hooks/ManageAldeiasContext.tsx b/src/pages/master/aldeias/hooks/ManageAldeiasContext.tsx index 80359b0..a4cf161 100644 --- a/src/pages/master/aldeias/hooks/ManageAldeiasContext.tsx +++ b/src/pages/master/aldeias/hooks/ManageAldeiasContext.tsx @@ -142,15 +142,17 @@ const ManageAldeiasContextProvider = ({ children }: { children: React.ReactNode const getAldeiasLists = async (page: number, limit: number, sorting: any, filter: any) => { try { + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; const response = await GetData(`${API_URL}/aldeias/list`, { limit, page: page + 1, - with_deleted: true, + with_deleted: false, order_field: sorting[0].id, order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', filter: JSON.stringify(filter) }); - // console.log(response?.data); + console.log(response?.data); setAldeias(response?.data.list); return { data: response?.data.list, totalCount: response?.data.total_count }; } catch (error) { diff --git a/src/pages/master/postoadms/blocks/ListToolbar.tsx b/src/pages/master/postoadms/blocks/ListToolbar.tsx index 56a758d..c476994 100644 --- a/src/pages/master/postoadms/blocks/ListToolbar.tsx +++ b/src/pages/master/postoadms/blocks/ListToolbar.tsx @@ -17,9 +17,9 @@ const ListToolbar = () => { - table.getColumn('posto_adms_name')?.setFilterValue(event.target.value) + table.getColumn('PostoAdms_name')?.setFilterValue(event.target.value) } /> diff --git a/src/pages/master/postoadms/blocks/SearchDialog.tsx b/src/pages/master/postoadms/blocks/SearchDialog.tsx index 2218e3e..6b83e74 100644 --- a/src/pages/master/postoadms/blocks/SearchDialog.tsx +++ b/src/pages/master/postoadms/blocks/SearchDialog.tsx @@ -83,7 +83,7 @@ const SearchDialog = () => { setIsFound(false); setSucos([]); }; - + return ( @@ -128,17 +128,17 @@ const SearchDialog = () => { {postoAdms.map((postoAdm) => ( { setFormField({ - id: postoAdm.posto_adms_id, - name: postoAdm.posto_adms_name + id: postoAdm.PostoAdms_id, + name: postoAdm.PostoAdms_name }); setOpen(false); }} > - {postoAdm.posto_adms_name} + {postoAdm.PostoAdms_name} ))} diff --git a/src/pages/master/postoadms/hooks/ManagePostoAdmsContext.tsx b/src/pages/master/postoadms/hooks/ManagePostoAdmsContext.tsx index 55b87c3..4c3ca65 100644 --- a/src/pages/master/postoadms/hooks/ManagePostoAdmsContext.tsx +++ b/src/pages/master/postoadms/hooks/ManagePostoAdmsContext.tsx @@ -9,8 +9,8 @@ import ListToolbar from '../blocks/ListToolbar'; import { useCallApi } from '@/hooks'; interface PostoAdmsProps { - posto_adms_id: number; - posto_adms_name: string; + PostoAdms_id: number; + PostoAdms_name: string; municipios_name: string; } @@ -84,8 +84,9 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod const columns = useMemo[]>( () => [ { - accessorFn: (row) => row.posto_adms_id, - id: 'id', + // accessorFn: (row) => row.PostoAdms_id, + // id: 'PostoAdms_id', + accessorKey: 'PostoAdms_id', header: ({ column }) => , enableSorting: true, enableHiding: false, @@ -96,7 +97,7 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod { // accessorFn: (row) => row.posto_adms_name, // id: 'posto_adms_name', - accessorKey: 'posto_adms_name', + accessorKey: 'PostoAdms_name', header: ({ column }) => ( ), @@ -127,13 +128,13 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod <> @@ -151,16 +152,17 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod const getPostoAdmsLists = async (page: number, limit: number, sorting: any, filter: any) => { try { - sorting: sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; const response = await GetData(`${API_URL}/postoadms/list`, { limit, page: page + 1, with_deleted: false, order_field: sorting[0].id, - order_direction: sorting[0].desc ? 'DESC' : 'ASC' + order_direction: sorting[0].desc ? 'DESC' : 'ASC', + filter: JSON.stringify(filter) }); - // console.log(response.data); + console.log(response?.data); // const sortedList = response.data.data.list.sort((a: PostoAdmsProps, b: PostoAdmsProps) => { // if (a.name < b.name) return -1; // if (a.name > b.name) return 1;