ui: make notifications separate view

fix: popup if no notifications are set
This commit is contained in:
Andras Bacsai 2024-03-07 12:58:04 +01:00
parent bbfbd4a105
commit 129a644781
9 changed files with 108 additions and 14 deletions

View File

@ -17,10 +17,14 @@ public function testEvent()
{ {
$this->dispatch('success', 'Realtime events configured!'); $this->dispatch('success', 'Realtime events configured!');
} }
public function disable() public function disableSponsorship()
{ {
auth()->user()->update(['is_notification_sponsorship_enabled' => false]); auth()->user()->update(['is_notification_sponsorship_enabled' => false]);
} }
public function disableNotifications()
{
auth()->user()->update(['is_notification_notifications_enabled' => false]);
}
public function render() public function render()
{ {
return view('livewire.layout-popups'); return view('livewire.layout-popups');

View File

@ -48,13 +48,15 @@ public function getRecepients($notification)
} }
return explode(',', $recipients); return explode(',', $recipients);
} }
static public function serverLimitReached() { static public function serverLimitReached()
{
$serverLimit = Team::serverLimit(); $serverLimit = Team::serverLimit();
$team = currentTeam(); $team = currentTeam();
$servers = $team->servers->count(); $servers = $team->servers->count();
return $servers >= $serverLimit; return $servers >= $serverLimit;
} }
public function serverOverflow() { public function serverOverflow()
{
if ($this->serverLimit() < $this->servers->count()) { if ($this->serverLimit() < $this->servers->count()) {
return true; return true;
} }
@ -170,4 +172,17 @@ public function trialEndedButSubscribed()
]); ]);
} }
} }
public function isAnyNotificationEnabled()
{
if (isCloud()) {
return true;
}
if (!data_get(auth()->user(), 'is_notification_notifications_enabled')) {
return true;
}
if ($this->smtp_enabled || $this->resend_enabled || $this->discord_enabled || $this->telegram_enabled || $this->use_instance_email_settings) {
return true;
}
return false;
}
} }

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('is_notification_notifications_enabled')->default(true);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('is_notification_notifications_enabled');
});
}
};

View File

@ -150,7 +150,17 @@ class="{{ request()->is('subscription*') ? 'text-warning icon' : 'icon' }}"
</a> </a>
</li> </li>
@endif @endif
<li title="Notifications" class="hover:bg-coolgray-200">
<a class="hover:bg-transparent hover:no-underline" href="{{ route('notification.index') }}">
<svg class="{{ request()->is('notifications*') ? 'text-warning icon' : 'icon' }}"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill="none" stroke="currentColor" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"
d="M10 5a2 2 0 1 1 4 0a7 7 0 0 1 4 6v3a4 4 0 0 0 2 3H4a4 4 0 0 0 2-3v-3a7 7 0 0 1 4-6M9 17v1a3 3 0 0 0 6 0v-1" />
</svg>
Notifications
</a>
</li>
@if (isInstanceAdmin()) @if (isInstanceAdmin())
<li title="Settings" class="hover:bg-coolgray-200"> <li title="Settings" class="hover:bg-coolgray-200">
<a class="hover:bg-transparent hover:no-underline" href="/settings"> <a class="hover:bg-transparent hover:no-underline" href="/settings">

View File

@ -0,0 +1,25 @@
<div class="pb-6">
<div class="flex items-end gap-2">
<h1>Team Notifications</h1>
</div>
<nav class="flex pt-2 pb-10">
<ol class="inline-flex items-center">
<li>
<div class="flex items-center">
<span>Currently active team: <span
class="text-warning">{{ session('currentTeam.name') }}</span></span>
</div>
</li>
</ol>
</nav>
<nav class="navbar-main">
<a class="{{ request()->routeIs('notification.index') ? 'text-white' : '' }}"
href="{{ route('notification.index') }}">
<button>General</button>
</a>
<div class="flex-1"></div>
<div class="-mt-9">
<livewire:switch-team />
</div>
</nav>
</div>

View File

@ -1,7 +1,7 @@
<div class="pb-6"> <div class="pb-6">
<div class="flex items-end gap-2"> <div class="flex items-end gap-2">
<h1>Team</h1> <h1>Team</h1>
<a href="/team/new"><x-forms.button>+ Add Team</x-forms.button></a> <a href="/team/new"><x-forms.button>+ Add Team</x-forms.button></a>
</div> </div>
<nav class="flex pt-2 pb-10"> <nav class="flex pt-2 pb-10">
<ol class="inline-flex items-center"> <ol class="inline-flex items-center">
@ -17,18 +17,15 @@ class="text-warning">{{ session('currentTeam.name') }}</span></span>
<a class="{{ request()->routeIs('team.index') ? 'text-white' : '' }}" href="{{ route('team.index') }}"> <a class="{{ request()->routeIs('team.index') ? 'text-white' : '' }}" href="{{ route('team.index') }}">
<button>General</button> <button>General</button>
</a> </a>
<a class="{{ request()->routeIs('team.member.index') ? 'text-white' : '' }}" href="{{ route('team.member.index') }}"> <a class="{{ request()->routeIs('team.member.index') ? 'text-white' : '' }}"
href="{{ route('team.member.index') }}">
<button>Members</button> <button>Members</button>
</a> </a>
<a class="{{ request()->routeIs('team.storage.index') ? 'text-white' : '' }}" <a class="{{ request()->routeIs('team.storage.index') ? 'text-white' : '' }}"
href="{{ route('team.storage.index') }}"> href="{{ route('team.storage.index') }}">
<button>S3 Storages</button> <button>S3 Storages</button>
</a> </a>
<a class="{{ request()->routeIs('team.notification.index') ? 'text-white' : '' }}" <a class="{{ request()->routeIs('team.shared-variables.index') ? 'text-white' : '' }}"
href="{{ route('team.notification.index') }}">
<button>Notifications</button>
</a>
<a class="{{ request()->routeIs('team.shared-variables.index') ? 'text-white' : '' }}"
href="{{ route('team.shared-variables.index') }}"> href="{{ route('team.shared-variables.index') }}">
<button>Shared Variables</button> <button>Shared Variables</button>
</a> </a>

View File

@ -7,7 +7,8 @@ class="underline text-warning">Please
consider donating!</a>💜</span> consider donating!</a>💜</span>
<span>It enables us to keep creating features without paywalls, ensuring our work remains free and <span>It enables us to keep creating features without paywalls, ensuring our work remains free and
open.</span> open.</span>
<x-forms.button class="bg-coolgray-400" wire:click='disable'>Disable This Popup</x-forms.button> <x-forms.button class="bg-coolgray-400" wire:click='disableSponsorship'>Disable This
Popup</x-forms.button>
</div> </div>
</div> </div>
@endif @endif
@ -20,4 +21,16 @@ class="text-white underline">/subscription</a> to update your subscription or re
</div> </div>
</x-banner> </x-banner>
@endif @endif
@if (!currentTeam()->isAnyNotificationEnabled())
<div class="toast">
<div class="flex flex-col text-white rounded alert bg-coolgray-200">
<span><span class="font-bold text-red-500">WARNING:</span> No notifications enabled.<br><br> It is highly recommended to enable at least
one
notification channel to receive important alerts.<br>Visit <a href="{{ route('notification.index') }}"
class="text-white underline">/notification</a> to enable notifications.</span>
<x-forms.button class="bg-coolgray-400" wire:click='disableNotifications'>Disable This
Popup</x-forms.button>
</div>
</div>
@endif
</div> </div>

View File

@ -1,5 +1,5 @@
<div> <div>
<x-team.navbar /> <x-notifications.navbar />
<h2 class="pb-4">Notifications</h2> <h2 class="pb-4">Notifications</h2>
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'email' }" class="flex h-full"> <div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'email' }" class="flex h-full">
<div class="flex flex-col gap-4 min-w-fit"> <div class="flex flex-col gap-4 min-w-fit">

View File

@ -121,11 +121,13 @@
Route::get('/', TagsIndex::class)->name('tags.index'); Route::get('/', TagsIndex::class)->name('tags.index');
Route::get('/{tag_name}', TagsShow::class)->name('tags.show'); Route::get('/{tag_name}', TagsShow::class)->name('tags.show');
}); });
Route::prefix('notifications')->group(function () {
Route::get('/', TeamNotificationIndex::class)->name('notification.index');
});
Route::prefix('team')->group(function () { Route::prefix('team')->group(function () {
Route::get('/', TeamIndex::class)->name('team.index'); Route::get('/', TeamIndex::class)->name('team.index');
Route::get('/new', TeamCreate::class)->name('team.create'); Route::get('/new', TeamCreate::class)->name('team.create');
Route::get('/members', TeamMemberIndex::class)->name('team.member.index'); Route::get('/members', TeamMemberIndex::class)->name('team.member.index');
Route::get('/notifications', TeamNotificationIndex::class)->name('team.notification.index');
Route::get('/shared-variables', TeamSharedVariablesIndex::class)->name('team.shared-variables.index'); Route::get('/shared-variables', TeamSharedVariablesIndex::class)->name('team.shared-variables.index');
Route::get('/storages', TeamStorageIndex::class)->name('team.storage.index'); Route::get('/storages', TeamStorageIndex::class)->name('team.storage.index');
Route::get('/storages/new', TeamStorageCreate::class)->name('team.storage.create'); Route::get('/storages/new', TeamStorageCreate::class)->name('team.storage.create');