mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-18 15:57:31 -03:00
hecho codigo para poder setear usuarios como admin
This commit is contained in:
@@ -1,22 +1,78 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
import { apiBase } from '@/stores/url';
|
||||||
import Button from '../ui/button/button.svelte';
|
import Button from '../ui/button/button.svelte';
|
||||||
import DialogContent from '../ui/dialog/dialog-content.svelte';
|
import DialogContent from '../ui/dialog/dialog-content.svelte';
|
||||||
import DialogHeader from '../ui/dialog/dialog-header.svelte';
|
import DialogHeader from '../ui/dialog/dialog-header.svelte';
|
||||||
import DialogTitle from '../ui/dialog/dialog-title.svelte';
|
import DialogTitle from '../ui/dialog/dialog-title.svelte';
|
||||||
import Dialog from '../ui/dialog/dialog.svelte';
|
import Dialog from '../ui/dialog/dialog.svelte';
|
||||||
|
import type { UserResponseDto } from '../../../types';
|
||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
import { sesionStore } from '@/stores/usuario';
|
||||||
|
|
||||||
let { open = $bindable(), usuario } = $props();
|
interface Props {
|
||||||
|
open: boolean;
|
||||||
|
usuario: UserResponseDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { open = $bindable(), usuario }: Props = $props();
|
||||||
|
|
||||||
|
let mensajeResultado = $state('');
|
||||||
|
let mostrarResultado = $state(false);
|
||||||
|
let esExitoso = $state(false);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if mostrarResultado}
|
||||||
|
<Dialog
|
||||||
|
open={mostrarResultado}
|
||||||
|
onOpenChange={() => {
|
||||||
|
mostrarResultado = false;
|
||||||
|
open = false;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent>
|
||||||
|
<div
|
||||||
|
class={esExitoso
|
||||||
|
? 'rounded border border-green-400 bg-green-100/10 px-4 py-3 text-green-700'
|
||||||
|
: 'rounded border border-red-400 bg-red-100/10 px-4 py-3 text-red-700'}
|
||||||
|
>
|
||||||
|
{mensajeResultado}
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
{/if}
|
||||||
<Dialog {open} onOpenChange={() => (open = false)}>
|
<Dialog {open} onOpenChange={() => (open = false)}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Confirmar Admin</DialogTitle>
|
<DialogTitle>Confirmar Admin</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<form
|
<form
|
||||||
onsubmit={(e) => {
|
onsubmit={async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
const req = await fetch(`${$apiBase}/api/admin/give`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
body: JSON.stringify({ isAdmin: usuario.isAdmin, id: usuario.id }),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${$sesionStore?.accessToken}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (req.ok) {
|
||||||
|
esExitoso = true;
|
||||||
|
mensajeResultado = 'Operación realizada con éxito';
|
||||||
|
mostrarResultado = true;
|
||||||
|
invalidate('admin:load');
|
||||||
|
} else {
|
||||||
|
const res = await req.json();
|
||||||
|
esExitoso = false;
|
||||||
|
mensajeResultado = res.message || 'Error desconocido';
|
||||||
|
mostrarResultado = true;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
esExitoso = false;
|
||||||
|
mensajeResultado = 'Error de conexión';
|
||||||
|
mostrarResultado = true;
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#if usuario}
|
{#if usuario}
|
||||||
|
|||||||
Reference in New Issue
Block a user