Przeglądaj źródła

fixed up client baseApi

jusrhee 5 lat temu
rodzic
commit
61d2d92bf3

+ 1 - 1
dashboard/src/main/Login.tsx

@@ -39,7 +39,7 @@ export default class Login extends Component<PropsType, StateType> {
       api.logInUser('<token>', {
       api.logInUser('<token>', {
         email: email,
         email: email,
         password: password
         password: password
-      }, (err: any, res: any) => {
+      }, {}, (err: any, res: any) => {
         // TODO: case and set credential error
         // TODO: case and set credential error
 
 
         console.log(err)
         console.log(err)

+ 2 - 2
dashboard/src/main/Main.tsx

@@ -20,8 +20,8 @@ type StateType = {
 export default class Main extends Component<PropsType, StateType> {
 export default class Main extends Component<PropsType, StateType> {
   state = {
   state = {
     isLoading: false,
     isLoading: false,
-    isLoggedIn: true,
-    uninitialized: false,
+    isLoggedIn: false,
+    uninitialized: true,
   };
   };
 
 
   componentDidMount() {
   componentDidMount() {

+ 1 - 1
dashboard/src/main/Register.tsx

@@ -47,7 +47,7 @@ export default class Register extends Component<PropsType, StateType> {
       api.registerUser('', {
       api.registerUser('', {
         email: email,
         email: email,
         password: password
         password: password
-      }, (err: any, res: any) => {
+      }, {}, (err: any, res: any) => {
         err ? setCurrentError(JSON.stringify(err)) : authenticate();
         err ? setCurrentError(JSON.stringify(err)) : authenticate();
       });
       });
     } 
     } 

+ 16 - 2
dashboard/src/main/home/sidebar/ClusterSection.tsx

@@ -2,7 +2,9 @@ import React, { Component } from 'react';
 import styled from 'styled-components';
 import styled from 'styled-components';
 import drawerBg from '../../../assets/drawer-bg.png';
 import drawerBg from '../../../assets/drawer-bg.png';
 
 
+import api from '../../../shared/api';
 import { Context } from '../../../shared/Context';
 import { Context } from '../../../shared/Context';
+
 import Drawer from './Drawer';
 import Drawer from './Drawer';
 
 
 type PropsType = {
 type PropsType = {
@@ -13,7 +15,8 @@ type PropsType = {
 type StateType = {
 type StateType = {
   configExists: boolean,
   configExists: boolean,
   showDrawer: boolean,
   showDrawer: boolean,
-  initializedDrawer: boolean
+  initializedDrawer: boolean,
+  clusters: any[]
 };
 };
 
 
 export default class ClusterSection extends Component<PropsType, StateType> {
 export default class ClusterSection extends Component<PropsType, StateType> {
@@ -23,10 +26,21 @@ export default class ClusterSection extends Component<PropsType, StateType> {
     configExists: false,
     configExists: false,
     showDrawer: false,
     showDrawer: false,
     initializedDrawer: false,
     initializedDrawer: false,
+    clusters: [],
   };
   };
 
 
   componentDidMount() {
   componentDidMount() {
-    // TODO: Check if
+    let { setCurrentError } = this.context;
+
+    api.getClusters('<token>', {}, { id: 0 }, (err: any, res: any) => {      
+      if (err) {
+        setCurrentError(JSON.stringify(err));
+      } else {
+        // TODO: need a separate query for checking if config has been set
+
+        this.setState({ clusters: res.data.clusters });
+      }
+    });
   }
   }
 
 
   // Need to override showDrawer when the sidebar is closed
   // Need to override showDrawer when the sidebar is closed

+ 1 - 1
dashboard/src/main/home/sidebar/Sidebar.tsx

@@ -81,7 +81,7 @@ export default class Sidebar extends Component<PropsType, StateType> {
     let { setCurrentError } = this.context;
     let { setCurrentError } = this.context;
 
 
     // Attempt user logout
     // Attempt user logout
-    api.logOutUser('<token>', {}, (err, res) => {
+    api.logOutUser('<token>', {}, {}, (err: any, res: any) => {
       // TODO: case and set logout error
       // TODO: case and set logout error
       
       
       err ? setCurrentError(JSON.stringify(err)) : logOut();
       err ? setCurrentError(JSON.stringify(err)) : logOut();

+ 6 - 1
dashboard/src/shared/api.tsx

@@ -21,9 +21,14 @@ const logInUser = baseApi<{
 
 
 const logOutUser = baseApi<{}>('GET', '/api/logout');
 const logOutUser = baseApi<{}>('GET', '/api/logout');
 
 
+const getClusters = baseApi<{}, { id: number }>('GET', (pathParams) => {
+  return `/api/users/${pathParams.id}/clusters`;
+});
+
 // Bundle export to allow default api import
 // Bundle export to allow default api import
 export default {
 export default {
   registerUser,
   registerUser,
   logInUser,
   logInUser,
-  logOutUser
+  logOutUser,
+  getClusters
 }
 }

+ 3 - 3
dashboard/src/shared/baseApi.tsx

@@ -1,15 +1,15 @@
 import axios from 'axios';
 import axios from 'axios';
 
 
 // Partial function that accepts a generic params type and returns an api method
 // Partial function that accepts a generic params type and returns an api method
-export const baseApi = <T extends {}, S = {}>(requestType: string, endpoint: ((pathParams?: S) => string) | string) => {
-  return (token: string, params: T, callback?: (err: any, res: any) => void) => {
+export const baseApi = <T extends {}, S = {}>(requestType: string, endpoint: ((pathParams: S) => string) | string) => {
+  return (token: string, params: T, pathParams: S, callback?: (err: any, res: any) => void) => {
 
 
     // Generate endpoint literal
     // Generate endpoint literal
     let endpointString: ((pathParams: S) => string) | string;
     let endpointString: ((pathParams: S) => string) | string;
     if (typeof endpoint === 'string') {
     if (typeof endpoint === 'string') {
       endpointString = endpoint;
       endpointString = endpoint;
     } else {
     } else {
-      endpointString = 'fuck'
+      endpointString = endpoint(pathParams);
     }
     }
 
 
     // Handle request type (can refactor)
     // Handle request type (can refactor)