diff --git a/public/index.html b/public/index.html
index a14562a..dc3c01c 100644
--- a/public/index.html
+++ b/public/index.html
@@ -268,7 +268,7 @@
- | Lead ID | Numero | Mensagem | Status |
+ | Lead ID | Numero | Mensagem | Status | Estagio |
diff --git a/public/js/campanhas.js b/public/js/campanhas.js
index aa4e72b..775b6f8 100644
--- a/public/js/campanhas.js
+++ b/public/js/campanhas.js
@@ -135,17 +135,41 @@ const Campanhas = (() => {
));
}
+ const STAGE_OPTIONS = [
+ 'respondeu', 'interessado', 'demonstracao_agendada', 'sem_interesse', 'opt_out', 'venda_fechada'
+ ];
+
async function carregarFila(campanhaId) {
const status = el('fila-filtro-status').value;
const { fila } = await API.get(`/api/campaigns/${campanhaId}/fila?status=${status}`);
- el('fila-tabela').replaceChildren(...fila.map((linha) =>
- h('tr', {},
+ el('fila-tabela').replaceChildren(...fila.map((linha) => {
+ const podeMarcarEstagio = linha.status === 'sent' || linha.status === 'error';
+ const stageSelect = h('select', { class: 'fila-estagio-select', disabled: podeMarcarEstagio ? null : 'disabled' },
+ h('option', { value: '' }, '—'),
+ ...STAGE_OPTIONS.map((s) => h('option', { value: s }, s)));
+ const marcarBtn = h('button', {
+ class: 'btn-ghost btn-sm', type: 'button', disabled: podeMarcarEstagio ? null : 'disabled',
+ onclick: async () => {
+ if (!stageSelect.value) return;
+ await API.post(`/api/campaigns/leads/${linha.lead_id}/estagio`, { stage: stageSelect.value, campaignId: campanhaId });
+ toast('Estagio atualizado');
+ if (stageSelect.value === 'demonstracao_agendada') {
+ const dataAgendamento = prompt('Data/hora do agendamento (AAAA-MM-DD HH:MM):');
+ if (dataAgendamento) {
+ await API.post(`/api/campaigns/leads/${linha.lead_id}/agendamentos`, { kind: 'demonstracao', scheduledAt: dataAgendamento });
+ toast('Agendamento registrado');
+ }
+ }
+ }
+ }, 'Marcar');
+ return h('tr', {},
h('td', {}, h('input', { type: 'checkbox', class: 'fila-check', value: linha.id })),
h('td', {}, String(linha.lead_id)),
h('td', {}, linha.numero),
h('td', {}, linha.rendered_message),
- h('td', {}, linha.status))
- ));
+ h('td', {}, linha.status),
+ h('td', { class: 'row' }, stageSelect, marcarBtn));
+ }));
}
function filaSelecionada() {