Просмотр исходного кода

moved welcome form webhook call to backend + show welcome form on staging

jusrhee 4 лет назад
Родитель
Сommit
0d46b39d2e

+ 5 - 2
dashboard/src/main/home/Home.tsx

@@ -388,13 +388,16 @@ class Home extends Component<PropsType, StateType> {
             <Icon src={discordLogo} />
             Join Our Discord
           </DiscordButton>
-          {this.context?.capabilities?.version === "production" &&
+          {
+            (this.context?.capabilities?.version === "production" ||
+            this.context?.capabilities?.version === "staging") &&
             this.state.showWelcomeForm &&
             localStorage.getItem("welcomed") != "true" && (
               <WelcomeForm
                 closeForm={() => this.setState({ showWelcomeForm: false })}
               />
-            )}
+            )
+          }
         </>
       );
     }

+ 9 - 9
dashboard/src/main/home/WelcomeForm.tsx

@@ -1,7 +1,7 @@
 import React, { useContext, useState } from "react";
 import styled from "styled-components";
 import { CSSTransition } from "react-transition-group";
-import axios from "axios";
+import api from "shared/api";
 
 import { Context } from "shared/Context";
 
@@ -21,22 +21,22 @@ const WelcomeForm: React.FunctionComponent<Props> = ({}) => {
   const [company, setCompany] = useState("");
 
   const submitForm = () => {
-    axios
-      .get(process.env.WELCOME_FORM_WEBHOOK, {
-        params: {
+    api
+      .getWelcome(
+        "<token>",
+        {
           email: context.user && context.user.email,
           isCompany,
           company,
           role,
         },
-      })
-      .then((res) => {
+        {}
+      )
+      .then(() => {
         localStorage.setItem("welcomed", "true");
         setActive(false);
       })
-      .catch((err) => {
-        console.log(err);
-      });
+      .catch((err) => console.log(err));
   };
 
   const renderContents = () => {

+ 10 - 0
dashboard/src/shared/api.tsx

@@ -785,6 +785,15 @@ const getCapabilities = baseApi<{}, {}>("GET", () => {
   return `/api/capabilities`;
 });
 
+const getWelcome = baseApi<{
+  email: string,
+  isCompany: boolean,
+  company: string,
+  role: string
+}, {}>("GET", () => {
+  return `/api/welcome`;
+});
+
 const linkGithubProject = baseApi<
   {},
   {
@@ -1087,6 +1096,7 @@ export default {
   getBranchContents,
   getBranches,
   getCapabilities,
+  getWelcome,
   getChart,
   getCharts,
   getChartComponents,

+ 2 - 0
internal/config/config.go

@@ -71,6 +71,8 @@ type ServerConf struct {
 	ProvisionerCluster string `env:"PROVISIONER_CLUSTER"`
 	IngressCluster     string `env:"INGRESS_CLUSTER"`
 	SelfKubeconfig     string `env:"SELF_KUBECONFIG"`
+
+	WelcomeFormWebhook string `env:"WELCOME_FORM_WEBHOOK"`
 }
 
 // DBConf is the database configuration: if generated from environment variables,

+ 1 - 1
server/api/k8s_handler.go

@@ -35,7 +35,7 @@ func (app *App) HandleListNamespaces(w http.ResponseWriter, r *http.Request) {
 	vals, err := url.ParseQuery(r.URL.RawQuery)
 
 	if err != nil {
-		app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
+		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
 

+ 34 - 0
server/api/welcome_handler.go

@@ -0,0 +1,34 @@
+package api
+
+import (
+	"net/http"
+	"net/url"
+)
+
+// HandleGetCapabilities gets the capabilities of the server
+func (app *App) HandleWelcome(w http.ResponseWriter, r *http.Request) {
+	vals, err := url.ParseQuery(r.URL.RawQuery)
+
+	if err != nil {
+		return
+	}
+
+	req, err := http.NewRequest("GET", app.ServerConf.WelcomeFormWebhook, nil)
+
+	if err != nil {
+		return
+	}
+
+	q := req.URL.Query()
+	q.Add("email", vals["email"][0])
+	q.Add("isCompany", vals["isCompany"][0])
+	q.Add("company", vals["company"][0])
+	q.Add("role", vals["role"][0])
+	req.URL.RawQuery = q.Encode()
+
+	_, err = http.Get(req.URL.String())
+
+	if err != nil {
+		return
+	}
+}

+ 7 - 0
server/router/router.go

@@ -1697,6 +1697,13 @@ func New(a *api.App) *chi.Mux {
 				http.HandlerFunc(a.HandleGetCapabilities),
 			)
 
+			// welcome form
+			r.Method(
+				"GET",
+				"/welcome",
+				http.HandlerFunc(a.HandleWelcome),
+			)
+
 			// /api/projects/{project_id}/deploy routes
 			r.Method(
 				"POST",