#4 - cr fix
This commit is contained in:
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Enums;
|
||||
|
||||
enum FormOfEmployment: string
|
||||
enum EmploymentForm: string
|
||||
{
|
||||
case EMPLOYMENT_CONTRACT = "employment_contract";
|
||||
case COMMISSION_CONTRACT = "commission_contract";
|
||||
@@ -18,10 +18,10 @@ enum FormOfEmployment: string
|
||||
|
||||
public static function casesToSelect(): array
|
||||
{
|
||||
$cases = collect(FormOfEmployment::cases());
|
||||
$cases = collect(EmploymentForm::cases());
|
||||
|
||||
return $cases->map(
|
||||
fn(FormOfEmployment $enum) => [
|
||||
fn(EmploymentForm $enum) => [
|
||||
"label" => $enum->label(),
|
||||
"value" => $enum->value,
|
||||
],
|
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Helpers;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
||||
@@ -30,17 +29,18 @@ class UserAvatarGenerator
|
||||
protected function generate(User $user): SVG
|
||||
{
|
||||
return $this->generator->rounded()
|
||||
->background($this->getRandomColor())
|
||||
->background($this->getColor($user->name))
|
||||
->color("#F4F8FD")
|
||||
->smooth()
|
||||
->fontSize(0.33)
|
||||
->generateSvg($user->name);
|
||||
}
|
||||
|
||||
protected function getRandomColor(): string
|
||||
protected function getColor(string $name): string
|
||||
{
|
||||
$colors = config("colors");
|
||||
|
||||
return Arr::random($colors);
|
||||
return $colors[strlen($name) % count($colors)];
|
||||
}
|
||||
|
||||
protected function generateUuid(): string
|
||||
|
@@ -7,7 +7,7 @@ namespace Toby\Http\Controllers;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Enums\FormOfEmployment;
|
||||
use Toby\Enums\EmploymentForm;
|
||||
use Toby\Http\Requests\UserRequest;
|
||||
use Toby\Http\Resources\UserFormDataResource;
|
||||
use Toby\Http\Resources\UserResource;
|
||||
@@ -33,7 +33,7 @@ class UserController extends Controller
|
||||
public function create(): Response
|
||||
{
|
||||
return inertia("Users/Create", [
|
||||
"employmentForms" => FormOfEmployment::casesToSelect(),
|
||||
"employmentForms" => EmploymentForm::casesToSelect(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class UserController extends Controller
|
||||
{
|
||||
return inertia("Users/Edit", [
|
||||
"user" => new UserFormDataResource($user),
|
||||
"employmentForms" => FormOfEmployment::casesToSelect(),
|
||||
"employmentForms" => EmploymentForm::casesToSelect(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ namespace Toby\Http\Requests;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Toby\Enums\FormOfEmployment;
|
||||
use Toby\Enums\EmploymentForm;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
@@ -16,7 +16,7 @@ class UserRequest extends FormRequest
|
||||
return [
|
||||
"name" => ["required", "min:3", "max: 150"],
|
||||
"email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)],
|
||||
"employmentForm" => ["required", new Enum(FormOfEmployment::class)],
|
||||
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
|
||||
"employmentDate" => ["required", "date"],
|
||||
];
|
||||
}
|
||||
|
@@ -8,6 +8,8 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
public static $wrap = false;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
@@ -16,7 +18,7 @@ class UserResource extends JsonResource
|
||||
"email" => $this->email,
|
||||
"role" => "Human Resources Manager",
|
||||
"avatar" => asset($this->avatar),
|
||||
"trashed" => $this->trashed(),
|
||||
"deleted" => $this->trashed(),
|
||||
"employmentForm" => $this->employment_form->label(),
|
||||
"employmentDate" => $this->employment_date->toDisplayString(),
|
||||
];
|
||||
|
@@ -10,14 +10,14 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Enums\FormOfEmployment;
|
||||
use Toby\Enums\EmploymentForm;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $avatar
|
||||
* @property FormOfEmployment $employment_form
|
||||
* @property EmploymentForm $employment_form
|
||||
* @property Carbon $employment_date
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
@@ -35,7 +35,7 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
"employment_form" => FormOfEmployment::class,
|
||||
"employment_form" => EmploymentForm::class,
|
||||
"employment_date" => "datetime",
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user