diff --git a/app/Console/Commands/MakeUserCommand.php b/app/Console/Commands/MakeUserCommand.php index f454def..4377826 100644 --- a/app/Console/Commands/MakeUserCommand.php +++ b/app/Console/Commands/MakeUserCommand.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Api\Concern\AllowedDomain; use App\Http\Controllers\Api\Enum\UserEnum; +use App\Models\Departments; use App\Models\Designations; use App\Models\Role; use App\Models\User; @@ -27,15 +28,12 @@ class MakeUserCommand extends Command {--role= : A valid role} {--password= : The password for the user (min. 8 characters)}'; - protected $description = 'Create a new Ninshiki user with an Owner Role and Permissions'; + protected $description = 'Create a new Ninshiki Admin User with an Owner Role and Permissions'; - /** - * @var array{'name': string | null, 'email': string | null, 'password': string | null, 'role': string | int | null} - */ protected array $options; /** - * @return array{'name': string | null, 'email': string | null, 'password': string | null, 'role': string | int | null} + * @return array{'name': string | null, 'email': string | null, 'password': string | null, 'role': string | int | null, 'department': string | int | null, 'designation': string | int | null} */ protected function getUserData(): array { @@ -56,11 +54,19 @@ protected function getUserData(): array }, ), + 'department' => $this->options['department'] ?? select( + label: 'What Department should the user have?', + options: Departments::pluck('name', 'id')->toArray(), + ), + + 'designation' => $this->options['designation'] ?? select( + label: 'What Job Title should the user have?', + options: Designations::pluck('name', 'id')->toArray(), + ), + 'role' => $this->options['role'] ?? select( label: 'What role should the user have?', options: Role::pluck('name', 'name')->toArray(), - default: 'Member', - scroll: 1, validate: fn (string $value) => Role::where('name', '=', $value)->doesntExist() ? 'Invalid Role Supplied' : null @@ -85,7 +91,8 @@ protected function createUser(): ?User 'name' => $this->options['name'], 'password' => $this->options['password'], 'email' => $this->options['email'], - 'designation' => Designations::first()->id, + 'designation' => $this->options['designation'], + 'department' => $this->options['department'], 'status' => UserEnum::Active, ]); $this->callSilently('shield:super-admin', ['--user' => $user->id, '--panel' => 0]); diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index 7d86dc5..e57f48c 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -109,7 +109,7 @@ public static function table(Table $table): Table ->label('Department') ->numeric() ->sortable(), - Tables\Columns\TextColumn::make('designation') + Tables\Columns\TextColumn::make('designation.name') ->label('Designation') ->searchable(), Tables\Columns\TextColumn::make('email_verified_at') diff --git a/app/Filament/Resources/UserResource/Pages/ManageUsers.php b/app/Filament/Resources/UserResource/Pages/ManageUsers.php index e9c23e3..4fbc7dd 100644 --- a/app/Filament/Resources/UserResource/Pages/ManageUsers.php +++ b/app/Filament/Resources/UserResource/Pages/ManageUsers.php @@ -4,12 +4,11 @@ use App\Filament\Resources\UserResource; use App\Http\Controllers\Api\Enum\UserEnum; -use App\Notifications\User\Invitation\InvitationNotification; +use App\Jobs\NewUserJob; use Filament\Actions; use Filament\Resources\Pages\ManageRecords; use Filament\Support\Enums\Alignment; use Filament\Support\Enums\MaxWidth; -use Illuminate\Support\Facades\Notification; use Illuminate\Support\Str; class ManageUsers extends ManageRecords @@ -31,9 +30,9 @@ protected function getHeaderActions(): array }) ->after(function ($record) { // send invitation email - /** @phpstan-ignore-next-line */ - Notification::route('mail', $record->email) - ->notify(new InvitationNotification); + NewUserJob::dispatch($record) + ->afterCommit() + ->afterResponse(); }) ->createAnother(false), ]; diff --git a/app/Jobs/NewUserJob.php b/app/Jobs/NewUserJob.php new file mode 100644 index 0000000..647069f --- /dev/null +++ b/app/Jobs/NewUserJob.php @@ -0,0 +1,26 @@ +user->notify(new InvitationNotification); + } +}