All files / src/components/Appointment/AppointmentSelection AppointmentPreview.vue

100% Statements 19/19
95.83% Branches 23/24
100% Functions 7/7
100% Lines 19/19

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  233x                                                               6x     4x                                           6x                                           102x               102x   102x   102x       102x 6x           102x 6x 6x     102x   6x       102x 2x     102x 2x      
<template>
  <div
    aria-live="polite"
    ref="summary"
  >
    <muc-callout
      v-if="
        selectedProvider &&
        selectedDay &&
        typeof selectedTimeslot === 'number' &&
        selectedTimeslot > 0
      "
      type="info"
    >
      <template #content>
        <div v-if="selectedProvider">
          <h3>{{ t("location") }}</h3>
          <p
            :id="`provider-${selectedProvider.id}`"
            class="m-teaser-contained-contact__summary"
          >
            <span v-if="isTelephoneOrVideoVariant">
              {{
                getVariant(variantId, selectedService?.variantOverwrite)?.name
              }}
            </span>
            <span v-else>
              {{ selectedProvider.name }}
              <br />
              {{ selectedProvider.address.street }}
              {{ selectedProvider.address.house_number }}
            </span>
          </p>
        </div>
        <div v-if="selectedDay">
          <h3>{{ t("time") }}</h3>
          <p class="m-teaser-contained-contact__detail">
            {{ formatDayFromDate(selectedDay) }},
            {{ formatTimeFromUnix(selectedTimeslot) }}
            {{ t("clock") }}
            <br />
            {{ t("estimatedDuration") }} {{ localEstimatedDuration }}
            {{ t("minutes") }}
          </p>
        </div>
        <div
          v-if="
            selectedProvider.scope && selectedProvider.scope.infoForAppointment
          "
        >
          <h3>{{ t("hint") }}</h3>
          <component
            :is="infoForAppointmentContainsPTag ? 'div' : 'p'"
            v-html="sanitizedInfoForAppointment"
          />
        </div>
      </template>
 
      <template #header>{{ t("selectedAppointment") }}</template>
    </muc-callout>
  </div>
</template>
 
<script setup lang="ts">
import type { OfficeImpl } from "@/types/OfficeImpl";
 
import { MucCallout } from "@muenchen/muc-patternlab-vue";
import { computed, ref } from "vue";
 
// Calculate duration locally
import { calculateEstimatedDuration } from "@/utils/calculateEstimatedDuration";
import { VARIANT_ID_TELEPHONE, VARIANT_ID_VIDEO } from "@/utils/Constants";
import { containsParagraphTag } from "@/utils/containsParagraphTag";
import {
  formatDayFromDate,
  formatTimeFromUnix,
} from "@/utils/formatAppointmentDateTime";
import { sanitizeHtml } from "@/utils/sanitizeHtml";
import { useVariant } from "@/utils/useVariant";
 
const props = defineProps<{
  t: (key: string) => string;
  selectedProvider: OfficeImpl | null | undefined;
  selectedDay: Date | undefined;
  selectedTimeslot: number;
  selectedService: any;
}>();
 
const getVariant = useVariant(props.t);
 
const summary = ref<HTMLElement | null>(null);
 
defineExpose({
  summary,
});
 
const localEstimatedDuration = computed(() =>
  calculateEstimatedDuration(
    props.selectedService,
    (props.selectedProvider ?? undefined) as OfficeImpl | undefined
  )
);
 
const variantId = computed<number | null>(() => {
  const id = (props.selectedService as any)?.variantId;
  return Number.isFinite(id) ? id : null;
});
 
const isTelephoneOrVideoVariant = computed(
  () =>
    variantId.value === VARIANT_ID_TELEPHONE ||
    variantId.value === VARIANT_ID_VIDEO
);
 
const sanitizedInfoForAppointment = computed(() =>
  sanitizeHtml(props.selectedProvider?.scope?.infoForAppointment)
);
 
const infoForAppointmentContainsPTag = computed(() =>
  containsParagraphTag(sanitizedInfoForAppointment.value)
);
</script>