Skip to content

Commit

Permalink
Add checkbox for never expire on document resource (#141)
Browse files Browse the repository at this point in the history
* Add checkbox for never expire on document resource

* apply cs-fixer

* fix: checkbox label

* simplify callbacks

* fix: group checkbox with expires_at
  • Loading branch information
alexPopaCode4 authored Jan 16, 2024
1 parent c0e8027 commit affa9f3
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 25 deletions.
1 change: 0 additions & 1 deletion app/Filament/Filters/ResourceTreeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Models\Resource\Category;
use Closure;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Select;
use Filament\Tables\Filters\BaseFilter;

Expand Down
29 changes: 25 additions & 4 deletions app/Filament/Resources/DocumentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
use App\Filament\Resources\DocumentResource\Pages;
use App\Filament\Tables\Actions\ExportAction;
use App\Models\Document;
use Closure;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
Expand Down Expand Up @@ -80,10 +83,28 @@ public static function form(Form $form): Form
->label(__('document.field.signed_at'))
->required(),

DatePicker::make('expires_at')
->label(__('document.field.expires_at'))
->after('signed_at')
->required(),
Group::make()
->schema([
DatePicker::make('expires_at')
->label(__('document.field.expires_at'))
->after('signed_at')
->required(fn (Closure $get) => ! $get('never_expires'))
->disabled(fn (Closure $get) => (bool) $get('never_expires'))
->afterStateHydrated(function (Closure $set, $state) {
if (blank($state)) {
$set('never_expires', true);
}
}),

Checkbox::make('never_expires')
->label(__('document.field.never_expires'))
->afterStateUpdated(function (Closure $set, $state) {
if ($state === true) {
$set('expires_at', null);
}
})
->reactive(),
]),
]),
]),

Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Widgets/PlatformStatsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PlatformStatsWidget extends BaseWidget
/**
* Available counties to select.
*
* @var \Illuminate\Support\Collection
* @var Collection
*/
public Collection $counties;

Expand Down
16 changes: 8 additions & 8 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

Expand All @@ -32,11 +32,11 @@ class Kernel extends HttpKernel
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

Expand All @@ -55,14 +55,14 @@ class Kernel extends HttpKernel
* @var array<string, class-string|string>
*/
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth' => Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'guest' => Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'signed' => Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RedirectIfAuthenticated
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Scopes/AlphabeticalOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function __construct(string $column = 'name', string $direction = 'asc')
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @param Builder $builder
* @param Model $model
* @return void
*/
public function apply(Builder $builder, Model $model): void
Expand Down
2 changes: 1 addition & 1 deletion app/Rules/EnumCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EnumCollection implements ValidationRule
/**
* The enum validation rule.
*
* @var \Illuminate\Validation\Rules\Enum
* @var Enum
*/
protected Enum $rule;

Expand Down
10 changes: 5 additions & 5 deletions config/filament-breezy.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@
|--------------------------------------------------------------------------
| Path to registration Livewire component.
*/
'registration_component_path' => \JeffGreco13\FilamentBreezy\Http\Livewire\Auth\Register::class,
'registration_component_path' => JeffGreco13\FilamentBreezy\Http\Livewire\Auth\Register::class,
/*
|--------------------------------------------------------------------------
| Path to password reset Livewire component.
*/
'password_reset_component_path' => \JeffGreco13\FilamentBreezy\Http\Livewire\Auth\ResetPassword::class,
'password_reset_component_path' => JeffGreco13\FilamentBreezy\Http\Livewire\Auth\ResetPassword::class,
/*
|--------------------------------------------------------------------------
| Path to email verification Livewire component.
*/
'email_verification_component_path' => \JeffGreco13\FilamentBreezy\Http\Livewire\Auth\Verify::class,
'email_verification_component_path' => JeffGreco13\FilamentBreezy\Http\Livewire\Auth\Verify::class,
/*
|--------------------------------------------------------------------------
| Path to email verification Controller component.
*/
'email_verification_controller_path' => \JeffGreco13\FilamentBreezy\Http\Controllers\EmailVerificationController::class,
'email_verification_controller_path' => JeffGreco13\FilamentBreezy\Http\Controllers\EmailVerificationController::class,
/*
|--------------------------------------------------------------------------
| Path to Profile page component.
*/
'profile_page_component_path' => \App\Filament\Pages\Auth\Settings::class,
'profile_page_component_path' => App\Filament\Pages\Auth\Settings::class,
/*
|--------------------------------------------------------------------------
| Where to redirect the user after registration.
Expand Down
2 changes: 1 addition & 1 deletion config/filament.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
|
*/

'default_avatar_provider' => \Filament\AvatarProviders\UiAvatarsProvider::class,
'default_avatar_provider' => Filament\AvatarProviders\UiAvatarsProvider::class,

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions lang/ro/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'signed_at' => 'Dată semnare',
'expires_at' => 'Dată expirare',
'document' => 'Document',
'never_expires' => 'Încheiat pe perioadă nedeterminată',
],

'type' => [
Expand Down
2 changes: 1 addition & 1 deletion routes/filament.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

use Illuminate\Support\Facades\Route;

Route::get('/welcome/{user}', \App\Http\Livewire\Welcome::class)->name('auth.welcome');
Route::get('/welcome/{user}', App\Http\Livewire\Welcome::class)->name('auth.welcome');

0 comments on commit affa9f3

Please sign in to comment.