This commit is contained in:
Adrian Hopek 2022-01-18 15:01:34 +01:00
parent 5d580a71d0
commit e59ae4a855
18 changed files with 40 additions and 37 deletions

View File

@ -55,4 +55,4 @@ GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=
USER_EMAIL=
LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE=

View File

@ -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'],
},
};

View File

@ -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,
],

View File

@ -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

View File

@ -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(),
]);
}

View File

@ -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"],
];
}

View File

@ -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(),
];

View File

@ -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",
];

View File

@ -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),
];

View File

@ -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();
}
}

View File

@ -291,7 +291,7 @@ export default {
name: 'Payroll',
href: '#',
iconForeground: 'text-yellow-700',
iconBackground: 'bg-yellow-50'
iconBackground: 'bg-yellow-50',
},
{
icon: ReceiptRefundIcon,

View File

@ -80,7 +80,7 @@ export default {
errors: {
type: Object,
default: () => ({oauth: null}),
}
},
},
};
</script>

View File

@ -201,6 +201,6 @@ export default {
}))
.post('/users');
},
}
},
};
</script>

View File

@ -205,6 +205,6 @@ export default {
}))
.put(`/users/${this.user.id}`);
},
}
},
};
</script>

View File

@ -71,7 +71,7 @@
<tr
v-for="user in users.data"
:key="user.id"
:class="{ 'bg-red-50': user.trashed, 'hover:bg-blumilk-25': !user.trashed }"
:class="{ 'bg-red-50': user.deleted, 'hover:bg-blumilk-25': !user.deleted }"
>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<div class="flex">
@ -125,7 +125,7 @@
>
<MenuItems class="origin-top-right absolute right-0 mt-2 w-56 z-10 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none">
<div
v-if="!user.trashed"
v-if="!user.deleted"
class="py-1"
>
<MenuItem
@ -295,6 +295,6 @@ export default {
return {
search,
};
}
},
};
</script>

View File

@ -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"
>
<span class="sr-only">Open user menu</span>
<span class="sr-only">{{ user.avatar }}</span>
<img
class="h-8 w-8 rounded-full"
:src="user.avatar"
@ -241,7 +241,7 @@ import {
PopoverOverlay,
PopoverPanel,
TransitionChild,
TransitionRoot
TransitionRoot,
} from '@headlessui/vue';
import {BellIcon, MenuIcon, XIcon} from '@heroicons/vue/outline';
import {computed} from 'vue';
@ -284,7 +284,7 @@ export default {
navigation,
userNavigation,
};
}
},
};
</script>

View File

@ -33,6 +33,6 @@ Flatpickr.setDefaults({
dateFormat: 'Y-m-d',
enableTime: false,
altFormat: 'j F Y',
altInput: true
altInput: true,
});

View File

@ -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(),
]);
}