Skip to content

Commit

Permalink
Merge pull request #388 from code4romania/218-implement-define-rol-in…
Browse files Browse the repository at this point in the history
…-team-case

select roles in specialists team on create beneficiary
  • Loading branch information
gheorghelupu17 authored Dec 9, 2024
2 parents 83840f2 + 2ef4ccf commit a78d7d6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Placeholder;
Expand Down Expand Up @@ -324,15 +325,50 @@ protected function getSteps(): array
->columns()
->schema(EditFlowPresentation::flowSection()),
]),
Step::make('specialist')
->label(__('beneficiary.wizard.specialist.label'))
->schema([
Section::make()
->label(__('beneficiary.wizard.specialist.label'))
->maxWidth('3xl')
->schema([
CheckboxList::make('roles')
->label(__('beneficiary.section.specialists.labels.select_roles', ['user_name' => auth()->user()->full_name]))
->options(function () {
$roles = auth()->user()->rolesInOrganization->pluck('name', 'id');
$roles[-1] = __('beneficiary.section.specialists.labels.without_role');

return $roles;
}),
]),
]),
];
}

public function afterCreate(): void
{
/** @var Beneficiary $record */
$record = $this->getRecord();
if ($record->same_as_legal_residence) {
$record->load(['legal_residence', 'effective_residence']);
Beneficiary::copyLegalResidenceToEffectiveResidence($record);
}

$roles = $this->data['roles'] ?? [];

if (! $roles) {
return;
}

foreach ($roles as $role) {
if (! $role) {
continue;
}
$record->specialistsTeam()->create([
'role_id' => $role !== '-1' ? $role : null,
'user_id' => auth()->id(),
'specialistable_type' => 'beneficiary',
]);
}
}
}
24 changes: 0 additions & 24 deletions app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,6 @@ class Beneficiary extends Model
'status' => CaseStatus::class,
];

protected static function booted()
{
static::created(function (Beneficiary $beneficiary) {
if (auth()->guest()) {
return;
}

/** @var User $user */
$user = auth()->user();
$beneficiary->specialistsTeam()->create([
'user_id' => $user->id,
'role_id' => $user->canBeCaseManager()
? $user->rolesInOrganization
->filter(fn ($role) => $role->case_manager)
->first()
?->id
: $user->rolesInOrganization
->first()
?->id,
'specialistable_type' => $beneficiary->getMorphClass(),
]);
});
}

public function scopeWhereUserHasAccess(Builder $query): Builder
{
$user = auth()->user();
Expand Down
5 changes: 5 additions & 0 deletions lang/ro/beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
'beneficiary_situation' => [
'label' => 'Situația beneficiarului',
],
'specialist' => [
'label' => 'Definește rol în echipa cazului ',
],
],

'section' => [
Expand Down Expand Up @@ -322,6 +325,8 @@
'status' => 'Status',
'roles' => 'Rol în echipa de caz',
'summarize' => '{1} +:count alt specialist|[2,19] +:count alți specialiști|[20,*] +:count de alți specialiști',
'select_roles' => 'Selectează rolul (sau rolurile) specialistului :user_name în echipa cazului',
'without_role' => 'Specialistul înregistrează cazul, dar nu are alt rol în echipa de caz',
],
'action' => [
'delete' => 'Elimină din echipa de caz',
Expand Down

0 comments on commit a78d7d6

Please sign in to comment.