EventParams.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!--
  2. Event parameters page in the create dialog
  3. -->
  4. <template>
  5. <v-container class="pa-4">
  6. <v-row class="align-center">
  7. <v-col cols="2">
  8. <span>{{ $t('start_on') }}</span>
  9. </v-col>
  10. <v-col cols="6">
  11. <UiDatePicker v-model="eventStart" with-time />
  12. </v-col>
  13. </v-row>
  14. <v-row v-show="eventStart < now" class="anteriorDateWarning mt-0">
  15. <v-col cols="2" class="pt-1"></v-col>
  16. <v-col cols="9" class="pt-1">
  17. <i class="fa fa-circle-info" /> {{ $t('please_note_that_this_reservation_start_on_date_anterior_to_now') }}
  18. </v-col>
  19. </v-row>
  20. <v-row class="align-center">
  21. <v-col cols="2">
  22. <span>{{ $t('for_time') }}</span>
  23. </v-col>
  24. <v-col cols="10" class="d-flex flex-row align-center">
  25. <UiInputNumber v-model="eventDurationDays" class="mx-3" :min="0" />
  26. <span>{{ $t('day(s)') }}</span>
  27. <UiInputNumber v-model="eventDurationHours" class="mx-3" :min="0" />
  28. <span>{{ $t('hour(s)') }}</span>
  29. <UiInputNumber v-model="eventDurationMinutes" class="mx-3" :min="0" />
  30. <span>{{ $t('minute(s)') }}</span>
  31. </v-col>
  32. </v-row>
  33. <v-row>
  34. <v-col cols="2">
  35. <span>{{ $t('ending_date') }}</span>
  36. </v-col>
  37. <v-col cols="6" class="endDate">
  38. <span>{{ formattedEventEnd }}</span>
  39. </v-col>
  40. </v-row>
  41. </v-container>
  42. </template>
  43. <script setup lang="ts">
  44. import {ref, Ref} from "@vue/reactivity";
  45. import {add, format, startOfHour, formatISO} from "date-fns";
  46. import {ComputedRef} from "vue";
  47. import DateUtils, {supportedLocales} from "~/services/utils/dateUtils";
  48. const i18n = useI18n()
  49. // An event is sent each time the resulting params are updated
  50. const emit = defineEmits(['paramsUpdated'])
  51. // Get the start of the next hour as a default event start
  52. const now: Date = new Date()
  53. const eventStart: Ref<Date> = ref(startOfHour(add(now, { 'hours': 1 })))
  54. const eventDurationDays: Ref<number> = ref(0)
  55. const eventDurationHours: Ref<number> = ref(1)
  56. const eventDurationMinutes: Ref<number> = ref(0)
  57. // Duration of the events, in minutes
  58. const eventDuration: ComputedRef<number> = computed(() => {
  59. return (eventDurationDays.value * 24 * 60) + (eventDurationHours.value * 60) + eventDurationMinutes.value
  60. })
  61. // Event end
  62. const eventEnd: ComputedRef<Date> = computed(() => add(eventStart.value, { 'minutes': eventDuration.value }))
  63. const fnsLocale = DateUtils.getFnsLocale(i18n.locale.value as supportedLocales)
  64. const formattedEventEnd: ComputedRef<string> = computed(() => {
  65. return format(eventEnd.value, 'EEEE dd MMMM yyyy HH:mm', {locale: fnsLocale})
  66. })
  67. // Build the event params
  68. const params: ComputedRef<{'start': string, 'end': string}> = computed(() => {
  69. return {
  70. 'start': formatISO(eventStart.value),
  71. 'end': formatISO(eventEnd.value),
  72. }
  73. })
  74. // Send an update event as soon as the page is mounted
  75. onMounted(() => {
  76. emit('paramsUpdated', params.value)
  77. })
  78. // Send an update event every time the params change
  79. const unwatch = watch(params, (newParams) => {
  80. emit('paramsUpdated', newParams)
  81. })
  82. onUnmounted(() => {
  83. unwatch()
  84. })
  85. </script>
  86. <style scoped lang="scss">
  87. .endDate {
  88. font-weight: 600;
  89. text-transform: capitalize;
  90. color: rgb(var(--v-theme-on-neutral));
  91. }
  92. .anteriorDateWarning {
  93. color: rgb(var(--v-theme-info));
  94. font-weight: 600;
  95. }
  96. </style>