rdv: fullcalendar vue: use store and add an event on date select

This commit is contained in:
nobohan 2021-07-21 13:59:31 +02:00
parent f508971b6a
commit 0585455bbe
2 changed files with 22 additions and 2 deletions

View File

@ -29,6 +29,7 @@ const store = createStore({
strict: debug, strict: debug,
state: { state: {
activity: mapEntity(window.entity), activity: mapEntity(window.entity),
events: []
}, },
mutations: { mutations: {
@ -60,6 +61,11 @@ const store = createStore({
state.activity.users = state.activity.users.filter(user => user !== payload); state.activity.users = state.activity.users.filter(user => user !== payload);
break; break;
}; };
},
// Calendar
onDateSelect(state, payload) {
console.log(payload)
state.events.push( {start: payload.start, end: payload.end})
} }
}, },
actions: { actions: {
@ -98,6 +104,12 @@ const store = createStore({
break; break;
}; };
commit('removePersonInvolved', payload); commit('removePersonInvolved', payload);
},
// Calendar
onDateSelect({ commit }, payload) {
console.log('### action onDateSelect', payload);
commit('onDateSelect', payload);
} }
} }
}); });

View File

@ -1,4 +1,5 @@
<template> <template>
<h2 class="chill-red">{{ $t('choose_your_date') }}</h2>
<FullCalendar :options="calendarOptions" /> <FullCalendar :options="calendarOptions" />
</template> </template>
<script> <script>
@ -9,15 +10,22 @@ import interactionPlugin from '@fullcalendar/interaction'
export default { export default {
components: { components: {
FullCalendar // make the <FullCalendar> tag available FullCalendar
}, },
data() { data() {
return { return {
calendarOptions: { calendarOptions: {
plugins: [ dayGridPlugin, interactionPlugin ], plugins: [ dayGridPlugin, interactionPlugin ],
initialView: 'dayGridMonth' initialView: 'dayGridMonth',
selectable: true,
select: this.onDateSelect
} }
} }
},
methods: {
onDateSelect(payload) {
this.$store.dispatch('onDateSelect', payload);
}
} }
} }
</script> </script>