refactor de admin usuarios
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||||
import type { Cliente, Grupo, UpdateCliente } from "../types";
|
import type { Cliente, Grupo, GrupoDto, UpdateCliente } from "../types";
|
||||||
import { urlG } from "../stores/urlStore";
|
import { urlG } from "../stores/urlStore";
|
||||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||||
@@ -63,12 +63,15 @@
|
|||||||
}
|
}
|
||||||
async function cargaGrupos(cli: Cliente) {
|
async function cargaGrupos(cli: Cliente) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+cli.dni, {
|
const response = await fetch(
|
||||||
|
$urlG + "/api/admin/clientes/grupo?Dni=" + cli.dni,
|
||||||
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": String(token),
|
Auth: String(token),
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
Grupos = data;
|
Grupos = data;
|
||||||
@@ -87,12 +90,15 @@
|
|||||||
//WIP añadir una flag para que muestre que no se pudo dar se alta/baja
|
//WIP añadir una flag para que muestre que no se pudo dar se alta/baja
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
try {
|
try {
|
||||||
const response = await fetch($urlG+"/api/admin/cliente?Dni="+cli.dni, {
|
const response = await fetch(
|
||||||
|
$urlG + "/api/admin/cliente?Dni=" + cli.dni,
|
||||||
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": String(token),
|
Auth: String(token),
|
||||||
}
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
modaldata = data.message;
|
modaldata = data.message;
|
||||||
@@ -100,9 +106,7 @@
|
|||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
modaldata = "";
|
modaldata = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
async function añadirGrupo(e: Event, cli: Cliente, grupo: string) {
|
async function añadirGrupo(e: Event, cli: Cliente, grupo: string) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -112,14 +116,17 @@
|
|||||||
}
|
}
|
||||||
const email = cli.email;
|
const email = cli.email;
|
||||||
try {
|
try {
|
||||||
const response = await fetch($urlG+"/api/admin/cliente/addGrupo", {
|
const response = await fetch(
|
||||||
|
$urlG + "/api/admin/cliente/addGrupo",
|
||||||
|
{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": String(token),
|
Auth: String(token),
|
||||||
'Content-Type' : 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({email, grupo})
|
body: JSON.stringify({ email, grupo }),
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
@@ -141,16 +148,21 @@
|
|||||||
}
|
}
|
||||||
const email = cli.email;
|
const email = cli.email;
|
||||||
if (grupo === "Propietario") {
|
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;
|
if (
|
||||||
|
confirm(
|
||||||
|
"Sos propietario si te desactivas de ese rol tus propiedades se van a dar de baja, Estas seguro?",
|
||||||
|
) == false
|
||||||
|
)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const response = await fetch($urlG + "/api/admin/cliente/rmGrupo", {
|
const response = await fetch($urlG + "/api/admin/cliente/rmGrupo", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": String(token),
|
Auth: String(token),
|
||||||
'Content-Type' : 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({email, grupo})
|
body: JSON.stringify({ email, grupo }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -167,7 +179,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let showModificarCliente: boolean = $state(false);
|
let showModificarCliente: boolean = $state(false);
|
||||||
let datoscli:UpdateCliente = $state({dni:0, apellido:"", celular:"", domicilio:"", nombre:""});
|
let datoscli: UpdateCliente = $state({
|
||||||
|
dni: 0,
|
||||||
|
apellido: "",
|
||||||
|
celular: "",
|
||||||
|
domicilio: "",
|
||||||
|
nombre: "",
|
||||||
|
});
|
||||||
|
|
||||||
async function abrirModalModificarCliente(e: Event, cli: Cliente) {
|
async function abrirModalModificarCliente(e: Event, cli: Cliente) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -175,8 +193,8 @@
|
|||||||
const r = await fetch($urlG + "/api/admin/cliente?dni=" + cli.dni, {
|
const r = await fetch($urlG + "/api/admin/cliente?dni=" + cli.dni, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": token||"",
|
Auth: token || "",
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
let data = await r.json();
|
let data = await r.json();
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
@@ -192,7 +210,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function patchCliente(a: UpdateCliente) {
|
async function patchCliente(a: UpdateCliente) {
|
||||||
if (a.apellido =="" || a.celular=="" || a.domicilio=="" || a.nombre==""){
|
if (
|
||||||
|
a.apellido == "" ||
|
||||||
|
a.celular == "" ||
|
||||||
|
a.domicilio == "" ||
|
||||||
|
a.nombre == ""
|
||||||
|
) {
|
||||||
modaldata = "Hay campos vacios";
|
modaldata = "Hay campos vacios";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -201,13 +224,13 @@
|
|||||||
celular: a.celular,
|
celular: a.celular,
|
||||||
domicilio: a.domicilio,
|
domicilio: a.domicilio,
|
||||||
nombre: a.nombre,
|
nombre: a.nombre,
|
||||||
}
|
};
|
||||||
try {
|
try {
|
||||||
const r = await fetch($urlG + "/api/admin/cliente?dni=" + a.dni, {
|
const r = await fetch($urlG + "/api/admin/cliente?dni=" + a.dni, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Auth": token||"",
|
Auth: token || "",
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(dto),
|
body: JSON.stringify(dto),
|
||||||
});
|
});
|
||||||
@@ -227,8 +250,11 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if showModificarCliente}
|
{#if showModificarCliente}
|
||||||
<ModalModificarPropietarios datos={datoscli} onCancel={()=>!!(showModificarCliente = false)}
|
<ModalModificarPropietarios
|
||||||
onConfirm={patchCliente}/>
|
datos={datoscli}
|
||||||
|
onCancel={() => !!(showModificarCliente = false)}
|
||||||
|
onConfirm={patchCliente}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="content-fluid align-items-start">
|
<div class="content-fluid align-items-start">
|
||||||
@@ -237,7 +263,9 @@
|
|||||||
<BarraHorizontalConTexto text="Clientes" />
|
<BarraHorizontalConTexto text="Clientes" />
|
||||||
|
|
||||||
<div style="height:70vh; overflow-y: auto; max-width: 100%">
|
<div style="height:70vh; overflow-y: auto; max-width: 100%">
|
||||||
<table class="table table-responsive table-striped table-hover table-bordered">
|
<table
|
||||||
|
class="table table-responsive table-striped table-hover table-bordered"
|
||||||
|
>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Dni</th>
|
<th>Dni</th>
|
||||||
@@ -254,15 +282,25 @@
|
|||||||
<td>{cli.email}</td>
|
<td>{cli.email}</td>
|
||||||
<td>
|
<td>
|
||||||
{#if cli.habilitado}
|
{#if cli.habilitado}
|
||||||
<button class="btn btn-warning" onclick={(e) => bajaCliente(e, cli)}>
|
<button
|
||||||
|
class="btn btn-warning"
|
||||||
|
onclick={(e) => bajaCliente(e, cli)}
|
||||||
|
>
|
||||||
Baja
|
Baja
|
||||||
</button>
|
</button>
|
||||||
{:else}
|
{:else}
|
||||||
<button class="btn btn-success" onclick={(e) => bajaCliente(e, cli)}>
|
<button
|
||||||
|
class="btn btn-success"
|
||||||
|
onclick={(e) => bajaCliente(e, cli)}
|
||||||
|
>
|
||||||
Alta
|
Alta
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
<button class="btn btn-secondary" onclick={(e)=>abrirModalModificarCliente(e, cli)}>
|
<button
|
||||||
|
class="btn btn-secondary"
|
||||||
|
onclick={(e) =>
|
||||||
|
abrirModalModificarCliente(e, cli)}
|
||||||
|
>
|
||||||
Modificar
|
Modificar
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
@@ -274,7 +312,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col me-2 ps-0">
|
<div class="col me-2 ps-0">
|
||||||
<BarraHorizontalConTexto text="Grupos del Cliente Seleccionado" />
|
<BarraHorizontalConTexto text="Grupos del Cliente Seleccionado" />
|
||||||
<table class="table table-striped table-responsive table-sm table-bordered">
|
<table
|
||||||
|
class="table table-striped table-responsive table-sm table-bordered"
|
||||||
|
>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Id</th>
|
<th>Id</th>
|
||||||
@@ -284,12 +324,21 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#if Grupos.length > 0}
|
{#if Grupos.length > 0}
|
||||||
|
|
||||||
{#each Grupos as g}
|
{#each Grupos as g}
|
||||||
<tr in:fade>
|
<tr in:fade>
|
||||||
<td>{g.id}</td>
|
<td>{g.id}</td>
|
||||||
<td>{g.descripcion}</td>
|
<td>{g.descripcion}</td>
|
||||||
<td><button class="btn btn-outline-danger" onclick={(e)=>BajaGrupo(e, SelCliente, g.descripcion)}>Baja</button></td>
|
<td
|
||||||
|
><button
|
||||||
|
class="btn btn-outline-danger"
|
||||||
|
onclick={(e) =>
|
||||||
|
BajaGrupo(
|
||||||
|
e,
|
||||||
|
SelCliente,
|
||||||
|
g.descripcion,
|
||||||
|
)}>Baja</button
|
||||||
|
></td
|
||||||
|
>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
{:else if SelCliente != null}
|
{:else if SelCliente != null}
|
||||||
@@ -298,7 +347,9 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{:else}
|
{:else}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">Seleccione un cliente para ver sus grupos</td>
|
<td colspan="3"
|
||||||
|
>Seleccione un cliente para ver sus grupos</td
|
||||||
|
>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -334,4 +385,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Reference in New Issue
Block a user