1
1
<script setup>
2
- import { ChevronLeftIcon , ChevronRightIcon } from ' @heroicons/vue/24/solid'
3
- import { computed , ref } from ' vue'
2
+ import { ChevronLeftIcon , ChevronRightIcon , ChevronDoubleRightIcon , ChevronDoubleLeftIcon , ChevronUpDownIcon } from ' @heroicons/vue/24/solid'
3
+ import { computed , ref , watch } from ' vue'
4
4
import { useMonthInfo } from ' @/Composables/monthInfo.js'
5
5
import VacationTypeCalendarIcon from ' @/Shared/VacationTypeCalendarIcon.vue'
6
6
import CalendarDay from ' @/Shared/CalendarDay.vue'
7
7
import UserProfileLink from ' @/Shared/UserProfileLink.vue'
8
+ import { Listbox , ListboxButton , ListboxOption , ListboxOptions } from ' @headlessui/vue'
9
+ import { useForm } from ' @inertiajs/inertia-vue3'
10
+ import { Inertia } from ' @inertiajs/inertia'
8
11
9
12
const props = defineProps ({
10
13
users: Object ,
11
14
auth: Object ,
12
15
calendar: Object ,
13
16
current: String ,
14
- selected : String ,
17
+ selectedMonth : String ,
15
18
years: Object ,
19
+ previousYearPeriod: Object ,
20
+ nextYearPeriod: Object ,
16
21
})
17
22
18
23
let activeElement = ref (undefined )
@@ -21,8 +26,17 @@ const { getMonths, findMonth } = useMonthInfo()
21
26
22
27
const months = getMonths ()
23
28
24
- const currentMonth = computed (() => findMonth (props .current ))
25
- const selectedMonth = computed (() => findMonth (props .selected ))
29
+ const form = useForm ({
30
+ selectedMonth: months .find (month => month .value === props .selectedMonth ),
31
+ })
32
+
33
+ watch (() => form .selectedMonth , (value ) => {
34
+ if (value) {
35
+ Inertia .visit (` /calendar/${ value .value } ` )
36
+ }
37
+ })
38
+
39
+ const selectedMonth = computed (() => findMonth (props .selectedMonth ))
26
40
const previousMonth = computed (() => months[months .indexOf (selectedMonth .value ) - 1 ])
27
41
const nextMonth = computed (() => months[months .indexOf (selectedMonth .value ) + 1 ])
28
42
@@ -52,33 +66,76 @@ function linkVacationRequest(user) {
52
66
<InertiaHead title =" Kalendarz" />
53
67
<div class =" bg-white shadow-md" >
54
68
<div class =" flex-row sm:flex justify-between items-center p-4 sm:px-6" >
55
- <div class =" flex items-center" >
56
- <h2 class =" text-lg font-medium leading-6 text-center text-gray-900" >
69
+ <div class =" flex-row sm:flex items-center" >
70
+ <h2 class =" text-lg font-medium leading-6 sm: text-center mb-2 sm:mb-0 text-gray-900" >
57
71
Kalendarz
58
72
</h2 >
59
- <div class =" flex items-center ml-3 rounded-md shadow-sm md:items-stretch" >
73
+ <div class =" flex items-center sm: ml-3 md:items-stretch" >
60
74
<InertiaLink
61
75
v-if =" previousMonth"
62
76
:href =" `/calendar/${previousMonth.value}`"
63
77
as =" button"
64
- 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"
78
+ 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"
65
79
>
66
80
<ChevronLeftIcon class =" w-5 h-5" />
67
81
</InertiaLink >
82
+ <InertiaLink
83
+ v-else-if =" previousYearPeriod"
84
+ :href =" `/calendar/${months[11].value}/${previousYearPeriod.year}`"
85
+ as =" button"
86
+ 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"
87
+ >
88
+ <ChevronDoubleLeftIcon class =" w-5 h-5" />
89
+ </InertiaLink >
68
90
<span
69
91
v-else
70
- 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"
92
+ class =" flex justify-center items-center text-gray-400 bg-gray-100 rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9"
71
93
>
72
- <ChevronLeftIcon class =" w-5 h-5" />
94
+ <ChevronDoubleLeftIcon class =" w-5 h-5" />
73
95
</span >
74
- <InertiaLink
75
- v-if =" years.current.year === years.selected.year"
76
- :href =" `/calendar/${currentMonth.value}`"
77
- as =" button"
78
- 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"
96
+ <Listbox
97
+ v-model =" form.selectedMonth"
98
+ as =" div"
99
+ class =" items-center grid-cols-3 w-[135px] h-[] 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"
79
100
>
80
- Dzisiaj
81
- </InertiaLink >
101
+ <div class =" relative sm:col-span-2 sm:mt-0" >
102
+ <ListboxButton
103
+ class =" relative pr-10 pl-3 w-full h-[36px] max-w-lg text-left bg-white focus:outline-none shadow-sm sm:text-sm cursor-pointer"
104
+ >
105
+ <template v-if =" form .selectedMonth " >
106
+ <span class =" block truncate text-center" >
107
+ {{ form.selectedMonth.name }}
108
+ </span >
109
+ <span class =" flex absolute inset-y-0 right-0 items-center pr-2 pointer-events-none" >
110
+ <ChevronUpDownIcon class =" w-5 h-5 text-gray-400" />
111
+ </span >
112
+ </template >
113
+ </ListboxButton >
114
+ <transition
115
+ leave-active-class =" transition ease-in duration-100"
116
+ leave-from-class =" opacity-100"
117
+ leave-to-class =" opacity-0"
118
+ >
119
+ <ListboxOptions
120
+ class =" overflow-auto absolute z-10 py-1 mt-1 w-auto 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"
121
+ >
122
+ <ListboxOption
123
+ v-for =" month in months"
124
+ :key =" month.value"
125
+ v-slot =" { active, selected }"
126
+ :value =" month"
127
+ as =" template"
128
+ >
129
+ <li :class =" [active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9 cursor-pointer']" >
130
+ <span :class =" [selected ? 'font-semibold' : 'font-normal', 'block truncate']" >
131
+ {{ month.name }}
132
+ </span >
133
+ </li >
134
+ </ListboxOption >
135
+ </ListboxOptions >
136
+ </transition >
137
+ </div >
138
+ </Listbox >
82
139
<InertiaLink
83
140
v-if =" nextMonth"
84
141
:href =" `/calendar/${nextMonth.value}`"
@@ -87,11 +144,19 @@ function linkVacationRequest(user) {
87
144
>
88
145
<ChevronRightIcon class =" w-5 h-5" />
89
146
</InertiaLink >
147
+ <InertiaLink
148
+ v-else-if =" nextYearPeriod"
149
+ :href =" `/calendar/${months[0].value}/${nextYearPeriod.year}`"
150
+ as =" button"
151
+ 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"
152
+ >
153
+ <ChevronDoubleRightIcon class =" w-5 h-5" />
154
+ </InertiaLink >
90
155
<span
91
156
v-else
92
- 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"
157
+ class =" flex justify-center items-center text-gray-400 bg-gray-100 rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9"
93
158
>
94
- <ChevronRightIcon class =" w-5 h-5" />
159
+ <ChevronDoubleRightIcon class =" w-5 h-5" />
95
160
</span >
96
161
</div >
97
162
</div >
0 commit comments