Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

57 fix designation column in user module #59

Merged
merged 5 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions app/Console/Commands/MakeUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 4 additions & 5 deletions app/Filament/Resources/UserResource/Pages/ManageUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
];
Expand Down
26 changes: 26 additions & 0 deletions app/Jobs/NewUserJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Jobs;

use App\Models\User;
use App\Notifications\User\Invitation\InvitationNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class NewUserJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* @param User $user
*/
public function __construct(private readonly User $user) {}

public function handle(): void
{
$this->user->notify(new InvitationNotification);
}
}
Loading