From a6d64de16cb082a8c949dd8929132fbc94dc6145 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 17 Dec 2022 15:51:49 -0600 Subject: [PATCH] Se pueden agregar Contactos, Grupos y aasignar contactos al grupo --- .../Utils/Notificaciones/Notificaciones.tsx | 243 ++++++++++++++++-- .../DTONotificacionesContactoGrupo.ts | 5 + src/Interfaces/Utils/INotificacionesGrupos.ts | 2 +- .../Notificaciones/Notificaciones.Services.ts | 14 +- 4 files changed, 239 insertions(+), 25 deletions(-) create mode 100644 src/DTO/Utils/Notificaciones/DTONotificacionesContactoGrupo.ts diff --git a/src/Components/Utils/Notificaciones/Notificaciones.tsx b/src/Components/Utils/Notificaciones/Notificaciones.tsx index fdcce6e..d6eef16 100644 --- a/src/Components/Utils/Notificaciones/Notificaciones.tsx +++ b/src/Components/Utils/Notificaciones/Notificaciones.tsx @@ -15,15 +15,27 @@ import INotificacionesContactos from '../../../Interfaces/Utils/INotificacionesC import INotificacionesGrupos from '../../../Interfaces/Utils/INotificacionesGrupos' import { MsgInformativo } from '../Toast/msgInformativo' import NotificacionesDS from '../../../Services/Utils/Notificaciones/Notificaciones.Services' -import { AiFillCaretLeft, AiFillCaretRight } from 'react-icons/ai' +import { + AiFillCaretLeft, + AiFillCaretRight, + AiOutlineTeam, + AiOutlineUsergroupAdd +} from 'react-icons/ai' +import { IconContext } from 'react-icons' +import { HiCurrencyDollar } from 'react-icons/hi' +import DTONotificacionesContactoGrupo from '../../../DTO/Utils/Notificaciones/DTONotificacionesContactoGrupo' +import { number } from 'yup/lib/locale' export interface INotificacionesProps {} export function Notificaciones(props: INotificacionesProps) { + const [selectedRows, setSelectedRows] = React.useState([]) const [Grupos, setGrupos] = useState([]) const [Contactos, setContactos] = useState([]) + const [ContactosdelGrupo, setContactosdelGrupo] = useState([]) const [Mensaje, setMensaje] = useState('') - const [Grupo, setGrupo] = useState(0) + const [Grupo, setGrupo] = useState('') + const [IdGrupo, setIdGrupo] = useState(0) const [IdContacto, setIdContacto] = useState(0) const [Nombre, setNombre] = useState('') const [Puesto, setPuesto] = useState('') @@ -31,12 +43,13 @@ export function Notificaciones(props: INotificacionesProps) { const [Empresa, setEmpresa] = useState('') const [Activo, setActivo] = useState(1) const [ShowModal, setShowModal] = useState(false) + const [ShowModalG, setShowModalG] = useState(false) const [header, setHeader] = useState('') const [show, setShowMsg] = useState(false) const [msg, setMsg] = useState('') const msgColor = 'primary' - const colContactosConcepts = [ + const colContactos = [ { name: 'id', width: '60px', @@ -115,6 +128,33 @@ export function Notificaciones(props: INotificacionesProps) { activo: Activo } NotificacionesDS.ContactosAppend(data) + .then((response) => { + setHeader('Informativo') + setMsg('Se encontro la siguiente informacion...') + setShowMsg(true) + loadAllContacts() + }) + .catch((e: Error) => { + setHeader('Error') + setMsg('Ocurrio un error: ' + e) + setShowMsg(true) + return + }) + } + + const saveGroup = () => { + if (!Grupo) { + setHeader('Error') + setMsg('Favor de proporcionar el nombre') + setShowMsg(true) + return + } + const data: INotificacionesGrupos = { + id: IdContacto, + grupo: Grupo, + activo: 1 + } + NotificacionesDS.GruposAppend(data) .then((response) => { setHeader('Informativo') setMsg('Se encontro la siguiente informacion...') @@ -128,7 +168,7 @@ export function Notificaciones(props: INotificacionesProps) { }) } - const loadContacts = () => { + const loadAllContacts = () => { NotificacionesDS.ContactosGet() .then((response) => { setContactos(response.data) @@ -141,10 +181,81 @@ export function Notificaciones(props: INotificacionesProps) { }) } + const loadGroupContacts = () => { + NotificacionesDS.ContactosdelGrupoGet(IdGrupo) + .then((response) => { + setContactosdelGrupo(response.data) + }) + .catch((e: Error) => { + setHeader('Error') + setMsg('Ocurrio un error: ' + e) + setShowMsg(true) + return + }) + } + + const loadGroups = () => { + NotificacionesDS.GruposGet() + .then((response) => { + setGrupos(response.data) + }) + .catch((e: Error) => { + setHeader('Error') + setMsg('Ocurrio un error: ' + e) + setShowMsg(true) + return + }) + } + useEffect(() => { - loadContacts() + loadAllContacts() + loadGroups() + }, []) + + + useEffect(() => { + loadGroupContacts() + }, [IdGrupo]) + + const handleRowSelected = React.useCallback((state) => { + setSelectedRows(state.selectedRows) }, []) + const asignaContactoAlGrupo = (accion: number) => { + if (IdGrupo === 0) { + setHeader('Error') + setMsg(`Antes de asignar un usuario a un grupo, seleccione el grupo`) + setShowMsg(true) + return + } + const listaContactos: INotificacionesContactos[] = selectedRows + var contactos: number[] = [] + listaContactos.forEach((row) => { + contactos.push(row.id) + }) + const data: DTONotificacionesContactoGrupo = { + idgrupo: IdGrupo, + accion, + contactos + } + NotificacionesDS.AsignacionContactosGrupos(data) + .then((response) => { + setHeader('Informativo') + setMsg( + accion === 1 + ? `Se agregaron los contactos al grupo` + : `Se eliminaron los contactos del grupo` + ) + setShowMsg(true) + }) + .catch((e: Error) => { + setHeader('Error') + setMsg('Ocurrio un error: ' + e) + setShowMsg(true) + return + }) + } + return (
@@ -162,12 +273,26 @@ export function Notificaciones(props: INotificacionesProps) { }} /> - Grupo + + Grupo + { + setShowModalG(!ShowModalG) + }} + > + + + + + { - setGrupo(parseInt(e.target.value)) + setIdGrupo(parseInt(e.target.value)) }} className="form-select form-select-sm" > @@ -194,12 +319,20 @@ export function Notificaciones(props: INotificacionesProps) { - { - setShowModal(!ShowModal) - }} - > + Contactos + { + setShowModal(!ShowModal) + }} + > + + + + @@ -212,9 +345,11 @@ export function Notificaciones(props: INotificacionesProps) { paginationPerPage={10} pagination highlightOnHover - columns={colContactosConcepts} - data={Contactos} + selectableRows + columns={colContactos} + data={Contactos.filter(obj1 => !ContactosdelGrupo.some(obj2 => obj1.id === obj2.id))} pointerOnHover + onSelectedRowsChange={handleRowSelected} /> @@ -229,8 +364,13 @@ export function Notificaciones(props: INotificacionesProps) {   - - @@ -245,9 +385,14 @@ export function Notificaciones(props: INotificacionesProps) {   - + @@ -257,7 +402,23 @@ export function Notificaciones(props: INotificacionesProps) { Contactos en el grupo - + + + @@ -389,6 +550,50 @@ export function Notificaciones(props: INotificacionesProps) {
+ + { + setShowModalG(false) + }} + size={'sm'} + dialogClassName={'modal-50w'} + closeButton + > + +
+ + + + { + setGrupo(e.target.value) + }} + style={{ height: '45px' }} + /> + + + + + + +
+
+
+ ("/Notificaciones/Contacto/Append", data); + return http.post(`/Notificaciones/Contacto/Append`, data); } ContactosGet() { return http.get(`/Notificaciones/Contacto/Get`); } GruposAppend(data: INotificacionesGrupos) { - return http.post("/Corresponsalias/Anticipos/Append", data); + return http.post(`/Notificaciones/Grupos/Append`, data); } GruposGet() { - return http.get(`/Corresponsalias/Anticipos/Get`); + return http.get(`/Notificaciones/Grupos/Get`); } - ContactosGruposAction(data: INotificacionesContactosGrupos) { - return http.post("/Corresponsalias/Anticipos/Append", data); + AsignacionContactosGrupos(data: DTONotificacionesContactoGrupo) { + return http.post(`/Notificaciones/Asignacion/Contactos/Grupos`, data); + } + ContactosdelGrupoGet(IdGrupo: number) { + return http.get(`/Notificaciones/ContactosdelGrupo/Get?idGrupo=${IdGrupo}`); }