Private
Public Access
59 lines
1.3 KiB
Svelte
59 lines
1.3 KiB
Svelte
<script lang="ts">
|
|
import { InlineNotification, Modal } from 'carbon-components-svelte';
|
|
import { altaCliente } from '$lib/hooks/clientes/altaCliente';
|
|
import { invalidate } from '$app/navigation';
|
|
import type { Cliente } from '../../types';
|
|
|
|
let {
|
|
open = $bindable(),
|
|
onClose,
|
|
cliente
|
|
}: {
|
|
open?: boolean;
|
|
onClose?: () => void;
|
|
cliente?: Cliente | null;
|
|
} = $props();
|
|
|
|
let error = $state('');
|
|
|
|
async function handleSubmit(e: Event) {
|
|
e.preventDefault();
|
|
error = '';
|
|
if (!cliente?.ID) {
|
|
error = 'No se pudo obtener el cliente. Recargá la página.';
|
|
return;
|
|
}
|
|
const result = await altaCliente(cliente.ID);
|
|
if (result !== 'Ok') {
|
|
error = result;
|
|
return;
|
|
}
|
|
await invalidate('clientes:load');
|
|
handleClose();
|
|
}
|
|
|
|
function handleClose() {
|
|
error = '';
|
|
onClose?.();
|
|
}
|
|
</script>
|
|
|
|
<form id="altaClienteForm" onsubmit={handleSubmit}>
|
|
<Modal
|
|
formId="altaClienteForm"
|
|
bind:open
|
|
size="lg"
|
|
modalHeading="Reactivar cliente"
|
|
primaryButtonText="Reactivar"
|
|
secondaryButtonText="Cancelar"
|
|
on:click:button--secondary={handleClose}
|
|
>
|
|
{#if error}
|
|
<div class="mb-4">
|
|
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
|
</div>
|
|
{/if}
|
|
<p>¿Está seguro de que desea reactivar este cliente?</p>
|
|
</Modal>
|
|
</form>
|