add button search postoadms
This commit is contained in:
@ -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<void>;
|
||||
getMunicipiosByName: (name: string) => Promise<void>;
|
||||
createMunicipios: (data: Partial<MunicipiosProps>) => Promise<void>;
|
||||
updateMunicipios: (id: number, data: Partial<MunicipiosProps>) => Promise<void>;
|
||||
deleteMunicipios: (id: number, hardDelete?: boolean) => Promise<void>;
|
||||
restoreMunicipios: (id: number) => Promise<void>;
|
||||
}
|
||||
// interface MunicipiosContext {
|
||||
// municipios: MunicipiosProps[];
|
||||
// getMunicipiosLists: (
|
||||
// limit: number,
|
||||
// page: number,
|
||||
// with_deleted: boolean,
|
||||
// order_field: any,
|
||||
// order_direction: any
|
||||
// ) => Promise<void>;
|
||||
// getMunicipiosByName: (name: string) => Promise<void>;
|
||||
// createMunicipios: (data: Partial<MunicipiosProps>) => Promise<void>;
|
||||
// updateMunicipios: (id: number, data: Partial<MunicipiosProps>) => Promise<void>;
|
||||
// deleteMunicipios: (id: number, hardDelete?: boolean) => Promise<void>;
|
||||
// restoreMunicipios: (id: number) => Promise<void>;
|
||||
// }
|
||||
|
||||
const ManageMunicipiosContext = createContext<ContextProps>(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<string | null>(null);
|
||||
const [municipios, setMunicipios] = useState<MunicipiosProps[]>([]);
|
||||
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<ColumnDef<any>[]>(
|
||||
() => [
|
||||
{
|
||||
@ -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 }) => <DataGridColumnHeader title="Postoadms" column={column} />,
|
||||
enableSorting: true,
|
||||
id: 'actions',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]'
|
||||
}
|
||||
headerClassName: 'w-[100px], text-center',
|
||||
cellClassName: 'text-center'
|
||||
},
|
||||
cell: (info) => (
|
||||
<Button
|
||||
variant={'outline'}
|
||||
onClick={() => navigate(`/master-data/municipios/postoadms/${info.row.original.id}`)}
|
||||
>
|
||||
Details
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
],
|
||||
[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 (
|
||||
<ManageMunicipiosContext.Provider
|
||||
value={{
|
||||
municipios,
|
||||
showSearchDialog,
|
||||
handleSearchDialog,
|
||||
showAddDialog,
|
||||
handleAddDialog,
|
||||
showDeleteDialog,
|
||||
@ -200,7 +231,7 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) =
|
||||
|
||||
<DataGridProvider
|
||||
columns={columns}
|
||||
pagination={{ size: 10 }}
|
||||
pagination={{ size: 25 }}
|
||||
toolbar={<ListToolbar />}
|
||||
layout={{ card: true }}
|
||||
sorting={[{ id: 'id', desc: false }]}
|
||||
|
||||
Reference in New Issue
Block a user