Skip to content

Commit

Permalink
Merge pull request #459 from code4romania/377-edit-specialist-without…
Browse files Browse the repository at this point in the history
…-role

Edit specialist without role
  • Loading branch information
gheorghelupu17 authored Dec 30, 2024
2 parents 9a4695b + 890b1fe commit f6685b9
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public function table(Table $table): Table
->actions([
EditAction::make()
->form($this->getFormSchema())
->fillForm(function (Specialist $record) {
if (!$record->role_id) {
$record->role_id = -1;
}

return $record->toArray();
})
->label(__('beneficiary.section.specialists.change_action'))
->modalHeading(__('beneficiary.section.specialists.heading.edit_modal'))
->extraModalFooterActions([
Expand Down Expand Up @@ -103,10 +110,12 @@ public function getFormSchema(): array
Select::make('role_id')
->label(__('beneficiary.section.specialists.labels.roles'))
->options(
UserRole::query()
->with('role')
->get()
->pluck('role.name', 'role.id')
fn (string $operation, ?string $state) => $operation === 'edit' && $state === '-1' ?
[-1 => __('beneficiary.section.specialists.labels.empty_state_role')] :
UserRole::query()
->with('role')
->get()
->pluck('role.name', 'role.id')
)
->searchable()
->preload()
Expand All @@ -119,7 +128,8 @@ public function getFormSchema(): array
->label(__('beneficiary.section.specialists.labels.name'))
->options(
function (Get $get, $state) {
if (! $roleID = (int) $get('role_id')) {
$roleID = (int)$get('role_id');
if ($roleID === -1) {
if ($state) {
return [$state => User::find($state)->full_name];
}
Expand Down

0 comments on commit f6685b9

Please sign in to comment.