Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | 104x 4x 1x 4x 4x 4x 1x 4x 10x 8x 7x 7x 4x 4x 4x 1x 4x 71x 75x 1x 34x 34x 70x 70x 3x 3x 3x 3x 3x 3x 1x 2x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 2x 1x 1x 1x 2x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 4x 4x 1x 1x 2x 70x 1x 1x 1x | <template>
<div>
<!-- Calendar Component -->
<div class="m-component calendar-root">
<div
class="muc-calendar-wrap"
@click.capture="onCalendarClick"
>
<muc-calendar
:key="calendarKey"
:model-value="selectedDay"
@update:model-value="
(date) => $emit('update:selectedDay', date as Date)
"
disable-view-change
variant="single"
:allowed-dates="allowedDates"
:min="minDate"
:max="maxDate"
:view-month="viewMonth"
/>
</div>
</div>
<!-- Hourly View (when appointments > threshold) -->
<div
v-if="
selectedDay &&
(timeSlotsInHoursByOffice.size > 0 || isLoadingAppointments) &&
appointmentsCount > APPOINTMENTS_THRESHOLD_FOR_HOURLY_VIEW
"
:key="
String(selectedDay) +
String(selectableProviders) +
String(timeSlotsInHoursByOffice)
"
class="m-component"
>
<div class="m-content">
<h3 class="no-top-margin">
{{ t("availableTimes") }}
</h3>
</div>
<template v-if="isLoadingAppointments && !isLoadingComplete">
<div class="m-content">
<div class="m-spinner-container">
<MucSpinner :text="t('spinnerText')" />
</div>
</div>
</template>
<template v-else>
<div
class="m-content"
style="margin: 8px 0 0 0"
v-if="availabilityInfoHtml"
>
<muc-button
variant="ghost"
icon="information"
icon-shown-left
@click="$emit('openInfo')"
>
<template #default>{{ t("newAppointmentsInfoLink") }}</template>
</muc-button>
</div>
<div
style="
margin-bottom: 20px;
background-color: var(--color-neutrals-blue-xlight);
padding: 12px 8px;
"
>
<h4>{{ formatDayFromDate(selectedDay) }}</h4>
</div>
<div
v-for="[officeId, office] in timeSlotsInHoursByOffice"
:key="String(officeId) + String(selectedProviders[officeId])"
>
<div
v-if="
selectedProviders[officeId] &&
currentHour !== null &&
office.appointments.get(currentHour)
"
>
<template
v-for="[timeslot, times] in office.appointments"
:key="timeslot"
>
<TimeSlotGrid
v-if="
timeslot == currentHour ||
providersWithAppointments.length === 1
"
:officeId="officeId"
:times="times"
:timeLabel="`${timeslot}:00-${timeslot}:59`"
:showLocationTitle="(selectableProviders?.length || 0) > 1"
:officeNameById="officeNameById"
:isSlotSelected="isSlotSelected"
:officeIdForTime="officeIdForTime"
:t="t"
@selectTimeSlot="$emit('selectTimeSlot', $event)"
/>
</template>
</div>
</div>
<div
class="wrapper m-button-group"
v-if="!isLoadingAppointments && providersWithAppointments.length > 1"
>
<muc-button
:key="currentHour ?? 0"
icon="chevron-left"
icon-shown-left
variant="ghost"
@click="onEarlier('hour')"
:disabled="
currentHour === null ||
firstHour === null ||
currentHour <= firstHour ||
isLoadingAppointments
"
>
<template #default>{{ t("earlier") }}</template>
</muc-button>
<muc-button
:key="currentHour ?? 0"
class="float-right"
icon="chevron-right"
icon-shown-right
variant="ghost"
@click="onLater('hour')"
:disabled="
currentHour === null ||
lastHour === null ||
currentHour >= lastHour ||
isLoadingAppointments
"
>
<template #default>{{ t("later") }}</template>
</muc-button>
</div>
</template>
</div>
<!-- Day Part View (when appointments <= threshold) -->
<div
v-else-if="
selectedDay &&
(timeSlotsInDayPartByOffice.size > 0 || isLoadingAppointments)
"
:key="
String(selectedDay) +
String(selectableProviders) +
String(timeSlotsInDayPartByOffice)
"
class="m-component"
>
<div class="m-content">
<h3 class="no-top-margin">
{{ t("availableTimes") }}
</h3>
</div>
<template v-if="isLoadingAppointments && !isLoadingComplete">
<div class="m-content">
<div class="m-spinner-container">
<MucSpinner :text="t('spinnerText')" />
</div>
</div>
</template>
<template v-else>
<div
class="m-content"
style="margin: 8px 0 0 0"
v-if="availabilityInfoHtml"
>
<muc-button
variant="ghost"
icon="information"
icon-shown-left
@click="$emit('openInfo')"
>
<template #default>{{ t("newAppointmentsInfoLink") }}</template>
</muc-button>
</div>
<div
style="
margin-bottom: 20px;
background-color: var(--color-neutrals-blue-xlight);
padding: 12px 8px;
"
>
<h4>{{ formatDayFromDate(selectedDay) }}</h4>
</div>
<div
v-for="[officeId, office] in timeSlotsInDayPartByOffice"
:key="String(officeId) + String(selectedProviders[officeId])"
>
<div
v-if="
selectedProviders[officeId] &&
office.appointments.get(currentDayPart)
"
>
<template
v-for="[timeslot, times] in office.appointments"
:key="timeslot"
>
<TimeSlotGrid
v-if="
timeslot == currentDayPart ||
providersWithAppointments.length === 1
"
:officeId="officeId"
:times="times"
:timeLabel="t(timeslot)"
:showLocationTitle="(selectableProviders?.length || 0) > 1"
:officeNameById="officeNameById"
:isSlotSelected="isSlotSelected"
:officeIdForTime="officeIdForTime"
:t="t"
@selectTimeSlot="$emit('selectTimeSlot', $event)"
/>
</template>
</div>
</div>
<div
class="wrapper m-button-group"
v-if="!isLoadingAppointments && providersWithAppointments.length > 1"
>
<muc-button
icon="chevron-left"
icon-shown-left
variant="ghost"
@click="onEarlier('dayPart')"
:disabled="
currentDayPart === 'am' ||
firstDayPart === 'pm' ||
isLoadingAppointments
"
>
<template #default>{{ t("earlier") }}</template>
</muc-button>
<muc-button
class="float-right"
icon="chevron-right"
icon-shown-right
variant="ghost"
@click="onLater('dayPart')"
:disabled="
currentDayPart === 'pm' ||
lastDayPart === 'am' ||
isLoadingAppointments
"
>
<template #default>{{ t("later") }}</template>
</muc-button>
</div>
</template>
</div>
</div>
</template>
<script setup lang="ts">
import type { OfficeImpl } from "@/types/OfficeImpl";
import {
MucButton,
MucCalendar,
MucSpinner,
} from "@muenchen/muc-patternlab-vue";
import { nextTick } from "vue";
import { APPOINTMENTS_THRESHOLD_FOR_HOURLY_VIEW } from "@/utils/Constants";
import { formatDayFromDate } from "@/utils/formatAppointmentDateTime";
import TimeSlotGrid from "./TimeSlotGrid.vue";
const props = defineProps<{
t: (key: string) => string;
selectedDay: Date | undefined;
calendarKey: number;
allowedDates: (date: Date) => boolean;
minDate: Date | undefined;
maxDate: Date | undefined;
viewMonth: Date;
prevBookableDate: string | null;
nextBookableDate: string | null;
timeSlotsInHoursByOffice: Map<
number,
{ appointments: Map<number, number[]> }
>;
timeSlotsInDayPartByOffice: Map<
number,
{ appointments: Map<string, number[]> }
>;
currentHour: number | null;
firstHour: number | null;
lastHour: number | null;
currentDayPart: "am" | "pm";
firstDayPart: "am" | "pm";
lastDayPart: "am" | "pm";
selectableProviders: OfficeImpl[] | undefined;
selectedProviders: { [id: string]: boolean };
providersWithAppointments: OfficeImpl[];
appointmentsCount: number;
isLoadingAppointments: boolean;
isLoadingComplete: boolean;
availabilityInfoHtml: string | null;
officeNameById: (id: number | string) => string | null;
isSlotSelected: (officeId: number | string, time: number) => boolean;
officeIdForTime?: (
time: number,
displayOfficeId: number | string
) => number | string;
}>();
const emit = defineEmits<{
(e: "update:selectedDay", day: Date): void;
(e: "jumpToBookableDate", isoDate: string): void;
(
e: "selectTimeSlot",
payload: { officeId: number | string; time: number }
): void;
(e: "openInfo"): void;
(e: "setSelectedHour", hour: number | null): void;
(e: "setSelectedDayPart", part: "am" | "pm" | null): void;
}>();
type MonthNavDirection = "prev" | "next";
/**
* MucCalendar month chevrons: prefer icon href (locale-stable), fall back to
* translated aria-labels from our i18n (muc-patternlab currently hardcodes DE).
*/
function findMonthNavDirection(
target: EventTarget | null
): MonthNavDirection | null {
Iif (!(target instanceof Element)) {
return null;
}
const button = target.closest("button");
Iif (!button) {
return null;
}
const useEl = button.querySelector("use");
const href =
useEl?.getAttribute("href") || useEl?.getAttribute("xlink:href") || "";
if (href.includes("chevron-left")) {
return "prev";
}
if (href.includes("chevron-right")) {
return "next";
}
const label = button.getAttribute("aria-label");
Iif (!label) {
return null;
}
Iif (label === props.t("calendarPreviousMonth")) {
return "prev";
}
Eif (label === props.t("calendarNextMonth")) {
return "next";
}
return null;
}
/**
* MucCalendar month chevrons only do ±1 month internally and do not emit.
* When a bookable marker exists, jump there; otherwise let MucCalendar change
* the month normally (do not swallow the click — that leaves the calendar dead).
*/
function onCalendarClick(event: MouseEvent) {
const direction = findMonthNavDirection(event.target);
Iif (!direction) {
return;
}
Iif (props.isLoadingAppointments) {
event.preventDefault();
event.stopPropagation();
return;
}
if (direction === "prev" && props.prevBookableDate) {
event.preventDefault();
event.stopPropagation();
emit("jumpToBookableDate", props.prevBookableDate);
return;
}
if (direction === "next" && props.nextBookableDate) {
event.preventDefault();
event.stopPropagation();
emit("jumpToBookableDate", props.nextBookableDate);
}
}
async function snapToNearestForCurrentSelection() {
await nextTick();
// Hourly view: snap selectedHour to the nearest available hour if current is not available
if (props.timeSlotsInHoursByOffice.size > 0) {
const availableHours = Array.from(props.timeSlotsInHoursByOffice.values())
.flatMap((office) => Array.from((office as any).appointments.keys()))
.filter((hour): hour is number => typeof hour === "number");
Eif (
props.currentHour === null ||
!availableHours.includes(props.currentHour as number)
) {
if (availableHours.length > 0) {
const prevHour = props.currentHour ?? availableHours[0];
let nearest = availableHours[0];
let minDiff = Math.abs(prevHour - nearest);
for (const hour of availableHours) {
const diff = Math.abs(prevHour - hour);
if (diff < minDiff || (diff === minDiff && hour < nearest)) {
nearest = hour;
minDiff = diff;
}
}
// request parent to update
emit("setSelectedHour", nearest);
} else E{
emit("setSelectedHour", null);
}
}
}
// DayPart view: snap selectedDayPart if current is not available
else Eif (props.timeSlotsInDayPartByOffice.size > 0) {
const availableDayParts = Array.from(
props.timeSlotsInDayPartByOffice.values()
)
.flatMap((office) => Array.from((office as any).appointments.keys()))
.filter((part): part is "am" | "pm" => part === "am" || part === "pm");
if (
!props.currentDayPart ||
!availableDayParts.includes(props.currentDayPart as "am" | "pm")
) {
let newPart: "am" | "pm" | null = null;
if (props.currentDayPart === "am" && availableDayParts.includes("pm")) {
newPart = "pm";
} else if (
props.currentDayPart === "pm" &&
availableDayParts.includes("am")
) {
newPart = "am";
} else if (availableDayParts.length > 0) {
newPart = availableDayParts[0];
}
emit("setSelectedDayPart", newPart);
}
}
}
defineExpose({ snapToNearest: snapToNearestForCurrentSelection });
function getAvailableHours(): number[] {
const hourSet = new Set<number>();
for (const [, office] of props.timeSlotsInHoursByOffice) {
for (const hour of office.appointments.keys()) {
if ((office.appointments.get(hour) || []).length > 0) {
hourSet.add(hour);
}
}
}
return Array.from(hourSet).sort((a, b) => a - b);
}
function onEarlier(type: "hour" | "dayPart") {
Eif (type === "dayPart") {
Eif (props.currentDayPart === "pm") emit("setSelectedDayPart", "am");
return;
}
const hours = getAvailableHours();
const current = props.currentHour;
if (current === null) return;
const idx = hours.indexOf(current);
if (idx > 0) emit("setSelectedHour", hours[idx - 1]);
}
function onLater(type: "hour" | "dayPart") {
if (type === "dayPart") {
if (props.currentDayPart === "am") emit("setSelectedDayPart", "pm");
return;
}
const hours = getAvailableHours();
const current = props.currentHour;
if (current === null) return;
const idx = hours.indexOf(current);
if (idx >= 0 && idx < hours.length - 1)
emit("setSelectedHour", hours[idx + 1]);
}
</script>
<style lang="scss" scoped>
@use "@/styles/style.scss";
.m-button--ghost.disabled,
.m-button--ghost:disabled {
background: #fff;
border-color: #fff;
}
.disabled {
opacity: 0.6;
cursor: not-allowed;
}
.float-right {
margin-left: auto;
margin-right: 0 !important;
}
.m-button-group {
margin-bottom: 20px;
padding-bottom: 0;
padding-top: 30px;
}
/* Ensure consistent width for earlier/later buttons */
.m-button-group .muc-button[icon-shown-left],
.m-button-group .muc-button[icon-shown-right] {
min-width: 100px !important;
}
.m-button-group button .m-button__icon--before,
.m-button-group button .m-button__icon--after {
min-width: 100px !important;
}
.m-button-group button:has(.m-button__icon--before),
.m-button-group button:has(.m-button__icon--after) {
min-width: 100px !important;
}
/* Remove focus effects from navigation buttons */
.m-button-group button:focus {
outline: none !important;
box-shadow: none !important;
border: none !important;
}
.m-button-group button:focus-visible {
outline: none !important;
box-shadow: none !important;
}
.no-top-margin,
.no-top-margin h3 {
margin-top: 0 !important;
}
.calendar-root
:deep(
.container-wrapper:has(
.muc-calendar-view-full-size
> .muc-calendar-container:nth-of-type(2)
> :nth-child(36)
/* :nth-child(36) checks whether the day grid has at least 36 direct children.
With 7 columns, 35 items fit into 5 rows; the 36th item means a 6th row is needed,
so we increase the calendar height only for 6-week months. */
)
.container-view-size
) {
--cal-container-view-height: 336px !important;
height: var(--cal-container-view-height) !important;
min-height: var(--cal-container-view-height) !important;
}
</style>
|