|
@@ -4,12 +4,12 @@ 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 { isEllipsis, eliminarRegistro } from "../../utilities";
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
|
|
import Formulario from "./Formulario";
|
|
|
-import HttpService from "../../services/httpService";
|
|
|
|
|
|
const endPoint = "condicionante";
|
|
|
+const endPointEliminar = "condicionante/eliminar";
|
|
|
|
|
|
const Condicionantes = () => {
|
|
|
let tablaRef = useRef(null);
|
|
@@ -35,123 +35,80 @@ const Condicionantes = () => {
|
|
|
},
|
|
|
], [navigate]);
|
|
|
|
|
|
- const eliminarRegistro = useCallback((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 linkText = (value, row, key) => (
|
|
|
+ <Link
|
|
|
+ to={`/condicionantes/editar?id=${row.id}`}
|
|
|
+ style={{ color: "black" }}
|
|
|
+ >
|
|
|
+ {isEllipsis(columns, key) ? (
|
|
|
+ <Tooltip title={value}>{value}</Tooltip>
|
|
|
+ ) : (
|
|
|
+ value
|
|
|
+ )}
|
|
|
+ </Link>
|
|
|
+ );
|
|
|
|
|
|
- const columns = useMemo(() => {
|
|
|
- const linkText = (value, row, key) => (
|
|
|
- <Link
|
|
|
- to={`/condicionantes/editar?id=${row.id}`}
|
|
|
- style={{ color: "black" }}
|
|
|
- >
|
|
|
- {isEllipsis(columns, key) ? (
|
|
|
- <Tooltip title={value}>{value}</Tooltip>
|
|
|
- ) : (
|
|
|
- value
|
|
|
- )}
|
|
|
- </Link>
|
|
|
- );
|
|
|
|
|
|
- return [
|
|
|
- {
|
|
|
- title: "Acciones",
|
|
|
- key: "id",
|
|
|
- dataIndex: "id",
|
|
|
- width: 100,
|
|
|
- align: "center",
|
|
|
- render: (_, item) => (
|
|
|
- <ActionsButton
|
|
|
- data={[
|
|
|
- {
|
|
|
- label: "Editar",
|
|
|
- onClick: () =>
|
|
|
- navigate(`/condicionantes/editar?id=${item?.id}`),
|
|
|
- },
|
|
|
- {
|
|
|
- label: "Eliminar",
|
|
|
- onClick: () => {
|
|
|
- eliminarRegistro(item?.titulo, item?.id, endPoint + '/eliminar', () =>
|
|
|
- tablaRef?.current?.refresh()
|
|
|
- );
|
|
|
- },
|
|
|
- danger: true,
|
|
|
+
|
|
|
+ const columns = [
|
|
|
+ {
|
|
|
+ title: "Acciones",
|
|
|
+ key: "id",
|
|
|
+ dataIndex: "id",
|
|
|
+ width: 100,
|
|
|
+ align: "center",
|
|
|
+ render: (_, item) => (
|
|
|
+ <ActionsButton
|
|
|
+ data={[
|
|
|
+ {
|
|
|
+ label: "Editar",
|
|
|
+ onClick: () =>
|
|
|
+ navigate(`/condicionantes/editar?id=${item?.id}`),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "Eliminar",
|
|
|
+ onClick: () => {
|
|
|
+ eliminarRegistro(item?.titulo, item?.id, endPointEliminar, () =>
|
|
|
+ tablaRef?.current?.refresh()
|
|
|
+ );
|
|
|
},
|
|
|
- ]}
|
|
|
- />
|
|
|
- ),
|
|
|
- },
|
|
|
- {
|
|
|
- title: "Título",
|
|
|
- key: "titulo",
|
|
|
- dataIndex: "titulo",
|
|
|
- render: linkText,
|
|
|
- },
|
|
|
- {
|
|
|
- title: "Descripción",
|
|
|
- key: "descripcion",
|
|
|
- dataIndex: "descripcion",
|
|
|
- render: linkText,
|
|
|
- },
|
|
|
- {
|
|
|
- title: "Activa",
|
|
|
- key: "activa",
|
|
|
- dataIndex: "activa",
|
|
|
- render: linkText,
|
|
|
- },
|
|
|
- {
|
|
|
- title: "Editado por",
|
|
|
- key: "editadoPor",
|
|
|
- dataIndex: "editadoPor",
|
|
|
- render: linkText,
|
|
|
- },
|
|
|
- {
|
|
|
- title: "Fecha de Edición",
|
|
|
- key: "fechaEdicion",
|
|
|
- dataIndex: "fechaEdicion",
|
|
|
- render: linkText,
|
|
|
- }
|
|
|
- ];
|
|
|
- }, [eliminarRegistro, navigate]);
|
|
|
+ danger: true,
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Título",
|
|
|
+ key: "titulo",
|
|
|
+ dataIndex: "titulo",
|
|
|
+ render: linkText,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Descripción",
|
|
|
+ key: "descripcion",
|
|
|
+ dataIndex: "descripcion",
|
|
|
+ render: linkText,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Activa",
|
|
|
+ key: "activa",
|
|
|
+ dataIndex: "activa",
|
|
|
+ render: linkText,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Editado por",
|
|
|
+ key: "editadoPor",
|
|
|
+ dataIndex: "editadoPor",
|
|
|
+ render: linkText,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Fecha de Edición",
|
|
|
+ key: "fechaEdicion",
|
|
|
+ dataIndex: "fechaEdicion",
|
|
|
+ render: linkText,
|
|
|
+ }
|
|
|
+ ];
|
|
|
|
|
|
return (
|
|
|
<SimpleTableLayout
|