coolify/app/Livewire/Help.php

68 lines
2.2 KiB
PHP
Raw Normal View History

2023-09-02 15:37:25 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire;
2023-09-02 15:37:25 +02:00
use App\Models\InstanceSettings;
2023-09-02 15:37:25 +02:00
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Http;
2023-09-25 09:34:32 +02:00
use Illuminate\Support\Facades\Route;
2023-09-02 15:37:25 +02: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 17:28:58 +02:00
$this->path = Route::current()?->uri() ?? null;
2023-09-02 15:37:25 +02:00
if (isDev()) {
$this->description = "I'm having trouble with {$this->path}";
$this->subject = "Help with {$this->path}";
}
}
public function submit()
{
try {
$this->rateLimit(3, 30);
2023-09-02 15:37:25 +02:00
$this->validate();
$debug = "Route: {$this->path}";
$mail = new MailMessage();
$mail->view(
'emails.help',
[
'description' => $this->description,
'debug' => $debug
]
);
$mail->subject("[HELP]: {$this->subject}");
$settings = InstanceSettings::get();
$type = set_transanctional_email_settings($settings);
if (!$type) {
$url = "https://app.coolify.io/api/feedback";
if (isDev()) {
$url = "http://localhost:80/api/feedback";
}
Http::post($url, [
'content' => "User: `" . auth()->user()?->email . "` with subject: `" . $this->subject . "` has the following problem: `" . $this->description . "`"
]);
} else {
send_user_an_email($mail, auth()->user()?->email, 'hi@coollabs.io');
}
$this->dispatch('success', 'Feedback sent.', 'We will get in touch with you as soon as possible.');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-09-02 15:37:25 +02:00
}
}
public function render()
{
return view('livewire.help')->layout('layouts.app');
}
}