Skip to content

Commit

Permalink
#469 - fixed bug with year period (#471)
Browse files Browse the repository at this point in the history
* #469 - fix: fixed bug with year period and added back button to current year and month on the calendar

* KT-469 - fix: fixed naming user history to user details because Kamila reported such a need

* Apply suggestions from code review

Co-authored-by: Ewelina Skrzypacz <[email protected]>

* #469 - fix: code review fixes

---------

Co-authored-by: Ewelina Skrzypacz <[email protected]>
  • Loading branch information
kamilpiech97 and EwelinaSkrzypacz authored Jul 22, 2024
1 parent 1b1264b commit 5c72a04
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 29 deletions.
10 changes: 3 additions & 7 deletions app/Helpers/YearPeriodRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Toby\Helpers;

use Illuminate\Cache\CacheManager;
use Illuminate\Contracts\Session\Session;
use Toby\Models\YearPeriod;

Expand All @@ -14,17 +13,14 @@ class YearPeriodRetriever

public function __construct(
protected Session $session,
protected CacheManager $cacheManager,
) {}

public function selected(): YearPeriod
{
return $this->cacheManager->remember("selected_year_period", 60, function () {
/** @var YearPeriod $yearPeriod */
$yearPeriod = YearPeriod::query()->find($this->session->get(static::SESSION_KEY));
/** @var YearPeriod $yearPeriod */
$yearPeriod = YearPeriod::query()->find($this->session->get(static::SESSION_KEY));

return $yearPeriod !== null ? $yearPeriod : $this->current();
});
return $yearPeriod !== null ? $yearPeriod : $this->current();
}

public function current(): YearPeriod
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/SelectYearPeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Models\YearPeriod;

Expand All @@ -15,7 +14,6 @@ class SelectYearPeriodController extends Controller
public function __invoke(Request $request, YearPeriod $yearPeriod): RedirectResponse
{
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);
Cache::forget("selected_year_period");

return redirect()
->back()
Expand Down
17 changes: 11 additions & 6 deletions app/Http/Controllers/VacationCalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Inertia\Response;
use Toby\Domain\CalendarGenerator;
use Toby\Enums\Month;
Expand Down Expand Up @@ -57,8 +56,10 @@ public function index(

return inertia("Calendar", [
"calendar" => $calendar,
"current" => Month::current(),
"currentMonth" => Month::current(),
"currentYear" => Carbon::now()->year,
"selectedMonth" => $month->value,
"selectedYear" => $yearPeriod->year,
"users" => SimpleUserResource::collection($users),
"withBlockedUsers" => $withTrashedUsers,
"previousYearPeriod" => $previousYearPeriod,
Expand All @@ -69,10 +70,14 @@ public function index(
private function changeYearPeriod(Request $request, string $month, int $year): RedirectResponse
{
$yearPeriod = YearPeriod::query()->where("year", $year)->firstOrFail();
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);
Cache::forget("selected_year_period");

return redirect()->route("calendar", ["month" => $month])
->with("info", __("Year period changed."));
if ($yearPeriod->id !== $request->session()->get(YearPeriodRetriever::SESSION_KEY)) {
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);

return redirect()->route("calendar", ["month" => $month])
->with("info", __("Year period changed."));
}

return redirect()->route("calendar", ["month" => $month]);
}
}
6 changes: 3 additions & 3 deletions lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@
"Is mobile": "Czy mobilny",
"Assignee": "Przypisany do",
"Assigned at": "Przypisany od",
"User history created.": "Historia użytkownika utworzona.",
"User history updated.": "Historia użytkownika zaktualizowana.",
"User history deleted.": "Historia użytkownika usunięta.",
"User history created.": "Szczegóły użytkownika utworzone.",
"User history updated.": "Szczegóły użytkownika zaktualizowane.",
"User history deleted.": "Szczegóły użytkownika usunięte.",
"settled": "rozliczony",
"The request :title is waiting for your technical approval.\nUser: :requester\nDate: :date (number of hours: :hours)": "Wniosek :title czeka na Twoją akceptację techniczną.\nPracownik: :requester\nData: :date (liczba godzin: :hours)",
"The request :title has been approved by you as a technical approver.\nUser: :requester\nDate: :date (number of hours: :hours)": "Wniosek :title został zaakceptowany przez Ciebie jako przełożonego technicznego.\nPracownik: :requester\nData: :date (liczba godzin: :hours)"
Expand Down
17 changes: 15 additions & 2 deletions resources/js/Pages/Calendar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleRightIcon, ChevronDoubleLeftIcon, ChevronUpDownIcon } from '@heroicons/vue/24/solid'
import { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleRightIcon, ChevronDoubleLeftIcon, ChevronUpDownIcon, ArrowUturnLeftIcon } from '@heroicons/vue/24/solid'
import { computed, ref, watch } from 'vue'
import { useMonthInfo } from '@/Composables/monthInfo.js'
import VacationTypeCalendarIcon from '@/Shared/VacationTypeCalendarIcon.vue'
Expand All @@ -13,8 +13,10 @@ const props = defineProps({
users: Object,
auth: Object,
calendar: Object,
current: String,
currentMonth: String,
currentYear: Number,
selectedMonth: String,
selectedYear: Number,
years: Object,
previousYearPeriod: Object,
nextYearPeriod: Object,
Expand Down Expand Up @@ -158,6 +160,17 @@ function linkVacationRequest(user) {
>
<ChevronDoubleRightIcon class="w-5 h-5" />
</span>
<InertiaLink
v-if="selectedMonth.value !== currentMonth || currentYear !== selectedYear"
:href="`/calendar/${props.currentMonth}/${props.currentYear}`"
as="button"
class="flex focus:relative justify-center items-center p-2 bg-white md:px-2 md:hover:bg-gray-50 ml-1"
>
<ArrowUturnLeftIcon class="w-5 h-5 text-blumilk-600 hover:text-blumilk-500" />
<span class="ml-1.5 text-sm font-semibold text-blumilk-600 hover:text-blumilk-500">
Dzisiaj
</span>
</InertiaLink>
</div>
</div>
<div
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/UserHistory/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const props = defineProps({
})
const form = useForm({
from: props.vacationFromDate,
to: props.vacationFromDate,
from: '',
to: '',
comment: '',
type: '',
employmentForm: '',
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Pages/UserHistory/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ defineProps({
</script>

<template>
<InertiaHead title="Historia użytkownika" />
<InertiaHead title="Szczegóły użytkownika" />
<div class="bg-white shadow-md">
<div class="flex justify-between items-center p-4 sm:px-6">
<div>
<h2 class="text-lg font-medium leading-6 text-gray-900">
Historia
Szczegóły
</h2>
</div>
<div>
<InertiaLink
class="inline-flex items-center py-3 px-4 text-sm font-medium leading-4 text-center text-white bg-blumilk-600 hover:bg-blumilk-700 rounded-md border border-transparent focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
:href="`/users/${userId}/history/create`"
class="inline-flex items-center py-3 px-4 text-sm font-medium leading-4 text-center text-white bg-blumilk-600 hover:bg-blumilk-700 rounded-md border border-transparent focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
>
Dodaj wpis
</InertiaLink>
Expand Down Expand Up @@ -139,8 +139,8 @@ defineProps({
>
<InertiaLink
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'font-medium block px-4 py-2 text-sm']"
:method="'delete'"
:href="`/users/history/${item.id}`"
:method="'delete'"
>
<TrashIcon class="mr-2 w-5 h-5 text-red-500" />
Usuń
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Pages/Users/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
ArrowPathIcon,
CheckIcon,
ChevronUpDownIcon,
ClockIcon,
EllipsisVerticalIcon,
LockClosedIcon,
NoSymbolIcon,
PencilIcon,
InformationCircleIcon,
} from '@heroicons/vue/24/solid'
import {
Listbox,
Expand Down Expand Up @@ -345,8 +345,8 @@ watch(form, debounce(() => {
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'font-medium block px-4 py-2 text-sm']"
:href="`/users/${user.id}/history`"
>
<ClockIcon class="mr-2 w-5 h-5 text-violet-500" />
Historia
<InformationCircleIcon class="mr-2 w-5 h-5 text-violet-500" />
Szczegóły
</InertiaLink>
</MenuItem>
<MenuItem
Expand Down

0 comments on commit 5c72a04

Please sign in to comment.