From dffd3531fa16d40a9da610e3ed0ee421e8e9e5ef Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 2 Nov 2024 22:12:00 +0100 Subject: [PATCH] add form to create new event --- web/src/App.vue | 12 ++-- web/src/components/AddEventModal.vue | 86 ++++++++++++++++++++++++++++ web/src/store.js | 19 ++++++ web/src/utils.js | 4 +- web/src/views/admin/Events.vue | 22 +++++-- 5 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 web/src/components/AddEventModal.vue diff --git a/web/src/App.vue b/web/src/App.vue index 83a3bb2..bd4956f 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,10 +1,11 @@ @@ -14,12 +15,13 @@ import AddItemModal from '@/components/AddItemModal'; import {mapState, mapMutations, mapActions, mapGetters} from 'vuex'; import AddTicketModal from "@/components/AddTicketModal.vue"; import AddBoxModal from "@/components/AddBoxModal.vue"; +import AddEventModal from "@/components/AddEventModal.vue"; export default { name: 'app', - components: {AddBoxModal, Navbar, AddItemModal, AddTicketModal}, + components: {AddBoxModal, AddEventModal, Navbar, AddItemModal, AddTicketModal}, computed: { - ...mapState(['loadedItems', 'layout', 'toasts', 'showAddBoxModal']), + ...mapState(['loadedItems', 'layout', 'toasts', 'showAddBoxModal', 'showAddEventModal']), ...mapGetters(['isLoggedIn']), }, data: () => ({ @@ -27,7 +29,7 @@ export default { addTicketModalOpen: false }), methods: { - ...mapMutations(['removeToast', 'createToast', 'closeAddBoxModal', 'openAddBoxModal']), + ...mapMutations(['removeToast', 'createToast', 'closeAddBoxModal', 'openAddBoxModal', 'closeAddEventModal']), ...mapActions(['loadEvents', 'scheduleAfterInit']), openAddItemModal() { this.addItemModalOpen = true; diff --git a/web/src/components/AddEventModal.vue b/web/src/components/AddEventModal.vue new file mode 100644 index 0000000..ed25265 --- /dev/null +++ b/web/src/components/AddEventModal.vue @@ -0,0 +1,86 @@ + + + + + \ No newline at end of file diff --git a/web/src/store.js b/web/src/store.js index e07c9e0..6cef8c6 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -48,6 +48,7 @@ const store = createStore({ afterInitHandlers: [], showAddBoxModal: false, + showAddEventModal: false, shippingVoucherTypes: { '2kg-de': '2kg Paket (DE)', @@ -172,6 +173,12 @@ const store = createStore({ closeAddBoxModal(state) { state.showAddBoxModal = false; }, + openAddEventModal(state) { + state.showAddEventModal = true; + }, + closeAddEventModal(state) { + state.showAddEventModal = false; + }, createToast(state, {title, message, color}) { var toast = {title, message, color, key: state.keyIncrement} state.toasts.push(toast); @@ -300,6 +307,18 @@ const store = createStore({ if (data && success) commit('replaceEvents', data); }, + async createEvent({commit, dispatch, state}, event) { + const {data, success} = await http.post('/2/events/', event, state.user.token); + if (data && success) + commit('replaceEvents', [...state.events, data]); + }, + async deleteEvent({commit, dispatch, state}, event_id) { + const {data, success} = await http.delete(`/2/events/${event_id}/`, state.user.token); + if (success) { + await dispatch('loadEvents') + commit('replaceEvents', [...state.events.filter(e => e.eid !== event_id)]) + } + }, async fetchTicketStates({commit, state}) { if (!state.user.token) return; if (state.fetchedData.states > Date.now() - 1000 * 60 * 60 * 24) return; diff --git a/web/src/utils.js b/web/src/utils.js index 6e9d8e4..5910521 100644 --- a/web/src/utils.js +++ b/web/src/utils.js @@ -95,8 +95,8 @@ const http = { "Authorization": `Token ${token}`, }, }); - const success = response.status === 200 || response.status === 201; - return {data: await response.json() || {}, success}; + const success = response.status === 204; + return {data: await response.text() || {}, success}; } } diff --git a/web/src/views/admin/Events.vue b/web/src/views/admin/Events.vue index 36fd5ca..1aab608 100644 --- a/web/src/views/admin/Events.vue +++ b/web/src/views/admin/Events.vue @@ -4,13 +4,19 @@ :items="events" :keyName="'slug'" > -