From 6b9c7aa9c56bc480107d6e59854075b96ee80907 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sat, 2 Sep 2023 15:37:25 +0200 Subject: [PATCH] feat: send request in cloud --- app/Http/Livewire/Help.php | 54 +++++++++++++++++++ .../Channels/TransactionalEmailChannel.php | 23 -------- bootstrap/helpers/shared.php | 6 --- bootstrap/helpers/subscriptions.php | 3 ++ resources/views/components/modal.blade.php | 4 -- resources/views/components/navbar.blade.php | 14 +++++ resources/views/emails/help.blade.php | 5 ++ resources/views/layouts/base.blade.php | 8 +++ resources/views/livewire/help.blade.php | 10 ++++ routes/web.php | 2 + 10 files changed, 96 insertions(+), 33 deletions(-) create mode 100644 app/Http/Livewire/Help.php create mode 100644 resources/views/emails/help.blade.php create mode 100644 resources/views/livewire/help.blade.php diff --git a/app/Http/Livewire/Help.php b/app/Http/Livewire/Help.php new file mode 100644 index 000000000..107821501 --- /dev/null +++ b/app/Http/Livewire/Help.php @@ -0,0 +1,54 @@ + 'required|min:10', + 'subject' => 'required|min:3' + ]; + public function mount() + { + $this->path = Route::current()->uri(); + if (isDev()) { + $this->description = "I'm having trouble with {$this->path}"; + $this->subject = "Help with {$this->path}"; + } + } + public function submit() + { + try { + $this->rateLimit(1, 60); + $this->validate(); + $subscriptionType = auth()->user()?->subscription?->type() ?? 'unknown'; + $debug = "Route: {$this->path}"; + $mail = new MailMessage(); + $mail->view( + 'emails.help', + [ + 'description' => $this->description, + 'debug' => $debug + ] + ); + $mail->subject("[HELP - {$subscriptionType}]: {$this->subject}"); + send_user_an_email($mail, 'hi@coollabs.io'); + $this->emit('success', 'Your message has been sent successfully. We will get in touch with you as soon as possible.'); + } catch (\Exception $e) { + return general_error_handler($e, $this); + } + } + public function render() + { + return view('livewire.help')->layout('layouts.app'); + } +} diff --git a/app/Notifications/Channels/TransactionalEmailChannel.php b/app/Notifications/Channels/TransactionalEmailChannel.php index aa5541dee..2985d5183 100644 --- a/app/Notifications/Channels/TransactionalEmailChannel.php +++ b/app/Notifications/Channels/TransactionalEmailChannel.php @@ -12,7 +12,6 @@ class TransactionalEmailChannel { - private bool $isResend = false; public function send(User $notifiable, Notification $notification): void { $settings = InstanceSettings::get(); @@ -26,33 +25,14 @@ public function send(User $notifiable, Notification $notification): void } $this->bootConfigs(); $mailMessage = $notification->toMail($notifiable); - // if ($this->isResend) { Mail::send( [], [], fn (Message $message) => $message - ->from( - data_get($settings, 'smtp_from_address'), - data_get($settings, 'smtp_from_name'), - ) ->to($email) ->subject($mailMessage->subject) ->html((string)$mailMessage->render()) ); - // } else { - // Mail::send( - // [], - // [], - // fn (Message $message) => $message - // ->from( - // data_get($settings, 'smtp_from_address'), - // data_get($settings, 'smtp_from_name'), - // ) - // ->bcc($email) - // ->subject($mailMessage->subject) - // ->html((string)$mailMessage->render()) - // ); - // } } private function bootConfigs(): void @@ -61,8 +41,5 @@ private function bootConfigs(): void if (!$type) { throw new Exception('No email settings found.'); } - if ($type === 'resend') { - $this->isResend = true; - } } } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 7056b159b..e45dfa08a 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -7,7 +7,6 @@ use Illuminate\Database\QueryException; use Illuminate\Mail\Message; use Illuminate\Notifications\Messages\MailMessage; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Route; @@ -261,15 +260,10 @@ function send_user_an_email(MailMessage $mail, string $email): void [], [], fn (Message $message) => $message - ->from( - data_get($settings, 'smtp_from_address'), - data_get($settings, 'smtp_from_name') - ) ->to($email) ->subject($mail->subject) ->html((string) $mail->render()) ); - } function isEmailEnabled($notifiable) { diff --git a/bootstrap/helpers/subscriptions.php b/bootstrap/helpers/subscriptions.php index 7691ca7d6..ae3506782 100644 --- a/bootstrap/helpers/subscriptions.php +++ b/bootstrap/helpers/subscriptions.php @@ -47,6 +47,9 @@ function getEndDate() function isSubscriptionActive() { + if (!isCloud()) { + return false; + } $team = currentTeam(); if (!$team) { return false; diff --git a/resources/views/components/modal.blade.php b/resources/views/components/modal.blade.php index 711515437..d31dc542a 100644 --- a/resources/views/components/modal.blade.php +++ b/resources/views/components/modal.blade.php @@ -43,10 +43,6 @@ @endisset @if ($modalSubmit) {{ $modalSubmit }} - @else - - Save - @endif diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 6fd4b218a..65cbc482b 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -95,6 +95,20 @@ class="{{ request()->is('settings*') ? 'text-warning icon' : 'icon' }}" viewBox= @endif + @if (isSubscriptionActive() || isDev()) +
  • +
    + + + + + + +
    +
  • + @endif
  • @csrf diff --git a/resources/views/emails/help.blade.php b/resources/views/emails/help.blade.php new file mode 100644 index 000000000..a9f8aeb69 --- /dev/null +++ b/resources/views/emails/help.blade.php @@ -0,0 +1,5 @@ +{{ $description }} + +{{ Illuminate\Mail\Markdown::parse('---') }} + +{{ Illuminate\Mail\Markdown::parse($debug) }} diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index 6302eddeb..6c69eecc3 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -25,6 +25,14 @@ @livewireScripts + @if (isSubscriptionActive() || isDev()) + + + + + +
    + @endif