Private
Public Access
62 lines
1.4 KiB
Svelte
62 lines
1.4 KiB
Svelte
<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>
|