Skip to content

Commit

Permalink
Fix Home Members Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CalumTowers committed Jan 21, 2024
1 parent cf96e13 commit 8431943
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use App\Models\Atc\Endorsement;
use App\Models\Mship\Account;
use App\Models\Training\WaitingList\WaitingListFlag;
use App\Rules\HomeMemberId;
use Carbon\Carbon;
use Filament\Actions;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Arr;

class ViewWaitingList extends ViewRecord
Expand Down Expand Up @@ -44,11 +44,22 @@ protected function getHeaderActions(): array
->form([
TextInput::make('account_id')
->label('Account CID')
->rules([new HomeMemberId, fn () => function ($attribute, $value, $fail) {
->rule(fn () => function ($attribute, $value, $fail) {
if ($this->record->accounts->contains('id', $value)) {
$fail('This account is already in this waiting list.');
}
}])
})
->rule(fn () => function ($attribute, $value, $fail) {
if ($this->record->home_members_only) {
try {
if (! Account::findOrFail($value)->primary_state->isDivision) {
$fail('The specified member is not a home UK member.');
}
} catch (ModelNotFoundException $e) {
$fail('The specified member was not found.');
}
}
})
->required(),
DatePicker::make('join_date')
->visible(fn () => auth()->user()->can('addAccountsAdmin', $this->record))
Expand Down
1 change: 1 addition & 0 deletions app/Models/Training/WaitingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected static function boot()
const ANY_FLAGS = 'any';

protected $casts = [
'home_members_only' => 'boolean',
'feature_toggles' => 'array',
'deleted_at' => 'datetime',
];
Expand Down
23 changes: 0 additions & 23 deletions app/Rules/HomeMemberId.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Models\Training\WaitingList;
use App\Models\Training\WaitingList\WaitingListFlag;
use App\Models\Training\WaitingList\WaitingListStatus;
use App\Rules\HomeMemberId;
use Filament\Tables\Actions\EditAction;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Livewire\Livewire;
Expand Down Expand Up @@ -111,7 +110,7 @@ public function test_non_home_student_cant_be_added()
->callAction('add_student', data: [
'account_id' => $accountToAdd->id,
])
->assertHasActionErrors(['account_id' => [HomeMemberId::class]]);
->assertHasActionErrors(['account_id']);

$this->assertNotContains($accountToAdd->id, $waitingList->fresh()->accounts->pluck('id'));

Expand Down

0 comments on commit 8431943

Please sign in to comment.