mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-16 00:23:01 +00:00
(fix) ui - reload key spend info
This commit is contained in:
@@ -48,6 +48,11 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
|
||||
const token = searchParams.get("token");
|
||||
const [accessToken, setAccessToken] = useState<string | null>(null);
|
||||
const [userModels, setUserModels] = useState<string[]>([]);
|
||||
window.addEventListener('beforeunload', function() {
|
||||
// Clear session storage
|
||||
sessionStorage.clear();
|
||||
});
|
||||
|
||||
|
||||
function formatUserRole(userRole: string) {
|
||||
if (!userRole) {
|
||||
@@ -70,6 +75,7 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
|
||||
|
||||
// Moved useEffect inside the component and used a condition to run fetch only if the params are available
|
||||
useEffect(() => {
|
||||
|
||||
if (token) {
|
||||
const decoded = jwtDecode(token) as { [key: string]: any };
|
||||
if (decoded) {
|
||||
@@ -97,22 +103,22 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
|
||||
}
|
||||
}
|
||||
if (userID && accessToken && userRole && !data) {
|
||||
const cachedData = localStorage.getItem("userData" + userID);
|
||||
const cachedSpendData = localStorage.getItem("userSpendData" + userID);
|
||||
const cachedUserModels = localStorage.getItem("userModels" + userID);
|
||||
const cachedData = sessionStorage.getItem("userData" + userID);
|
||||
const cachedSpendData = sessionStorage.getItem("userSpendData" + userID);
|
||||
const cachedUserModels = sessionStorage.getItem("userModels" + userID);
|
||||
if (cachedData && cachedSpendData && cachedUserModels) {
|
||||
setData(JSON.parse(cachedData));
|
||||
setUserSpendData(JSON.parse(cachedSpendData));
|
||||
setUserModels(JSON.parse(cachedUserModels));
|
||||
|
||||
|
||||
} else {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response = await userInfoCall(accessToken, userID, userRole);
|
||||
setUserSpendData(response["user_info"]);
|
||||
setData(response["keys"]); // Assuming this is the correct path to your data
|
||||
localStorage.setItem("userData" + userID, JSON.stringify(response["keys"]));
|
||||
localStorage.setItem(
|
||||
sessionStorage.setItem("userData" + userID, JSON.stringify(response["keys"]));
|
||||
sessionStorage.setItem(
|
||||
"userSpendData" + userID,
|
||||
JSON.stringify(response["user_info"])
|
||||
);
|
||||
@@ -126,7 +132,7 @@ const UserDashboard: React.FC<UserDashboardProps> = ({
|
||||
|
||||
console.log("userModels:", userModels);
|
||||
|
||||
localStorage.setItem("userModels" + userID, JSON.stringify(available_model_names));
|
||||
sessionStorage.setItem("userModels" + userID, JSON.stringify(available_model_names));
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user