143 lines
9.3 KiB
PHP
143 lines
9.3 KiB
PHP
<div>
|
|
<div class="flex items-center justify-between mb-4">
|
|
<h1 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
|
|
<svg class="w-7 h-7 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
|
</svg>
|
|
Mensajes Programados
|
|
</h1>
|
|
<button wire:click="$set('showForm', true)"
|
|
class="bg-green-500 hover:bg-green-600 text-white text-sm px-4 py-2 rounded-lg flex items-center gap-2 transition">
|
|
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
|
|
Programar Mensaje
|
|
</button>
|
|
</div>
|
|
|
|
<div class="flex gap-3 mb-4 flex-wrap">
|
|
<input wire:model.live.debounce.300ms="search" type="text" placeholder="Buscar por teléfono..."
|
|
class="border border-gray-300 rounded-lg px-4 py-2 text-sm w-64 focus:outline-none focus:ring-2 focus:ring-green-400">
|
|
<select wire:model.live="filterStatus" class="border border-gray-300 rounded-lg px-4 py-2 text-sm focus:outline-none">
|
|
<option value="">— Todos —</option>
|
|
<option value="pending">Pendiente</option>
|
|
<option value="sent">Enviado</option>
|
|
<option value="failed">Fallido</option>
|
|
<option value="cancelled">Cancelado</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-xl shadow overflow-hidden">
|
|
<table class="w-full text-sm">
|
|
<thead class="bg-gray-50 border-b">
|
|
<tr>
|
|
<th class="px-4 py-3 text-left text-gray-600">Teléfono</th>
|
|
<th class="px-4 py-3 text-left text-gray-600">Tipo</th>
|
|
<th class="px-4 py-3 text-left text-gray-600">Contenido / Plantilla</th>
|
|
<th class="px-4 py-3 text-left text-gray-600">Fecha programada</th>
|
|
<th class="px-4 py-3 text-center text-gray-600">Estado</th>
|
|
<th class="px-4 py-3 text-center text-gray-600">Acciones</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-100">
|
|
@forelse($messages as $msg)
|
|
<tr class="hover:bg-gray-50">
|
|
<td class="px-4 py-3 font-mono text-xs">{{ $msg->phone_number }}</td>
|
|
<td class="px-4 py-3">
|
|
<span class="text-xs bg-blue-50 text-blue-700 px-2 py-0.5 rounded uppercase">{{ $msg->message_type }}</span>
|
|
</td>
|
|
<td class="px-4 py-3 text-gray-600 max-w-xs truncate">
|
|
{{ $msg->message_type === 'text' ? Str::limit($msg->message_content, 50) : $msg->template_name }}
|
|
</td>
|
|
<td class="px-4 py-3 text-gray-600">
|
|
{{ \Carbon\Carbon::parse($msg->scheduled_date)->format('d/m/Y') }}
|
|
{{ $msg->scheduled_time }}
|
|
</td>
|
|
<td class="px-4 py-3 text-center">
|
|
@php
|
|
$colors = ['pending'=>'yellow','sent'=>'green','failed'=>'red','cancelled'=>'gray'];
|
|
$c = $colors[$msg->status] ?? 'gray';
|
|
@endphp
|
|
<span class="text-xs px-2 py-0.5 rounded-full bg-{{ $c }}-100 text-{{ $c }}-700 capitalize">{{ $msg->status }}</span>
|
|
</td>
|
|
<td class="px-4 py-3">
|
|
<div class="flex justify-center gap-2">
|
|
@if($msg->status === 'pending')
|
|
<button wire:click="cancel({{ $msg->id }})" wire:confirm="¿Cancelar este mensaje?"
|
|
class="text-yellow-500 hover:text-yellow-700 text-xs">Cancelar</button>
|
|
@endif
|
|
<button wire:click="delete({{ $msg->id }})" wire:confirm="¿Eliminar este registro?"
|
|
class="text-red-400 hover:text-red-600 transition">
|
|
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr><td colspan="6" class="px-4 py-8 text-center text-gray-400">No hay mensajes programados</td></tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
<div class="p-3 border-t border-gray-100">{{ $messages->links() }}</div>
|
|
</div>
|
|
|
|
{{-- Modal formulario --}}
|
|
@if($showForm)
|
|
<div class="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
|
|
<div class="bg-white rounded-2xl shadow-xl w-full max-w-md p-6">
|
|
<h3 class="text-lg font-bold text-gray-800 mb-4">Programar Mensaje</h3>
|
|
<form wire:submit.prevent="save" class="space-y-4">
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Número de teléfono *</label>
|
|
<input wire:model="phoneNumber" type="text" placeholder="573001234567"
|
|
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
|
|
@error('phoneNumber') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
|
|
</div>
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Fecha *</label>
|
|
<input wire:model="scheduledDate" type="date"
|
|
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
|
|
@error('scheduledDate') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Hora *</label>
|
|
<input wire:model="scheduledTime" type="time"
|
|
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
|
|
@error('scheduledTime') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Tipo de mensaje</label>
|
|
<select wire:model.live="messageType" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none">
|
|
<option value="text">Texto libre</option>
|
|
<option value="template">Plantilla</option>
|
|
</select>
|
|
</div>
|
|
@if($messageType === 'text')
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Mensaje *</label>
|
|
<textarea wire:model="messageContent" rows="3"
|
|
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-green-400"></textarea>
|
|
@error('messageContent') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
|
|
</div>
|
|
@else
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Plantilla *</label>
|
|
<select wire:model="templateId" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none">
|
|
<option value="">— Seleccionar —</option>
|
|
@foreach($templates as $tpl)
|
|
<option value="{{ $tpl->id }}">{{ $tpl->name }} ({{ $tpl->template_name }})</option>
|
|
@endforeach
|
|
</select>
|
|
@error('templateId') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
|
|
</div>
|
|
@endif
|
|
<div class="flex justify-end gap-3 pt-2 border-t border-gray-100">
|
|
<button type="button" wire:click="resetForm()" class="px-4 py-2 text-sm text-gray-600 hover:text-gray-800">Cancelar</button>
|
|
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white text-sm px-4 py-2 rounded-lg">Programar</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|