feat: Implement CheerfulNotification for login, registration, and email verification processes to enhance user experience and feedback.
This commit is contained in:
parent
8ddad47c01
commit
b522b4ff6f
70
app/Filament/Pages/Auth/EmailVerification.php
Normal file
70
app/Filament/Pages/Auth/EmailVerification.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Auth;
|
||||
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Auth\Pages\EmailVerification\EmailVerificationPrompt;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
||||
class EmailVerification extends EmailVerificationPrompt
|
||||
{
|
||||
// protected function sendEmailVerificationNotification(MustVerifyEmail $user): void
|
||||
// {
|
||||
// try {
|
||||
// $this->rateLimit(2);
|
||||
// } catch (TooManyRequestsException $exception) {
|
||||
// $this->getRateLimitedNotification($exception)?->send();
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (! $user->hasVerifiedEmail()) {
|
||||
// $user->sendEmailVerificationNotification();
|
||||
|
||||
// CheerfulNotification::success(
|
||||
// 'Mail Meluncur! 📧🚀',
|
||||
// 'Tautan verifikasi baru sudah dikirim ke alamat surelmu. Cek inbox (atau spam) ya! 😉✨'
|
||||
// )->send();
|
||||
// } else {
|
||||
// CheerfulNotification::success(
|
||||
// 'Sudah Aman Kok! ✅',
|
||||
// 'Alamat surel sudah terverifikasi sebelumnya. Langsung lanjut aja! 🏎️💨'
|
||||
// )->send();
|
||||
// }
|
||||
// }
|
||||
|
||||
public function resendNotificationAction(): Action
|
||||
{
|
||||
return Action::make('resendNotification')
|
||||
->link()
|
||||
->label(__('filament-panels::auth/pages/email-verification/email-verification-prompt.actions.resend_notification.label').'.')
|
||||
->size('sm')
|
||||
->action(function (): void {
|
||||
try {
|
||||
$this->rateLimit(2);
|
||||
} catch (TooManyRequestsException $exception) {
|
||||
$this->getRateLimitedNotification($exception)?->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendEmailVerificationNotification($this->getVerifiable());
|
||||
|
||||
CheerfulNotification::success(
|
||||
'Mail Meluncur! 📧🚀',
|
||||
'Tautan verifikasi baru sudah dikirim ke alamat surelmu. Cek inbox (atau spam) ya! 😉✨'
|
||||
)->send();
|
||||
});
|
||||
}
|
||||
|
||||
protected function getRateLimitedNotification(TooManyRequestsException $exception): ?Notification
|
||||
{
|
||||
return CheerfulNotification::danger(
|
||||
'Pelan-pelan ya ⏳',
|
||||
'Permintaan terlalu sering. Tunggu sebentar lalu coba lagi dalam '.$exception->secondsUntilAvailable.' detik.'
|
||||
)->send();
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Pages\Auth;
|
||||
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
||||
use Filament\Auth\Http\Responses\Contracts\LoginResponse;
|
||||
use Filament\Auth\MultiFactor\Contracts\HasBeforeChallengeHook;
|
||||
@ -9,7 +10,6 @@
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
@ -131,22 +131,20 @@ public function authenticate(): ?LoginResponse
|
||||
|
||||
session()->regenerate();
|
||||
|
||||
Notification::make()
|
||||
->title('Berhasil Masuk')
|
||||
->body('Selamat datang, '.$user->name.'!')
|
||||
->success()
|
||||
->send();
|
||||
CheerfulNotification::success(
|
||||
'Hore! Berhasil Masuk 🎉',
|
||||
'Selamat datang kembali, '.$user->name.'! Siap untuk beraksi hari ini? 🚀✨'
|
||||
)->send();
|
||||
|
||||
return app(LoginResponse::class);
|
||||
}
|
||||
|
||||
protected function throwFailureValidationException(): never
|
||||
{
|
||||
Notification::make()
|
||||
->title('Gagal Masuk')
|
||||
->body('Alamat surel, nama pengguna atau kata sandi salah. Silakan coba lagi.')
|
||||
->danger()
|
||||
->send();
|
||||
CheerfulNotification::danger(
|
||||
'Ups! Gagal Masuk 😅',
|
||||
'Sepertinya ada yang salah nih. Coba cek email atau kata sandi mu lagi ya! 🤔🔐'
|
||||
)->send();
|
||||
|
||||
throw ValidationException::withMessages([]);
|
||||
}
|
||||
|
||||
@ -72,8 +72,8 @@ protected function handleRegistration(array $data): Model
|
||||
$user->assignRole('Perusahaan');
|
||||
|
||||
CheerfulNotification::success(
|
||||
'Warga Baru Nih! 👋🎉',
|
||||
"{$user->name} baru saja mendaftar. Yuk cek kelengkapannya! 🚀"
|
||||
'Selamat Datang! 👋🎉',
|
||||
"Halooo, {$user->name}!, terima kasih sudah bergabung! Akunmu berhasil dibuat. Silakan verifikasi alamat surelmu! 🚀✨"
|
||||
)
|
||||
->send();
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use App\Filament\Pages\Auth\EmailVerification;
|
||||
use App\Filament\Pages\Auth\Login;
|
||||
use App\Filament\Pages\Auth\Registration;
|
||||
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
|
||||
@ -49,7 +50,7 @@ public function panel(Panel $panel): Panel
|
||||
->path('dashboard')
|
||||
->login(Login::class)
|
||||
->registration(Registration::class)
|
||||
->emailVerification()
|
||||
->emailVerification(EmailVerification::class)
|
||||
->colors([
|
||||
'primary' => Color::Blue,
|
||||
])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user