2023-09-02 13:37:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
2023-09-25 07:34:32 +00:00
|
|
|
use Illuminate\Support\Facades\Route;
|
2023-09-02 13:37:25 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Help extends Component
|
|
|
|
{
|
|
|
|
use WithRateLimiting;
|
|
|
|
public string $description;
|
|
|
|
public string $subject;
|
|
|
|
public ?string $path = null;
|
|
|
|
protected $rules = [
|
|
|
|
'description' => 'required|min:10',
|
|
|
|
'subject' => 'required|min:3'
|
|
|
|
];
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-09-14 15:28:58 +00:00
|
|
|
$this->path = Route::current()?->uri() ?? null;
|
2023-09-02 13:37:25 +00:00
|
|
|
if (isDev()) {
|
|
|
|
$this->description = "I'm having trouble with {$this->path}";
|
|
|
|
$this->subject = "Help with {$this->path}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
2023-09-25 07:34:32 +00:00
|
|
|
$this->rateLimit(3, 60);
|
2023-09-02 13:37:25 +00:00
|
|
|
$this->validate();
|
2023-09-12 12:53:54 +00:00
|
|
|
$subscriptionType = auth()->user()?->subscription?->type() ?? 'Free';
|
2023-09-02 13:37:25 +00:00
|
|
|
$debug = "Route: {$this->path}";
|
|
|
|
$mail = new MailMessage();
|
|
|
|
$mail->view(
|
|
|
|
'emails.help',
|
|
|
|
[
|
|
|
|
'description' => $this->description,
|
|
|
|
'debug' => $debug
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$mail->subject("[HELP - {$subscriptionType}]: {$this->subject}");
|
2023-09-14 16:41:21 +00:00
|
|
|
send_user_an_email($mail, auth()->user()?->email, 'hi@coollabs.io');
|
2023-09-25 07:34:32 +00:00
|
|
|
$this->emit('success', 'Your message has been sent successfully. <br>We will get in touch with you as soon as possible.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-09-02 13:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.help')->layout('layouts.app');
|
|
|
|
}
|
|
|
|
}
|