CalendarEventHandler.vue
8.38 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<script setup>
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
import { VForm } from 'vuetify/components/VForm'
import { useCalendarStore } from './useCalendarStore'
import avatar1 from '@images/avatars/avatar-1.png'
import avatar2 from '@images/avatars/avatar-2.png'
import avatar3 from '@images/avatars/avatar-3.png'
import avatar5 from '@images/avatars/avatar-5.png'
import avatar6 from '@images/avatars/avatar-6.png'
import avatar7 from '@images/avatars/avatar-7.png'
// 👉 store
const props = defineProps({
isDrawerOpen: {
type: Boolean,
required: true,
},
event: {
type: null,
required: true,
},
})
const emit = defineEmits([
'update:isDrawerOpen',
'addEvent',
'updateEvent',
'removeEvent',
])
const store = useCalendarStore()
const refForm = ref()
// 👉 Event
const event = ref(JSON.parse(JSON.stringify(props.event)))
const resetEvent = () => {
event.value = JSON.parse(JSON.stringify(props.event))
nextTick(() => {
refForm.value?.resetValidation()
})
}
watch(() => props.isDrawerOpen, resetEvent)
const removeEvent = () => {
emit('removeEvent', String(event.value.id))
// Close drawer
emit('update:isDrawerOpen', false)
}
const handleSubmit = () => {
refForm.value?.validate().then(({ valid }) => {
if (valid) {
// If id exist on id => Update event
if ('id' in event.value)
emit('updateEvent', event.value)
// Else => add new event
else
emit('addEvent', event.value)
// Close drawer
emit('update:isDrawerOpen', false)
}
})
}
const guestsOptions = [
{
avatar: avatar1,
name: 'Jane Foster',
},
{
avatar: avatar3,
name: 'Donna Frank',
},
{
avatar: avatar5,
name: 'Gabrielle Robertson',
},
{
avatar: avatar7,
name: 'Lori Spears',
},
{
avatar: avatar6,
name: 'Sandy Vega',
},
{
avatar: avatar2,
name: 'Cheryl May',
},
]
// 👉 Form
const onCancel = () => {
// Close drawer
emit('update:isDrawerOpen', false)
nextTick(() => {
refForm.value?.reset()
resetEvent()
refForm.value?.resetValidation()
})
}
const startDateTimePickerConfig = computed(() => {
const config = {
enableTime: !event.value.allDay,
dateFormat: `Y-m-d${ event.value.allDay ? '' : ' H:i' }`,
}
if (event.value.end)
config.maxDate = event.value.end
return config
})
const endDateTimePickerConfig = computed(() => {
const config = {
enableTime: !event.value.allDay,
dateFormat: `Y-m-d${ event.value.allDay ? '' : ' H:i' }`,
}
if (event.value.start)
config.minDate = event.value.start
return config
})
const dialogModelValueUpdate = val => {
emit('update:isDrawerOpen', val)
}
</script>
<template>
<VNavigationDrawer
temporary
location="end"
:model-value="props.isDrawerOpen"
width="420"
class="scrollable-content"
@update:model-value="dialogModelValueUpdate"
>
<!-- 👉 Header -->
<AppDrawerHeaderSection
:title="event.id ? 'Update Event' : 'Add Event'"
@cancel="$emit('update:isDrawerOpen', false)"
>
<template #beforeClose>
<IconBtn
v-show="event.id"
@click="removeEvent"
>
<VIcon
size="18"
icon="ri-delete-bin-7-line"
/>
</IconBtn>
</template>
</AppDrawerHeaderSection>
<VDivider />
<PerfectScrollbar :options="{ wheelPropagation: false }">
<VCard flat>
<VCardText>
<!-- SECTION Form -->
<VForm
ref="refForm"
@submit.prevent="handleSubmit"
>
<VRow>
<!-- 👉 Title -->
<VCol cols="12">
<VTextField
v-model="event.title"
label="Title"
placeholder="Meeting with Jane"
:rules="[requiredValidator]"
/>
</VCol>
<!-- 👉 Calendar -->
<VCol cols="12">
<VSelect
v-model="event.extendedProps.calendar"
label="Label"
placeholder="Select Event Label"
:rules="[requiredValidator]"
:items="store.availableCalendars"
:item-title="item => item.label"
:item-value="item => item.label"
>
<template #selection="{ item }">
<div
v-show="event.extendedProps.calendar"
class="align-center"
:class="event.extendedProps.calendar ? 'd-flex' : ''"
>
<VIcon
size="8"
icon="ri-circle-fill"
:color="item.raw.color"
class="me-2"
/>
<span>{{ item.raw.label }}</span>
</div>
</template>
<template #item="{ item, props: itemProps }">
<VListItem v-bind="itemProps">
<template #prepend>
<VIcon
size="8"
icon="ri-circle-fill"
:color="item.raw.color"
/>
</template>
</VListItem>
</template>
</VSelect>
</VCol>
<!-- 👉 Start date -->
<VCol cols="12">
<AppDateTimePicker
:key="JSON.stringify(startDateTimePickerConfig)"
v-model="event.start"
:rules="[requiredValidator]"
label="Start date"
placeholder="Select Date"
:config="startDateTimePickerConfig"
/>
</VCol>
<!-- 👉 End date -->
<VCol cols="12">
<AppDateTimePicker
:key="JSON.stringify(endDateTimePickerConfig)"
v-model="event.end"
:rules="[requiredValidator]"
label="End date"
placeholder="Select End Date"
:config="endDateTimePickerConfig"
/>
</VCol>
<!-- 👉 All day -->
<VCol cols="12">
<VSwitch
v-model="event.allDay"
label="All day"
/>
</VCol>
<!-- 👉 Event URL -->
<VCol cols="12">
<VTextField
v-model="event.url"
label="Event URL"
placeholder="https://event.com/meeting"
:rules="[urlValidator]"
type="url"
/>
</VCol>
<!-- 👉 Guests -->
<VCol cols="12">
<VSelect
v-model="event.extendedProps.guests"
label="Guests"
placeholder="Select guests"
:items="guestsOptions"
:item-title="item => item.name"
:item-value="item => item.name"
chips
multiple
eager
/>
</VCol>
<!-- 👉 Location -->
<VCol cols="12">
<VTextField
v-model="event.extendedProps.location"
label="Location"
placeholder="Meeting room"
/>
</VCol>
<!-- 👉 Description -->
<VCol cols="12">
<VTextarea
v-model="event.extendedProps.description"
label="Description"
placeholder="Meeting description"
/>
</VCol>
<!-- 👉 Form buttons -->
<VCol cols="12">
<VBtn
type="submit"
class="me-3"
>
Submit
</VBtn>
<VBtn
variant="outlined"
color="secondary"
@click="onCancel"
>
Cancel
</VBtn>
</VCol>
</VRow>
</VForm>
<!-- !SECTION -->
</VCardText>
</VCard>
</PerfectScrollbar>
</VNavigationDrawer>
</template>