Skip to content

Commit

Permalink
Merge pull request #498 from code4romania/178-ngo-admin-acasa-impleme…
Browse files Browse the repository at this point in the history
…nt-the-fa-primii-pasi-in-utilizarea-aplicatiei-sunrise-component

Config progress
  • Loading branch information
gheorghelupu17 authored Jan 14, 2025
2 parents 1bf4c20 + a02737f commit c8fe40e
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/Filament/Organizations/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@

use Filament\Pages\Dashboard as BaseDashboard;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;

class Dashboard extends BaseDashboard
{
public function render(): View
{
if (request()->get('close_config_progress') && auth()->user()->isNgoAdmin()) {
auth()->user()->update(['config_process' => true]);
}

return parent::render();
}

public function getHeading(): string | Htmlable
{
return __('dashboard.welcome', [
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Organizations/Widgets/CaseStatsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class CaseStatsWidget extends BaseWidget
{
protected static bool $isLazy = false;

protected static ?string $pollingInterval = null;

protected function getStats(): array
{
return [
Expand Down
112 changes: 112 additions & 0 deletions app/Filament/Organizations/Widgets/ConfigProgress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

declare(strict_types=1);

namespace App\Filament\Organizations\Widgets;

use App\Filament\Organizations\Pages\Dashboard;
use App\Filament\Organizations\Resources\CommunityProfileResource;
use App\Filament\Organizations\Resources\ServiceResource;
use App\Filament\Organizations\Resources\UserResource;
use App\Infolists\Components\SectionHeader;
use App\Models\OrganizationService;
use App\Models\User;
use App\Widgets\InfolistWidget;
use Filament\Facades\Filament;
use Filament\Infolists\Components\Actions\Action;
use Illuminate\Database\Eloquent\Model;

class ConfigProgress extends InfolistWidget
{
protected static string $view = 'filament.organizations.widgets.config-progress';

protected Model | null $record = null;

protected int | string | array $columnSpan = 2;

protected static bool | null $organizationServices = null;

protected static bool | null $specialistsStatus = null;

public static function canView(): bool
{
if (! auth()->user()->isNgoAdmin() || auth()->user()->config_process) {
return false;
}

return true;
}

public function getProgressData(): array
{
return [
[
'label' => __('dashboard.labels.accept_invitation'),
'link' => Dashboard::getUrl(),
'completed' => true,
],
[
'label' => __('dashboard.labels.config_services_nomenclature'),
'link' => ServiceResource::getUrl(),
'completed' => self::getOrganizationServiceStatus(),
],
[
'label' => __('dashboard.labels.config_specialists'),
'link' => UserResource::getUrl(),
'completed' => self::getSpecialistsStatus(),
],
[
'label' => __('dashboard.labels.config_organization_profile'),
'link' => CommunityProfileResource::getUrl(),
// TODO change this after implement community profile
'completed' => false,
],
];
}

public function getInfolistSchema(): array
{
return [
SectionHeader::make('header')
->state(fn () => $this->getWidgetTitle())
->action(
Action::make('close_action')
->icon('heroicon-o-x-mark')
->iconButton()
->url(Dashboard::getUrl(['close_config_progress' => true]))
// TODO add community profile
->visible(fn () => self::getOrganizationServiceStatus() && self::getSpecialistsStatus())
),
];
}

public function getWidgetTitle(): string
{
return __('dashboard.headings.config_progress');
}

protected static function getOrganizationServiceStatus(): bool
{
if (self::$organizationServices !== null) {
return self::$organizationServices;
}

self::$organizationServices = (bool) OrganizationService::count();

return self::$organizationServices;
}

public function getSpecialistsStatus(): bool
{
if (self::$specialistsStatus !== null) {
return self::$specialistsStatus;
}

self::$specialistsStatus = (bool) Filament::getTenant()
->users
->filter(fn (User $user) => ! $user->isNgoAdmin())
->count();

return self::$specialistsStatus;
}
}
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasName,
'latest_organization_id',
'is_admin',
'ngo_admin',
'config_process',
];

/**
Expand All @@ -87,6 +88,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasName,
'password' => 'hashed',
'is_admin' => 'boolean',
'ngo_admin' => 'boolean',
'config_process' => 'boolean'
];

protected static function booted()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('config_process')->default(false);
});
}
};
8 changes: 8 additions & 0 deletions lang/ro/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
'welcome' => 'Bine ai venit, :name',
'labels' => [
'navigation' => 'Acasa',
'accept_invitation' => 'Acceptă invitația',
'config_services_nomenclature' => 'Configurează nomenclatorul de servicii',
'config_specialists' => 'Configurează nomenclatorul de specialiști',
'config_organization_profile' => 'Configurează profilul organizației în rețeaua Sunrise',
],

'headings' => [
'config_progress' => 'Fă primii pași în utilizarea aplicației Sunrise',
],

];
2 changes: 1 addition & 1 deletion resources/views/components/section-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@



@if (count($actions))
@if (count($actions))
<div
class="flex items-center gap-3 shrink-0">

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<x-filament-widgets::widget>
<x-filament::section>
<div class="space-y-4">
{{ $this->getWidgetInfolist() }}
<div class="flex items-center space-x-2 gap-2">
@php
$firstIncompleteItem = false;
@endphp
@foreach ($this->getProgressData() as $step)
<div class="flex flex-col items-center group w-32 text-center">
<a href="{{ $step['link'] }}" class=" items-center space-x-2 group"
title="{{ $step['label'] }}">
<div class="items-center">
@if ($step['completed'])
<svg xmlns="http://www.w3.org/2000/svg" class="w-32 h-8 text-primary-500" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm-1.707-6.293a1 1 0 011.414 0L14 7.414l-1.293-1.293-3.293 3.293L8 7.414l-1.293 1.293a1 1 0 010 1.414l2.586 2.586z" clip-rule="evenodd" />
</svg>
@elseif (!$firstIncompleteItem)
@php
$firstIncompleteItem = true;
@endphp
<svg xmlns="http://www.w3.org/2000/svg" class="w-32 h-8 text-primary-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10" />
</svg>
@else
<svg xmlns="http://www.w3.org/2000/svg" class="w-32 h-8 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10" />
</svg>
@endif
</div>
<span class="w-32 text-sm mt-1 text-center break-normal text-balance group-hover:underline">
{{ $step['label'] }}
</span>
</a>
</div>

@if (!$loop->last)
<div class="flex-1 h-1 space-x-2 {{ $step['completed'] ? 'bg-primary-500' : 'bg-gray-400' }}"></div>
@endif
@endforeach
</div>
</div>
</x-filament::section>
</x-filament-widgets::widget>

0 comments on commit c8fe40e

Please sign in to comment.