From 6665c17f0b7838caba1e0a012f90b69d0a769777 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 6 Oct 2021 14:47:03 +0200 Subject: [PATCH] feat: Global Catch of Publisher ID to Store --- frontend/src/main.js | 5 +++++ frontend/src/store/store.js | 3 +++ frontend/src/store/store.test.js | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/frontend/src/main.js b/frontend/src/main.js index ba7015049..32a15103e 100755 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -50,6 +50,11 @@ Vue.config.productionTip = false loadAllRules(i18n) router.beforeEach((to, from, next) => { + const publisherId = to.query.pid + if (publisherId) { + store.commit('publisherId', publisherId) + to.query.pid = undefined + } if (to.meta.requiresAuth && !store.state.token) { next({ path: '/login' }) } else { diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 5bb55c9d8..cfaafec1e 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -29,6 +29,9 @@ export const mutations = { newsletterState: (state, newsletterState) => { state.newsletterState = newsletterState }, + publisherId: (state, publisherId) => { + state.publisherId = publisherId + }, } export const actions = { diff --git a/frontend/src/store/store.test.js b/frontend/src/store/store.test.js index 7ae3344d9..f40f25d92 100644 --- a/frontend/src/store/store.test.js +++ b/frontend/src/store/store.test.js @@ -9,6 +9,7 @@ const { lastName, description, newsletterState, + publisherId, } = mutations const { login, logout } = actions @@ -77,6 +78,14 @@ describe('Vuex store', () => { expect(state.newsletterState).toEqual(true) }) }) + + describe('publisherId', () => { + it('sets the state of publisherId', () => { + const state = {} + publisherId(state, 42) + expect(state.publisherId).toEqual(42) + }) + }) }) describe('actions', () => {