Skip to content

Commit

Permalink
min
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Apr 9, 2024
1 parent abf5552 commit adf39e0
Showing 1 changed file with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ protected function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub


$this->label(__('volunteer.field.import'));
$this->successNotificationTitle(__('volunteer.field.success_import'));
$this->visible(fn () => auth()->user->isPlatformAdmin() || auth()->user->isOrgAdmin());
$this->visible(fn () => auth()->user()->isPlatformAdmin() || auth()->user()->isOrgAdmin());
$this->fields([
Select::make('organisation_id')
->options(function () {
if (auth()->user()->isOrgAdmin()) {
$organisation = auth()->user()->organisation;

return [$organisation->id => $organisation->name];
}

return Organisation::all()
->pluck('name', 'id');
})
->searchable()
->label(__('organisation.label.singular'))
->required(),
ImportField::make('first_name')
->label(__('volunteer.field.first_name'))
->required(),
Expand Down Expand Up @@ -54,7 +66,6 @@ protected function setUp(): void
]);

$this->handleRecordCreation(function (array $data) {
dd($data);
if (! isset($data['first_name']) ||
! isset($data['last_name']) ||
! isset($data['email']) ||
Expand All @@ -63,14 +74,6 @@ protected function setUp(): void
return new Volunteer();
}

$organisation = Organisation::query()
->where('name', 'like', $data['organisation_name'])
->first();

if (! $organisation) {
return new Volunteer();
}

$roles = VolunteerRole::options();
$role = array_search($data['role'], $roles);

Expand All @@ -86,7 +89,7 @@ protected function setUp(): void
$firstAID = (bool) $data['has_first_aid_accreditation'];
}

$fields = ['organisation_id' => $organisation->id,
$fields = ['organisation_id' => $data['organisation_id'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
Expand Down Expand Up @@ -120,26 +123,5 @@ protected function setUp(): void

return Volunteer::create($fields);
});

// $formSchema = array_merge(
// [Select::make('organisation')
// ->options(Organisation::all()
// ->pluck('name', 'id'))
// ->searchable()
// ->label(__('organisation.label.singular'))
// ->required(),
// ],
// $this->getFormSchema()
// );

$formSchema = $this->getFormSchema();
$formSchema[] = Select::make('organisation')
->options(Organisation::all()
->pluck('name', 'id'))
->searchable()
->label(__('organisation.label.singular'))
->required();

$this->form($formSchema);
}
}

0 comments on commit adf39e0

Please sign in to comment.