coolify/app/Livewire/Help.php

59 lines
1.7 KiB
PHP
Raw Normal View History

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
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Http;
use Livewire\Attributes\Validate;
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
#[Validate(['required', 'min:10', 'max:1000'])]
2023-09-02 13:37:25 +00:00
public string $description;
2024-06-10 20:43:34 +00:00
#[Validate(['required', 'min:3'])]
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 function submit()
{
try {
$this->validate();
$this->rateLimit(3, 30);
$settings = instanceSettings();
$mail = new MailMessage;
$mail->view(
2023-09-02 13:37:25 +00:00
'emails.help',
[
'description' => $this->description,
]
);
$mail->subject("[HELP]: {$this->subject}");
$type = set_transanctional_email_settings($settings);
// Sending feedback through Cloud API
if (blank($type)) {
2024-06-10 20:43:34 +00:00
$url = 'https://app.coolify.io/api/feedback';
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.'`',
]);
} 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.');
$this->reset('description', 'subject');
} catch (\Throwable $e) {
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');
}
}