Private
Public Access
falta testeo
This commit is contained in:
1 parent
9205fea8d8
commit
61ca620c8e
50 files changed
+3061
-1112
No files matched your search
@@ -0,0 +1,93 @@
|
||||
<script lang="ts">
|
||||
import { InlineNotification, Modal, TextInput } from 'carbon-components-svelte';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { comentarStock } from '$lib/hooks/stock/comentarStock';
|
||||
import type { StockItem } from '../../types';
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
onClose,
|
||||
stock = null
|
||||
}: {
|
||||
open?: boolean;
|
||||
onClose?: () => void;
|
||||
stock?: StockItem | null;
|
||||
} = $props();
|
||||
|
||||
let observacion = $state('');
|
||||
let error = $state('');
|
||||
let enviando = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (open) {
|
||||
observacion = stock?.observacion ?? '';
|
||||
error = '';
|
||||
enviando = false;
|
||||
}
|
||||
});
|
||||
|
||||
function handleClose() {
|
||||
onClose?.();
|
||||
}
|
||||
|
||||
async function enviar() {
|
||||
if (enviando || !stock) return;
|
||||
enviando = true;
|
||||
error = '';
|
||||
|
||||
const texto = observacion.trim();
|
||||
if (texto.length > 60) {
|
||||
error = 'La observación no puede superar los 60 caracteres.';
|
||||
}
|
||||
|
||||
if (error === '') {
|
||||
const res = await comentarStock(stock.id, texto);
|
||||
if (typeof res === 'string') {
|
||||
error = res;
|
||||
} else {
|
||||
await invalidate('stock:load');
|
||||
handleClose();
|
||||
}
|
||||
}
|
||||
enviando = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
id="comentarStockForm"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void enviar();
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="comentarStockForm"
|
||||
bind:open
|
||||
size="lg"
|
||||
modalHeading="Registrar observación"
|
||||
primaryButtonText="Guardar"
|
||||
primaryButtonDisabled={enviando}
|
||||
secondaryButtonText="Cancelar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="mb-4">
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="mb-4">
|
||||
<p class="text-sm text-gray-400">Repuesto</p>
|
||||
<p class="font-semibold">{stock?.repuesto?.nombre ?? stock?.repuestoId ?? '-'}</p>
|
||||
</div>
|
||||
|
||||
<TextInput
|
||||
labelText="Observación"
|
||||
bind:value={observacion}
|
||||
maxlength={60}
|
||||
placeholder="Máximo 60 caracteres"
|
||||
helperText="Dejá el campo vacío para quitar la observación."
|
||||
/>
|
||||
<div class="mt-1 text-sm text-gray-500">{observacion.length}/60</div>
|
||||
</Modal>
|
||||
</form>
|
||||
Reference in new issue
Block a user