2023-09-02 13:37:25 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire;
|
2023-09-02 13:37:25 +00:00
|
|
|
|
2024-02-06 10:36:20 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2023-09-02 13:37:25 +00:00
|
|
|
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
2024-02-06 10:36:20 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
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;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
public string $description;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
public string $subject;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
public ?string $path = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
protected $rules = [
|
|
|
|
'description' => 'required|min:10',
|
2024-06-10 20:43:34 +00:00
|
|
|
'subject' => 'required|min:3',
|
2023-09-02 13:37:25 +00:00
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
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}";
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
2024-02-06 10:36:20 +00:00
|
|
|
$this->rateLimit(3, 30);
|
2023-09-02 13:37:25 +00:00
|
|
|
$this->validate();
|
|
|
|
$debug = "Route: {$this->path}";
|
|
|
|
$mail = new MailMessage();
|
|
|
|
$mail->view(
|
|
|
|
'emails.help',
|
|
|
|
[
|
|
|
|
'description' => $this->description,
|
2024-06-10 20:43:34 +00:00
|
|
|
'debug' => $debug,
|
2023-09-02 13:37:25 +00:00
|
|
|
]
|
|
|
|
);
|
2024-02-06 10:36:20 +00:00
|
|
|
$mail->subject("[HELP]: {$this->subject}");
|
|
|
|
$settings = InstanceSettings::get();
|
|
|
|
$type = set_transanctional_email_settings($settings);
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $type) {
|
|
|
|
$url = 'https://app.coolify.io/api/feedback';
|
2024-02-06 10:36:20 +00:00
|
|
|
if (isDev()) {
|
2024-06-10 20:43:34 +00:00
|
|
|
$url = 'http://localhost:80/api/feedback';
|
2024-02-06 10:36:20 +00:00
|
|
|
}
|
|
|
|
Http::post($url, [
|
2024-06-10 20:43:34 +00:00
|
|
|
'content' => 'User: `'.auth()->user()?->email.'` with subject: `'.$this->subject.'` has the following problem: `'.$this->description.'`',
|
2024-02-06 10:36:20 +00:00
|
|
|
]);
|
|
|
|
} else {
|
2024-06-10 20:43:34 +00:00
|
|
|
send_user_an_email($mail, auth()->user()?->email, 'hi@coollabs.io');
|
2024-02-06 10:36:20 +00:00
|
|
|
}
|
|
|
|
$this->dispatch('success', 'Feedback sent.', '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
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-02 13:37:25 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.help')->layout('layouts.app');
|
|
|
|
}
|
|
|
|
}
|