diff --git a/.env.example b/.env.example index 02934cc..0499d29 100644 --- a/.env.example +++ b/.env.example @@ -55,4 +55,4 @@ GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= GOOGLE_REDIRECT= -USER_EMAIL= +LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE= diff --git a/.eslintrc.js b/.eslintrc.js index 898a3a0..5245fdc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,5 +12,6 @@ module.exports = { indent: ['error', 4], 'vue/html-indent': ['error', 4], 'vue/multi-word-component-names': 'off', - } + 'comma-dangle': ['error', 'always-multiline'], + }, }; diff --git a/app/Enums/FormOfEmployment.php b/app/Enums/EmploymentForm.php similarity index 81% rename from app/Enums/FormOfEmployment.php rename to app/Enums/EmploymentForm.php index c8c3e5d..27c1bb7 100644 --- a/app/Enums/FormOfEmployment.php +++ b/app/Enums/EmploymentForm.php @@ -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, ], diff --git a/app/Helpers/UserAvatarGenerator.php b/app/Helpers/UserAvatarGenerator.php index 7f96c33..beb39c7 100644 --- a/app/Helpers/UserAvatarGenerator.php +++ b/app/Helpers/UserAvatarGenerator.php @@ -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 diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index d40da65..a390687 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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(), ]); } diff --git a/app/Http/Requests/UserRequest.php b/app/Http/Requests/UserRequest.php index a33d4c2..b1a92a0 100644 --- a/app/Http/Requests/UserRequest.php +++ b/app/Http/Requests/UserRequest.php @@ -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"], ]; } diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 00bf989..c9217a6 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -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(), ]; diff --git a/app/Models/User.php b/app/Models/User.php index 7f7269c..aa76021 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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", ]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 1daa285..b6cf77f 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -6,7 +6,7 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; -use Toby\Enums\FormOfEmployment; +use Toby\Enums\EmploymentForm; class UserFactory extends Factory { @@ -15,7 +15,7 @@ class UserFactory extends Factory return [ "name" => "{$this->faker->firstName} {$this->faker->lastName}", "email" => $this->faker->unique()->safeEmail(), - "employment_form" => $this->faker->randomElement(FormOfEmployment::cases()), + "employment_form" => $this->faker->randomElement(EmploymentForm::cases()), "employment_date" => $this->faker->dateTimeBetween("2020-10-27"), "remember_token" => Str::random(10), ]; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6a896fc..f11b4c8 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -13,7 +13,7 @@ class DatabaseSeeder extends Seeder { User::factory(35)->create(); User::factory([ - "email" => env("USER_EMAIL"), + "email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"), ])->create(); } } diff --git a/resources/js/Pages/Dashboard.vue b/resources/js/Pages/Dashboard.vue index 605d48d..4eb47d9 100644 --- a/resources/js/Pages/Dashboard.vue +++ b/resources/js/Pages/Dashboard.vue @@ -291,7 +291,7 @@ export default { name: 'Payroll', href: '#', iconForeground: 'text-yellow-700', - iconBackground: 'bg-yellow-50' + iconBackground: 'bg-yellow-50', }, { icon: ReceiptRefundIcon, diff --git a/resources/js/Pages/Login.vue b/resources/js/Pages/Login.vue index e3ba099..4b52501 100644 --- a/resources/js/Pages/Login.vue +++ b/resources/js/Pages/Login.vue @@ -80,7 +80,7 @@ export default { errors: { type: Object, default: () => ({oauth: null}), - } + }, }, }; diff --git a/resources/js/Pages/Users/Create.vue b/resources/js/Pages/Users/Create.vue index 6da63ed..3402b70 100644 --- a/resources/js/Pages/Users/Create.vue +++ b/resources/js/Pages/Users/Create.vue @@ -201,6 +201,6 @@ export default { })) .post('/users'); }, - } + }, }; diff --git a/resources/js/Pages/Users/Edit.vue b/resources/js/Pages/Users/Edit.vue index 7c92e5e..ca4afef 100644 --- a/resources/js/Pages/Users/Edit.vue +++ b/resources/js/Pages/Users/Edit.vue @@ -205,6 +205,6 @@ export default { })) .put(`/users/${this.user.id}`); }, - } + }, }; diff --git a/resources/js/Pages/Users/Index.vue b/resources/js/Pages/Users/Index.vue index 2b6be44..b566a7d 100644 --- a/resources/js/Pages/Users/Index.vue +++ b/resources/js/Pages/Users/Index.vue @@ -71,7 +71,7 @@
@@ -125,7 +125,7 @@ >
diff --git a/resources/js/Shared/MainMenu.vue b/resources/js/Shared/MainMenu.vue index 552929e..7373e89 100644 --- a/resources/js/Shared/MainMenu.vue +++ b/resources/js/Shared/MainMenu.vue @@ -40,7 +40,7 @@ class="rounded-full flex text-sm ring-2 ring-white ring-opacity-20 focus:outline-none focus:ring-opacity-100" dusk="user-menu" > - Open user menu + {{ user.avatar }} diff --git a/resources/js/app.js b/resources/js/app.js index 101e245..64f1131 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -33,6 +33,6 @@ Flatpickr.setDefaults({ dateFormat: 'Y-m-d', enableTime: false, altFormat: 'j F Y', - altInput: true + altInput: true, }); diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index dad847f..8dcfae4 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -9,7 +9,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Storage; use Inertia\Testing\AssertableInertia as Assert; use Tests\TestCase; -use Toby\Enums\FormOfEmployment; +use Toby\Enums\EmploymentForm; use Toby\Models\User; class UserTest extends TestCase @@ -90,7 +90,7 @@ class UserTest extends TestCase ->post("/users", [ "name" => "John Doe", "email" => "john.doe@example.com", - "employmentForm" => FormOfEmployment::B2B_CONTRACT->value, + "employmentForm" => EmploymentForm::B2B_CONTRACT->value, "employmentDate" => Carbon::now()->toDateTimeString(), ]) ->assertSessionHasNoErrors(); @@ -98,7 +98,7 @@ class UserTest extends TestCase $this->assertDatabaseHas("users", [ "name" => "John Doe", "email" => "john.doe@example.com", - "employment_form" => FormOfEmployment::B2B_CONTRACT->value, + "employment_form" => EmploymentForm::B2B_CONTRACT->value, "employment_date" => Carbon::now()->toDateTimeString(), ]); } @@ -121,7 +121,7 @@ class UserTest extends TestCase ->put("/users/{$user->id}", [ "name" => "John Doe", "email" => "john.doe@example.com", - "employmentForm" => FormOfEmployment::B2B_CONTRACT->value, + "employmentForm" => EmploymentForm::B2B_CONTRACT->value, "employmentDate" => Carbon::now()->toDateTimeString(), ]) ->assertSessionHasNoErrors(); @@ -129,7 +129,7 @@ class UserTest extends TestCase $this->assertDatabaseHas("users", [ "name" => "John Doe", "email" => "john.doe@example.com", - "employment_form" => FormOfEmployment::B2B_CONTRACT->value, + "employment_form" => EmploymentForm::B2B_CONTRACT->value, "employment_date" => Carbon::now()->toDateTimeString(), ]); }