This is an automated email from the ASF dual-hosted git repository.

hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new e2eb7edb [type:fix] fetch namespace problem when not login (#477)
e2eb7edb is described below

commit e2eb7edb5537060565424ec8ecb4737ca206f1d6
Author: VampireAchao <ac...@apache.org>
AuthorDate: Sat Aug 24 23:14:42 2024 +0800

    [type:fix] fetch namespace problem when not login (#477)
---
 src/components/GlobalHeader/index.js | 2 +-
 src/models/global.js                 | 2 +-
 src/models/login.js                  | 8 +++++++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/components/GlobalHeader/index.js 
b/src/components/GlobalHeader/index.js
index faba06cc..b0b93f8a 100644
--- a/src/components/GlobalHeader/index.js
+++ b/src/components/GlobalHeader/index.js
@@ -120,8 +120,8 @@ class GlobalHeader extends PureComponent {
           this.setState({ visible: true, display: "block" });
         }
       });
+      this.fetchNamespaces();
     }
-    this.fetchNamespaces();
   }
 
   componentWillUnmount() {
diff --git a/src/models/global.js b/src/models/global.js
index 2ddba64c..0fbec4c9 100644
--- a/src/models/global.js
+++ b/src/models/global.js
@@ -52,7 +52,7 @@ export default {
     },
     *fetchNamespaces(_, { call, put }) {
       const json = yield call(getNamespaceList);
-      if (json.code === 200) {
+      if (json?.code === 200) {
         yield put({
           type: "saveNamespaces",
           payload: json.data,
diff --git a/src/models/login.js b/src/models/login.js
index 69afd8d0..49f1e4b6 100644
--- a/src/models/login.js
+++ b/src/models/login.js
@@ -29,10 +29,11 @@ export default {
   },
 
   effects: {
-    *login({ payload }, { call, put }) {
+    *login({ payload }, { call, put, select }) {
       const { callback } = payload;
       const response = yield call(queryLogin, payload);
       yield call(callback, response);
+      const namespaces = yield select((state) => state.global.namespaces);
 
       // Login successfully
       if (response.data) {
@@ -46,6 +47,11 @@ export default {
         window.sessionStorage.setItem("token", response.data.token);
         window.sessionStorage.setItem("userName", response.data.userName);
         window.sessionStorage.setItem("userId", response.data.id);
+        if (!namespaces?.length) {
+          yield put({
+            type: "global/fetchNamespaces",
+          });
+        }
         /* const urlParams = new URL(window.location.href);
          const params = getPageQuery();
          let { redirect } = params;

Reply via email to