diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index 07af6dd..f80c915 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -41,6 +41,7 @@ class PublicChat extends Component public string $celularRegistro = ''; public string $codigoIngresado = ''; public ?string $emailMascarado = null; + public ?string $errorEnvioOtp = null; public ?int $contactIdPending = null; // contact.id mientras espera verificacion public string $input = ''; public array $mensajes = []; @@ -262,15 +263,23 @@ class PublicChat extends Component // Paso 2b: verificar código OTP // ───────────────────────────────────────────────────────── - private function enviarCodigoOtp(int $contactId, User $user): void + private function enviarCodigoOtp(int $contactId, User $user): bool { $codigo = (string) random_int(100000, 999999); Cache::put("chat_otp_{$contactId}", $codigo, now()->addMinutes(10)); try { Mail::to($user->email)->send(new ChatOtpMail($codigo, $user->name)); + $this->errorEnvioOtp = null; + return true; } catch (\Throwable $e) { - \Illuminate\Support\Facades\Log::warning('[ChatOTP] Error enviando correo: ' . $e->getMessage()); + \Illuminate\Support\Facades\Log::error('[ChatOTP] Error enviando correo a ' . $user->email . ': ' . $e->getMessage(), [ + 'exception' => $e, + 'mailer' => config('mail.default'), + 'host' => config('mail.mailers.smtp.host'), + ]); + $this->errorEnvioOtp = 'No pudimos enviar el correo. Verifica tu email o intenta reenviar.'; + return false; } } @@ -321,8 +330,10 @@ class PublicChat extends Component $user = User::find($contact->user_id); if ($user) { - $this->enviarCodigoOtp($this->contactIdPending, $user); - session()->flash('otp_reenviado', 'Codigo reenviado a tu correo.'); + $ok = $this->enviarCodigoOtp($this->contactIdPending, $user); + if ($ok) { + session()->flash('otp_reenviado', 'Código reenviado a tu correo.'); + } } } diff --git a/resources/views/livewire/chat/public-chat.blade.php b/resources/views/livewire/chat/public-chat.blade.php index ff7e4e0..e2de411 100755 --- a/resources/views/livewire/chat/public-chat.blade.php +++ b/resources/views/livewire/chat/public-chat.blade.php @@ -118,6 +118,12 @@

{{ session('otp_reenviado') }}

@endif + @if ($errorEnvioOtp) +
+ {{ $errorEnvioOtp }} +
+ @endif +