From 4942387bab89c4aca1cb00a6cec25d9b9235be76 Mon Sep 17 00:00:00 2001 From: "lalitdeore12@gmail.com" Date: Tue, 20 May 2025 13:51:36 +0530 Subject: [PATCH 1/5] add theming changes for onprem --- backend/go-app/main.go | 2 ++ frontend/src/App.jsx | 5 ++++ frontend/src/components/LeftSideBar.jsx | 38 +++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) 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, }} From 3544562eea6e4150a389424fa4159675c1059ff1 Mon Sep 17 00:00:00 2001 From: "lalitdeore12@gmail.com" Date: Tue, 20 May 2025 14:12:54 +0530 Subject: [PATCH 2/5] Fix - hide toast pop up while changing theme --- frontend/src/components/Branding.jsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/components/Branding.jsx b/frontend/src/components/Branding.jsx index 649c509a..92e434e5 100644 --- a/frontend/src/components/Branding.jsx +++ b/frontend/src/components/Branding.jsx @@ -414,9 +414,6 @@ const Branding = (props) => { if (changingTheme === true) { return } - - - toast.info("Changing theme to " + newTheme + ". Please wait a moment.") setChangingTheme(true) handleEditOrg(newTheme); }} From 1eaad4e9bebad56c74b41d5747651aef27668d68 Mon Sep 17 00:00:00 2001 From: "lalitdeore12@gmail.com" Date: Tue, 20 May 2025 14:17:38 +0530 Subject: [PATCH 3/5] remove brading from userinfo --- backend/go-app/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/go-app/main.go b/backend/go-app/main.go index a03f7d28..06021b6b 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -1069,8 +1069,6 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) { activatedAppIds = append(activatedAppIds, app.ID) } - userInfo.ActiveOrg.Branding = org.Branding - returnValue := shuffle.HandleInfo{ Success: true, Username: userInfo.Username, From 6264150592409aed3a0390a6c2da75928c9e9878 Mon Sep 17 00:00:00 2001 From: "lalitdeore12@gmail.com" Date: Thu, 22 May 2025 14:26:13 +0530 Subject: [PATCH 4/5] remove extra api for changing theme --- backend/go-app/main.go | 1 - frontend/src/components/LeftSideBar.jsx | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 06021b6b..2e1cf238 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -5103,7 +5103,6 @@ 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/components/LeftSideBar.jsx b/frontend/src/components/LeftSideBar.jsx index db93754b..39fce780 100644 --- a/frontend/src/components/LeftSideBar.jsx +++ b/frontend/src/components/LeftSideBar.jsx @@ -450,15 +450,16 @@ const LeftSideBar = ({ userdata, serverside, globalUrl, notifications, }) => { }; const handleUpdateTheme = (newTheme) => { - + const data = { + "user_id": userdata?.id, "theme": newTheme, } - const url = globalUrl + `/api/v1/users/${userdata?.id}/theme`; + const url = globalUrl + `/api/v1/users/updateuser`; fetch(url, { mode: "cors", - method: "POST", + method: "PUT", body: JSON.stringify(data), credentials: "include", crossDomain: true, From cdffb159f9b18e28485f98fd7b8185141de50210 Mon Sep 17 00:00:00 2001 From: "lalitdeore12@gmail.com" Date: Tue, 3 Jun 2025 14:09:28 +0530 Subject: [PATCH 5/5] if not login then show dark theme --- frontend/src/App.jsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 7f110c98..13289352 100755 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -92,7 +92,7 @@ const App = (message, props) => { const [dataset, setDataset] = useState(false) const [isLoaded, setIsLoaded] = useState(false) const [curpath, setCurpath] = useState(typeof window === "undefined" || window.location === undefined ? "" : window.location.pathname) - const { themeMode, handleThemeChange, setBrandColor, brandColor} = useContext(Context); + const { themeMode, handleThemeChange, setBrandColor, brandColor,setThemeMode} = useContext(Context); const currentTheme = getTheme(themeMode, brandColor); const mainColor = currentTheme?.palette?.backgroundColor const [isPreviousThemeLight, setIsPreviousThemeLight] = useState(false) @@ -197,7 +197,11 @@ const App = (message, props) => { }else{ handleThemeChange("dark") } - } + }else { + handleThemeChange("dark") + setThemeMode("dark") + localStorage.removeItem("theme"); + } // Handling Ethereum update