فهرست منبع

Added requering for billing

jnfrati 4 سال پیش
والد
کامیت
ddb1084f47
3فایلهای تغییر یافته به همراه16 افزوده شده و 2 حذف شده
  1. 2 1
      dashboard/src/main/home/project-settings/BillingPage.tsx
  2. 13 1
      dashboard/src/shared/Context.tsx
  3. 1 0
      dashboard/src/shared/types.tsx

+ 2 - 1
dashboard/src/main/home/project-settings/BillingPage.tsx

@@ -5,7 +5,7 @@ import { Context } from "shared/Context";
 
 function BillingPage() {
   const [customerToken, setCustomerToken] = useState("");
-  const { currentProject, setCurrentError } = useContext(Context);
+  const { currentProject, setCurrentError, queryUsage } = useContext(Context);
 
   useEffect(() => {
     let isSubscripted = true;
@@ -22,6 +22,7 @@ function BillingPage() {
       });
     return () => {
       isSubscripted = false;
+      queryUsage();
     };
   }, [currentProject?.id]);
 

+ 13 - 1
dashboard/src/shared/Context.tsx

@@ -9,6 +9,7 @@ import {
 } from "shared/types";
 
 import { pushQueryParams } from "shared/routing";
+import api from "./api";
 
 const Context = React.createContext<Partial<ContextProps>>(null);
 
@@ -160,8 +161,19 @@ class ContextProvider extends Component<PropsType, StateType> {
     },
   };
 
+  queryUsage() {
+    api
+      .getUsage("<token>", {}, { project_id: this.state?.currentProject?.id })
+      .then((res) => {
+        this.state.setUsage(res.data);
+      });
+  }
   render() {
-    return <Provider value={this.state}>{this.props.children}</Provider>;
+    return (
+      <Provider value={{ ...this.state, queryUsage: this.queryUsage }}>
+        {this.props.children}
+      </Provider>
+    );
   }
 }
 

+ 1 - 0
dashboard/src/shared/types.tsx

@@ -302,6 +302,7 @@ export interface ContextProps {
   setHasBillingEnabled: (isBillingEnabled: boolean) => void;
   usage: UsageData;
   setUsage: (usage: UsageData) => void;
+  queryUsage: () => void;
 }
 
 export enum JobStatusType {