diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 62652d92..97aede9d 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -4923,7 +4923,7 @@ 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/subOrgs/{orgId}", shuffle.HandleGetSubOrgs).Methods("GET", "OPTIONS") + r.HandleFunc("/api/v1/sub_orgs/{orgId}", 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. diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx index 63800693..15351d38 100755 --- a/frontend/src/views/Admin.jsx +++ b/frontend/src/views/Admin.jsx @@ -163,6 +163,7 @@ const Admin = (props) => { 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({}); @@ -1111,40 +1112,41 @@ If you're interested, please let me know a time that works for you, or set up a toast("Error getting current organization"); }); }; -const handleGetSubOrgs = (orgId) => { - if (serverside !== true && window.location.search !== undefined && window.location.search !== null) { - const urlSearchParams = new URLSearchParams(window.location.search); - const params = Object.fromEntries(urlSearchParams.entries()); - const foundorgid = params["org_id"]; - if (foundorgid !== undefined && foundorgid !== null) { - orgId = foundorgid; - } - } - - if (orgId.length === 0) { - toast("Organization ID not defined. Please contact us on https://shuffler.io if this persists logout."); - return; - } + const handleGetSubOrgs = (orgId) => { - fetch(`${globalUrl}/api/v1/subOrgs/${orgId}`, { - method: "GET", - credentials: "include", - headers: { - "Content-Type": "application/json", - }, - }) + 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/sub_orgs/${orgId}`, { + 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) => { - setSubOrgs(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"); - }); -}; + .catch((error) => { + console.log("Error getting sub orgs: ", error); + toast("Error getting sub organizations"); + }); + }; const handleClickChangeOrg = (orgId) => { // Don't really care about the logout @@ -4745,6 +4747,13 @@ const handleClickChangeOrg = (orgId) => { ) : null; + const imagesize = 40; + const imageStyle = { + width: imagesize, + height: imagesize, + pointerEvents: "none", + }; + const organizationsTab = curTab === 7 ? (