feat: terminado tema desabilitacion cliente
This commit is contained in:
@@ -11,7 +11,10 @@
|
||||
let Grupos:any[] = $state([]);
|
||||
let modaldata = $state();
|
||||
let token = sessionStorage.getItem("token");
|
||||
let showAddmenu: boolean = $state(false)
|
||||
let showAddmenu: boolean = $state(false);
|
||||
|
||||
let grupo:string;
|
||||
let SelCliente: Cliente = $state();
|
||||
|
||||
onMount(async () => {
|
||||
try{
|
||||
@@ -33,9 +36,9 @@
|
||||
|
||||
});
|
||||
|
||||
async function cargaGrupos(dni: number){
|
||||
async function cargaGrupos(cli: Cliente){
|
||||
try {
|
||||
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+dni, {
|
||||
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+cli.dni, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
@@ -45,6 +48,7 @@
|
||||
let data = await response.json();
|
||||
Grupos = data;
|
||||
showAddmenu = true;
|
||||
SelCliente = cli;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,6 +78,67 @@
|
||||
}
|
||||
|
||||
}
|
||||
async function añadirGrupo(e:Event, cli: Cliente, grupo:string){
|
||||
e.preventDefault();
|
||||
if (cli.dni == 0 || cli.email == "" || grupo == ""){
|
||||
modaldata = "No se selecciono un cliente o Grupo";
|
||||
return;
|
||||
}
|
||||
const email = cli.email;
|
||||
try {
|
||||
const response = await fetch($urlG+"/api/admin/cliente/addGrupo", {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
'Content-Type' : 'application/json',
|
||||
},
|
||||
body: JSON.stringify({email, grupo})
|
||||
});
|
||||
|
||||
if (response.ok){
|
||||
let data = await response.json();
|
||||
modaldata = data.message;
|
||||
cargaGrupos(cli);
|
||||
return;
|
||||
}
|
||||
let data = await response.json();
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "Falla la conexion al servidor";
|
||||
}
|
||||
}
|
||||
async function BajaGrupo(e:Event, cli: Cliente, grupo:string){
|
||||
e.preventDefault();
|
||||
if (cli.dni == 0 || cli.email == "" || grupo == ""){
|
||||
modaldata = "No se selecciono un cliente o Grupo";
|
||||
return;
|
||||
}
|
||||
const email = cli.email;
|
||||
if (grupo === "Propietario"){
|
||||
if (confirm("Sos propietario si te desactivas de ese rol tus propiedades se van a dar de baja, Estas seguro?") == false) return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch($urlG+"/api/admin/cliente/rmGrupo", {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Auth": String(token),
|
||||
'Content-Type' : 'application/json',
|
||||
},
|
||||
body: JSON.stringify({email, grupo})
|
||||
});
|
||||
|
||||
if (response.ok){
|
||||
let data = await response.json();
|
||||
modaldata = data.message;
|
||||
cargaGrupos(cli);
|
||||
return;
|
||||
}
|
||||
let data = await response.json();
|
||||
modaldata = data.message;
|
||||
} catch {
|
||||
modaldata = "Falla la conexion al servidor";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
@@ -99,7 +164,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Clientes as cli}
|
||||
<tr onclick={() => cargaGrupos(cli.dni)} in:fade>
|
||||
<tr onclick={() => cargaGrupos(cli)} in:fade>
|
||||
<td>{cli.dni}</td>
|
||||
<td>{cli.nombre}</td>
|
||||
<td>{cli.email}</td>
|
||||
@@ -131,13 +196,24 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#if Grupos.length>0}
|
||||
|
||||
{#each Grupos as g}
|
||||
<tr in:fade>
|
||||
<td>{g.id}</td>
|
||||
<td>{g.descripcion}</td>
|
||||
<td><button class="btn btn-outline-danger" onclick={()=>modaldata = "Hi babe"}>Baja</button></td>
|
||||
<td><button class="btn btn-outline-danger" onclick={(e)=>BajaGrupo(e, SelCliente, g.descripcion)}>Baja</button></td>
|
||||
</tr>
|
||||
{/each}
|
||||
{:else if SelCliente != null}
|
||||
<tr>
|
||||
<td colspan="2">Este Cliente no tiene Grupos</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr>
|
||||
<td colspan="2">Seleccione un cliente para ver sus grupos</td>
|
||||
</tr>
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -145,14 +221,14 @@
|
||||
<div in:fade>
|
||||
|
||||
<BarraHorizontalConTexto text="Añadir Grupos al Usuario"/>
|
||||
<form class="card card-body">
|
||||
<form class="card card-body" onsubmit={(e) => añadirGrupo(e,SelCliente, grupo)}>
|
||||
<div class="mb-3">
|
||||
<label for="userRole" class="form-label">Seleccionar Grupo</label>
|
||||
<select id="userRole" class="form-select">
|
||||
<option value="1">Propietario</option>
|
||||
<option value="2">Inquilino</option>
|
||||
<option value="3">Admin</option>
|
||||
<option value="4">Informes</option>
|
||||
<select id="userRole" class="form-select" bind:value={grupo}>
|
||||
<option value="Propietario">Propietario</option>
|
||||
<option value="Inquilino">Inquilino</option>
|
||||
<option value="Admin">Admin</option>
|
||||
<option value="Informes">Informes</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Añadir</button>
|
||||
|
||||
Reference in New Issue
Block a user