#90 - user profile (#125)

* fix css focuses

* #90 - wip

* #90 - fix to generate PDF

* #90 - wip

* #90 - wip

* #90 - wip

* #90 - wip

* #90 - fix to calendar

* #90 - wip

* #90 - fix

* #90 - fix lint

* #90 - fix

* Apply suggestions from code review

Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* #90 - cr fixes

* #90 - fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
Adrian Hopek 2022-04-14 11:58:45 +02:00 committed by GitHub
parent 459b62500e
commit cc981b02b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 765 additions and 251 deletions

View File

@ -17,11 +17,29 @@ class ExceptionHandler extends Handler
"password_confirmation", "password_confirmation",
]; ];
protected array $handleByInertia = [
Response::HTTP_INTERNAL_SERVER_ERROR,
Response::HTTP_SERVICE_UNAVAILABLE,
Response::HTTP_TOO_MANY_REQUESTS,
419, // CSRF
Response::HTTP_NOT_FOUND,
Response::HTTP_FORBIDDEN,
Response::HTTP_UNAUTHORIZED,
];
public function render($request, Throwable $e): Response public function render($request, Throwable $e): Response
{ {
$response = parent::render($request, $e); $response = parent::render($request, $e);
if (app()->environment("production") && in_array($response->status(), [500, 503, 429, 419, 404, 403, 401], true)) { if (!app()->environment("production")) {
return $response;
}
if ($response->status() === Response::HTTP_METHOD_NOT_ALLOWED) {
$response->setStatusCode(Response::HTTP_NOT_FOUND);
}
if (in_array($response->status(), $this->handleByInertia, true)) {
return Inertia::render("Error", [ return Inertia::render("Error", [
"status" => $response->status(), "status" => $response->status(),
]) ])

View File

@ -9,12 +9,14 @@ use Toby\Eloquent\Models\YearPeriod;
class CreateUserAction class CreateUserAction
{ {
public function execute(array $data): User public function execute(array $userData, array $profileData): User
{ {
$user = new User($data); $user = new User($userData);
$user->save(); $user->save();
$user->profile()->create($profileData);
$this->createVacationLimitsFor($user); $this->createVacationLimitsFor($user);
return $user; return $user;

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Toby\Domain\Actions;
use Toby\Eloquent\Models\User;
class UpdateUserAction
{
public function execute(User $user, array $userData, array $profileData): User
{
$user->update($userData);
$user->profile->update($profileData);
return $user;
}
}

View File

@ -39,7 +39,7 @@ class VacationRequestCreatedNotification extends Notification
protected function buildMailMessage(string $url): MailMessage protected function buildMailMessage(string $url): MailMessage
{ {
$user = $this->vacationRequest->user->first_name; $user = $this->vacationRequest->user->profile->first_name;
$type = $this->vacationRequest->type->label(); $type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayString(); $from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString(); $to = $this->vacationRequest->to->toDisplayString();
@ -92,7 +92,7 @@ class VacationRequestCreatedNotification extends Notification
return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [ return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
"title" => $this->vacationRequest->name, "title" => $this->vacationRequest->name,
"appName" => $appName, "appName" => $appName,
"creator" => $this->vacationRequest->creator->fullName, "creator" => $this->vacationRequest->creator->profile->full_name,
]); ]);
} }
} }

View File

@ -42,14 +42,14 @@ class VacationRequestStatusChangedNotification extends Notification
protected function buildMailMessage(string $url): MailMessage protected function buildMailMessage(string $url): MailMessage
{ {
$user = $this->user->first_name; $user = $this->user->profile->first_name;
$title = $this->vacationRequest->name; $title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label(); $type = $this->vacationRequest->type->label();
$status = $this->vacationRequest->state->label(); $status = $this->vacationRequest->state->label();
$from = $this->vacationRequest->from->toDisplayString(); $from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString(); $to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count(); $days = $this->vacationRequest->vacations()->count();
$requester = $this->vacationRequest->user->fullName; $requester = $this->vacationRequest->user->profile->full_name;
return (new MailMessage()) return (new MailMessage())
->greeting(__("Hi :user!", [ ->greeting(__("Hi :user!", [
@ -59,7 +59,7 @@ class VacationRequestStatusChangedNotification extends Notification
"title" => $title, "title" => $title,
"status" => $status, "status" => $status,
])) ]))
->line(__("The vacation request :title for user :requester has been :status.", [ ->line(__("The vacation request :title from user :requester has been :status.", [
"title" => $title, "title" => $title,
"requester" => $requester, "requester" => $requester,
"status" => $status, "status" => $status,

View File

@ -43,7 +43,7 @@ class VacationRequestWaitsForApprovalNotification extends Notification
protected function buildMailMessage(string $url): MailMessage protected function buildMailMessage(string $url): MailMessage
{ {
$user = $this->user->first_name; $user = $this->user->profile->first_name;
$type = $this->vacationRequest->type->label(); $type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayString(); $from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString(); $to = $this->vacationRequest->to->toDisplayString();
@ -84,7 +84,7 @@ class VacationRequestWaitsForApprovalNotification extends Notification
protected function buildDescription(): string protected function buildDescription(): string
{ {
$title = $this->vacationRequest->name; $title = $this->vacationRequest->name;
$requester = $this->vacationRequest->user->fullName; $requester = $this->vacationRequest->user->profile->full_name;
if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) { if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) {
return __("The vacation request :title from user :requester is waiting for your technical approval.", [ return __("The vacation request :title from user :requester is waiting for your technical approval.", [

View File

@ -46,7 +46,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
public function title(): string public function title(): string
{ {
return $this->user->fullName; return $this->user->profile->full_name;
} }
public function headings(): array public function headings(): array

View File

@ -33,7 +33,8 @@ class YearPeriodRetriever
$selected = $this->selected(); $selected = $this->selected();
$current = $this->current(); $current = $this->current();
$years = YearPeriod::query()->whereIn("year", $this->offset($selected->year))->get(); $years = YearPeriod::all();
$navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod)); $navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod));
return [ return [
@ -43,11 +44,6 @@ class YearPeriodRetriever
]; ];
} }
protected function offset(int $year): array
{
return range($year - 2, $year + 2);
}
protected function toNavigation(YearPeriod $yearPeriod): array protected function toNavigation(YearPeriod $yearPeriod): array
{ {
return [ return [

View File

@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\ProfileFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Rackbeat\UIAvatars\HasAvatar;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Eloquent\Helpers\ColorGenerator;
/**
* @property string $first_name
* @property string $last_name
* @property string $position
* @property EmploymentForm $employment_form
* @property Carbon $employment_date
*/
class Profile extends Model
{
use HasFactory;
use HasAvatar;
protected $primaryKey = "user_id";
protected $guarded = [];
protected $casts = [
"employment_form" => EmploymentForm::class,
"employment_date" => "date",
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function getAvatar(): string
{
return $this->getAvatarGenerator()
->backgroundColor(ColorGenerator::generate($this->full_name))
->image();
}
public function getfullNameAttribute(): string
{
return "{$this->first_name} {$this->last_name}";
}
protected function getAvatarName(): string
{
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
}
protected static function newFactory(): ProfileFactory
{
return ProfileFactory::new();
}
}

View File

@ -8,27 +8,20 @@ use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Rackbeat\UIAvatars\HasAvatar;
use Toby\Domain\Enums\EmploymentForm; use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role; use Toby\Domain\Enums\Role;
use Toby\Eloquent\Helpers\ColorGenerator;
/** /**
* @property int $id * @property int $id
* @property string $first_name
* @property string $last_name
* @property string $email * @property string $email
* @property string $password * @property string $password
* @property string $avatar
* @property string $position
* @property Role $role * @property Role $role
* @property EmploymentForm $employment_form * @property Profile $profile
* @property Carbon $employment_date
* @property Collection $vacationLimits * @property Collection $vacationLimits
* @property Collection $vacationRequests * @property Collection $vacationRequests
* @property Collection $vacations * @property Collection $vacations
@ -38,12 +31,12 @@ class User extends Authenticatable
use HasFactory; use HasFactory;
use Notifiable; use Notifiable;
use SoftDeletes; use SoftDeletes;
use HasAvatar;
protected $guarded = []; protected $guarded = [];
protected $casts = [ protected $casts = [
"role" => Role::class, "role" => Role::class,
"last_active_at" => "datetime",
"employment_form" => EmploymentForm::class, "employment_form" => EmploymentForm::class,
"employment_date" => "date", "employment_date" => "date",
]; ];
@ -52,6 +45,15 @@ class User extends Authenticatable
"remember_token", "remember_token",
]; ];
protected $with = [
"profile",
];
public function profile(): HasOne
{
return $this->hasOne(Profile::class);
}
public function vacationLimits(): HasMany public function vacationLimits(): HasMany
{ {
return $this->hasMany(VacationLimit::class); return $this->hasMany(VacationLimit::class);
@ -72,18 +74,6 @@ class User extends Authenticatable
return $this->hasMany(Vacation::class); return $this->hasMany(Vacation::class);
} }
public function getAvatar(): string
{
return $this->getAvatarGenerator()
->backgroundColor(ColorGenerator::generate($this->fullName))
->image();
}
public function getFullNameAttribute(): string
{
return "{$this->first_name} {$this->last_name}";
}
public function hasRole(Role $role): bool public function hasRole(Role $role): bool
{ {
return $this->role === $role; return $this->role === $role;
@ -104,9 +94,20 @@ class User extends Authenticatable
} }
return $query return $query
->where("first_name", "ILIKE", "%{$text}%") ->where("email", "ILIKE", "%{$text}%")
->orWhere("last_name", "ILIKE", "%{$text}%") ->orWhereRelation(
->orWhere("email", "ILIKE", "%{$text}%"); "profile",
fn(Builder $query) => $query
->where("first_name", "ILIKE", "%{$text}%")
->orWhere("last_name", "ILIKE", "%{$text}%"),
);
}
public function scopeOrderByProfileField(Builder $query, string $field): Builder
{
$profileQuery = Profile::query()->select($field)->whereColumn("users.id", "profiles.user_id");
return $query->orderBy($profileQuery);
} }
public function scopeWithVacationLimitIn(Builder $query, YearPeriod $yearPeriod): Builder public function scopeWithVacationLimitIn(Builder $query, YearPeriod $yearPeriod): Builder
@ -119,11 +120,6 @@ class User extends Authenticatable
); );
} }
protected function getAvatarName(): string
{
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
}
protected static function newFactory(): UserFactory protected static function newFactory(): UserFactory
{ {
return UserFactory::new(); return UserFactory::new();

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Toby\Eloquent\Models; namespace Toby\Eloquent\Models;
use Database\Factories\VacationLimitFactory; use Database\Factories\VacationLimitFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -37,13 +36,6 @@ class VacationLimit extends Model
return $this->belongsTo(YearPeriod::class); return $this->belongsTo(YearPeriod::class);
} }
public function scopeOrderByUserField(Builder $query, string $field): Builder
{
$userQuery = User::query()->select($field)->whereColumn("vacation_limits.user_id", "users.id");
return $query->orderBy($userQuery);
}
protected static function newFactory(): VacationLimitFactory protected static function newFactory(): VacationLimitFactory
{ {
return VacationLimitFactory::new(); return VacationLimitFactory::new();

View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Console\Commands;
use Illuminate\Console\Command;
use Toby\Eloquent\Models\User;
class MoveUserDataToProfile extends Command
{
protected $signature = "toby:move-user-data-to-profile";
protected $description = "Move user data to their profiles";
public function handle(): void
{
$users = User::all();
foreach ($users as $user) {
$user->profile()->updateOrCreate(["user_id" => $user->id], [
"first_name" => $user->first_name,
"last_name" => $user->last_name,
"position" => $user->position,
"employment_form" => $user->employment_form,
"employment_date" => $user->employment_date,
]);
}
}
}

View File

@ -21,7 +21,7 @@ class GetAvailableVacationTypesController extends Controller
$user = User::query()->find($request->get("user")); $user = User::query()->find($request->get("user"));
$types = VacationType::all() $types = VacationType::all()
->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->employment_form)) ->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->profile->employment_form))
->map(fn(VacationType $type) => [ ->map(fn(VacationType $type) => [
"label" => $type->label(), "label" => $type->label(),
"value" => $type->value, "value" => $type->value,

View File

@ -9,21 +9,23 @@ use Illuminate\Support\Carbon;
use Inertia\Response; use Inertia\Response;
use Toby\Domain\UserVacationStatsRetriever; use Toby\Domain\UserVacationStatsRetriever;
use Toby\Domain\VacationRequestStatesRetriever; use Toby\Domain\VacationRequestStatesRetriever;
use Toby\Eloquent\Models\Holiday; use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\Vacation; use Toby\Eloquent\Models\Vacation;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
use Toby\Eloquent\Models\YearPeriod;
use Toby\Infrastructure\Http\Resources\AbsenceResource; use Toby\Infrastructure\Http\Resources\AbsenceResource;
use Toby\Infrastructure\Http\Resources\HolidayResource; use Toby\Infrastructure\Http\Resources\HolidayResource;
use Toby\Infrastructure\Http\Resources\VacationRequestResource; use Toby\Infrastructure\Http\Resources\VacationRequestResource;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function __invoke(Request $request, UserVacationStatsRetriever $vacationStatsRetriever): Response public function __invoke(
{ Request $request,
YearPeriodRetriever $yearPeriodRetriever,
UserVacationStatsRetriever $vacationStatsRetriever,
): Response {
$user = $request->user(); $user = $request->user();
$now = Carbon::now(); $now = Carbon::now();
$yearPeriod = YearPeriod::findByYear($now->year); $yearPeriod = $yearPeriodRetriever->selected();
$absences = Vacation::query() $absences = Vacation::query()
->with(["user", "vacationRequest"]) ->with(["user", "vacationRequest"])
@ -32,19 +34,21 @@ class DashboardController extends Controller
->get(); ->get();
if ($user->can("listAll", VacationRequest::class)) { if ($user->can("listAll", VacationRequest::class)) {
$vacationRequests = VacationRequest::query() $vacationRequests = $yearPeriod->vacationRequests()
->states(VacationRequestStatesRetriever::waitingForUserActionStates($user)) ->states(VacationRequestStatesRetriever::waitingForUserActionStates($user))
->latest("updated_at") ->latest("updated_at")
->limit(3) ->limit(3)
->get(); ->get();
} else { } else {
$vacationRequests = $user->vacationRequests() $vacationRequests = $user->vacationRequests()
->whereBelongsTo($yearPeriod)
->latest("updated_at") ->latest("updated_at")
->limit(3) ->limit(3)
->get(); ->get();
} }
$holidays = Holiday::query() $holidays = $yearPeriod
->holidays()
->whereDate("date", ">=", $now) ->whereDate("date", ">=", $now)
->orderBy("date") ->orderBy("date")
->limit(3) ->limit(3)

View File

@ -10,7 +10,7 @@ use Toby\Domain\Enums\Month;
use Toby\Domain\UserVacationStatsRetriever; use Toby\Domain\UserVacationStatsRetriever;
use Toby\Eloquent\Helpers\YearPeriodRetriever; use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Http\Resources\UserResource; use Toby\Infrastructure\Http\Resources\SimpleUserResource;
class MonthlyUsageController extends Controller class MonthlyUsageController extends Controller
{ {
@ -27,8 +27,8 @@ class MonthlyUsageController extends Controller
$users = User::query() $users = User::query()
->withVacationLimitIn($currentYearPeriod) ->withVacationLimitIn($currentYearPeriod)
->where("id", "!=", $currentUser->id) ->where("id", "!=", $currentUser->id)
->orderBy("last_name") ->orderByProfileField("last_name")
->orderBy("first_name") ->orderByProfileField("first_name")
->get(); ->get();
if ($currentUser->hasVacationLimit($currentYearPeriod)) { if ($currentUser->hasVacationLimit($currentYearPeriod)) {
@ -45,7 +45,7 @@ class MonthlyUsageController extends Controller
$remaining = $limit - $used - $pending; $remaining = $limit - $used - $pending;
$monthlyUsage[] = [ $monthlyUsage[] = [
"user" => new UserResource($user), "user" => new SimpleUserResource($user),
"months" => $vacationsByMonth, "months" => $vacationsByMonth,
"stats" => [ "stats" => [
"used" => $used, "used" => $used,

View File

@ -28,9 +28,9 @@ class TimesheetController extends Controller
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber()); $carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());
$users = User::query() $users = User::query()
->where("employment_form", EmploymentForm::EmploymentContract) ->whereRelation("profile", "employment_form", EmploymentForm::EmploymentContract)
->orderBy("last_name") ->orderByProfileField("last_name")
->orderBy("first_name") ->orderByProfileField("first_name")
->get(); ->get();
$types = VacationType::all() $types = VacationType::all()

View File

@ -9,6 +9,7 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Response; use Inertia\Response;
use Toby\Domain\Actions\CreateUserAction; use Toby\Domain\Actions\CreateUserAction;
use Toby\Domain\Actions\UpdateUserAction;
use Toby\Domain\Enums\EmploymentForm; use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role; use Toby\Domain\Enums\Role;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
@ -28,8 +29,8 @@ class UserController extends Controller
$users = User::query() $users = User::query()
->withTrashed() ->withTrashed()
->search($request->query("search")) ->search($request->query("search"))
->orderBy("last_name") ->orderByProfileField("last_name")
->orderBy("first_name") ->orderByProfileField("first_name")
->paginate() ->paginate()
->withQueryString(); ->withQueryString();
@ -59,7 +60,7 @@ class UserController extends Controller
{ {
$this->authorize("manageUsers"); $this->authorize("manageUsers");
$createUserAction->execute($request->data()); $createUserAction->execute($request->userData(), $request->profileData());
return redirect() return redirect()
->route("users.index") ->route("users.index")
@ -83,11 +84,11 @@ class UserController extends Controller
/** /**
* @throws AuthorizationException * @throws AuthorizationException
*/ */
public function update(UserRequest $request, User $user): RedirectResponse public function update(UserRequest $request, UpdateUserAction $updateUserAction, User $user): RedirectResponse
{ {
$this->authorize("manageUsers"); $this->authorize("manageUsers");
$user->update($request->data()); $updateUserAction->execute($user, $request->userData(), $request->profileData());
return redirect() return redirect()
->route("users.index") ->route("users.index")

View File

@ -11,7 +11,7 @@ use Toby\Domain\CalendarGenerator;
use Toby\Domain\Enums\Month; use Toby\Domain\Enums\Month;
use Toby\Eloquent\Helpers\YearPeriodRetriever; use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Http\Resources\UserResource; use Toby\Infrastructure\Http\Resources\SimpleUserResource;
class VacationCalendarController extends Controller class VacationCalendarController extends Controller
{ {
@ -29,8 +29,8 @@ class VacationCalendarController extends Controller
$users = User::query() $users = User::query()
->where("id", "!=", $currentUser->id) ->where("id", "!=", $currentUser->id)
->orderBy("last_name") ->orderByProfileField("last_name")
->orderBy("first_name") ->orderByProfileField("first_name")
->get(); ->get();
$users->prepend($currentUser); $users->prepend($currentUser);
@ -41,7 +41,7 @@ class VacationCalendarController extends Controller
"calendar" => $calendar, "calendar" => $calendar,
"current" => Month::current(), "current" => Month::current(),
"selected" => $month->value, "selected" => $month->value,
"users" => UserResource::collection($users), "users" => SimpleUserResource::collection($users),
"can" => [ "can" => [
"generateTimesheet" => $request->user()->can("generateTimesheet"), "generateTimesheet" => $request->user()->can("generateTimesheet"),
], ],

View File

@ -11,7 +11,7 @@ use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\VacationLimit; use Toby\Eloquent\Models\VacationLimit;
use Toby\Eloquent\Models\YearPeriod; use Toby\Eloquent\Models\YearPeriod;
use Toby\Infrastructure\Http\Requests\VacationLimitRequest; use Toby\Infrastructure\Http\Requests\VacationLimitRequest;
use Toby\Infrastructure\Http\Resources\UserResource; use Toby\Infrastructure\Http\Resources\SimpleUserResource;
class VacationLimitController extends Controller class VacationLimitController extends Controller
{ {
@ -24,15 +24,15 @@ class VacationLimitController extends Controller
$limits = $yearPeriod $limits = $yearPeriod
->vacationLimits() ->vacationLimits()
->with("user") ->with("user.profile")
->has("user") ->has("user")
->orderByUserField("last_name") ->get()
->orderByUserField("first_name") ->sortBy(fn(VacationLimit $limit): string => "{$limit->user->profile->last_name} {$limit->user->profile->first_name}")
->get(); ->values();
$limitsResource = $limits->map(fn(VacationLimit $limit) => [ $limitsResource = $limits->map(fn(VacationLimit $limit) => [
"id" => $limit->id, "id" => $limit->id,
"user" => new UserResource($limit->user), "user" => new SimpleUserResource($limit->user),
"hasVacation" => $limit->hasVacation(), "hasVacation" => $limit->hasVacation(),
"days" => $limit->days, "days" => $limit->days,
"remainingLastYear" => $previousYearPeriod "remainingLastYear" => $previousYearPeriod

View File

@ -27,14 +27,18 @@ use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
use Toby\Infrastructure\Http\Requests\VacationRequestRequest; use Toby\Infrastructure\Http\Requests\VacationRequestRequest;
use Toby\Infrastructure\Http\Resources\UserResource; use Toby\Infrastructure\Http\Resources\SimpleUserResource;
use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource; use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource;
use Toby\Infrastructure\Http\Resources\VacationRequestResource; use Toby\Infrastructure\Http\Resources\VacationRequestResource;
class VacationRequestController extends Controller class VacationRequestController extends Controller
{ {
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response|RedirectResponse
{ {
if ($request->user()->can("listAll", VacationRequest::class)) {
return redirect()->route("vacation.requests.indexForApprovers");
}
$status = $request->get("status", "all"); $status = $request->get("status", "all");
$vacationRequests = $request->user() $vacationRequests = $request->user()
@ -103,13 +107,13 @@ class VacationRequestController extends Controller
->paginate(); ->paginate();
$users = User::query() $users = User::query()
->orderBy("last_name") ->orderByProfileField("last_name")
->orderBy("first_name") ->orderByProfileField("first_name")
->get(); ->get();
return inertia("VacationRequest/IndexForApprovers", [ return inertia("VacationRequest/IndexForApprovers", [
"requests" => VacationRequestResource::collection($vacationRequests), "requests" => VacationRequestResource::collection($vacationRequests),
"users" => UserResource::collection($users), "users" => SimpleUserResource::collection($users),
"filters" => [ "filters" => [
"status" => $status, "status" => $status,
"user" => (int)$user, "user" => (int)$user,
@ -158,13 +162,13 @@ class VacationRequestController extends Controller
public function create(Request $request): Response public function create(Request $request): Response
{ {
$users = User::query() $users = User::query()
->orderBy("last_name") ->orderByProfileField("last_name")
->orderBy("first_name") ->orderByProfileField("first_name")
->get(); ->get();
return inertia("VacationRequest/Create", [ return inertia("VacationRequest/Create", [
"vacationTypes" => VacationType::casesToSelect(), "vacationTypes" => VacationType::casesToSelect(),
"users" => UserResource::collection($users), "users" => SimpleUserResource::collection($users),
"can" => [ "can" => [
"createOnBehalfOfEmployee" => $request->user()->can("createOnBehalfOfEmployee", VacationRequest::class), "createOnBehalfOfEmployee" => $request->user()->can("createOnBehalfOfEmployee", VacationRequest::class),
"skipFlow" => $request->user()->can("skipFlow", VacationRequest::class), "skipFlow" => $request->user()->can("skipFlow", VacationRequest::class),

View File

@ -4,8 +4,10 @@ declare(strict_types=1);
namespace Toby\Infrastructure\Http\Middleware; namespace Toby\Infrastructure\Http\Middleware;
use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Middleware; use Inertia\Middleware;
use Toby\Domain\VacationRequestStatesRetriever;
use Toby\Eloquent\Helpers\YearPeriodRetriever; use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
use Toby\Infrastructure\Http\Resources\UserResource; use Toby\Infrastructure\Http\Resources\UserResource;
@ -18,24 +20,54 @@ class HandleInertiaRequests extends Middleware
public function share(Request $request): array public function share(Request $request): array
{ {
$user = $request->user();
return array_merge(parent::share($request), [ return array_merge(parent::share($request), [
"auth" => fn() => [ "auth" => $this->getAuthData($request),
"user" => $user ? new UserResource($user) : null, "flash" => $this->getFlashData($request),
"can" => [ "years" => $this->getYearsData($request),
"manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false, "vacationRequestsCount" => $this->getVacationRequestsCount($request),
"manageUsers" => $user ? $user->can("manageUsers") : false,
"listAllVacationRequests" => $user ? $user->can("listAll", VacationRequest::class) : false,
"listMonthlyUsage" => $user ? $user->can("listMonthlyUsage") : false,
],
],
"flash" => fn() => [
"success" => $request->session()->get("success"),
"error" => $request->session()->get("error"),
"info" => $request->session()->get("info"),
],
"years" => fn() => $user ? $this->yearPeriodRetriever->links() : [],
]); ]);
} }
protected function getAuthData(Request $request): Closure
{
$user = $request->user();
return fn() => [
"user" => $user ? new UserResource($user) : null,
"can" => [
"manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false,
"manageUsers" => $user ? $user->can("manageUsers") : false,
"listAllVacationRequests" => $user ? $user->can("listAll", VacationRequest::class) : false,
"listMonthlyUsage" => $user ? $user->can("listMonthlyUsage") : false,
],
];
}
protected function getFlashData(Request $request): Closure
{
return fn() => [
"success" => $request->session()->get("success"),
"error" => $request->session()->get("error"),
"info" => $request->session()->get("info"),
];
}
protected function getYearsData(Request $request): Closure
{
return fn(): array => $request->user() ? $this->yearPeriodRetriever->links() : [];
}
protected function getVacationRequestsCount(Request $request): Closure
{
$user = $request->user();
return fn(): ?int => $user && $user->can("listAll", VacationRequest::class)
? VacationRequest::query()
->whereBelongsTo($this->yearPeriodRetriever->selected())
->states(
VacationRequestStatesRetriever::waitingForUserActionStates($user),
)
->count()
: null;
}
} }

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
class TrackUserLastActivity
{
public function handle(Request $request, Closure $next)
{
$request->user()?->update([
"last_active_at" => Carbon::now(),
]);
return $next($request);
}
}

View File

@ -25,14 +25,20 @@ class UserRequest extends FormRequest
]; ];
} }
public function data(): array public function userData(): array
{
return [
"email" => $this->get("email"),
"role" => $this->get("role"),
];
}
public function profileData(): array
{ {
return [ return [
"first_name" => $this->get("firstName"), "first_name" => $this->get("firstName"),
"last_name" => $this->get("lastName"), "last_name" => $this->get("lastName"),
"email" => $this->get("email"),
"position" => $this->get("position"), "position" => $this->get("position"),
"role" => $this->get("role"),
"employment_form" => $this->get("employmentForm"), "employment_form" => $this->get("employmentForm"),
"employment_date" => $this->get("employmentDate"), "employment_date" => $this->get("employmentDate"),
]; ];

View File

@ -14,7 +14,7 @@ class AbsenceResource extends JsonResource
{ {
return [ return [
"id" => $this->id, "id" => $this->id,
"user" => new UserResource($this->user), "user" => new SimpleUserResource($this->user),
"date" => $this->date->toDisplayString(), "date" => $this->date->toDisplayString(),
]; ];
} }

View File

@ -16,6 +16,7 @@ class HolidayResource extends JsonResource
"id" => $this->id, "id" => $this->id,
"name" => $this->name, "name" => $this->name,
"date" => $this->date->toDateString(), "date" => $this->date->toDateString(),
"isPast" => $this->date->isPast(),
"displayDate" => $this->date->toDisplayString(), "displayDate" => $this->date->toDisplayString(),
"dayOfWeek" => $this->date->dayName, "dayOfWeek" => $this->date->dayName,
]; ];

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class SimpleUserResource extends JsonResource
{
public static $wrap = null;
public function toArray($request): array
{
return [
"id" => $this->id,
"name" => $this->profile->full_name,
"email" => $this->email,
"avatar" => $this->profile->getAvatar(),
];
}
}

View File

@ -14,13 +14,13 @@ class UserFormDataResource extends JsonResource
{ {
return [ return [
"id" => $this->id, "id" => $this->id,
"firstName" => $this->first_name, "firstName" => $this->profile->first_name,
"lastName" => $this->last_name, "lastName" => $this->profile->last_name,
"email" => $this->email, "email" => $this->email,
"role" => $this->role, "role" => $this->role,
"position" => $this->position, "position" => $this->profile->position,
"employmentForm" => $this->employment_form, "employmentForm" => $this->profile->employment_form,
"employmentDate" => $this->employment_date->toDateString(), "employmentDate" => $this->profile->employment_date->toDateString(),
]; ];
} }
} }

View File

@ -14,14 +14,15 @@ class UserResource extends JsonResource
{ {
return [ return [
"id" => $this->id, "id" => $this->id,
"name" => $this->fullName, "name" => $this->profile->full_name,
"email" => $this->email, "email" => $this->email,
"role" => $this->role->label(), "role" => $this->role->label(),
"position" => $this->position, "position" => $this->profile->position,
"avatar" => $this->getAvatar(), "avatar" => $this->profile->getAvatar(),
"deleted" => $this->trashed(), "deleted" => $this->trashed(),
"employmentForm" => $this->employment_form->label(), "lastActiveAt" => $this->last_active_at?->toDateTimeString(),
"employmentDate" => $this->employment_date->toDisplayString(), "employmentForm" => $this->profile->employment_form->label(),
"employmentDate" => $this->profile->employment_date->toDisplayString(),
]; ];
} }
} }

View File

@ -15,7 +15,7 @@ class VacationRequestActivityResource extends JsonResource
return [ return [
"date" => $this->created_at->toDisplayString(), "date" => $this->created_at->toDisplayString(),
"time" => $this->created_at->format("H:i"), "time" => $this->created_at->format("H:i"),
"user" => $this->user ? $this->user->fullName : __("System"), "user" => $this->user ? $this->user->profile->full_name : __("System"),
"state" => $this->to, "state" => $this->to,
]; ];
} }

View File

@ -15,7 +15,7 @@ class VacationRequestResource extends JsonResource
return [ return [
"id" => $this->id, "id" => $this->id,
"name" => $this->name, "name" => $this->name,
"user" => new UserResource($this->user), "user" => new SimpleUserResource($this->user),
"type" => $this->type, "type" => $this->type,
"state" => $this->state, "state" => $this->state,
"from" => $this->from->toDisplayString(), "from" => $this->from->toDisplayString(),

View File

@ -21,7 +21,7 @@ class ClearVacationRequestDaysInGoogleCalendar implements ShouldQueue
public function handle(): void public function handle(): void
{ {
foreach ($this->vacationRequest->event_ids as $eventId) { foreach ($this->vacationRequest->event_ids ?? [] as $eventId) {
$calendarEvent = Event::find($eventId); $calendarEvent = Event::find($eventId);
if ($calendarEvent->googleEvent->getStatus() !== "cancelled") { if ($calendarEvent->googleEvent->getStatus() !== "cancelled") {

View File

@ -32,7 +32,7 @@ class SendVacationRequestDaysToGoogleCalendar implements ShouldQueue
$ranges = $this->prepareRanges($days); $ranges = $this->prepareRanges($days);
foreach ($ranges as $range) { foreach ($ranges as $range) {
$text = "{$this->vacationRequest->type->label()} - {$this->vacationRequest->user->fullName} [{$this->vacationRequest->name}]"; $text = "{$this->vacationRequest->type->label()} - {$this->vacationRequest->user->profile->full_name} [{$this->vacationRequest->name}]";
$event = Event::create([ $event = Event::create([
"name" => $text, "name" => $text,

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Eloquent\Models\Profile;
use Toby\Eloquent\Models\User;
class ProfileFactory extends Factory
{
protected $model = Profile::class;
public function definition(): array
{
return [
"user_id" => User::factory(),
"first_name" => $this->faker->firstName(),
"last_name" => $this->faker->lastName(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"position" => $this->faker->jobTitle(),
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
];
}
}

View File

@ -5,10 +5,9 @@ declare(strict_types=1);
namespace Database\Factories; namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role; use Toby\Domain\Enums\Role;
use Toby\Eloquent\Models\Profile;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
class UserFactory extends Factory class UserFactory extends Factory
@ -18,17 +17,21 @@ class UserFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
"first_name" => $this->faker->firstName(),
"last_name" => $this->faker->lastName(),
"email" => $this->faker->unique()->safeEmail(), "email" => $this->faker->unique()->safeEmail(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"position" => $this->faker->jobTitle(),
"role" => Role::Employee, "role" => Role::Employee,
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]; ];
} }
public function configure(): self
{
return $this->afterCreating(function (User $user): void {
if (!$user->profile()->exists()) {
Profile::factory()->for($user)->create();
}
});
}
public function admin(): static public function admin(): static
{ {
return $this->state([ return $this->state([

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Toby\Eloquent\Models\User;
return new class() extends Migration {
public function up(): void
{
Schema::create("profiles", function (Blueprint $table): void {
$table->foreignIdFor(User::class)->primary();
$table->string("first_name")->nullable();
$table->string("last_name")->nullable();
$table->string("position")->nullable();
$table->string("employment_form")->nullable();
$table->date("employment_date")->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists("profiles");
}
};

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
public function up(): void
{
Artisan::call("toby:move-user-data-to-profile");
Schema::table("users", function (Blueprint $table): void {
$table->dropColumn("first_name");
$table->dropColumn("last_name");
$table->dropColumn("position");
$table->dropColumn("employment_form");
$table->dropColumn("employment_date");
});
}
public function down(): void
{
Schema::table("users", function (Blueprint $table): void {
$table->string("first_name")->nullable();
$table->string("last_name")->nullable();
$table->string("position")->nullable();
$table->string("employment_form")->nullable();
$table->date("employment_date")->nullable();
});
}
};

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
public function up(): void
{
Schema::table("users", function (Blueprint $table): void {
$table->timestamp("last_active_at")->nullable();
});
}
public function down(): void
{
Schema::table("users", function (Blueprint $table): void {
$table->dropColumn("last_active_at");
});
}
};

View File

@ -30,75 +30,87 @@ class DemoSeeder extends Seeder
public function run(): void public function run(): void
{ {
$user = User::factory([ $user = User::factory([
"first_name" => "Jan",
"last_name" => "Kowalski",
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"), "email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
"employment_form" => EmploymentForm::EmploymentContract,
"position" => "programista",
"role" => Role::Administrator, "role" => Role::Administrator,
"employment_date" => Carbon::createFromDate(2021, 12, 31),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]) ])
->hasProfile([
"first_name" => "Jan",
"last_name" => "Kowalski",
"employment_form" => EmploymentForm::EmploymentContract,
"position" => "programista",
"employment_date" => Carbon::createFromDate(2021, 12, 31),
])
->create(); ->create();
User::factory([ User::factory([
"first_name" => "Anna",
"last_name" => "Nowak",
"email" => "anna.nowak@example.com", "email" => "anna.nowak@example.com",
"employment_form" => EmploymentForm::CommissionContract,
"position" => "tester",
"role" => Role::Employee, "role" => Role::Employee,
"employment_date" => Carbon::createFromDate(2021, 5, 10),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]) ])
->hasProfile([
"first_name" => "Anna",
"last_name" => "Nowak",
"employment_form" => EmploymentForm::CommissionContract,
"position" => "tester",
"employment_date" => Carbon::createFromDate(2021, 5, 10),
])
->create(); ->create();
User::factory([ User::factory([
"first_name" => "Tola",
"last_name" => "Sawicka",
"email" => "tola.sawicka@example.com", "email" => "tola.sawicka@example.com",
"employment_form" => EmploymentForm::B2bContract,
"position" => "programista",
"role" => Role::Employee, "role" => Role::Employee,
"employment_date" => Carbon::createFromDate(2021, 1, 4),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]) ])
->hasProfile([
"first_name" => "Tola",
"last_name" => "Sawicka",
"employment_form" => EmploymentForm::B2bContract,
"position" => "programista",
"employment_date" => Carbon::createFromDate(2021, 1, 4),
])
->create(); ->create();
$technicalApprover = User::factory([ $technicalApprover = User::factory([
"first_name" => "Maciej",
"last_name" => "Ziółkowski",
"email" => "maciej.ziolkowski@example.com", "email" => "maciej.ziolkowski@example.com",
"employment_form" => EmploymentForm::BoardMemberContract,
"position" => "programista",
"role" => Role::TechnicalApprover, "role" => Role::TechnicalApprover,
"employment_date" => Carbon::createFromDate(2021, 1, 4),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]) ])
->hasProfile([
"first_name" => "Maciej",
"last_name" => "Ziółkowski",
"employment_form" => EmploymentForm::BoardMemberContract,
"position" => "programista",
"employment_date" => Carbon::createFromDate(2021, 1, 4),
])
->create(); ->create();
$administrativeApprover = User::factory([ $administrativeApprover = User::factory([
"first_name" => "Katarzyna",
"last_name" => "Zając",
"email" => "katarzyna.zajac@example.com", "email" => "katarzyna.zajac@example.com",
"employment_form" => EmploymentForm::EmploymentContract,
"position" => "dyrektor",
"role" => Role::AdministrativeApprover, "role" => Role::AdministrativeApprover,
"employment_date" => Carbon::createFromDate(2021, 1, 4),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]) ])
->hasProfile([
"first_name" => "Katarzyna",
"last_name" => "Zając",
"employment_form" => EmploymentForm::EmploymentContract,
"position" => "dyrektor",
"employment_date" => Carbon::createFromDate(2021, 1, 4),
])
->create(); ->create();
User::factory([ User::factory([
"first_name" => "Miłosz",
"last_name" => "Borowski",
"email" => "milosz.borowski@example.com", "email" => "milosz.borowski@example.com",
"employment_form" => EmploymentForm::EmploymentContract,
"position" => "administrator",
"role" => Role::Administrator, "role" => Role::Administrator,
"employment_date" => Carbon::createFromDate(2021, 1, 4),
"remember_token" => Str::random(10), "remember_token" => Str::random(10),
]) ])
->hasProfile([
"first_name" => "Miłosz",
"last_name" => "Borowski",
"employment_form" => EmploymentForm::EmploymentContract,
"position" => "administrator",
"employment_date" => Carbon::createFromDate(2021, 1, 4),
])
->create(); ->create();
$users = User::all(); $users = User::all();
@ -118,7 +130,7 @@ class DemoSeeder extends Seeder
->afterCreating(function (YearPeriod $yearPeriod) use ($users): void { ->afterCreating(function (YearPeriod $yearPeriod) use ($users): void {
foreach ($users as $user) { foreach ($users as $user) {
VacationLimit::factory([ VacationLimit::factory([
"days" => $user->employment_form === EmploymentForm::EmploymentContract ? 26 : null, "days" => $user->profile->employment_form === EmploymentForm::EmploymentContract ? 26 : null,
]) ])
->for($yearPeriod) ->for($yearPeriod)
->for($user) ->for($user)

View File

@ -14,8 +14,8 @@ const types = [
text: 'Urlop wypoczynkowy', text: 'Urlop wypoczynkowy',
value: 'vacation', value: 'vacation',
icon: WhiteBalanceSunnyIcon, icon: WhiteBalanceSunnyIcon,
color: 'text-amber-300', color: 'text-yellow-500',
border: 'border-amber-300', border: 'border-yellow-500',
}, },
{ {
text: 'Urlop na żądanie', text: 'Urlop na żądanie',

View File

@ -39,7 +39,7 @@
offset-distance="0" offset-distance="0"
> >
<div :class="[day.isPendingVacation && 'mx-0.5']"> <div :class="[day.isPendingVacation && 'mx-0.5']">
<button :class="[day.isPendingVacation && `border-dashed`, `${getVacationBorder(day)} isolate bg-white w-full hover:bg-blumilk-25 border-b-4 py-1.5 font-medium`]"> <button :class="[day.isPendingVacation && `border-dashed`, `${getVacationBorder(day)} isolate bg-white w-full hover:bg-blumilk-25 border-b-4 py-1.5 font-medium focus:outline-blumilk-500`]">
<time <time
:datetime="day.date.toISODate()" :datetime="day.date.toISODate()"
:class="[ day.isToday && 'bg-blumilk-500 font-semibold text-white rounded-full', 'mx-auto flex h-7 w-7 p-4 items-center justify-center']" :class="[ day.isToday && 'bg-blumilk-500 font-semibold text-white rounded-full', 'mx-auto flex h-7 w-7 p-4 items-center justify-center']"
@ -58,7 +58,7 @@
hover hover
offset-distance="0" offset-distance="0"
> >
<button class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent"> <button class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent focus:outline-blumilk-500">
<time <time
:datetime="day.date.toISODate()" :datetime="day.date.toISODate()"
:class="[ day.isToday && 'bg-blumilk-500 font-semibold text-white rounded-full', 'text-red-700 font-bold mx-auto flex h-7 w-7 p-4 items-center justify-center']" :class="[ day.isToday && 'bg-blumilk-500 font-semibold text-white rounded-full', 'text-red-700 font-bold mx-auto flex h-7 w-7 p-4 items-center justify-center']"
@ -74,7 +74,7 @@
</Popper> </Popper>
<button <button
v-else v-else
class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent" class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent focus:outline-blumilk-500"
> >
<time <time
:datetime="day.date.toISODate()" :datetime="day.date.toISODate()"

View File

@ -11,20 +11,21 @@
v-if="previousMonth" v-if="previousMonth"
as="button" as="button"
:href="`/vacation/calendar/${previousMonth.value}`" :href="`/vacation/calendar/${previousMonth.value}`"
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50" class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 focus:outline-blumilk-500 md:px-2 md:w-9 md:hover:bg-gray-50"
> >
<ChevronLeftIcon class="w-5 h-5" /> <ChevronLeftIcon class="w-5 h-5" />
</InertiaLink> </InertiaLink>
<span <span
v-else v-else
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50" class="flex justify-center items-center p-2 text-gray-400 bg-gray-100 rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9"
> >
<ChevronLeftIcon class="w-5 h-5" /> <ChevronLeftIcon class="w-5 h-5" />
</span> </span>
<InertiaLink <InertiaLink
v-if="years.current.year === years.selected.year"
as="button" as="button"
:href="`/vacation/calendar/${currentMonth.value}`" :href="`/vacation/calendar/${currentMonth.value}`"
class="hidden focus:relative items-center p-2 text-sm font-medium text-gray-700 hover:text-gray-900 bg-white hover:bg-gray-50 border-y border-gray-300 md:flex" class="hidden focus:relative items-center p-2 text-sm font-medium text-gray-700 hover:text-gray-900 bg-white hover:bg-gray-50 border-y border-gray-300 focus:outline-blumilk-500 md:flex"
> >
Dzisiaj Dzisiaj
</InertiaLink> </InertiaLink>
@ -32,13 +33,13 @@
v-if="nextMonth" v-if="nextMonth"
as="button" as="button"
:href="`/vacation/calendar/${nextMonth.value}`" :href="`/vacation/calendar/${nextMonth.value}`"
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50" class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 focus:outline-blumilk-500 md:px-2 md:w-9 md:hover:bg-gray-50"
> >
<ChevronRightIcon class="w-5 h-5" /> <ChevronRightIcon class="w-5 h-5" />
</InertiaLink> </InertiaLink>
<span <span
v-else v-else
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50" class="flex justify-center items-center p-2 text-gray-400 bg-gray-100 rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9"
> >
<ChevronRightIcon class="w-5 h-5" /> <ChevronRightIcon class="w-5 h-5" />
</span> </span>

View File

@ -14,8 +14,14 @@
v-else v-else
:requests="vacationRequests.data" :requests="vacationRequests.data"
/> />
<AbsenceList :absences="absences.data" /> <AbsenceList
<UpcomingHolidays :holidays="holidays.data" /> v-if="years.current.year === years.selected.year"
:absences="absences.data"
/>
<UpcomingHolidays
v-if="years.current.year === years.selected.year"
:holidays="holidays.data"
/>
</div> </div>
</div> </div>
</template> </template>
@ -35,5 +41,6 @@ defineProps({
holidays: Object, holidays: Object,
can: Object, can: Object,
stats: Object, stats: Object,
years: Object,
}) })
</script> </script>

View File

@ -49,9 +49,9 @@
<tr <tr
v-for="holiday in holidays.data" v-for="holiday in holidays.data"
:key="holiday.id" :key="holiday.id"
class="hover:bg-blumilk-25" :class="[holiday.isPast ? 'bg-gray-100' : 'hover:bg-blumilk-25']"
> >
<td class="p-4 text-sm font-semibold text-gray-500 capitalize whitespace-nowrap"> <td class="p-4 text-sm font-semibold text-gray-700 capitalize whitespace-nowrap">
{{ holiday.name }} {{ holiday.name }}
</td> </td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">

View File

@ -112,7 +112,7 @@
</ListboxLabel> </ListboxLabel>
<div class="relative mt-1 sm:col-span-2 sm:mt-0"> <div class="relative mt-1 sm:col-span-2 sm:mt-0">
<ListboxButton <ListboxButton
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm" class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.role, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.role }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.role, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.role }"
> >
<span class="block truncate">{{ form.role.label }}</span> <span class="block truncate">{{ form.role.label }}</span>
@ -166,7 +166,7 @@
</ListboxLabel> </ListboxLabel>
<div class="relative mt-1 sm:col-span-2 sm:mt-0"> <div class="relative mt-1 sm:col-span-2 sm:mt-0">
<ListboxButton <ListboxButton
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm" class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
> >
<span class="block truncate">{{ form.employmentForm.label }}</span> <span class="block truncate">{{ form.employmentForm.label }}</span>

View File

@ -112,7 +112,7 @@
</ListboxLabel> </ListboxLabel>
<div class="relative mt-1 sm:col-span-2 sm:mt-0"> <div class="relative mt-1 sm:col-span-2 sm:mt-0">
<ListboxButton <ListboxButton
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm" class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
> >
<span class="block truncate">{{ form.role.label }}</span> <span class="block truncate">{{ form.role.label }}</span>
@ -170,7 +170,7 @@
</ListboxLabel> </ListboxLabel>
<div class="relative mt-1 sm:col-span-2 sm:mt-0"> <div class="relative mt-1 sm:col-span-2 sm:mt-0">
<ListboxButton <ListboxButton
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm" class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }" :class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
> >
<span class="block truncate">{{ form.employmentForm.label }}</span> <span class="block truncate">{{ form.employmentForm.label }}</span>

View File

@ -46,6 +46,12 @@
> >
Rola Rola
</th> </th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Ostatnia aktywność
</th>
<th <th
scope="col" scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap" class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
@ -97,6 +103,9 @@
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ user.role }} {{ user.role }}
</td> </td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ user.lastActiveAt ? DateTime.fromSQL(user.lastActiveAt).toRelative() : '-' }}
</td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ user.position }} {{ user.position }}
</td> </td>
@ -150,7 +159,7 @@
:href="`/users/${user.id}`" :href="`/users/${user.id}`"
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']" :class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']"
> >
<TrashIcon class="mr-2 w-5 h-5 text-red-500" /> Usuń <BanIcon class="mr-2 w-5 h-5 text-red-500" /> Zablokuj
</InertiaLink> </InertiaLink>
</MenuItem> </MenuItem>
</div> </div>
@ -201,8 +210,9 @@ import { ref, watch } from 'vue'
import { Inertia } from '@inertiajs/inertia' import { Inertia } from '@inertiajs/inertia'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import { SearchIcon } from '@heroicons/vue/outline' import { SearchIcon } from '@heroicons/vue/outline'
import { DotsVerticalIcon, PencilIcon, TrashIcon, RefreshIcon } from '@heroicons/vue/solid' import { DotsVerticalIcon, PencilIcon, BanIcon, RefreshIcon } from '@heroicons/vue/solid'
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue' import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
import { DateTime } from 'luxon'
import Pagination from '@/Shared/Pagination' import Pagination from '@/Shared/Pagination'
const props = defineProps({ const props = defineProps({

View File

@ -63,7 +63,7 @@
leave-to-class="opacity-0" leave-to-class="opacity-0"
> >
<ListboxOptions <ListboxOptions
class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 focus:ring-blumilk-500 ring-opacity-5 shadow-lg sm:text-sm" class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg sm:text-sm"
> >
<ListboxOption <ListboxOption
v-for="user in users.data" v-for="user in users.data"
@ -156,7 +156,7 @@
leave-from-class="opacity-100" leave-from-class="opacity-100"
leave-to-class="opacity-0" leave-to-class="opacity-0"
> >
<ListboxOptions class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 focus:ring-blumilk-500 ring-opacity-5 shadow-lg sm:text-sm"> <ListboxOptions class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg sm:text-sm">
<ListboxOption <ListboxOption
v-for="vacationType in vacationTypes" v-for="vacationType in vacationTypes"
:key="vacationType.value" :key="vacationType.value"

View File

@ -19,7 +19,7 @@
<button <button
v-for="(status, index) in statuses" v-for="(status, index) in statuses"
:key="index" :key="index"
:class="[status.value === filters.status ? 'text-blumilk-600 font-semibold' : 'hover:bg-blumilk-25 text-gray-700 focus:z-10', 'group relative min-w-0 flex-1 overflow-hidden bg-white py-4 px-4 text-sm font-medium text-center']" :class="[status.value === filters.status ? 'text-blumilk-600 font-semibold' : 'hover:bg-blumilk-25 text-gray-700 focus:z-10', 'group relative min-w-0 flex-1 overflow-hidden focus:outline-blumilk-500 bg-white py-4 px-4 text-sm font-medium text-center']"
@click="form.status = status" @click="form.status = status"
> >
<span>{{ status.name }}</span> <span>{{ status.name }}</span>
@ -140,7 +140,7 @@
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">
<InertiaLink <InertiaLink
:href="`/vacation/requests/${request.id}`" :href="`/vacation/requests/${request.id}`"
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline" class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline focus:outline-blumilk-500"
> >
{{ request.name }} {{ request.name }}
</InertiaLink> </InertiaLink>
@ -163,13 +163,13 @@
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">
<InertiaLink <InertiaLink
:href="`/vacation/requests/${request.id}`" :href="`/vacation/requests/${request.id}`"
class="flex justify-around" class="flex justify-around focus:outline-blumilk-500"
> >
<ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" /> <ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" />
</InertiaLink> </InertiaLink>
<InertiaLink <InertiaLink
:href="`/vacation/requests/${request.id}`" :href="`/vacation/requests/${request.id}`"
class="absolute inset-0" class="absolute inset-0 focus:outline-blumilk-500"
/> />
</td> </td>
</tr> </tr>

View File

@ -219,7 +219,7 @@
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">
<InertiaLink <InertiaLink
:href="`/vacation/requests/${request.id}`" :href="`/vacation/requests/${request.id}`"
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline" class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline focus:outline-blumilk-500"
> >
{{ request.name }} {{ request.name }}
</InertiaLink> </InertiaLink>
@ -257,13 +257,13 @@
<td class="p-4 text-sm text-gray-500 whitespace-nowrap"> <td class="p-4 text-sm text-gray-500 whitespace-nowrap">
<InertiaLink <InertiaLink
:href="`/vacation/requests/${request.id}`" :href="`/vacation/requests/${request.id}`"
class="flex justify-around" class="flex justify-around focus:outline-blumilk-500"
> >
<ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" /> <ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" />
</InertiaLink> </InertiaLink>
<InertiaLink <InertiaLink
:href="`/vacation/requests/${request.id}`" :href="`/vacation/requests/${request.id}`"
class="absolute inset-0" class="absolute inset-0 focus:outline-blumilk-500"
/> />
</td> </td>
</tr> </tr>

View File

@ -0,0 +1,65 @@
import { h, ref } from 'vue'
import { Inertia, mergeDataIntoQueryString, shouldIntercept } from '@inertiajs/inertia'
export default {
name: 'InertiaLink',
props: {
as: {
type: String,
default: 'a',
},
data: {
type: Object,
default: () => ({}),
},
href: {
type: String,
},
method: {
type: String,
default: 'get',
},
replace: {
type: Boolean,
default: false,
},
preserveScroll: {
type: Boolean,
default: false,
},
preserveState: {
type: Boolean,
default: null,
},
},
setup(props, { slots, attrs }) {
const processing = ref(false)
return props => {
const as = props.as.toLowerCase()
const method = props.method.toLowerCase()
const [href, data] = mergeDataIntoQueryString(method, props.href || '', props.data, 'brackets')
return h(props.as, {
...attrs,
...as === 'a' ? { href } : {},
onClick: (event) => {
if (shouldIntercept(event)) {
event.preventDefault()
Inertia.visit(href, {
data: data,
method: method,
replace: props.replace,
preserveScroll: props.preserveScroll,
preserveState: props.preserveState ?? (method !== 'get'),
onBefore: () => !processing.value,
onStart: () => processing.value = true,
onFinish: () => processing.value = false,
})
}
},
}, slots)
}
},
}

View File

@ -3,6 +3,7 @@
<MainMenu <MainMenu
:auth="auth" :auth="auth"
:years="years" :years="years"
:vacation-requests-count="vacationRequestsCount"
/> />
<main class="flex flex-col flex-1 py-8 lg:ml-64"> <main class="flex flex-col flex-1 py-8 lg:ml-64">
<div class="lg:px-4"> <div class="lg:px-4">
@ -21,6 +22,7 @@ const props = defineProps({
flash: Object, flash: Object,
auth: Object, auth: Object,
years: Object, years: Object,
vacationRequestsCount: Number,
}) })
const toast = useToast() const toast = useToast()

View File

@ -71,12 +71,12 @@
</InertiaLink> </InertiaLink>
</div> </div>
<div class="pt-3 mt-3"> <div class="pt-3 mt-3">
<div class="px-2 space-y-1"> <div class="py-1 px-2 space-y-1">
<InertiaLink <InertiaLink
v-for="item in navigation" v-for="item in navigation"
:key="item.name" :key="item.name"
:href="item.href" :href="item.href"
:class="[$page.component === item.component ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-base font-medium rounded-md']" :class="[$page.component.startsWith(item.section) ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-base font-medium rounded-md']"
@click="sidebarOpen = false;" @click="sidebarOpen = false;"
> >
<component <component
@ -84,6 +84,12 @@
class="shrink-0 mr-4 w-6 h-6 text-blumilk-200" class="shrink-0 mr-4 w-6 h-6 text-blumilk-200"
/> />
{{ item.name }} {{ item.name }}
<span
v-if="item.badge"
class="py-0.5 px-2.5 ml-3 text-xs font-semibold text-gray-600 bg-gray-100 rounded-full 2xl:inline-block"
>
{{ item.badge }}
</span>
</InertiaLink> </InertiaLink>
</div> </div>
</div> </div>
@ -107,7 +113,7 @@
<nav class="flex overflow-y-auto flex-col flex-1 px-2 mt-5 divide-y divide-blumilk-800"> <nav class="flex overflow-y-auto flex-col flex-1 px-2 mt-5 divide-y divide-blumilk-800">
<InertiaLink <InertiaLink
href="/" href="/"
:class="[$page.component === 'Dashboard' ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']" :class="[$page.component === 'Dashboard' ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 mt-1 text-sm leading-6 font-medium rounded-md']"
> >
<HomeIcon class="shrink-0 mr-4 w-6 h-6 text-blumilk-200" /> <HomeIcon class="shrink-0 mr-4 w-6 h-6 text-blumilk-200" />
Strona główna Strona główna
@ -117,13 +123,19 @@
v-for="item in navigation" v-for="item in navigation"
:key="item.name" :key="item.name"
:href="item.href" :href="item.href"
:class="[$page.component === item.component ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']" :class="[$page.component.startsWith(item.section) ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']"
> >
<component <component
:is="item.icon" :is="item.icon"
class="shrink-0 mr-4 w-6 h-6 text-blumilk-200" class="shrink-0 mr-4 w-6 h-6 text-blumilk-200"
/> />
{{ item.name }} {{ item.name }}
<span
v-if="item.badge"
class="py-0.5 px-2.5 ml-3 text-xs font-semibold text-gray-600 bg-gray-100 rounded-full 2xl:inline-block"
>
{{ item.badge }}
</span>
</InertiaLink> </InertiaLink>
</div> </div>
</nav> </nav>
@ -152,7 +164,7 @@
</div> </div>
<div> <div>
<MenuButton <MenuButton
class="inline-flex justify-center py-2 px-4 w-full text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm" class="inline-flex justify-center py-2 px-4 w-full text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blumilk-500 shadow-sm"
> >
{{ years.selected.year }} {{ years.selected.year }}
<ChevronDownIcon class="-mr-1 ml-2 w-5 h-5" /> <ChevronDownIcon class="-mr-1 ml-2 w-5 h-5" />
@ -288,6 +300,7 @@ import { CheckIcon, ChevronDownIcon } from '@heroicons/vue/solid'
const props = defineProps({ const props = defineProps({
auth: Object, auth: Object,
years: Object, years: Object,
vacationRequestsCount: Number,
}) })
const sidebarOpen = ref(false) const sidebarOpen = ref(false)
@ -297,42 +310,43 @@ const navigation = computed(() =>
{ {
name: 'Moje wnioski', name: 'Moje wnioski',
href: '/vacation/requests/me', href: '/vacation/requests/me',
component: 'VacationRequest/Index', section: 'VacationRequest',
icon: DocumentTextIcon, icon: DocumentTextIcon,
can: true, can: !props.auth.can.listAllVacationRequests,
}, },
{ {
name: 'Lista wniosków', name: 'Lista wniosków',
href: '/vacation/requests', href: '/vacation/requests',
component: 'VacationRequest/IndexForApprovers', section: 'VacationRequest',
icon: CollectionIcon, icon: CollectionIcon,
can: props.auth.can.listAllVacationRequests, can: props.auth.can.listAllVacationRequests,
badge: props.vacationRequestsCount,
}, },
{ {
name: 'Kalendarz urlopów', name: 'Kalendarz urlopów',
href: '/vacation/calendar', href: '/vacation/calendar',
component: 'Calendar', section: 'Calendar',
icon: CalendarIcon, icon: CalendarIcon,
can: true, can: true,
}, },
{ {
name: 'Wykorzystanie urlopu', name: 'Wykorzystanie urlopu',
href: '/vacation/monthly-usage', href: '/vacation/monthly-usage',
component: 'MonthlyUsage', section: 'MonthlyUsage',
icon: AdjustmentsIcon, icon: AdjustmentsIcon,
can: props.auth.can.listMonthlyUsage, can: props.auth.can.listMonthlyUsage,
}, },
{ {
name: 'Dni wolne', name: 'Dni wolne',
href: '/holidays', href: '/holidays',
component: 'Holidays/Index', section: 'Holidays/',
icon: StarIcon, icon: StarIcon,
can: true, can: true,
}, },
{ {
name: 'Limity urlopów', name: 'Limity urlopów',
href: '/vacation/limits', href: '/vacation/limits',
component: 'VacationLimits', section: 'VacationLimits',
icon: SunIcon, icon: SunIcon,
can: props.auth.can.manageVacationLimits, can: props.auth.can.manageVacationLimits,
}, },
@ -340,14 +354,14 @@ const navigation = computed(() =>
name: 'Podsumowanie roczne', name: 'Podsumowanie roczne',
href: '/vacation/annual-summary', href: '/vacation/annual-summary',
component: 'AnnualSummary', section: 'AnnualSummary',
icon: ClipboardListIcon, icon: ClipboardListIcon,
can: true, can: true,
}, },
{ {
name: 'Użytkownicy', name: 'Użytkownicy',
href: '/users', href: '/users',
component: 'Users/Index', section: 'Users/',
icon: UserGroupIcon, icon: UserGroupIcon,
can: props.auth.can.manageUsers, can: props.auth.can.manageUsers,
}, },

View File

@ -53,6 +53,7 @@
<script setup> <script setup>
import useVacationTypeInfo from '@/Composables/vacationTypeInfo' import useVacationTypeInfo from '@/Composables/vacationTypeInfo'
import Status from '@/Shared/Status'
defineProps({ defineProps({
requests: Object, requests: Object,

View File

@ -1,10 +1,12 @@
import { createApp, h } from 'vue' import { createApp, h } from 'vue'
import { createInertiaApp, Head, Link } from '@inertiajs/inertia-vue3' import { createInertiaApp, Head } from '@inertiajs/inertia-vue3'
import { InertiaProgress } from '@inertiajs/progress' import { InertiaProgress } from '@inertiajs/progress'
import AppLayout from '@/Shared/Layout/AppLayout' import AppLayout from '@/Shared/Layout/AppLayout'
import Flatpickr from 'flatpickr' import Flatpickr from 'flatpickr'
import { Settings } from 'luxon'
import { Polish } from 'flatpickr/dist/l10n/pl.js' import { Polish } from 'flatpickr/dist/l10n/pl.js'
import Toast from 'vue-toastification' import Toast from 'vue-toastification'
import InertiaLink from '@/Shared/InertiaLink'
createInertiaApp({ createInertiaApp({
resolve: name => { resolve: name => {
@ -23,7 +25,7 @@ createInertiaApp({
timeout: 3000, timeout: 3000,
pauseOnFocusLoss: false, pauseOnFocusLoss: false,
}) })
.component('InertiaLink', Link) .component('InertiaLink', InertiaLink)
.component('InertiaHead', Head) .component('InertiaHead', Head)
.mount(el) .mount(el)
}, },
@ -44,3 +46,4 @@ Flatpickr.setDefaults({
disableMobile: true, disableMobile: true,
}) })
Settings.defaultLocale = 'pl'

View File

@ -59,12 +59,12 @@
"Vacation type: :type": "Rodzaj wniosku: :type", "Vacation type: :type": "Rodzaj wniosku: :type",
"From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)", "From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)",
"Click here for details": "Kliknij, aby zobaczyć szczegóły", "Click here for details": "Kliknij, aby zobaczyć szczegóły",
"Vacation request :title is waiting for your technical approval": "Wniosek urlopowy :title czeka na akceptacje techniczną", "Vacation request :title is waiting for your technical approval": "Wniosek urlopowy :title czeka na akceptację techniczną",
"Vacation request :title is waiting for your administrative approval": "Wniosek urlopowy :title czeka na akceptacje administracyjną", "Vacation request :title is waiting for your administrative approval": "Wniosek urlopowy :title czeka na akceptację administracyjną",
"The vacation request :title from user :requester is waiting for your technical approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację techniczną.", "The vacation request :title from user :requester is waiting for your technical approval.": "Wniosek urlopowy :title użytkownika :requester czeka na Twoją akceptację techniczną.",
"The vacation request :title from user :requester is waiting for your administrative approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację administracyjną.", "The vacation request :title from user :requester is waiting for your administrative approval.": "Wniosek urlopowy :title użytkownika :requester czeka na Twoją akceptację administracyjną.",
"Vacation request :title has been :status": "Wniosek urlopowy :title został :status", "Vacation request :title has been :status": "Wniosek urlopowy :title został :status",
"The vacation request :title for user :requester has been :status.": "Wniosek urlopowy :title od użytkownika :requester został :status.", "The vacation request :title from user :requester has been :status.": "Wniosek urlopowy :title użytkownika :requester został :status.",
"Vacation request :title has been created on your behalf": "Wniosek urlopowy :title został utworzony w Twoim imieniu", "Vacation request :title has been created on your behalf": "Wniosek urlopowy :title został utworzony w Twoim imieniu",
"The vacation request :title has been created correctly by user :creator on your behalf in the :appName.": "W systemie :appName został poprawnie utworzony wniosek urlopowy :title w Twoim imieniu przez użytkownika :creator." "The vacation request :title has been created correctly by user :creator on your behalf in the :appName.": "W systemie :appName został poprawnie utworzony wniosek urlopowy :title w Twoim imieniu przez użytkownika :creator."
} }

View File

@ -54,14 +54,14 @@
<table> <table>
<tbody> <tbody>
<tr> <tr>
<td>{{ $vacationRequest->user->fullName }}</td> <td>{{ $vacationRequest->user->profile->fullName }}</td>
<td>Legnica, {{ $vacationRequest->created_at->format("d.m.Y") }}</td> <td>Legnica, {{ $vacationRequest->created_at->format("d.m.Y") }}</td>
</tr> </tr>
<tr> <tr>
<td class="helper-text">imię i nazwisko</td> <td class="helper-text">imię i nazwisko</td>
</tr> </tr>
<tr> <tr>
<td>{{ $vacationRequest->user->position }}</td> <td>{{ $vacationRequest->user->profile->position }}</td>
</tr> </tr>
<tr> <tr>
<td class="helper-text">stanowisko</td> <td class="helper-text">stanowisko</td>

View File

@ -15,18 +15,26 @@ use Toby\Infrastructure\Http\Controllers\UserController;
use Toby\Infrastructure\Http\Controllers\VacationCalendarController; use Toby\Infrastructure\Http\Controllers\VacationCalendarController;
use Toby\Infrastructure\Http\Controllers\VacationLimitController; use Toby\Infrastructure\Http\Controllers\VacationLimitController;
use Toby\Infrastructure\Http\Controllers\VacationRequestController; use Toby\Infrastructure\Http\Controllers\VacationRequestController;
use Toby\Infrastructure\Http\Middleware\TrackUserLastActivity;
Route::middleware("auth")->group(function (): void { Route::middleware(["auth", TrackUserLastActivity::class])->group(function (): void {
Route::get("/", DashboardController::class) Route::get("/", DashboardController::class)
->name("dashboard"); ->name("dashboard");
Route::post("/logout", LogoutController::class); Route::post("/logout", LogoutController::class);
Route::resource("users", UserController::class); Route::resource("users", UserController::class)
->except("show")
->whereNumber("user");
Route::post("/users/{user}/restore", [UserController::class, "restore"]) Route::post("/users/{user}/restore", [UserController::class, "restore"])
->whereNumber("user")
->withTrashed(); ->withTrashed();
Route::resource("holidays", HolidayController::class); Route::resource("holidays", HolidayController::class)
->except("show")
->whereNumber("holiday");
Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class) Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class)
->whereNumber("yearPeriod")
->name("year-periods.select"); ->name("year-periods.select");
Route::prefix("/vacation")->as("vacation.")->group(function (): void { Route::prefix("/vacation")->as("vacation.")->group(function (): void {
@ -49,23 +57,30 @@ Route::middleware("auth")->group(function (): void {
->name("requests.create"); ->name("requests.create");
Route::post("/requests", [VacationRequestController::class, "store"]) Route::post("/requests", [VacationRequestController::class, "store"])
->name("requests.store"); ->name("requests.store");
Route::get("/requests/{vacationRequest}", [VacationRequestController::class, "show"]) Route::get("/requests/{vacationRequest}", [VacationRequestController::class, "show"])
->whereNumber("vacationRequest")
->name("requests.show"); ->name("requests.show");
Route::get("/requests/{vacationRequest}/download", [VacationRequestController::class, "download"]) Route::get("/requests/{vacationRequest}/download", [VacationRequestController::class, "download"])
->whereNumber("vacationRequest")
->name("requests.download"); ->name("requests.download");
Route::post("/requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"]) Route::post("/requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"])
->whereNumber("vacationRequest")
->name("requests.reject"); ->name("requests.reject");
Route::post("/requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"]) Route::post("/requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"])
->whereNumber("vacationRequest")
->name("requests.cancel"); ->name("requests.cancel");
Route::post("/requests/{vacationRequest}/accept-as-technical", [VacationRequestController::class, "acceptAsTechnical"], ) Route::post("/requests/{vacationRequest}/accept-as-technical", [VacationRequestController::class, "acceptAsTechnical"], )
->whereNumber("vacationRequest")
->name("requests.accept-as-technical"); ->name("requests.accept-as-technical");
Route::post("/requests/{vacationRequest}/accept-as-administrative", [VacationRequestController::class, "acceptAsAdministrative"], ) Route::post("/requests/{vacationRequest}/accept-as-administrative", [VacationRequestController::class, "acceptAsAdministrative"], )
->whereNumber("vacationRequest")
->name("requests.accept-as-administrative"); ->name("requests.accept-as-administrative");
Route::get("/monthly-usage", MonthlyUsageController::class) Route::get("/monthly-usage", MonthlyUsageController::class)
->name("monthly-usage"); ->name("monthly-usage");
Route::get("/annual-summary", AnnualSummaryController::class) Route::get("/annual-summary", AnnualSummaryController::class)
->name("annual-summmary"); ->name("annual-summary");
}); });
}); });

View File

@ -25,6 +25,7 @@ class HolidayTest extends FeatureTestCase
$this->actingAs($user) $this->actingAs($user)
->get("/holidays") ->get("/holidays")
->assertOk()
->assertInertia( ->assertInertia(
fn(Assert $page) => $page fn(Assert $page) => $page
->component("Holidays/Index") ->component("Holidays/Index")

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Carbon;
use Tests\FeatureTestCase;
use Toby\Eloquent\Models\User;
class TrackLastActivityMiddlewareTest extends FeatureTestCase
{
use DatabaseMigrations;
public function testLastActiveAtFieldIsUpdatedWhenUserDidRequest(): void
{
$now = Carbon::now();
Carbon::setTestNow($now);
$user = User::factory()->create();
$this->assertDatabaseHas("users", [
"id" => $user->id,
"last_active_at" => null,
]);
$this->actingAs($user)
->get("/")
->assertOk();
$this->assertDatabaseHas("users", [
"id" => $user->id,
"last_active_at" => $now,
]);
}
}

View File

@ -34,25 +34,30 @@ class UserTest extends FeatureTestCase
public function testAdminCanSearchUsersList(): void public function testAdminCanSearchUsersList(): void
{ {
User::factory([ User::factory()
"first_name" => "Test", ->hasprofile([
"last_name" => "User1", "first_name" => "Test",
])->create(); "last_name" => "User1",
])
->create();
User::factory([ User::factory()
"first_name" => "Test", ->hasProfile([
"last_name" => "User2", "first_name" => "Test",
])->create(); "last_name" => "User2",
])->create();
User::factory([ User::factory()
"first_name" => "Test", ->hasProfile([
"last_name" => "User3", "first_name" => "Test",
])->create(); "last_name" => "User3",
])->create();
$admin = User::factory([ $admin = User::factory()
"first_name" => "John", ->hasProfile([
"last_name" => "Doe", "first_name" => "John",
])->admin()->create(); "last_name" => "Doe",
])->admin()->create();
$this->assertDatabaseCount("users", 4); $this->assertDatabaseCount("users", 4);
@ -99,11 +104,20 @@ class UserTest extends FeatureTestCase
]) ])
->assertSessionHasNoErrors(); ->assertSessionHasNoErrors();
$user = User::query()
->where("email", "john.doe@example.com")
->first();
$this->assertDatabaseHas("users", [ $this->assertDatabaseHas("users", [
"first_name" => "John", "id" => $user->id,
"last_name" => "Doe",
"email" => "john.doe@example.com", "email" => "john.doe@example.com",
"role" => Role::Employee->value, "role" => Role::Employee->value,
]);
$this->assertDatabaseHas("profiles", [
"user_id" => $user->id,
"first_name" => "John",
"last_name" => "Doe",
"position" => "Test position", "position" => "Test position",
"employment_form" => EmploymentForm::B2bContract->value, "employment_form" => EmploymentForm::B2bContract->value,
"employment_date" => Carbon::now()->toDateString(), "employment_date" => Carbon::now()->toDateString(),
@ -118,12 +132,12 @@ class UserTest extends FeatureTestCase
Carbon::setTestNow(); Carbon::setTestNow();
$this->assertDatabaseHas("users", [ $this->assertDatabaseHas("profiles", [
"first_name" => $user->first_name, "user_id" => $user->id,
"last_name" => $user->last_name, "first_name" => $user->profile->first_name,
"email" => $user->email, "last_name" => $user->profile->last_name,
"employment_form" => $user->employment_form->value, "employment_form" => $user->profile->employment_form->value,
"employment_date" => $user->employment_date->toDateString(), "employment_date" => $user->profile->employment_date->toDateString(),
]); ]);
$this->actingAs($admin) $this->actingAs($admin)
@ -139,10 +153,15 @@ class UserTest extends FeatureTestCase
->assertSessionHasNoErrors(); ->assertSessionHasNoErrors();
$this->assertDatabaseHas("users", [ $this->assertDatabaseHas("users", [
"first_name" => "John", "id" => $user->id,
"last_name" => "Doe",
"email" => "john.doe@example.com", "email" => "john.doe@example.com",
"role" => Role::Employee->value, "role" => Role::Employee->value,
]);
$this->assertDatabaseHas("profiles", [
"user_id" => $user->id,
"first_name" => "John",
"last_name" => "Doe",
"position" => "Test position", "position" => "Test position",
"employment_form" => EmploymentForm::B2bContract->value, "employment_form" => EmploymentForm::B2bContract->value,
"employment_date" => Carbon::now()->toDateString(), "employment_date" => Carbon::now()->toDateString(),

View File

@ -17,7 +17,8 @@ class VacationCalendarTest extends FeatureTestCase
{ {
$administrativeApprover = User::factory()->administrativeApprover()->create(); $administrativeApprover = User::factory()->administrativeApprover()->create();
User::factory(["employment_form" => EmploymentForm::EmploymentContract]) User::factory()
->hasProfile(["employment_form" => EmploymentForm::EmploymentContract])
->count(10) ->count(10)
->create(); ->create();

View File

@ -9,6 +9,7 @@ use Tests\TestCase;
use Tests\Traits\InteractsWithYearPeriods; use Tests\Traits\InteractsWithYearPeriods;
use Toby\Domain\Actions\CreateUserAction; use Toby\Domain\Actions\CreateUserAction;
use Toby\Domain\Actions\CreateYearPeriodAction; use Toby\Domain\Actions\CreateYearPeriodAction;
use Toby\Eloquent\Models\Profile;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod; use Toby\Eloquent\Models\YearPeriod;
@ -31,9 +32,10 @@ class VacationLimitTest extends TestCase
$currentYearPeriod = YearPeriod::current(); $currentYearPeriod = YearPeriod::current();
$createUserAction = $this->app->make(CreateUserAction::class); $createUserAction = $this->app->make(CreateUserAction::class);
$dumpData = User::factory()->raw(); $dumpUserData = User::factory()->raw();
$dumpProfileData = Profile::factory()->raw();
$user = $createUserAction->execute($dumpData); $user = $createUserAction->execute($dumpUserData, $dumpProfileData);
$this->assertDatabaseCount("vacation_limits", 1); $this->assertDatabaseCount("vacation_limits", 1);