EventParams.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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"/>
  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 type { supportedLocales } from '~/services/utils/dateUtils';
  51. import DateUtils from '~/services/utils/dateUtils'
  52. const i18n = useI18n()
  53. // An event is sent each time the resulting params are updated
  54. const emit = defineEmits(['paramsUpdated'])
  55. // Get the start of the next hour as a default event start
  56. const now: Date = new Date()
  57. const eventStart: Ref<Date> = ref(startOfHour(add(now, { hours: 1 })))
  58. const eventDurationDays: Ref<number> = ref(0)
  59. const eventDurationHours: Ref<number> = ref(1)
  60. const eventDurationMinutes: Ref<number> = ref(0)
  61. // Duration of the events, in minutes
  62. const eventDuration: ComputedRef<number> = computed(() => {
  63. return (
  64. eventDurationDays.value * 24 * 60 +
  65. eventDurationHours.value * 60 +
  66. eventDurationMinutes.value
  67. )
  68. })
  69. // Event end
  70. const eventEnd: ComputedRef<Date> = computed(() =>
  71. add(eventStart.value, { minutes: eventDuration.value }),
  72. )
  73. const fnsLocale = DateUtils.getFnsLocale(i18n.locale.value as supportedLocales)
  74. const formattedEventEnd: ComputedRef<string> = computed(() => {
  75. return format(eventEnd.value, 'EEEE dd MMMM yyyy HH:mm', {
  76. locale: fnsLocale,
  77. })
  78. })
  79. // Build the event params
  80. const params: ComputedRef<{ start: string; end: string }> = computed(() => {
  81. return {
  82. start: formatISO(eventStart.value),
  83. end: formatISO(eventEnd.value),
  84. }
  85. })
  86. // Send an update event as soon as the page is mounted
  87. onMounted(() => {
  88. emit('paramsUpdated', params.value)
  89. })
  90. // Send an update event every time the params change
  91. const unwatch = watch(params, (newParams) => {
  92. emit('paramsUpdated', newParams)
  93. })
  94. onUnmounted(() => {
  95. unwatch()
  96. })
  97. </script>
  98. <style scoped lang="scss">
  99. .endDate {
  100. font-weight: 600;
  101. text-transform: capitalize;
  102. color: rgb(var(--v-theme-on-neutral));
  103. }
  104. .anteriorDateWarning {
  105. color: rgb(var(--v-theme-info));
  106. font-weight: 600;
  107. }
  108. </style>