diff --git a/app/Filament/Resources/VolunteerResource/Actions/ImportVolunteersAction.php b/app/Filament/Resources/VolunteerResource/Actions/ImportVolunteersAction.php index 01597bc..2744f07 100644 --- a/app/Filament/Resources/VolunteerResource/Actions/ImportVolunteersAction.php +++ b/app/Filament/Resources/VolunteerResource/Actions/ImportVolunteersAction.php @@ -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(), @@ -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']) || @@ -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); @@ -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'], @@ -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); } }