diff --git a/backend/go-app/main.go b/backend/go-app/main.go index d0b99620..efc61caf 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -4929,7 +4929,8 @@ func initHandlers() { r.HandleFunc("/api/v1/orgs/{orgId}/change", shuffle.HandleChangeUserOrg).Methods("POST", "OPTIONS") // Swaps to the org r.HandleFunc("/api/v1/orgs/{orgId}", shuffle.HandleDeleteOrg).Methods("DELETE", "OPTIONS") - + r.HandleFunc("/api/v1/orgs/{orgId}/suborgs", shuffle.HandleGetSubOrgs).Methods("GET", "OPTIONS") + // This is a new API that validates if a key has been seen before. // Not sure what the best course of action is for it. r.HandleFunc("/api/v1/environments/{key}/stop", shuffle.HandleStopExecutions).Methods("GET", "POST", "OPTIONS") diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx index 2c5175eb..e4559e69 100755 --- a/frontend/src/views/Admin.jsx +++ b/frontend/src/views/Admin.jsx @@ -160,6 +160,8 @@ const Admin = (props) => { const [loginInfo, setLoginInfo] = React.useState(""); const [curTab, setCurTab] = React.useState(0); const [users, setUsers] = React.useState([]); + const [subOrgs, setSubOrgs] = useState([]); + const [parentOrg, setParentOrg] = React.useState(null); const [organizations, setOrganizations] = React.useState([]); const [orgSyncResponse, setOrgSyncResponse] = React.useState(""); const [userSettings, setUserSettings] = React.useState({}); @@ -202,6 +204,14 @@ const Admin = (props) => { } }, [isDropzone]); + useEffect(() => { + if (userdata.orgs !== undefined && userdata.orgs !== null && userdata.orgs.length > 0) { + handleGetSubOrgs(userdata.active_org.id); + } + else console.log("error in user data") + }, [userdata]); + + const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io"; const get2faCode = (userId) => { @@ -1101,6 +1111,92 @@ If you're interested, please let me know a time that works for you, or set up a }); }; + const handleGetSubOrgs = (orgId) => { + + if (orgId.length === 0) { + toast("Organization ID not defined. Please contact us on https://shuffler.io if this persists logout."); + return; + } + + fetch(`${globalUrl}/api/v1/orgs/${orgId}/suborgs`, { + method: "GET", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }) + .then((response) => { + if (!response.ok) { + throw new Error('Failed to fetch sub organizations'); + } + return response.json(); + }) + .then((responseJson) => { + if (responseJson.success === false) { + toast("Failed getting your org. If this persists, please contact support."); + } else { + const { subOrgs, parentOrg } = responseJson; + setSubOrgs(subOrgs); + setParentOrg(parentOrg); + } + }) + .catch((error) => { + console.log("Error getting sub orgs: ", error); + toast("Error getting sub organizations"); + }); + }; + +const handleClickChangeOrg = (orgId) => { + // Don't really care about the logout + //name: org.name, + //orgId = "asd" + const data = { + org_id: orgId, + } + + localStorage.setItem("globalUrl", "") + localStorage.setItem("getting_started_sidebar", "open"); + + fetch(`${globalUrl}/api/v1/orgs/${orgId}/change`, { + mode: 'cors', + credentials: 'include', + crossDomain: true, + method: 'POST', + body: JSON.stringify(data), + withCredentials: true, + headers: { + 'Content-Type': 'application/json; charset=utf-8', + }, + }) + .then(function(response) { + if (response.status !== 200) { + console.log("Error in response") + } + + return response.json(); + }).then(function(responseJson) { + if (responseJson.success === true) { + if (responseJson.region_url !== undefined && responseJson.region_url !== null && responseJson.region_url.length > 0) { + console.log("Region Change: ", responseJson.region_url) + localStorage.setItem("globalUrl", responseJson.region_url) + //globalUrl = responseJson.region_url + } + + setTimeout(() => { + window.location.reload() + }, 2000) + toast("Successfully changed active organization - refreshing!") + } else { + toast("Failed changing org: ", responseJson.reason) + } + }) + .catch(error => { + console.log("error changing: ", error) + //removeCookie("session_token", {path: "/"}) + }) +} + + const inviteUser = (data) => { //console.log("INPUT: ", data); setLoginInfo(""); @@ -4662,6 +4758,13 @@ If you're interested, please let me know a time that works for you, or set up a ) : null; + const imagesize = 40; + const imageStyle = { + width: imagesize, + height: imagesize, + pointerEvents: "none", + }; + const organizationsTab = curTab === 7 ? (