From f09eb82585990082426ffaafc73789e14752d263 Mon Sep 17 00:00:00 2001 From: MrNaif2018 Date: Tue, 10 Jan 2023 01:57:22 +0300 Subject: [PATCH] Add new troubleshooting view, fixes #318 --- components/Header.vue | 4 +-- components/TroubleshootingGuide.vue | 46 +++++++++++++++++++++++++++++ layouts/default.vue | 13 ++++++-- store/index.js | 21 +++++++++---- store/product/actions.js | 1 + 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 components/TroubleshootingGuide.vue diff --git a/components/Header.vue b/components/Header.vue index e8a6741..d1351e2 100644 --- a/components/Header.vue +++ b/components/Header.vue @@ -3,7 +3,7 @@ role="navigation", aria-label="main navigation") .container.is-flex-touch - .navbar-brand + .navbar-brand(v-if="$store.state.store?.name") nuxt-link.navbar-item(exact, :to="getHomeURL") strong i {{$store.state.store.name}} @@ -34,7 +34,7 @@ export default { ...cartGetters(["total"]), ...mapGetters(["onionURL"]), isIndexRoute() { - return this.$route.name === "index" + return this.$store.state.apiError ? true : this.$route.name === "index" }, getHomeURL() { const storeID = this.$route.params.id diff --git a/components/TroubleshootingGuide.vue b/components/TroubleshootingGuide.vue new file mode 100644 index 0000000..340910d --- /dev/null +++ b/components/TroubleshootingGuide.vue @@ -0,0 +1,46 @@ + diff --git a/layouts/default.vue b/layouts/default.vue index cdcd40c..37ef439 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -5,8 +5,11 @@ UIExtensionSlot(name="header") app-header .hero-body - nuxt - UIExtensionSlot(name="body") + div(v-if="$store.state.apiError") + troubleshooting-guide(title="Store POS unconfigured") + div(v-else) + nuxt + UIExtensionSlot(name="body") .hero-foot UIExtensionSlot(name="footer") .container @@ -20,12 +23,14 @@ import UIExtensionSlot from "@/components/UIExtensionSlot" import Header from "@/components/Header" import VERSION from "@/version" import CartSidebar from "@/components/CartSidebar" +import TroubleshootingGuide from "@/components/TroubleshootingGuide" export default { components: { UIExtensionSlot, AppHeader: Header, AppCartSidebar: CartSidebar, + TroubleshootingGuide, }, data() { return { @@ -33,7 +38,9 @@ export default { } }, async fetch() { - await this.$store.dispatch("syncStats") + try { + await this.$store.dispatch("syncStats") + } catch (e) {} }, head() { const themeURL = this.$store.state.store?.theme_settings?.store_theme_url diff --git a/store/index.js b/store/index.js index 3c39898..97c0131 100644 --- a/store/index.js +++ b/store/index.js @@ -8,6 +8,7 @@ export const state = () => ({ path: "/", onion: false, storeID: 1, + apiError: null, }) export const mutations = { @@ -38,6 +39,9 @@ export const mutations = { policies(state, val) { state.policies = val }, + apiError(state, value) { + state.apiError = value + }, } export const getters = { url: ({ url }) => url, @@ -66,12 +70,17 @@ export const getters = { export const actions = { async nuxtServerInit({ commit, dispatch }, { req, $axios, params }) { await dispatch("loadEnv", { env: this.$config, req }) - const { data } = await $axios.get("/manage/stores") - commit("policies", data) - const storeID = params.id ? params.id : data.pos_id - commit("storeID", storeID) - const { data: services } = await $axios.get("/tor/services") - commit("services", services) + try { + const { data } = await $axios.get("/manage/stores") + commit("policies", data) + const storeID = params.id ? params.id : data.pos_id + commit("storeID", storeID) + const { data: services } = await $axios.get("/tor/services") + commit("services", services) + commit("apiError", null) // reset error + } catch (e) { + commit("apiError", e) + } }, async loadEnv({ commit }, { env, req }) { let onionURL = null diff --git a/store/product/actions.js b/store/product/actions.js index b0d7548..6fa0319 100644 --- a/store/product/actions.js +++ b/store/product/actions.js @@ -40,6 +40,7 @@ export default { .get(`/products/categories?store=${this.state.storeID}`) .then((resp) => commit("SET_CATEGORIES", resp.data)) }) + .catch((e) => []) }, fetchCount({ commit }) { return this.$axios