mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
- Introduced a new UnifiedLoadingScreen component for consistent loading indicators in the application. - Replaced existing loading implementations in LoginPage, AuthCallbackPage, DashboardLayout, and other components with the new unified loading screen. - Updated translations for loading messages to enhance user experience and clarity. - Improved loading states in the ElectricProvider and TokenHandler components to utilize the new loading screen, ensuring a cohesive look and feel during loading processes.
37 lines
1,006 B
TypeScript
37 lines
1,006 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { useTranslations } from "next-intl";
|
|
import { UnifiedLoadingScreen } from "@/components/ui/unified-loading-screen";
|
|
import { getBearerToken, redirectToLogin } from "@/lib/auth-utils";
|
|
|
|
interface DashboardLayoutProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export default function DashboardLayout({ children }: DashboardLayoutProps) {
|
|
const t = useTranslations("dashboard");
|
|
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
|
|
|
|
useEffect(() => {
|
|
// Check if user is authenticated
|
|
const token = getBearerToken();
|
|
if (!token) {
|
|
// Save current path and redirect to login
|
|
redirectToLogin();
|
|
return;
|
|
}
|
|
setIsCheckingAuth(false);
|
|
}, []);
|
|
|
|
// Show loading screen while checking authentication
|
|
if (isCheckingAuth) {
|
|
return <UnifiedLoadingScreen variant="default" message={t("checking_auth")} />;
|
|
}
|
|
|
|
return (
|
|
<div className="h-full flex flex-col ">
|
|
<div className="flex-1 min-h-0">{children}</div>
|
|
</div>
|
|
);
|
|
}
|