|
@@ -0,0 +1,159 @@
|
|
|
+import { useRef, useState } from "react";
|
|
|
+import { Form, Modal, Tooltip, notification } from "antd";
|
|
|
+import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";
|
|
|
+import { Tabla } from "../../../components";
|
|
|
+import { SimpleTableLayout } from "../../../components/layouts";
|
|
|
+import { ActionsButton } from "../../../components";
|
|
|
+import { isEllipsis } from "../../../utilities";
|
|
|
+import { Link, useNavigate } from "react-router-dom";
|
|
|
+import Formulario from "./Formulario";
|
|
|
+import HttpService from "../../../services/httpService";
|
|
|
+
|
|
|
+const endPoint = "municipio";
|
|
|
+
|
|
|
+const Municipios = () => {
|
|
|
+ let tablaRef = useRef(null);
|
|
|
+ const navigate = useNavigate();
|
|
|
+ const [form] = Form.useForm();
|
|
|
+ const [buscarParams, setBuscarParams] = useState({
|
|
|
+ padre: true,
|
|
|
+ });
|
|
|
+
|
|
|
+ const onFinish = (values) => {
|
|
|
+ const { q } = values;
|
|
|
+ const params = {
|
|
|
+ q: q ?? "",
|
|
|
+ padre: true,
|
|
|
+ };
|
|
|
+ setBuscarParams(params);
|
|
|
+ };
|
|
|
+
|
|
|
+ const botones = [
|
|
|
+ {
|
|
|
+ onClick: () => navigate(`/administracion/catalogos/municipios/agregar`),
|
|
|
+ props: { disabled: false, type: "primary", block: false },
|
|
|
+ text: "Nuevo",
|
|
|
+ icon: <PlusOutlined />,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ const linkText = (value, row, key) => (
|
|
|
+ <Link
|
|
|
+ to={`/administracion/catalogos/municipios/editar?id=${row.id}`}
|
|
|
+ style={{ color: "black" }}
|
|
|
+ >
|
|
|
+ {isEllipsis(columns, key) ? (
|
|
|
+ <Tooltip title={value}>{value}</Tooltip>
|
|
|
+ ) : (
|
|
|
+ value
|
|
|
+ )}
|
|
|
+ </Link>
|
|
|
+ );
|
|
|
+
|
|
|
+ const eliminarRegistro = (nombre, id, url, alTerminar) => {
|
|
|
+ if (!id) return;
|
|
|
+ Modal.confirm({
|
|
|
+ title: "Eliminar",
|
|
|
+ content: `¿Está seguro de eliminar "${nombre}"?`,
|
|
|
+ icon: <DeleteOutlined style={{ color: "#ff0000" }} />,
|
|
|
+ okText: "Eliminar",
|
|
|
+ okButtonProps: {
|
|
|
+ type: "primary",
|
|
|
+ danger: true,
|
|
|
+ },
|
|
|
+ cancelText: "Cancelar",
|
|
|
+ onOk: async () => {
|
|
|
+ try {
|
|
|
+ let body = { id: id };
|
|
|
+ if (typeof id === "object") {
|
|
|
+ body = id;
|
|
|
+ }
|
|
|
+ const res = await HttpService.delete(url, body);
|
|
|
+ if (res && res.status === 200) {
|
|
|
+ notification.success({
|
|
|
+ message: "Éxito",
|
|
|
+ description: res?.mensaje,
|
|
|
+ });
|
|
|
+ alTerminar && alTerminar();
|
|
|
+ } else if (res?.status === 400) {
|
|
|
+ notification.error({
|
|
|
+ message: "Atención",
|
|
|
+ description: res?.mensaje,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ notification.error({
|
|
|
+ message: "Error",
|
|
|
+ description: error,
|
|
|
+ });
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const columns = [
|
|
|
+ {
|
|
|
+ title: "Acciones",
|
|
|
+ key: "acciones",
|
|
|
+ dataIndex: "acciones",
|
|
|
+ width: 100,
|
|
|
+ align: "center",
|
|
|
+ render: (_, item) => (
|
|
|
+ <ActionsButton
|
|
|
+ data={[
|
|
|
+ {
|
|
|
+ label: "Editar",
|
|
|
+ onClick: () =>
|
|
|
+ navigate(`/administracion/catalogos/municipios/editar?id=${item?.id}`),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "Eliminar",
|
|
|
+ onClick: () => {
|
|
|
+ eliminarRegistro(item?.nombre, item?.id, endPoint+'/eliminar', () =>
|
|
|
+ tablaRef?.current?.refresh()
|
|
|
+ );
|
|
|
+ },
|
|
|
+ danger: true,
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Nombre",
|
|
|
+ key: "nombre",
|
|
|
+ dataIndex: "nombre",
|
|
|
+ render: linkText,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Estado",
|
|
|
+ key: "estado",
|
|
|
+ dataIndex: ["estado", "nombre"],
|
|
|
+ render: (value) => value,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ return (
|
|
|
+ <SimpleTableLayout
|
|
|
+ btnGroup={{
|
|
|
+ btnGroup: botones,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Formulario
|
|
|
+ form={form}
|
|
|
+ onFinish={onFinish}
|
|
|
+ />
|
|
|
+ <Tabla
|
|
|
+ columns={columns}
|
|
|
+ nameURL={endPoint}
|
|
|
+ expand="estado"
|
|
|
+ extraParams={buscarParams}
|
|
|
+ scroll={{ x: "30vw" }}
|
|
|
+ />
|
|
|
+ </SimpleTableLayout>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default Municipios;
|