From 6210d43908ab1fdf46160b2589e4ed8ab3df8dcc Mon Sep 17 00:00:00 2001 From: Andy Susanto Date: Mon, 9 Oct 2023 11:01:15 +0700 Subject: [PATCH] update versi 3 --- app/Filament/Pages/Auth/Login.php | 69 ++++++++++++ app/Filament/Resources/UserResource.php | 105 ++++++++++++++++++ .../UserResource/Pages/CreateUser.php | 2 +- .../Resources/UserResource/Pages/EditUser.php | 4 +- .../UserResource/Pages/ListUsers.php | 4 +- app/Livewire/Auth/Login.php | 58 ---------- app/Providers/AppServiceProvider.php | 11 +- app/Providers/Filament/AdminPanelProvider.php | 6 +- .../views/filament/pages/auth/login.blade.php | 3 + .../filament-panels/components/logo.blade.php | 21 ++-- 10 files changed, 204 insertions(+), 79 deletions(-) create mode 100644 app/Filament/Pages/Auth/Login.php create mode 100644 app/Filament/Resources/UserResource.php delete mode 100644 app/Livewire/Auth/Login.php create mode 100644 resources/views/filament/pages/auth/login.blade.php diff --git a/app/Filament/Pages/Auth/Login.php b/app/Filament/Pages/Auth/Login.php new file mode 100644 index 0000000..20f7b36 --- /dev/null +++ b/app/Filament/Pages/Auth/Login.php @@ -0,0 +1,69 @@ + $data['name'], + 'password' => $data['password'], + ]; + } + + protected function getFormActions(): array + { + return [ + $this->getAuthenticateFormAction(), + ]; + } + + protected function hasFullWidthFormActions(): bool + { + return true; + } + + protected function getNameFormComponent(): Component + { + return TextInput::make('name') + ->label(__('Username')) + ->required() + ->autocomplete() + ->autofocus() + ->extraInputAttributes(['tabindex' => 1]); + } + + protected function getForms(): array + { + return [ + 'form' => $this->form( + $this->makeForm() + ->schema([ + $this->getNameFormComponent(), + $this->getPasswordFormComponent(), + $this->getRememberFormComponent(), + ]) + ->statePath('data'), + ), + ]; + } + + + protected function getAuthenticateFormAction(): Action + { + return Action::make('authenticate') + ->label(__('filament-panels::pages/auth/login.form.actions.authenticate.label')) + ->submit('authenticate'); + } +} diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php new file mode 100644 index 0000000..2551b69 --- /dev/null +++ b/app/Filament/Resources/UserResource.php @@ -0,0 +1,105 @@ +schema([ + Forms\Components\TextInput::make('pegawai_id') + ->maxLength(65), + Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + Forms\Components\TextInput::make('email') + ->email() + ->maxLength(255), + Forms\Components\DateTimePicker::make('email_verified_at'), + Forms\Components\TextInput::make('password') + ->password() + ->required() + ->maxLength(255), + Forms\Components\TextInput::make('google_id') + ->maxLength(255), + Forms\Components\TextInput::make('theme') + ->maxLength(255) + ->default('default'), + Forms\Components\TextInput::make('theme_color') + ->maxLength(255), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('pegawai_id') + ->searchable(), + Tables\Columns\TextColumn::make('name') + ->searchable(), + Tables\Columns\TextColumn::make('email') + ->searchable(), + Tables\Columns\TextColumn::make('email_verified_at') + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('google_id') + ->searchable(), + Tables\Columns\TextColumn::make('theme') + ->searchable(), + Tables\Columns\TextColumn::make('theme_color') + ->searchable(), + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListUsers::route('/'), + 'create' => Pages\CreateUser::route('/create'), + 'edit' => Pages\EditUser::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/UserResource/Pages/CreateUser.php b/app/Filament/Resources/UserResource/Pages/CreateUser.php index 0f9094f..73aa46d 100644 --- a/app/Filament/Resources/UserResource/Pages/CreateUser.php +++ b/app/Filament/Resources/UserResource/Pages/CreateUser.php @@ -3,7 +3,7 @@ namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; -use Filament\Pages\Actions; +use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateUser extends CreateRecord diff --git a/app/Filament/Resources/UserResource/Pages/EditUser.php b/app/Filament/Resources/UserResource/Pages/EditUser.php index df17e9f..b8770a9 100644 --- a/app/Filament/Resources/UserResource/Pages/EditUser.php +++ b/app/Filament/Resources/UserResource/Pages/EditUser.php @@ -3,14 +3,14 @@ namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; -use Filament\Pages\Actions; +use Filament\Actions; use Filament\Resources\Pages\EditRecord; class EditUser extends EditRecord { protected static string $resource = UserResource::class; - protected function getActions(): array + protected function getHeaderActions(): array { return [ Actions\DeleteAction::make(), diff --git a/app/Filament/Resources/UserResource/Pages/ListUsers.php b/app/Filament/Resources/UserResource/Pages/ListUsers.php index 54c3be8..0766ffe 100644 --- a/app/Filament/Resources/UserResource/Pages/ListUsers.php +++ b/app/Filament/Resources/UserResource/Pages/ListUsers.php @@ -3,14 +3,14 @@ namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; -use Filament\Pages\Actions; +use Filament\Actions; use Filament\Resources\Pages\ListRecords; class ListUsers extends ListRecords { protected static string $resource = UserResource::class; - protected function getActions(): array + protected function getHeaderActions(): array { return [ Actions\CreateAction::make(), diff --git a/app/Livewire/Auth/Login.php b/app/Livewire/Auth/Login.php deleted file mode 100644 index c249bb6..0000000 --- a/app/Livewire/Auth/Login.php +++ /dev/null @@ -1,58 +0,0 @@ -rateLimit(5); - } catch (TooManyRequestsException $exception) { - throw ValidationException::withMessages([ - 'name' => __('filament::login.messages.throttled', [ - 'seconds' => $exception->secondsUntilAvailable, - 'minutes' => ceil($exception->secondsUntilAvailable / 60), - ]), - ]); - } - - $data = $this->form->getState(); - - if (!Filament::auth()->attempt([ - 'name' => $data['name'], - 'password' => $data['password'], - ], $data['remember'])) { - throw ValidationException::withMessages([ - 'name' => __('filament::login.messages.failed'), - ]); - } - - session()->regenerate(); - return app(LoginResponse::class); - } - - protected function getFormSchema(): array - { - return [ - TextInput::make('name') - ->label('Username') - ->required() - ->autocomplete(), - TextInput::make('password') - ->label(__('filament::login.fields.password.label')) - ->password() - ->required(), - Checkbox::make('remember') - ->label(__('filament::login.fields.remember.label')), - ]; - } -} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ab2770e..39096d7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,13 +2,14 @@ namespace App\Providers; +use Filament\Tables\Table; use Filament\Facades\Filament; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; -use Filament\Support\Facades\FilamentView; -use Illuminate\Contracts\View\View; use Filament\Tables\Enums\FiltersLayout; -use Filament\Tables\Table; +use Filament\Support\Facades\FilamentView; class AppServiceProvider extends ServiceProvider { @@ -17,7 +18,9 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { - + if (env(key: 'APP_ENV') =='local') { + URL::forceScheme(scheme:'https'); + } } /** diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 7d0be7b..da31c4e 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -2,6 +2,7 @@ namespace App\Providers\Filament; +use App\Filament\Pages\Auth\Login; use Filament\Http\Middleware\Authenticate; use Filament\Http\Middleware\DisableBladeIconComponents; use Filament\Http\Middleware\DispatchServingFilamentEvent; @@ -26,11 +27,14 @@ public function panel(Panel $panel): Panel ->default() ->id('admin') ->path('app') + ->registration() + ->spa() + ->maxContentWidth('full') ->brandLogo(asset('image/logouinjambi.svg')) ->brandName('Presensi Pegawai') ->favicon(asset('image/favicon.svg')) ->font('Poppins') - ->login() + ->login(Login::class) ->colors([ 'primary' => Color::Amber, ]) diff --git a/resources/views/filament/pages/auth/login.blade.php b/resources/views/filament/pages/auth/login.blade.php new file mode 100644 index 0000000..cc61477 --- /dev/null +++ b/resources/views/filament/pages/auth/login.blade.php @@ -0,0 +1,3 @@ + + + diff --git a/resources/views/vendor/filament-panels/components/logo.blade.php b/resources/views/vendor/filament-panels/components/logo.blade.php index 1bf5b3b..ea86a1b 100644 --- a/resources/views/vendor/filament-panels/components/logo.blade.php +++ b/resources/views/vendor/filament-panels/components/logo.blade.php @@ -1,19 +1,18 @@ @php $brandName = filament()->getBrandName(); - $brandLogo = filament()->getBrandLogo() + $brandLogo = filament()->getBrandLogo(); @endphp @if (filled($brandLogo)) - {{ $brandName }}class(['fi-logo h-10']) }} - /> +
+ {{ $brandName }}class(['fi-logo h-10']) }} /> +
+ {{ $brandName }} +
+
@else -
class(['fi-logo text-xl font-bold leading-5 tracking-tight text-gray-950 dark:text-white']) }} - > +
class(['fi-logo text-xl font-bold leading-5 tracking-tight text-gray-950 dark:text-white']) }}> {{ $brandName }}
-@endif \ No newline at end of file +@endif