Browse Source

Moved check if can create project to home component

jnfrati 4 years ago
parent
commit
46adc200f6
2 changed files with 21 additions and 14 deletions
  1. 0 14
      dashboard/src/main/Main.tsx
  2. 21 0
      dashboard/src/main/home/Home.tsx

+ 0 - 14
dashboard/src/main/Main.tsx

@@ -69,20 +69,6 @@ export default class Main extends Component<PropsType, StateType> {
         this.setState({ local: !res.data?.provisioner });
       })
       .catch((err) => console.log(err));
-
-    api
-      .getCanCreateProject("<token>", {}, {})
-      .then((res) => {
-        if (res.status === 403) {
-          this.context.setCanCreateProject(false);
-          return;
-        }
-        this.context.setCanCreateProject(true);
-      })
-      .catch((err) => {
-        this.context.setCanCreateProject(false);
-        console.error(err);
-      });
   }
 
   initialize = () => {

+ 21 - 0
dashboard/src/main/home/Home.tsx

@@ -136,8 +136,25 @@ class Home extends Component<PropsType, StateType> {
       .catch(console.log);
   };
 
+  checkIfCanCreateProject = () => {
+    api
+      .getCanCreateProject("<token>", {}, {})
+      .then((res) => {
+        if (res.status === 403) {
+          this.context.setCanCreateProject(false);
+          return;
+        }
+        this.context.setCanCreateProject(true);
+      })
+      .catch((err) => {
+        this.context.setCanCreateProject(false);
+        console.error(err);
+      });
+  };
+
   componentDidMount() {
     this.checkOnboarding();
+    this.checkIfCanCreateProject();
     let { match } = this.props;
 
     let { user } = this.context;
@@ -176,6 +193,10 @@ class Home extends Component<PropsType, StateType> {
     }
   }
 
+  componentWillUnmount(): void {
+    this.context.setCanCreateProject(false);
+  }
+
   async checkIfProjectHasBilling(projectId: number) {
     if (!projectId) {
       return false;