All files / components/AppointmentOverview AppointmentCard.vue

97.29% Statements 36/37
90.9% Branches 20/22
100% Functions 11/11
97.29% Lines 36/37

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  10x                   10x     4x       10x                                                                 10x               10x 8x 8x       10x 10x 8x       10x 10x     10x 10x 1x     9x 1x     8x     10x 10x 1x     9x 1x     8x     10x 10x 1x     9x 1x     8x               10x 10x 10x       10x           10x                  
<template>
  <muc-card
    class="multiline-text"
    :tagline="appointmentTypeLabel"
    :title="formatMultilineTitle(appointment)"
    :href="getAppointmentLink()"
  >
    <template #headerPrefix>
      <calendar-icon
        :timestamp="appointment.timestamp"
        aria-hidden="true"
      />
    </template>
    <template #content>
      <p class="m-teaser-contained-contact__detail">
        <muc-icon icon="calendar" />
        {{ formatAppointmentDateTime(appointment.timestamp) }}
        {{ t("timeStampSuffix") }} <br />
      </p>
      <p
        data-test="appointment-location"
        class="m-teaser-contained-contact__detail"
      >
        <muc-icon :icon="locationIcon" />
        {{ locationText }}
      </p>
      <strong>{{ t("appointmentNumber") }}:</strong>
      {{ appointment.displayNumber ?? appointment.processId }}
    </template>
  </muc-card>
</template>
 
<script setup lang="ts">
import { MucCard, MucIcon } from "@muenchen/muc-patternlab-vue";
import { computed } from "vue";
 
import { AppointmentDTO } from "@/api/models/AppointmentDTO";
import { Office } from "@/api/models/Office";
import { Service } from "@/api/models/Service";
import CalendarIcon from "@/components/Common/CalendarIcon.vue";
import {
  QUERY_PARAM_APPOINTMENT_DISPLAY_NUMBER,
  QUERY_PARAM_APPOINTMENT_ID,
  resolveAgainstCurrentPage,
  VARIANT_ID_PRESENCE,
  VARIANT_ID_TELEPHONE,
  VARIANT_ID_VIDEO,
} from "@/utils/Constants";
import { formatAppointmentDateTime } from "@/utils/formatAppointmentDateTime";
import { formatMultilineTitle } from "@/utils/formatMultilineTitle";
 
const props = defineProps<{
  appointment: AppointmentDTO;
  appointmentDetailUrl: string;
  offices: Office[];
  services: Service[];
  t: (key: string) => string;
}>();
 
const selectedProvider = computed<Office | undefined>(() =>
  props.offices.find(
    (office) => String(office.id) === String(props.appointment.officeId)
  )
);
 
const selectedService = computed<Service | undefined>(() =>
  props.services.find(
    (service) => String(service.id) === String(props.appointment.serviceId)
  )
);
 
const variantId = computed<number | null>(
  () => selectedService.value?.variantId ?? null
);
 
const appointmentTypeLabel = computed<string>(() => {
  if (variantId.value === VARIANT_ID_TELEPHONE) {
    return props.t(`appointmentTypes.${VARIANT_ID_TELEPHONE}`);
  }
 
  if (variantId.value === VARIANT_ID_VIDEO) {
    return props.t(`appointmentTypes.${VARIANT_ID_VIDEO}`);
  }
 
  return props.t(`appointmentTypes.${VARIANT_ID_PRESENCE}`);
});
 
const locationIcon = computed<string>(() => {
  if (variantId.value === VARIANT_ID_TELEPHONE) {
    return "telephone";
  }
 
  if (variantId.value === VARIANT_ID_VIDEO) {
    return "video-camera";
  }
 
  return "map-pin";
});
 
const locationText = computed<string>(() => {
  if (variantId.value === VARIANT_ID_TELEPHONE) {
    return props.appointment.telephone ?? "";
  }
 
  if (variantId.value === VARIANT_ID_VIDEO) {
    return props.t("appointmentDetailVideoIntroLocation");
  }
 
  return [
    selectedProvider.value?.address.street,
    selectedProvider.value?.address.house_number,
  ]
    .filter(Boolean)
    .join(" ");
});
 
const getAppointmentLink = () => {
  const url = resolveAgainstCurrentPage(props.appointmentDetailUrl);
  url.searchParams.set(
    QUERY_PARAM_APPOINTMENT_ID,
    props.appointment.processId!
  );
  Iif (props.appointment.displayNumber) {
    url.searchParams.set(
      QUERY_PARAM_APPOINTMENT_DISPLAY_NUMBER,
      props.appointment.displayNumber
    );
  }
  return url.toString();
};
</script>
 
<style scoped>
.multiline-text {
  white-space: pre-wrap;
}
</style>