feat: add DFD number management to pedidos, including editing functionality and validation for sending to acceptance, enhancing data integrity and user feedback
This commit is contained in:
@@ -385,6 +385,11 @@
|
||||
let seiValue = $state('');
|
||||
let updatingSei = $state(false);
|
||||
|
||||
// Edit DFD State
|
||||
let editingDfd = $state(false);
|
||||
let dfdValue = $state('');
|
||||
let updatingDfd = $state(false);
|
||||
|
||||
// Item Details Modal State
|
||||
let showDetailsModal = $state(false);
|
||||
let selectedObjeto = $state<Doc<'objetos'> | null>(null);
|
||||
@@ -820,6 +825,36 @@
|
||||
seiValue = '';
|
||||
}
|
||||
|
||||
async function handleUpdateDfd() {
|
||||
if (!dfdValue.trim()) {
|
||||
toast.error('O número DFD não pode estar vazio.');
|
||||
return;
|
||||
}
|
||||
updatingDfd = true;
|
||||
try {
|
||||
await client.mutation(api.pedidos.updateDfdNumber, {
|
||||
pedidoId,
|
||||
numeroDfd: dfdValue
|
||||
});
|
||||
editingDfd = false;
|
||||
toast.success('Número DFD atualizado com sucesso!');
|
||||
} catch (e) {
|
||||
toast.error('Erro ao atualizar número DFD: ' + (e as Error).message);
|
||||
} finally {
|
||||
updatingDfd = false;
|
||||
}
|
||||
}
|
||||
|
||||
function startEditingDfd() {
|
||||
dfdValue = pedido?.numeroDfd || '';
|
||||
editingDfd = true;
|
||||
}
|
||||
|
||||
function cancelEditingDfd() {
|
||||
editingDfd = false;
|
||||
dfdValue = '';
|
||||
}
|
||||
|
||||
function getStatusColor(status: string) {
|
||||
switch (status) {
|
||||
case 'em_rascunho':
|
||||
@@ -853,6 +888,8 @@
|
||||
return '🔄';
|
||||
case 'atualizacao_sei':
|
||||
return '📋';
|
||||
case 'atualizacao_dfd':
|
||||
return '📋';
|
||||
case 'edicao_item':
|
||||
return '✏️';
|
||||
case 'solicitacao_ajuste':
|
||||
@@ -898,7 +935,9 @@
|
||||
case 'alteracao_status':
|
||||
return `${entry.usuarioNome} alterou o status para "${formatStatus(detalhes.novoStatus)}"`;
|
||||
case 'atualizacao_sei':
|
||||
return `${entry.usuarioNome} atualizou o número SEI para "${detalhes.numeroSei}"`;
|
||||
return `${entry.usuarioNome} atualizou o número SEI para "${detalhes.para}"`;
|
||||
case 'atualizacao_dfd':
|
||||
return `${entry.usuarioNome} atualizou o número DFD para "${detalhes.para}"`;
|
||||
case 'edicao_item': {
|
||||
const objeto = objetos.find((o) => o._id === detalhes.objetoId);
|
||||
const nomeObjeto = objeto?.nome || 'Objeto desconhecido';
|
||||
@@ -1111,53 +1150,102 @@
|
||||
<div class="mb-6 flex items-start justify-between">
|
||||
<div>
|
||||
<h1 class="flex items-center gap-3 text-2xl font-bold">
|
||||
{#if editingSei}
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={seiValue}
|
||||
class="rounded border px-2 py-1 text-sm"
|
||||
placeholder="Número SEI"
|
||||
disabled={updatingSei}
|
||||
/>
|
||||
<button
|
||||
onclick={handleUpdateSei}
|
||||
disabled={updatingSei}
|
||||
class="rounded bg-green-600 p-1 text-white hover:bg-green-700 disabled:opacity-50"
|
||||
title="Salvar"
|
||||
>
|
||||
<Save size={16} />
|
||||
</button>
|
||||
<button
|
||||
onclick={cancelEditingSei}
|
||||
disabled={updatingSei}
|
||||
class="rounded bg-gray-400 p-1 text-white hover:bg-gray-500 disabled:opacity-50"
|
||||
title="Cancelar"
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center gap-2">
|
||||
<span>Pedido {pedido.numeroSei || 'sem número SEI'}</span>
|
||||
{#if pedido.status === 'em_rascunho' || pedido.status === 'precisa_ajustes'}
|
||||
<div class="flex items-center gap-4">
|
||||
{#if editingSei}
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={seiValue}
|
||||
class="rounded border px-2 py-1 text-sm"
|
||||
placeholder="Número SEI"
|
||||
disabled={updatingSei}
|
||||
/>
|
||||
<button
|
||||
onclick={startEditingSei}
|
||||
class="rounded bg-blue-100 p-1 text-blue-600 hover:bg-blue-200"
|
||||
title="Editar número SEI"
|
||||
onclick={handleUpdateSei}
|
||||
disabled={updatingSei}
|
||||
class="rounded bg-green-600 p-1 text-white hover:bg-green-700 disabled:opacity-50"
|
||||
title="Salvar"
|
||||
>
|
||||
<Edit size={16} />
|
||||
<Save size={16} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<button
|
||||
onclick={cancelEditingSei}
|
||||
disabled={updatingSei}
|
||||
class="rounded bg-gray-400 p-1 text-white hover:bg-gray-500 disabled:opacity-50"
|
||||
title="Cancelar"
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center gap-2">
|
||||
<span>SEI: {pedido.numeroSei || 'sem número SEI'}</span>
|
||||
{#if pedido.status === 'em_rascunho' || pedido.status === 'precisa_ajustes'}
|
||||
<button
|
||||
onclick={startEditingSei}
|
||||
class="rounded bg-blue-100 p-1 text-blue-600 hover:bg-blue-200"
|
||||
title="Editar número SEI"
|
||||
>
|
||||
<Edit size={16} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if editingDfd}
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={dfdValue}
|
||||
class="rounded border px-2 py-1 text-sm"
|
||||
placeholder="Número DFD"
|
||||
disabled={updatingDfd}
|
||||
/>
|
||||
<button
|
||||
onclick={handleUpdateDfd}
|
||||
disabled={updatingDfd}
|
||||
class="rounded bg-green-600 p-1 text-white hover:bg-green-700 disabled:opacity-50"
|
||||
title="Salvar"
|
||||
>
|
||||
<Save size={16} />
|
||||
</button>
|
||||
<button
|
||||
onclick={cancelEditingDfd}
|
||||
disabled={updatingDfd}
|
||||
class="rounded bg-gray-400 p-1 text-white hover:bg-gray-500 disabled:opacity-50"
|
||||
title="Cancelar"
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center gap-2">
|
||||
<span>DFD: {pedido.numeroDfd || 'sem número DFD'}</span>
|
||||
{#if pedido.status === 'em_rascunho' || pedido.status === 'precisa_ajustes'}
|
||||
<button
|
||||
onclick={startEditingDfd}
|
||||
class="rounded bg-blue-100 p-1 text-blue-600 hover:bg-blue-200"
|
||||
title="Editar número DFD"
|
||||
>
|
||||
<Edit size={16} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<span class="rounded-full px-3 py-1 text-sm font-medium {getStatusColor(pedido.status)}">
|
||||
{formatStatus(pedido.status)}
|
||||
</span>
|
||||
</h1>
|
||||
{#if !pedido.numeroSei}
|
||||
<p class="mt-1 text-sm text-amber-600">
|
||||
⚠️ Este pedido não possui número SEI. Adicione um número SEI quando disponível.
|
||||
⚠️ Este pedido não possui número SEI. Um número SEI deve ser informado antes de enviar
|
||||
para aceite.
|
||||
</p>
|
||||
{/if}
|
||||
{#if !pedido.numeroDfd}
|
||||
<p class="mt-1 text-sm text-amber-600">
|
||||
⚠️ Este pedido não possui número DFD. Um número DFD deve ser informado antes de enviar
|
||||
para aceite.
|
||||
</p>
|
||||
{/if}
|
||||
{#if pedido.status === 'precisa_ajustes' && pedido.descricaoAjuste}
|
||||
@@ -1174,7 +1262,11 @@
|
||||
{#if permissions?.canSendToAcceptance}
|
||||
<button
|
||||
onclick={handleEnviarParaAceite}
|
||||
class="flex items-center gap-2 rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700"
|
||||
disabled={!pedido.numeroSei || !pedido.numeroDfd}
|
||||
class={[
|
||||
'flex items-center gap-2 rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700',
|
||||
!pedido.numeroSei || !pedido.numeroDfd ? 'cursor-not-allowed opacity-50' : ''
|
||||
]}
|
||||
>
|
||||
<Send size={18} /> Enviar para Aceite
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user