From 668b6005f0ce55f1c9c8d2cdcdf48903d6207dc7 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 21 Mar 2021 19:44:08 +0100 Subject: api: update and delete reservations --- resources/js/store.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'resources') diff --git a/resources/js/store.js b/resources/js/store.js index e0c4383..117db93 100644 --- a/resources/js/store.js +++ b/resources/js/store.js @@ -65,13 +65,32 @@ export default new Vuex.Store({ }); }, async pushReservation(context, data) { - context.commit('setDataRow', { - index: data.index, - data: data.reservation + await axios.post('/api/reservations', { + action: 'update', + ...data.reservation + }).then(() => { + context.commit('setDataRow', { + index: data.index, + data: data.reservation + }); + }).catch(error => { + console.log(error); + alert("Couldn't update reservation! Bad data!"); }); }, async removeReservation(context, index) { - context.commit('removeDataRow', index); + let data = { + action: 'delete', + ...this.state.data[index] + }; + if (confirm(`Are you sure you want to delete reservation #${data.id} made by ${data.operatorCall}?`) === true) { + await axios.post('/api/reservations', data).then(() => { + context.commit('removeDataRow', index); + }).catch(error => { + console.log(error); + alert('Unable to remove reservation!'); + }); + } } } }); -- cgit v1.2.3