From 9f1e7648345c1cbca8246b8d8356b3977c59dbc5 Mon Sep 17 00:00:00 2001 From: Md Azizul Hakim Date: Sat, 14 Oct 2023 19:24:17 +0600 Subject: [PATCH] tabs & database notification added --- app/Filament/Pages/Settings.php | 18 ++++++----- app/Filament/Resources/UserResource.php | 1 - .../UserResource/Pages/CreateUser.php | 9 ++++-- .../UserResource/Pages/ListUsers.php | 23 ++++++++++---- app/Providers/Filament/AdminPanelProvider.php | 1 + ...0_14_120201_create_notifications_table.php | 30 +++++++++++++++++++ lang/bn/notifications.php | 11 +++++++ lang/bn/pages.php | 3 -- lang/en/notifications.php | 11 +++++++ lang/en/pages.php | 3 -- 10 files changed, 88 insertions(+), 22 deletions(-) create mode 100644 database/migrations/2023_10_14_120201_create_notifications_table.php create mode 100644 lang/bn/notifications.php create mode 100644 lang/en/notifications.php diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 44c3aad..8b1f4a0 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -103,13 +103,13 @@ public function saveProfile(): void $user->save(); Notification::make() - ->title(__('pages.profile.saved_successfully')) + ->title(__('notifications.save.success')) ->success() ->send(); } catch (\Throwable $th) { //throw $th; Notification::make() - ->title(__('pages.profile.save_failed')) + ->title(__('notifications.profile.save.failed')) ->danger() ->send(); } @@ -128,13 +128,14 @@ public function updatePassword(): void $user->save(); Notification::make() - ->title(__('pages.profile.password.saved')) + ->title(__('notifications.profile.password.save.success')) ->success() - ->send(); + ->send() + ->sendToDatabase(Auth::user()); } catch (\Throwable $th) { //throw $th; Notification::make() - ->title(__('pages.profile.save_failed')) + ->title(__('notifications.profile.save.failed')) ->danger() ->send(); } @@ -152,15 +153,16 @@ public function updateSettings() Carbon::setLocale($this->language); Notification::make() - ->title(__('pages.profile.saved_successfully')) + ->title(__('notifications.save.success')) ->success() - ->send(); + ->send() + ->sendToDatabase(Auth::user()); return redirect('/admin'); } catch (\Throwable $th) { //throw $th; Notification::make() - ->title(__('pages.profile.save_failed')) + ->title(__('notifications.profile.save.failed')) ->danger() ->send(); } diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index e0dc3d1..3293b6f 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -186,7 +186,6 @@ public static function table(Table $table): Table ->deselectRecordsAfterCompletion() ]) ]) - // ->checkIfRecordIsSelectableUsing( // fn (User $record): bool => !$record->isSuperAdmin() && Auth::user()->hasPermissionTo('user.delete'), // ); //performance issue diff --git a/app/Filament/Resources/UserResource/Pages/CreateUser.php b/app/Filament/Resources/UserResource/Pages/CreateUser.php index ceb70c5..eba777d 100644 --- a/app/Filament/Resources/UserResource/Pages/CreateUser.php +++ b/app/Filament/Resources/UserResource/Pages/CreateUser.php @@ -3,14 +3,19 @@ namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; +use Filament\Notifications\Notification; use Filament\Resources\Pages\CreateRecord; class CreateUser extends CreateRecord { protected static string $resource = UserResource::class; - protected function getCreatedNotificationTitle(): ?string + protected function getCreatedNotification(): ?Notification { - return 'User Created Successfully'; + return Notification::make() + ->success() + ->title(__('notifications.user.created.success')) + ->send() + ->sendToDatabase(auth()->user()); } } diff --git a/app/Filament/Resources/UserResource/Pages/ListUsers.php b/app/Filament/Resources/UserResource/Pages/ListUsers.php index 3f93ee2..4e6503a 100644 --- a/app/Filament/Resources/UserResource/Pages/ListUsers.php +++ b/app/Filament/Resources/UserResource/Pages/ListUsers.php @@ -6,6 +6,7 @@ use App\Filament\Resources\UserResource; use Filament\Actions; use Filament\Actions\Action; +use Filament\Resources\Components\Tab; use Filament\Resources\Pages\ListRecords; use Maatwebsite\Excel\Facades\Excel; @@ -21,18 +22,30 @@ protected function getHeaderActions(): array ]; } + public function getTabs(): array + { + return [ + 'all' => Tab::make(), + 'active' => Tab::make() + ->modifyQueryUsing(fn ($query) => $query->where('is_active', true)) + ->icon('heroicon-o-check-badge'), + 'inactive' => Tab::make() + ->modifyQueryUsing(fn ($query) => $query->where('is_active', false)) + ->icon('heroicon-o-x-circle'), + ]; + } + private function getExportAction() { return Action::make('export') - ->label(__('resources.user.export.all')) - ->icon('heroicon-o-arrow-down-on-square-stack') - ->action('exportAllUsers') - ->color('success'); + ->label(__('resources.user.export.all')) + ->icon('heroicon-o-arrow-down-on-square-stack') + ->action('exportAllUsers') + ->color('success'); } public function exportAllUsers() { return Excel::download(new UsersExport, 'users.csv'); } - } diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 2d8774d..a569e56 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -54,6 +54,7 @@ public function panel(Panel $panel): Panel Widgets\AccountWidget::class, //Widgets\FilamentInfoWidget::class, ]) + ->databaseNotifications() ->userMenuItems([ MenuItem::make() ->label('Settings') diff --git a/database/migrations/2023_10_14_120201_create_notifications_table.php b/database/migrations/2023_10_14_120201_create_notifications_table.php new file mode 100644 index 0000000..d7ec93b --- /dev/null +++ b/database/migrations/2023_10_14_120201_create_notifications_table.php @@ -0,0 +1,30 @@ +uuid('id')->primary(); + $table->string('type'); + $table->morphs('notifiable'); + $table->text('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('notifications'); + } +}; diff --git a/lang/bn/notifications.php b/lang/bn/notifications.php new file mode 100644 index 0000000..f15cc87 --- /dev/null +++ b/lang/bn/notifications.php @@ -0,0 +1,11 @@ + 'সফলভাবে সংরক্ষিত হয়েছে', + 'profile.save.failed' => 'প্রোফাইল তথ্য আপডেট করতে ব্যর্থ হয়েছে', + 'profile.password.save.success' => 'পাসওয়ার্ড সফলভাবে আপডেট করা হয়েছে', + 'user.created.success' => 'ব্যবহারকারী সফলভাবে তৈরি করা হয়েছে', + +]; diff --git a/lang/bn/pages.php b/lang/bn/pages.php index b44cffc..f7cf089 100644 --- a/lang/bn/pages.php +++ b/lang/bn/pages.php @@ -8,9 +8,6 @@ 'profile.account_settings' => 'আপনার অ্যাকাউন্টের জন্য সেটিংস', 'profile.password' => 'পাসওয়ার্ড', 'profile.update_password' => 'আপনার পাসওয়ার্ড আপডেট করুন', - 'profile.saved_successfully' => 'সফলভাবে সংরক্ষিত হয়েছে', - 'profile.save_failed' => 'প্রোফাইল তথ্য আপডেট করতে ব্যর্থ হয়েছে', - 'profile.password.saved' => 'পাসওয়ার্ড সফলভাবে আপডেট করা হয়েছে', 'system.settings' => 'অ্যাপ্লিকেশন সিস্টেম সেটিংস', 'system.settings.desc' => 'আপনার সিস্টেম সেটিংস আপডেট করুন', 'system.settings.language' => 'সিস্টেমের ভাষা পরিবর্তন করুন', diff --git a/lang/en/notifications.php b/lang/en/notifications.php new file mode 100644 index 0000000..05d6b28 --- /dev/null +++ b/lang/en/notifications.php @@ -0,0 +1,11 @@ + 'Saved successfully', + 'profile.save.failed' => 'Failed to update profile information', + 'profile.password.save.success' => 'Password Updated Successfully', + 'user.created.success' => 'User Created Successfully', + +]; diff --git a/lang/en/pages.php b/lang/en/pages.php index 558e8b6..1ad95bf 100644 --- a/lang/en/pages.php +++ b/lang/en/pages.php @@ -8,9 +8,6 @@ 'profile.account_settings' => 'settings for your account', 'profile.password' => 'password', 'profile.update_password' => 'update your pasword', - 'profile.saved_successfully' => 'saved successfully', - 'profile.save_failed' => 'Failed to update profile information', - 'profile.password.saved' => 'Password Updated Successfully', 'system.settings' => 'Application System Settings', 'system.settings.desc' => 'Update your system settings', 'system.settings.language' => 'Change System Language',