added not subscribed page, added premium inbox
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use App\Models\UsageLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Component;
|
||||
|
||||
class Dashboard extends Component
|
||||
{
|
||||
public $message;
|
||||
public $usageLog;
|
||||
public $subscription;
|
||||
public $plans;
|
||||
|
||||
@@ -61,7 +63,11 @@ class Dashboard extends Component
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$usageLog = UsageLog::where('user_id', auth()->user()->id)->first();
|
||||
$this->usageLog = [
|
||||
'emails_created_count' => $usageLog->emails_created_count ?? 0,
|
||||
'emails_received_count' => $usageLog->emails_received_count ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -5,15 +5,18 @@ namespace App\Livewire\Dashboard\Mailbox;
|
||||
use App\ColorPicker;
|
||||
use App\Models\Log;
|
||||
use App\Models\Premium;
|
||||
use App\Models\PremiumEmail;
|
||||
use App\Models\UsageLog;
|
||||
use Artisan;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Livewire\Component;
|
||||
use Session;
|
||||
|
||||
class Inbox extends Component
|
||||
{
|
||||
use ColorPicker;
|
||||
|
||||
public $messages = [];
|
||||
public $deleted = [];
|
||||
public $error = '';
|
||||
@@ -24,8 +27,11 @@ class Inbox extends Component
|
||||
public $messageId;
|
||||
public $list = false;
|
||||
public $emails;
|
||||
public $mailboxHistory;
|
||||
public $emailsHistory;
|
||||
public $username, $domain, $domains, $action;
|
||||
public $email_limit = 20;
|
||||
private $isSubscribed;
|
||||
|
||||
protected $listeners = ['updateEmail' => 'syncEmail', 'getEmail' => 'generateEmail', 'fetchMessages' => 'fetch', 'setMessageId' => 'setMessageId'];
|
||||
|
||||
@@ -38,8 +44,11 @@ class Inbox extends Component
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
$this->emailsHistory = array_reverse(PremiumEmail::parseEmail(\auth()->user()->id)['data']) ?? [];
|
||||
|
||||
if(auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id'])) {
|
||||
$subscriptionCheck = auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id']);
|
||||
Session::put('isSubscribed', $subscriptionCheck);
|
||||
if($subscriptionCheck) {
|
||||
try {
|
||||
$result = auth()->user()->subscriptions()->where(['stripe_status' => 'active'])->orderByDesc('updated_at')->first();
|
||||
$userPriceID = $result['items'][0]['stripe_price'];
|
||||
@@ -57,6 +66,9 @@ class Inbox extends Component
|
||||
\Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$mailboxHistory = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$this->mailboxHistory = $mailboxHistory->emails_created_history ?? [];
|
||||
}
|
||||
|
||||
private function checkMultipleEmails(): void
|
||||
@@ -73,7 +85,22 @@ class Inbox extends Component
|
||||
|
||||
public function switchEmail($email)
|
||||
{
|
||||
return redirect()->route('switch', ['email' => $email]);
|
||||
try {
|
||||
if ($email != null) {
|
||||
$data = explode('@', $email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
if (!in_array($domain, $domains)) {
|
||||
return $this->showAlert('error', __('This mailbox can not be recovered.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
\Log::error($exception->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->route('switchP', ['email' => $email]);
|
||||
}
|
||||
|
||||
public function syncEmail(): void
|
||||
@@ -183,19 +210,25 @@ class Inbox extends Component
|
||||
|
||||
private function validateDomainInEmail(): void
|
||||
{
|
||||
$data = explode('@', $this->email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
if (!in_array($domain, $domains)) {
|
||||
$key = array_search($this->email, $this->emails);
|
||||
Premium::removeEmail($this->email);
|
||||
if ($key == 0 && count($this->emails) == 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
redirect()->route('dashboard.premium');
|
||||
} else {
|
||||
redirect()->route('dashboard.premium');
|
||||
try {
|
||||
if ($this->email != null) {
|
||||
$data = explode('@', $this->email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
if (!in_array($domain, $domains)) {
|
||||
$key = array_search($this->email, $this->emails);
|
||||
Premium::removeEmail($this->email);
|
||||
if ($key == 0 && count($this->emails) == 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
redirect()->route('dashboard.premium');
|
||||
} else {
|
||||
redirect()->route('dashboard.premium');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
\Log::error($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +274,15 @@ class Inbox extends Component
|
||||
$this->dispatch('showNewMailNotification', $notification);
|
||||
}
|
||||
Premium::incrementMessagesStats(count($notifications));
|
||||
|
||||
if ($this->email != null && count($this->messages) > 0) {
|
||||
foreach ($this->messages as $message) {
|
||||
PremiumEmail::createEmail($message, $this->email);
|
||||
}
|
||||
}
|
||||
|
||||
$this->emailsHistory = array_reverse(PremiumEmail::parseEmail(\auth()->user()->id)['data']) ?? [];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
if (Auth::check() && Auth::user()->level == 9) {
|
||||
$this->error = $e->getMessage();
|
||||
@@ -252,6 +294,17 @@ class Inbox extends Component
|
||||
$this->initial = true;
|
||||
}
|
||||
|
||||
public function processQueue(): void
|
||||
{
|
||||
try {
|
||||
Artisan::call('queue:work', [
|
||||
'--once' => true,
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
\Log::error($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($messageId) {
|
||||
|
||||
try {
|
||||
@@ -274,7 +327,11 @@ class Inbox extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.dashboard.mailbox.inbox')->layout('components.layouts.dashboard');
|
||||
if (Session::get('isSubscribed')) {
|
||||
return view('livewire.dashboard.mailbox.inbox')->layout('components.layouts.dashboard');
|
||||
} else {
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
private function rrmdir($dir): void
|
||||
|
||||
13
app/Livewire/Dashboard/NotSubscribed.php
Normal file
13
app/Livewire/Dashboard/NotSubscribed.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class NotSubscribed extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user