From 6d6570f79f55769a7881cbcc4a5520ce89f9c392 Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Tue, 30 Jan 2024 23:43:07 +0100 Subject: [PATCH] fix(admin): clear parent/table on type change #23 (#45) --- .../Resources/ApplicationResource.php | 3 ++- app/Models/Application.php | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index 459291c..f61804f 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -70,13 +70,14 @@ public static function form(Form $form): Form "table_accepted" => "Table accepted", "checked_in" => "Checked in (on-site)", "checked_out" => "Checked out (on-site)", - ])->disablePlaceholderSelection()->required()->reactive(), + ])->selectablePlaceholder(false)->required()->reactive(), Forms\Components\TextInput::make('table_number') ->maxLength(255), ]), Forms\Components\Fieldset::make('Relationships')->inlineLabel()->columns(1)->schema([ Forms\Components\Select::make('type')->options(ApplicationType::class) + ->selectablePlaceholder(false) ->reactive() ->required(), Forms\Components\Select::make('user_id')->searchable()->relationship('user', 'name') diff --git a/app/Models/Application.php b/app/Models/Application.php index 080953d..81b7df1 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -135,6 +135,33 @@ public function comments() return $this->hasMany(Comment::class, 'application_id'); } + public function type(): Attribute + { + return Attribute::make( + set: function (ApplicationType|string $value) { + $type = ($value instanceof ApplicationType) ? $value : ApplicationType::from($value); + switch ($type) { + case ApplicationType::Dealer: + // Dealer has no parent + return [ + 'parent' => null, + 'type' => $type, + ]; + case ApplicationType::Assistant: + case ApplicationType::Share: + // Assistant and share has no table + return [ + 'type' => $type, + 'table_type_requested' => null, + 'table_type_assigned' => null, + ]; + default: + return; + } + } + ); + } + public function getStatus() { return ApplicationStatus::for($this);