Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADVAPP-302]: Update the home screen to include notifications and product awareness #510

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,10 @@
namespace App\Filament\Pages;

use App\Models\User;
use App\Filament\Widgets\MyTasks;
use App\Filament\Widgets\MyStudents;
use App\Filament\Widgets\MyProspects;
use App\Filament\Widgets\TotalStudents;
use App\Filament\Widgets\Features;
use App\Filament\Widgets\Notifications;
use App\Filament\Widgets\WelcomeWidget;
use App\Filament\Widgets\TotalProspects;
use Filament\Pages\Dashboard as BasePage;
use App\Filament\Widgets\MyServiceRequests;
use App\Filament\Widgets\ProspectGrowthChart;
use App\Filament\Widgets\RecentProspectsList;
use App\Filament\Widgets\RecentKnowledgeBaseArticlesList;
use AdvisingApp\Authorization\Filament\Widgets\UnlicensedNotice;

class Dashboard extends BasePage
Expand All @@ -71,27 +64,11 @@ public function getWidgets(): array
return $widgets;
}

if ($user->can('authorization.view_dashboard')) {
$widgets = [
// 1
...$widgets,
// 2
TotalStudents::class,
TotalProspects::class,
MyStudents::class,
MyProspects::class,
// 3
ProspectGrowthChart::class,
// 4
RecentProspectsList::class,
RecentKnowledgeBaseArticlesList::class,
// 5
MyServiceRequests::class,
MyTasks::class,
];
}

return $widgets;
return [
...$widgets,
Features::class,
Notifications::class,
];
}

public function getColumns(): int | string | array
Expand Down
46 changes: 46 additions & 0 deletions app/Filament/Widgets/Features.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
<COPYRIGHT>

Copyright © 2016-2024, Canyon GBS LLC. All rights reserved.

Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.

Notice:

- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.

For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at legal@canyongbs.com.

</COPYRIGHT>
*/

namespace App\Filament\Widgets;

use Filament\Widgets\Widget;

class Features extends Widget
{
protected static string $view = 'filament.widgets.features';

protected int | string | array $columnSpan = 'full';
}
130 changes: 130 additions & 0 deletions app/Filament/Widgets/Notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/*
<COPYRIGHT>

Copyright © 2016-2024, Canyon GBS LLC. All rights reserved.

Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.

Notice:

- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.

For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at legal@canyongbs.com.

</COPYRIGHT>
*/

namespace App\Filament\Widgets;

use Carbon\CarbonInterface;
use Livewire\Attributes\On;
use Filament\Widgets\Widget;
use Livewire\WithPagination;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Database\Eloquent\Relations\Relation;

class Notifications extends Widget
{
use WithPagination;

protected static string $view = 'filament.widgets.notifications';

protected int | string | array $columnSpan = 'full';

#[On('notificationClosed')]
public function removeNotification(string $id): void
{
$this->getNotificationsQuery()
->where('id', $id)
->delete();
}

public function clearNotifications(): void
{
$this->getNotificationsQuery()->delete();
}

public function markAllNotificationsAsRead(): void
{
$this->getUnreadNotificationsQuery()->update(['read_at' => now()]);
}

public function getNotifications(): Paginator
{
return $this->getNotificationsQuery()->simplePaginate(10);
}

public function getNotificationsQuery(): Builder | Relation
{
return auth()->user()->notifications()->where('data->format', 'filament');
}

public function getUnreadNotificationsQuery(): Builder | Relation
{
return $this->getNotificationsQuery()->unread();
}

public function getUnreadNotificationsCount(): int
{
return $this->getUnreadNotificationsQuery()->count();
}

public function getBroadcastChannel(): ?string
{
$user = auth()->user();

if (! $user) {
return null;
}

if (method_exists($user, 'receivesBroadcastNotificationsOn')) {
return $user->receivesBroadcastNotificationsOn();
}

$userClass = str_replace('\\', '.', $user::class);

return "{$userClass}.{$user->getKey()}";
}

public function getNotification(DatabaseNotification $notification): Notification
{
return Notification::fromDatabase($notification)
->date($this->formatNotificationDate($notification->getAttributeValue('created_at')));
}

/**
* @return array<string>
*/
public function queryStringHandlesPagination(): array
{
return [];
}

protected function formatNotificationDate(CarbonInterface $date): string
{
return $date->diffForHumans();
}
}
133 changes: 133 additions & 0 deletions resources/views/filament/widgets/features.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{{--
<COPYRIGHT>

Copyright © 2016-2024, Canyon GBS LLC. All rights reserved.

Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.

Notice:

- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.

For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at legal@canyongbs.com.

</COPYRIGHT>
--}}
@php
use AdvisingApp\Assistant\Filament\Pages\PersonalAssistant;
use AdvisingApp\Authorization\Enums\LicenseType;
use AdvisingApp\Prospect\Filament\Pages\RecruitmentCrmDashboard;
use AdvisingApp\StudentDataModel\Filament\Pages\RetentionCrmDashboard;
@endphp

<x-filament-widgets::widget>
<div class="grid gap-6 md:grid-cols-3">
@php
$hasFeature = auth()
->user()
->hasLicense(LicenseType::RecruitmentCrm);
@endphp
<x-filament::section @class([
'opacity-50 pointer-events-none' => !$hasFeature,
])>
<div class="flex flex-col gap-3">
<div class="text-center text-lg font-bold">
{{ $hasFeature ? 'Available' : 'Unavailable' }}
</div>

<div class="flex items-center justify-center">
<x-filament::button
:href="$hasFeature ? RecruitmentCrmDashboard::getUrl() : null"
size="xl"
tag="a"
color="gray"
>
Start now
</x-filament::button>
</div>

<div class="text-center font-medium text-gray-700 dark:text-gray-300">
Recruitment CRM
</div>
</div>
</x-filament::section>

@php
$hasFeature = auth()
->user()
->hasLicense(LicenseType::RetentionCrm);
@endphp
<x-filament::section @class([
'opacity-50 pointer-events-none' => !$hasFeature,
])>
<div class="flex flex-col gap-3">
<div class="text-center text-lg font-bold">
{{ $hasFeature ? 'Available' : 'Unavailable' }}
</div>

<div class="flex items-center justify-center">
<x-filament::button
:href="$hasFeature ? RetentionCrmDashboard::getUrl() : null"
size="xl"
tag="a"
color="gray"
>
Start now
</x-filament::button>
</div>

<div class="text-center font-medium text-gray-700 dark:text-gray-300">
Student Success Suite
</div>
</div>
</x-filament::section>

@php
$hasFeature = auth()
->user()
->hasLicense(LicenseType::ConversationalAi);
@endphp
<x-filament::section @class([
'opacity-50 pointer-events-none' => !$hasFeature,
])>
<div class="flex flex-col gap-3">
<div class="text-center text-lg font-bold">
{{ $hasFeature ? 'Available' : 'Unavailable' }}
</div>

<div class="flex items-center justify-center">
<x-filament::button
:href="$hasFeature ? PersonalAssistant::getUrl() : null"
size="xl"
tag="a"
color="gray"
>
Start now
</x-filament::button>
</div>

<div class="text-center font-medium text-gray-700 dark:text-gray-300">
Enterprise AI Assistant
</div>
</div>
</x-filament::section>
</div>
</x-filament-widgets::widget>
Loading