Falta hacer la notificacion nueva
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import type { MensajeDto } from "../types";
|
||||
import type { GaranteDto, MensajeDto } from "../types";
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalConfirm from "../Componentes/ModalConfirm.svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import { text } from "@sveltejs/kit";
|
||||
import ModalPrecontrato from "../Componentes/ModalPrecontrato.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import ModalAddGarantes from "../Componentes/ModalAddGarantes.svelte";
|
||||
|
||||
const token = sessionStorage.getItem("token");
|
||||
let mensajes: MensajeDto[] = $state([]);
|
||||
let showspinner:boolean =$state(false);
|
||||
let mostrarleidos: boolean = $state(false);
|
||||
let modaldata:string =$state("");
|
||||
let Selmens: MensajeDto;
|
||||
let Selmens: MensajeDto = $state({accion: "",receptor:"", fecha: Date.UTC, mensaje:"", propiedad:0, remitente:""});
|
||||
|
||||
let show:boolean = $state(false);
|
||||
let title:string = $state("");
|
||||
let message:string = $state("");
|
||||
let setCantGarantes = $state(0);
|
||||
|
||||
onMount(async () => {
|
||||
SinLeer();
|
||||
@@ -70,12 +72,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setModalConfirm(men:MensajeDto){
|
||||
Selmens = men;
|
||||
message = "${}"
|
||||
show = true;
|
||||
|
||||
}
|
||||
|
||||
async function marcarleido( fecha: Date, email: string, men:MensajeDto ) {
|
||||
show = true;
|
||||
@@ -92,7 +89,12 @@
|
||||
if (responce.ok) {
|
||||
let data = await responce.json();
|
||||
modaldata = data.message;
|
||||
mensajes = mensajes.filter(m => m !== men);
|
||||
|
||||
if (mostrarleidos) {
|
||||
Leidos();
|
||||
} else {
|
||||
SinLeer();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let dataerror = await responce.json();
|
||||
@@ -102,12 +104,89 @@
|
||||
}
|
||||
}
|
||||
|
||||
function abrirModal(mensaje: MensajeDto) {
|
||||
if (mensaje.accion === "Nuevo Alquiler") {
|
||||
Selmens = { ...mensaje };
|
||||
return;
|
||||
}
|
||||
|
||||
function abrirModal(mensaje: MensajeDto) {
|
||||
Selmens = mensaje;
|
||||
title = "Confirmar proceso de alquiler";
|
||||
message ="Aceptar este proceso eliminará la propiedad del menú de búsqueda. Se informará al inquilino que debe pasar los datos de sus garantías. ¿Desea continuar?";
|
||||
show = true;
|
||||
if (mensaje.accion === "Carge Garantes") {
|
||||
Selmens = { ...mensaje };
|
||||
setCantGarantes = Number(Selmens.mensaje.split(" ").reverse()[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje2(data: {opcionVenta:boolean, cantGarantes:number, mesesHastaAumento:number}) {
|
||||
if (data.opcionVenta == null || data.cantGarantes <=0 || data.mesesHastaAumento<=0) {
|
||||
modaldata = "Estan mal cargados los datos del form";
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let fecha = Selmens.fecha.toString();
|
||||
const datata = {
|
||||
tieneopcionventa: data.opcionVenta,
|
||||
mesesHastaAumento: data.mesesHastaAumento,
|
||||
cantidadGarantes: data.cantGarantes,
|
||||
idPropiedad: Selmens.propiedad,
|
||||
fechaprimernotificacion: fecha,
|
||||
emailInquilino: localStorage.getItem("email"),
|
||||
emailPropietario: Selmens.receptor,
|
||||
};
|
||||
|
||||
let responce = await fetch($urlG+"/api/contratos/precontrato", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(datata),
|
||||
});
|
||||
if(responce.ok) {
|
||||
let dataaa = await responce.json();
|
||||
modaldata = dataaa.message;
|
||||
if (mostrarleidos) {
|
||||
Leidos();
|
||||
} else {
|
||||
SinLeer();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let dataaa = await responce.json();
|
||||
modaldata = dataaa.message;
|
||||
return;
|
||||
} catch (e) {
|
||||
modaldata = "fallo al intentar conectar con el servidor: "+e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje3(garantes: GaranteDto[]) {
|
||||
try {
|
||||
let dat = {
|
||||
emailInquilino: localStorage.getItem("email") || "",
|
||||
idpropiedad: Selmens.propiedad,
|
||||
fecha: Selmens.fecha,
|
||||
garantes: garantes
|
||||
}
|
||||
|
||||
let responce = await fetch($urlG+"/api/contratos/addGarantes", {
|
||||
method : "PUT",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(dat),
|
||||
});
|
||||
|
||||
if (responce.ok){
|
||||
let data = await responce.json();
|
||||
|
||||
}
|
||||
} catch {
|
||||
modaldata = "no se pudo comunicar con el Servidor";
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -118,13 +197,20 @@
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")} />
|
||||
{/if}
|
||||
|
||||
<ModalConfirm
|
||||
<!--
|
||||
<ModalConfirm
|
||||
{show}
|
||||
{title}
|
||||
{message}
|
||||
onCancel={() => (show = false)}
|
||||
onConfirm={()=>1+1}
|
||||
/>
|
||||
/>
|
||||
-->
|
||||
{#if Selmens.accion == "Nuevo Alquiler" }
|
||||
<ModalPrecontrato onClose={() => (Selmens.accion = "")} onSubmit={handleEnviarmensaje2} />
|
||||
{:else if Selmens.accion == "Carge Garantes"}
|
||||
<ModalAddGarantes maxGarantes={setCantGarantes} onClose={() => (Selmens.accion = "")} onSubmit={handleEnviarmensaje3}/>
|
||||
{/if}
|
||||
<div class="container">
|
||||
<br>
|
||||
<BarraHorizontalConTexto text="Notificaciones"/>
|
||||
@@ -148,6 +234,7 @@
|
||||
<tr>
|
||||
<th>Remitente</th>
|
||||
<th>Accion</th>
|
||||
<th>Receptor</th>
|
||||
<th>Mensaje</th>
|
||||
<th>Fecha</th>
|
||||
<th>Propiedad</th>
|
||||
@@ -169,18 +256,29 @@
|
||||
<tr>
|
||||
<td>{men.remitente}</td>
|
||||
<td>{men.accion}</td>
|
||||
<td>{men.receptor}</td>
|
||||
<td>{men.mensaje}</td>
|
||||
<td>{men.fecha}</td>
|
||||
<td>{men.propiedad}</td>
|
||||
|
||||
{#if mostrarleidos == false}
|
||||
<td>
|
||||
<button
|
||||
class="btn btn-outline-primary btn-sm"
|
||||
onclick={() => abrirModal(men)}
|
||||
>
|
||||
Expandir
|
||||
</button>
|
||||
<div class="d-flex">
|
||||
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
onclick={() => abrirModal(men)}
|
||||
>
|
||||
Expandir
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-outline-danger"
|
||||
onclick={() => marcarleido(men.fecha, localStorage.getItem("email")|| "", men)}
|
||||
>
|
||||
Marcar Leido
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
{/if}
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user