Skip to content

Commit

Permalink
fix(admin): clear parent/table on type change #23 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenrikur authored Jan 30, 2024
1 parent 2ab8104 commit 6d6570f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Filament/Resources/ApplicationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
27 changes: 27 additions & 0 deletions app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6d6570f

Please sign in to comment.