Skip to content

Commit 5c72a04

Browse files
#469 - fixed bug with year period (#471)
* #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]>
1 parent 1b1264b commit 5c72a04

File tree

8 files changed

+41
-29
lines changed

8 files changed

+41
-29
lines changed

app/Helpers/YearPeriodRetriever.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Toby\Helpers;
66

7-
use Illuminate\Cache\CacheManager;
87
use Illuminate\Contracts\Session\Session;
98
use Toby\Models\YearPeriod;
109

@@ -14,17 +13,14 @@ class YearPeriodRetriever
1413

1514
public function __construct(
1615
protected Session $session,
17-
protected CacheManager $cacheManager,
1816
) {}
1917

2018
public function selected(): YearPeriod
2119
{
22-
return $this->cacheManager->remember("selected_year_period", 60, function () {
23-
/** @var YearPeriod $yearPeriod */
24-
$yearPeriod = YearPeriod::query()->find($this->session->get(static::SESSION_KEY));
20+
/** @var YearPeriod $yearPeriod */
21+
$yearPeriod = YearPeriod::query()->find($this->session->get(static::SESSION_KEY));
2522

26-
return $yearPeriod !== null ? $yearPeriod : $this->current();
27-
});
23+
return $yearPeriod !== null ? $yearPeriod : $this->current();
2824
}
2925

3026
public function current(): YearPeriod

app/Http/Controllers/SelectYearPeriodController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Illuminate\Http\RedirectResponse;
88
use Illuminate\Http\Request;
9-
use Illuminate\Support\Facades\Cache;
109
use Toby\Helpers\YearPeriodRetriever;
1110
use Toby\Models\YearPeriod;
1211

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

2018
return redirect()
2119
->back()

app/Http/Controllers/VacationCalendarController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Http\RedirectResponse;
88
use Illuminate\Http\Request;
99
use Illuminate\Support\Carbon;
10-
use Illuminate\Support\Facades\Cache;
1110
use Inertia\Response;
1211
use Toby\Domain\CalendarGenerator;
1312
use Toby\Enums\Month;
@@ -57,8 +56,10 @@ public function index(
5756

5857
return inertia("Calendar", [
5958
"calendar" => $calendar,
60-
"current" => Month::current(),
59+
"currentMonth" => Month::current(),
60+
"currentYear" => Carbon::now()->year,
6161
"selectedMonth" => $month->value,
62+
"selectedYear" => $yearPeriod->year,
6263
"users" => SimpleUserResource::collection($users),
6364
"withBlockedUsers" => $withTrashedUsers,
6465
"previousYearPeriod" => $previousYearPeriod,
@@ -69,10 +70,14 @@ public function index(
6970
private function changeYearPeriod(Request $request, string $month, int $year): RedirectResponse
7071
{
7172
$yearPeriod = YearPeriod::query()->where("year", $year)->firstOrFail();
72-
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);
73-
Cache::forget("selected_year_period");
7473

75-
return redirect()->route("calendar", ["month" => $month])
76-
->with("info", __("Year period changed."));
74+
if ($yearPeriod->id !== $request->session()->get(YearPeriodRetriever::SESSION_KEY)) {
75+
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);
76+
77+
return redirect()->route("calendar", ["month" => $month])
78+
->with("info", __("Year period changed."));
79+
}
80+
81+
return redirect()->route("calendar", ["month" => $month]);
7782
}
7883
}

lang/pl.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@
194194
"Is mobile": "Czy mobilny",
195195
"Assignee": "Przypisany do",
196196
"Assigned at": "Przypisany od",
197-
"User history created.": "Historia użytkownika utworzona.",
198-
"User history updated.": "Historia użytkownika zaktualizowana.",
199-
"User history deleted.": "Historia użytkownika usunięta.",
197+
"User history created.": "Szczegóły użytkownika utworzone.",
198+
"User history updated.": "Szczegóły użytkownika zaktualizowane.",
199+
"User history deleted.": "Szczegóły użytkownika usunięte.",
200200
"settled": "rozliczony",
201201
"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)",
202202
"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)"

resources/js/Pages/Calendar.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleRightIcon, ChevronDoubleLeftIcon, ChevronUpDownIcon } from '@heroicons/vue/24/solid'
2+
import { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleRightIcon, ChevronDoubleLeftIcon, ChevronUpDownIcon, ArrowUturnLeftIcon } from '@heroicons/vue/24/solid'
33
import { computed, ref, watch } from 'vue'
44
import { useMonthInfo } from '@/Composables/monthInfo.js'
55
import VacationTypeCalendarIcon from '@/Shared/VacationTypeCalendarIcon.vue'
@@ -13,8 +13,10 @@ const props = defineProps({
1313
users: Object,
1414
auth: Object,
1515
calendar: Object,
16-
current: String,
16+
currentMonth: String,
17+
currentYear: Number,
1718
selectedMonth: String,
19+
selectedYear: Number,
1820
years: Object,
1921
previousYearPeriod: Object,
2022
nextYearPeriod: Object,
@@ -158,6 +160,17 @@ function linkVacationRequest(user) {
158160
>
159161
<ChevronDoubleRightIcon class="w-5 h-5" />
160162
</span>
163+
<InertiaLink
164+
v-if="selectedMonth.value !== currentMonth || currentYear !== selectedYear"
165+
:href="`/calendar/${props.currentMonth}/${props.currentYear}`"
166+
as="button"
167+
class="flex focus:relative justify-center items-center p-2 bg-white md:px-2 md:hover:bg-gray-50 ml-1"
168+
>
169+
<ArrowUturnLeftIcon class="w-5 h-5 text-blumilk-600 hover:text-blumilk-500" />
170+
<span class="ml-1.5 text-sm font-semibold text-blumilk-600 hover:text-blumilk-500">
171+
Dzisiaj
172+
</span>
173+
</InertiaLink>
161174
</div>
162175
</div>
163176
<div

resources/js/Pages/UserHistory/Create.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const props = defineProps({
1111
})
1212
1313
const form = useForm({
14-
from: props.vacationFromDate,
15-
to: props.vacationFromDate,
14+
from: '',
15+
to: '',
1616
comment: '',
1717
type: '',
1818
employmentForm: '',

resources/js/Pages/UserHistory/Index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ defineProps({
1717
</script>
1818

1919
<template>
20-
<InertiaHead title="Historia użytkownika" />
20+
<InertiaHead title="Szczegóły użytkownika" />
2121
<div class="bg-white shadow-md">
2222
<div class="flex justify-between items-center p-4 sm:px-6">
2323
<div>
2424
<h2 class="text-lg font-medium leading-6 text-gray-900">
25-
Historia
25+
Szczegóły
2626
</h2>
2727
</div>
2828
<div>
2929
<InertiaLink
30-
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"
3130
:href="`/users/${userId}/history/create`"
31+
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"
3232
>
3333
Dodaj wpis
3434
</InertiaLink>
@@ -139,8 +139,8 @@ defineProps({
139139
>
140140
<InertiaLink
141141
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'font-medium block px-4 py-2 text-sm']"
142-
:method="'delete'"
143142
:href="`/users/history/${item.id}`"
143+
:method="'delete'"
144144
>
145145
<TrashIcon class="mr-2 w-5 h-5 text-red-500" />
146146
Usuń

resources/js/Pages/Users/Index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
ArrowPathIcon,
88
CheckIcon,
99
ChevronUpDownIcon,
10-
ClockIcon,
1110
EllipsisVerticalIcon,
1211
LockClosedIcon,
1312
NoSymbolIcon,
1413
PencilIcon,
14+
InformationCircleIcon,
1515
} from '@heroicons/vue/24/solid'
1616
import {
1717
Listbox,
@@ -345,8 +345,8 @@ watch(form, debounce(() => {
345345
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'font-medium block px-4 py-2 text-sm']"
346346
:href="`/users/${user.id}/history`"
347347
>
348-
<ClockIcon class="mr-2 w-5 h-5 text-violet-500" />
349-
Historia
348+
<InformationCircleIcon class="mr-2 w-5 h-5 text-violet-500" />
349+
Szczegóły
350350
</InertiaLink>
351351
</MenuItem>
352352
<MenuItem

0 commit comments

Comments
 (0)