diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 60f162b4..a03f7d28 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -1093,6 +1093,7 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) { Priorities: orgPriorities, Licensed: licensed, ActiveApps: activatedAppIds, + Theme: userInfo.Theme, } returnData, err := json.Marshal(returnValue) @@ -5104,6 +5105,7 @@ func initHandlers() { r.HandleFunc("/api/v1/users/{key}/get2fa", shuffle.HandleGet2fa).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/{key}/set2fa", shuffle.HandleSet2fa).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/users", shuffle.HandleGetUsers).Methods("GET", "OPTIONS") + r.HandleFunc("/api/v1/users/{userid}/theme", shuffle.HandleSetUserTheme).Methods("POST", "OPTIONS") // General - duplicates and old. r.HandleFunc("/api/v1/getusers", shuffle.HandleGetUsers).Methods("GET", "OPTIONS") diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index fa3ac7ea..7a8c31da 100755 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -192,6 +192,11 @@ const App = (message, props) => { { path: "/" } ); } + if (responseJson?.theme?.length > 0) { + handleThemeChange(responseJson.theme) + }else{ + handleThemeChange("dark") + } } // Handling Ethereum update diff --git a/frontend/src/components/LeftSideBar.jsx b/frontend/src/components/LeftSideBar.jsx index 2d9bad44..db93754b 100644 --- a/frontend/src/components/LeftSideBar.jsx +++ b/frontend/src/components/LeftSideBar.jsx @@ -449,6 +449,36 @@ const LeftSideBar = ({ userdata, serverside, globalUrl, notifications, }) => { }); }; + const handleUpdateTheme = (newTheme) => { + + const data = { + "theme": newTheme, + } + + const url = globalUrl + `/api/v1/users/${userdata?.id}/theme`; + fetch(url, { + mode: "cors", + method: "POST", + body: JSON.stringify(data), + credentials: "include", + crossDomain: true, + withCredentials: true, + headers: { + "Content-Type": "application/json; charset=utf-8", + }, + }).then((response) => + response.json().then((responseJson) => { + if (responseJson["success"] === false) { + toast("Failed updating theme: ", responseJson.reason); + } else { + handleThemeChange(newTheme); + setCurrentSelectedTheme(newTheme); + } + }) + ).catch((error) => { + console.log("Error changing theme: ", error); + }); + }; const removeCookie = (name, path = "/") => { @@ -543,7 +573,7 @@ const LeftSideBar = ({ userdata, serverside, globalUrl, notifications, }) => { }, }} > - {userdata && ( + {userdata && (userdata?.org_status?.includes("integration_partner") && userdata?.org_status?.includes("sub_org")) ? null : ( <> { if (newTheme === currentSelectedTheme) { return; } - handleChangeTheme(newTheme); + if (userdata?.org_status?.includes("integration_partner")){ + handleChangeTheme(newTheme); + }else { + handleUpdateTheme(newTheme); + } }} aria-label="theme" style={{display: 'flex', justifyContent: "center", marginBottom: 10, }}