fix+feat: añadido crear usuario y separado en componentes los modals

This commit is contained in:
fede committed 2026-06-05 20:29:23 -03:00
1 parent eff116fab0
commit 62ec25b768
14 files changed
+387 -131

No files matched your search

@@ -0,0 +1,61 @@
<script lang="ts">
import { crearUsuario } from '$lib/hooks/crearUsuario.js';
import { Button, Modal, PasswordInput, TextInput } from 'carbon-components-svelte';
let { show = $bindable(), onclose }: { show?: boolean; onclose: () => void } = $props();
let name = $state('');
let email = $state('');
let password = $state('');
let error = $state('');
async function handleSubmit(e: Event) {
e.preventDefault();
error = '';
const result = await crearUsuario({ name, email, password });
if (result !== 'Ok') {
error = result;
return;
}
reset();
onclose();
}
function handleClose() {
reset();
onclose();
}
function reset() {
name = '';
email = '';
password = '';
error = '';
}
</script>
<form id="crearForm" onsubmit={handleSubmit}>
<Modal
formId="crearForm"
bind:open={show}
modalHeading="Registrar Nuevo Usuario"
primaryButtonText="Crear"
secondaryButtonText="Cerrar"
on:click:button--secondary={handleClose}
>
{#if error}
<div class="error-msg">{error}</div>
{/if}
<TextInput bind:value={name} labelText="Nombre" placeholder="Tu nombre" />
<TextInput bind:value={email} labelText="Email" placeholder="tu@email.com" type="email" />
<PasswordInput bind:value={password} labelText="Contraseña" placeholder="••••••••" minlength={8} />
</Modal>
</form>
<style>
.error-msg {
color: #da1e28;
margin-bottom: 1rem;
font-size: 0.875rem;
}
</style>