feat: Implement pedido adjustment workflow with description field and dedicated mutations.

This commit is contained in:
2025-12-08 18:58:40 -03:00
parent ff91d8a3ab
commit e92b10668e
3 changed files with 189 additions and 30 deletions

View File

@@ -286,15 +286,6 @@
}
}
async function handleSolicitarAjustes() {
if (!confirm('Solicitar ajustes?')) return;
try {
await client.mutation(api.pedidos.solicitarAjustes, { pedidoId });
} catch (e) {
alert('Erro: ' + (e as Error).message);
}
}
async function handleCancelar() {
if (!confirm('Cancelar pedido?')) return;
try {
@@ -600,6 +591,40 @@
alert('Erro ao dividir pedido: ' + (e as Error).message);
}
}
// Adjustment Modal State
let showRequestAdjustmentsModal = $state(false);
let adjustmentDescription = $state('');
function openRequestAdjustmentsModal() {
adjustmentDescription = '';
showRequestAdjustmentsModal = true;
}
async function confirmRequestAdjustments() {
if (!adjustmentDescription.trim()) {
alert('Por favor, informe a descrição dos ajustes necessários.');
return;
}
try {
await client.mutation(api.pedidos.solicitarAjustes, {
pedidoId,
descricao: adjustmentDescription
});
showRequestAdjustmentsModal = false;
} catch (e) {
alert('Erro: ' + (e as Error).message);
}
}
async function handleConcluirAjustes() {
if (!confirm('Concluir ajustes e retornar para análise?')) return;
try {
await client.mutation(api.pedidos.concluirAjustes, { pedidoId });
} catch (e) {
alert('Erro: ' + (e as Error).message);
}
}
</script>
<div class="container mx-auto p-6">
@@ -660,6 +685,14 @@
⚠️ Este pedido não possui número SEI. Adicione um número SEI quando disponível.
</p>
{/if}
{#if pedido.status === 'precisa_ajustes' && pedido.descricaoAjuste}
<div class="mt-2 rounded-md border border-orange-200 bg-orange-50 p-4">
<h3 class="flex items-center gap-2 text-sm font-semibold text-orange-800">
<AlertTriangle size={16} /> Ajustes Solicitados:
</h3>
<p class="mt-1 text-sm whitespace-pre-wrap text-orange-700">{pedido.descricaoAjuste}</p>
</div>
{/if}
</div>
<div class="flex gap-2">
@@ -692,13 +725,22 @@
{#if permissions?.canRequestAdjustments}
<button
onclick={handleSolicitarAjustes}
onclick={openRequestAdjustmentsModal}
class="flex items-center gap-2 rounded bg-orange-500 px-4 py-2 text-white hover:bg-orange-600"
>
<AlertTriangle size={18} /> Solicitar Ajustes
</button>
{/if}
{#if permissions?.canCompleteAdjustments}
<button
onclick={handleConcluirAjustes}
class="flex items-center gap-2 rounded bg-teal-600 px-4 py-2 text-white hover:bg-teal-700"
>
<CheckCircle size={18} /> Concluir Ajustes
</button>
{/if}
{#if permissions?.canCancel}
<button
onclick={handleCancelar}
@@ -1313,4 +1355,38 @@
</div>
</div>
{/if}
{#if showRequestAdjustmentsModal}
<div
class="fixed inset-0 z-50 flex h-full w-full items-center justify-center overflow-y-auto bg-black/40"
>
<div class="relative w-full max-w-md rounded-lg bg-white p-6 shadow-xl">
<h3 class="mb-4 text-lg font-bold">Solicitar Ajustes</h3>
<p class="mb-2 text-sm text-gray-600">
Descreva os ajustes necessários para este pedido. O status será alterado para "Precisa de
Ajustes".
</p>
<textarea
bind:value={adjustmentDescription}
class="mb-4 w-full rounded border p-2 text-sm"
rows="5"
placeholder="Ex: O valor do Item 1 está acima do mercado..."
></textarea>
<div class="flex justify-end gap-2">
<button
onclick={() => (showRequestAdjustmentsModal = false)}
class="rounded bg-gray-200 px-4 py-2 text-gray-700 hover:bg-gray-300"
>
Cancelar
</button>
<button
onclick={confirmRequestAdjustments}
class="rounded bg-orange-500 px-4 py-2 text-white hover:bg-orange-600"
>
Confirmar Solicitação
</button>
</div>
</div>
</div>
{/if}
</div>