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;
|
namespace App\Filament\Pages\Auth;
|
||||||
|
|
||||||
|
use App\Filament\Support\CheerfulNotification;
|
||||||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
||||||
use Filament\Auth\Http\Responses\Contracts\LoginResponse;
|
use Filament\Auth\Http\Responses\Contracts\LoginResponse;
|
||||||
use Filament\Auth\MultiFactor\Contracts\HasBeforeChallengeHook;
|
use Filament\Auth\MultiFactor\Contracts\HasBeforeChallengeHook;
|
||||||
@ -9,7 +10,6 @@
|
|||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Models\Contracts\FilamentUser;
|
use Filament\Models\Contracts\FilamentUser;
|
||||||
use Filament\Notifications\Notification;
|
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
use Illuminate\Auth\SessionGuard;
|
use Illuminate\Auth\SessionGuard;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable;
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
@ -131,22 +131,20 @@ public function authenticate(): ?LoginResponse
|
|||||||
|
|
||||||
session()->regenerate();
|
session()->regenerate();
|
||||||
|
|
||||||
Notification::make()
|
CheerfulNotification::success(
|
||||||
->title('Berhasil Masuk')
|
'Hore! Berhasil Masuk 🎉',
|
||||||
->body('Selamat datang, '.$user->name.'!')
|
'Selamat datang kembali, '.$user->name.'! Siap untuk beraksi hari ini? 🚀✨'
|
||||||
->success()
|
)->send();
|
||||||
->send();
|
|
||||||
|
|
||||||
return app(LoginResponse::class);
|
return app(LoginResponse::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function throwFailureValidationException(): never
|
protected function throwFailureValidationException(): never
|
||||||
{
|
{
|
||||||
Notification::make()
|
CheerfulNotification::danger(
|
||||||
->title('Gagal Masuk')
|
'Ups! Gagal Masuk 😅',
|
||||||
->body('Alamat surel, nama pengguna atau kata sandi salah. Silakan coba lagi.')
|
'Sepertinya ada yang salah nih. Coba cek email atau kata sandi mu lagi ya! 🤔🔐'
|
||||||
->danger()
|
)->send();
|
||||||
->send();
|
|
||||||
|
|
||||||
throw ValidationException::withMessages([]);
|
throw ValidationException::withMessages([]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,8 +72,8 @@ protected function handleRegistration(array $data): Model
|
|||||||
$user->assignRole('Perusahaan');
|
$user->assignRole('Perusahaan');
|
||||||
|
|
||||||
CheerfulNotification::success(
|
CheerfulNotification::success(
|
||||||
'Warga Baru Nih! 👋🎉',
|
'Selamat Datang! 👋🎉',
|
||||||
"{$user->name} baru saja mendaftar. Yuk cek kelengkapannya! 🚀"
|
"Halooo, {$user->name}!, terima kasih sudah bergabung! Akunmu berhasil dibuat. Silakan verifikasi alamat surelmu! 🚀✨"
|
||||||
)
|
)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers\Filament;
|
namespace App\Providers\Filament;
|
||||||
|
|
||||||
|
use App\Filament\Pages\Auth\EmailVerification;
|
||||||
use App\Filament\Pages\Auth\Login;
|
use App\Filament\Pages\Auth\Login;
|
||||||
use App\Filament\Pages\Auth\Registration;
|
use App\Filament\Pages\Auth\Registration;
|
||||||
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
|
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
|
||||||
@ -49,7 +50,7 @@ public function panel(Panel $panel): Panel
|
|||||||
->path('dashboard')
|
->path('dashboard')
|
||||||
->login(Login::class)
|
->login(Login::class)
|
||||||
->registration(Registration::class)
|
->registration(Registration::class)
|
||||||
->emailVerification()
|
->emailVerification(EmailVerification::class)
|
||||||
->colors([
|
->colors([
|
||||||
'primary' => Color::Blue,
|
'primary' => Color::Blue,
|
||||||
])
|
])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user