EventParams.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <v-container class="pa-4">
  3. <v-row class="align-center">
  4. <v-col cols="2">
  5. <span>{{ $t('start_on') }}</span>
  6. </v-col>
  7. <v-col cols="6">
  8. <!-- @see https://vue3datepicker.com/props/modes/#multi-calendars -->
  9. <!-- TODO: déplacer le VueDatePicker dans un composant Input -->
  10. <VueDatePicker
  11. v-model="eventStart"
  12. :locale="i18n.locale.value"
  13. :format-locale="fnsLocale"
  14. :format="dateFormatPattern"
  15. enable-time-picker
  16. :teleport="true"
  17. text-input
  18. :auto-apply="true"
  19. :select-text="$t('select')"
  20. :cancel-text="$t('cancel')"
  21. @update:model-value="onUpdate"
  22. />
  23. </v-col>
  24. </v-row>
  25. <v-row v-show="eventStart < now" class="anteriorDateWarning mt-0">
  26. <v-col cols="2" class="pt-1"></v-col>
  27. <v-col cols="9" class="pt-1">
  28. <i class="fa fa-circle-info" /> {{ $t('please_note_that_this_reservation_start_on_date_anterior_to_now') }}
  29. </v-col>
  30. </v-row>
  31. <v-row class="align-center">
  32. <v-col cols="2">
  33. <span>{{ $t('for_time') }}</span>
  34. </v-col>
  35. <v-col cols="10" class="d-flex flex-row align-center">
  36. <UiInputNumber v-model="eventDurationDays" class="mx-3" :min="0" @update:model-value="onUpdate" />
  37. <span>{{ $t('day(s)') }}</span>
  38. <UiInputNumber v-model="eventDurationHours" class="mx-3" :min="0" @update:model-value="onUpdate" />
  39. <span>{{ $t('hour(s)') }}</span>
  40. <UiInputNumber v-model="eventDurationMinutes" class="mx-3" :min="0" @update:model-value="onUpdate" />
  41. <span>{{ $t('minute(s)') }}</span>
  42. </v-col>
  43. </v-row>
  44. <v-row>
  45. <v-col cols="2">
  46. <span>{{ $t('ending_date') }}</span>
  47. </v-col>
  48. <v-col cols="6" class="endDate">
  49. <span>{{ formattedEventEnd }}</span>
  50. </v-col>
  51. </v-row>
  52. </v-container>
  53. </template>
  54. <script setup lang="ts">
  55. const i18n = useI18n()
  56. // Get the start of the next hour as a default event start
  57. import {ref, Ref} from "@vue/reactivity";
  58. import {add, format, startOfHour, formatISO} from "date-fns";
  59. import {ComputedRef} from "vue";
  60. import DateUtils, {supportedLocales} from "~/services/utils/dateUtils";
  61. const now: Date = new Date()
  62. const eventStart: Ref<Date> = ref(startOfHour(add(now, { 'hours': 1 })))
  63. const eventDurationDays: Ref<number> = ref(0)
  64. const eventDurationHours: Ref<number> = ref(1)
  65. const eventDurationMinutes: Ref<number> = ref(0)
  66. // Duration of the events, in minutes
  67. const eventDuration: ComputedRef<number> = computed(() => {
  68. return (eventDurationDays.value * 24 * 60) + (eventDurationHours.value * 60) + eventDurationMinutes.value
  69. })
  70. const eventEnd: ComputedRef<Date> = computed(() => add(eventStart.value, { 'minutes': eventDuration.value }))
  71. const dateFormatPattern = DateUtils.getFormatPattern(i18n.locale.value as supportedLocales)
  72. // Date picker conf
  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', {locale: fnsLocale})
  76. })
  77. const emit = defineEmits(['paramsUpdated'])
  78. const onUpdate = () => {
  79. const params = {
  80. 'start': formatISO(eventStart.value),
  81. 'end': formatISO(eventEnd.value),
  82. }
  83. emit('paramsUpdated', params)
  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>