From 2376e26dc970e9bd90cd6cedb019860f5a5b1936 Mon Sep 17 00:00:00 2001 From: Mateja Date: Fri, 30 Jul 2021 01:51:25 +0200 Subject: Added Orders page for users to see their purchases. --- client/src/store/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'client/src/store') diff --git a/client/src/store/index.js b/client/src/store/index.js index 47f8f47..8d74c5a 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -7,7 +7,8 @@ export default createStore({ currentProduct: {}, cart: [], token: localStorage.getItem('token') || '', - isAdmin: localStorage.getItem('isAdmin') === 'true' + isAdmin: localStorage.getItem('isAdmin') === 'true', + userOrders: [] }, getters: { getProducts(state) { @@ -45,6 +46,9 @@ export default createStore({ }, isAdmin(state) { return state.isAdmin; + }, + getUserOrders(state) { + return state.userOrders; } }, mutations: { @@ -90,6 +94,9 @@ export default createStore({ localStorage.removeItem('token'); localStorage.removeItem('isAdmin'); delete axios.defaults.headers.common['Authorization']; + }, + setUserOrders(state, orders) { + state.userOrders = orders; } }, actions: { @@ -138,6 +145,16 @@ export default createStore({ }) .catch(error => reject(error)); }); + }, + pullUserOrders(context) { + return new Promise((resolve, reject) => { + axios.get(`${process.env.VUE_APP_ROOT_API}/transactions/personal`) + .then(response => { + context.commit('setUserOrders', response.data); + resolve(response); + }) + .catch(error => reject(error)); + }); } }, modules: { -- cgit v1.2.3