From f13496a26263483185f6f58259f7fb8586ba9873 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Fri, 28 Feb 2025 18:36:32 +0700 Subject: [PATCH] add button search postoadms --- src/pages/master/municipios/Municipios.tsx | 2 + .../master/municipios/blocks/ListToolbar.tsx | 13 +- .../master/municipios/blocks/SearchDialog.tsx | 177 ++++++++++++++++++ .../hooks/ManageMunicipiosContext.tsx | 85 ++++++--- 4 files changed, 246 insertions(+), 31 deletions(-) create mode 100644 src/pages/master/municipios/blocks/SearchDialog.tsx diff --git a/src/pages/master/municipios/Municipios.tsx b/src/pages/master/municipios/Municipios.tsx index 653cbb8..0538fbd 100644 --- a/src/pages/master/municipios/Municipios.tsx +++ b/src/pages/master/municipios/Municipios.tsx @@ -1,6 +1,7 @@ import { Container, DataGridInner } from '@/components'; import { ManageMunicipiosProvider } from './hooks/ManageMunicipiosContext'; import AddDialog from './blocks/AddDialog'; +import SearchDialog from './blocks/SearchDialog'; const Municipios = () => { return ( @@ -11,6 +12,7 @@ const Municipios = () => { + ); diff --git a/src/pages/master/municipios/blocks/ListToolbar.tsx b/src/pages/master/municipios/blocks/ListToolbar.tsx index a1a90db..0129c85 100644 --- a/src/pages/master/municipios/blocks/ListToolbar.tsx +++ b/src/pages/master/municipios/blocks/ListToolbar.tsx @@ -4,7 +4,7 @@ import { Button } from '@/components/ui/button'; const ListToolbar = () => { const { table, reload } = useDataGrid(); - const { handleAddDialog } = useManageMunicipiosContext(); + const { handleAddDialog, handleSearchDialog } = useManageMunicipiosContext(); return (
@@ -17,9 +17,7 @@ const ListToolbar = () => { type="text" placeholder="Search Municipios" value={(table.getColumn('name')?.getFilterValue() as string) ?? ''} - onChange={(event) => - table.getColumn('name')?.setFilterValue(event.target.value) - } + onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)} /> @@ -33,6 +31,13 @@ const ListToolbar = () => { +
+ +
+ + + + + + + ); +}; + +export default SearchDialog; diff --git a/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx b/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx index 031f8a2..808f57e 100644 --- a/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx +++ b/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx @@ -6,6 +6,8 @@ import axios from 'axios'; import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react'; import { useCallApi } from '@/hooks'; import ListToolbar from '../blocks/ListToolbar'; +import { Button } from '@/components/ui/button'; +import { useNavigate } from 'react-router'; interface MunicipiosProps { id: number; @@ -13,6 +15,9 @@ interface MunicipiosProps { } interface ContextProps { + municipios: MunicipiosProps[]; + showSearchDialog: boolean; + handleSearchDialog: (show: boolean) => void; showEditDialog: boolean; handleEditDialog: (show: boolean, selected_user: string | null) => void; showAddDialog: boolean; @@ -30,42 +35,51 @@ interface ContextProps { } const initialProps: ContextProps = { + municipios: [], + showSearchDialog: false, + handleSearchDialog: (show: boolean) => {}, showEditDialog: false, - handleEditDialog: () => {}, + handleEditDialog: (show: boolean, selected_user: string | null) => {}, showAddDialog: false, - handleAddDialog: () => {}, + handleAddDialog: (show: boolean) => {}, showDeleteDialog: false, - handleDeleteDialog: () => {}, + handleDeleteDialog: (show: boolean, selected_user: string | null) => {}, selectedMunicipios: null, getMunicipiosLists: async () => ({ data: [], totalCount: 0 }) }; -interface MunicipiosContext { - municipios: MunicipiosProps[]; - getMunicipiosLists: ( - limit: number, - page: number, - with_deleted: boolean, - order_field: any, - order_direction: any - ) => Promise; - getMunicipiosByName: (name: string) => Promise; - createMunicipios: (data: Partial) => Promise; - updateMunicipios: (id: number, data: Partial) => Promise; - deleteMunicipios: (id: number, hardDelete?: boolean) => Promise; - restoreMunicipios: (id: number) => Promise; -} +// interface MunicipiosContext { +// municipios: MunicipiosProps[]; +// getMunicipiosLists: ( +// limit: number, +// page: number, +// with_deleted: boolean, +// order_field: any, +// order_direction: any +// ) => Promise; +// getMunicipiosByName: (name: string) => Promise; +// createMunicipios: (data: Partial) => Promise; +// updateMunicipios: (id: number, data: Partial) => Promise; +// deleteMunicipios: (id: number, hardDelete?: boolean) => Promise; +// restoreMunicipios: (id: number) => Promise; +// } const ManageMunicipiosContext = createContext(initialProps); const API_URL = apiConfig.service_master_data; const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) => { + const [showSearchDialog, setShowSearchDialog] = useState(false); const [showEditDialog, setShowEditDialog] = useState(false); const [showAddDialog, setShowAddDialog] = useState(false); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [selectedMunicipios, setSelectedMunicipios] = useState(null); const [municipios, setMunicipios] = useState([]); const { GetData } = useCallApi(); + const navigate = useNavigate(); + + const handleSearchDialog = useCallback((show: boolean) => { + setShowSearchDialog(show); + }, []); const handleAddDialog = useCallback((show: boolean) => { setShowAddDialog(show); @@ -81,6 +95,11 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) = setShowDeleteDialog(show); }, []); + const handleNavigate = (path: string) => { + const url = navigate(`${API_URL}/municipios/postoadms/${path}`); + console.log(url); + }; + const columns = useMemo[]>( () => [ { @@ -100,18 +119,26 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) = enableSorting: true, enableHiding: false, meta: { - headerClassName: 'w-[250px]' + headerClassName: 'w-[1000px]' } }, { - accessorFn: (row) => row.postoadms, - id: 'postoadms', - header: ({ column }) => , - enableSorting: true, + id: 'actions', + header: ({ column }) => , + enableSorting: false, enableHiding: false, meta: { - headerClassName: 'w-[100px]' - } + headerClassName: 'w-[100px], text-center', + cellClassName: 'text-center' + }, + cell: (info) => ( + + ) } ], [handleEditDialog, handleDeleteDialog] @@ -131,6 +158,7 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) = } }); console.log(response.data); + setMunicipios(response.data.data.list); return { data: response?.data.data.list, totalCount: response?.data.data.total_count }; } catch (error) { console.error('Error fetching municipios', error); @@ -182,10 +210,13 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) = console.error('Error restoring municipios', error); } }; - + console.log(municipios); return ( } layout={{ card: true }} sorting={[{ id: 'id', desc: false }]}