EventParams.vue 3.3 KB

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