From efa0296c1dd310a19ea406541f93d1881b7a9262 Mon Sep 17 00:00:00 2001 From: Jonathan Chevalier Date: Thu, 29 Sep 2022 16:20:16 +0200 Subject: [PATCH] WIP MMCM --- src/router/guards/piniaCheck.js | 20 ++++++++++++++++++++ src/router/index.js | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/router/guards/piniaCheck.js diff --git a/src/router/guards/piniaCheck.js b/src/router/guards/piniaCheck.js new file mode 100644 index 0000000..0f132ac --- /dev/null +++ b/src/router/guards/piniaCheck.js @@ -0,0 +1,20 @@ +import {useMMCMStore} from '../../stores/mmcm.js' + +export default function (routeTo) { + + const store = useMMCMStore() + + if (routeTo.path === '/delivery-option-step-1') { + return store.street !== '' && store.city !== '' && store.zipCode !== ''; + + } else if (routeTo.path === '/delivery-option-step-2') { + return store.withPrescription !== null + + } else if (routeTo.path === '/delivery-option-step-3') { + return store.idProduct !== null + } else if (routeTo.path === '/delivery-option-summary') { + return store.dateDelivery !== null + } else { + return true + } +} diff --git a/src/router/index.js b/src/router/index.js index e2fc364..14a8085 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,5 +1,7 @@ import {createRouter, createWebHistory} from 'vue-router' +import piniaCheck from "./guards/piniaCheck.js"; + const routes = [ { path: '/', @@ -38,4 +40,16 @@ const router = createRouter({ routes, }) +router.beforeEach(async (to, from) => { + // canUserAccess() returns `true` or `false` + + if (from.path === '/' || to.path === '/') { + return true + } + + const canAccessStep = piniaCheck(to) + if (!canAccessStep) return from.path + +}) + export default router