Files
Socialflow/client/src/App.tsx
T
michaelschal e69472d4b0 Update dashboard to show post history and allow direct photo uploads
Remove the calendar and analytics pages, and update the sidebar navigation. Add functionality for direct image uploads on the new post page. Update the favicon for the application.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/G8GuKB7
2025-10-08 13:52:38 +00:00

96 lines
3.2 KiB
TypeScript

import { Switch, Route, Redirect, useLocation } from "wouter";
import { useEffect } from "react";
import { queryClient } from "./lib/queryClient";
import { QueryClientProvider, useQuery } from "@tanstack/react-query";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import NotFound from "@/pages/not-found";
import Login from "@/pages/login";
import Dashboard from "@/pages/dashboard";
import NewPost from "@/pages/new-post";
import Calendar from "@/pages/calendar";
import Media from "@/pages/media";
import PagesManagement from "@/pages/pages";
import AI from "@/pages/ai";
import History from "@/pages/history";
import Settings from "@/pages/settings";
import SqlAdmin from "@/pages/sql";
import UsersAdmin from "@/pages/users-admin";
function ProtectedRoute({ component: Component, adminOnly = false }: { component: React.ComponentType; adminOnly?: boolean }) {
const [, setLocation] = useLocation();
const { data: session, isLoading } = useQuery({
queryKey: ["/api/auth/session"],
retry: false,
});
useEffect(() => {
if (!isLoading && !session) {
setLocation("/login");
}
}, [isLoading, session, setLocation]);
if (isLoading) {
return (
<div className="flex items-center justify-center h-screen bg-background">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"></div>
<p className="text-muted-foreground">Chargement...</p>
</div>
</div>
);
}
if (!session) {
return null;
}
if (adminOnly && (session as any).role !== "admin") {
return (
<div className="flex items-center justify-center h-screen bg-background">
<div className="text-center">
<h1 className="text-2xl font-bold mb-2">Accès refusé</h1>
<p className="text-muted-foreground">Cette page est réservée aux administrateurs.</p>
</div>
</div>
);
}
return <Component />;
}
function Router() {
return (
<Switch>
<Route path="/login" component={Login} />
<Route path="/">{() => <ProtectedRoute component={Dashboard} />}</Route>
<Route path="/new">{() => <ProtectedRoute component={NewPost} />}</Route>
<Route path="/calendar">{() => <ProtectedRoute component={Calendar} />}</Route>
<Route path="/media">{() => <ProtectedRoute component={Media} />}</Route>
<Route path="/pages">{() => <ProtectedRoute component={PagesManagement} />}</Route>
<Route path="/ai">{() => <ProtectedRoute component={AI} />}</Route>
<Route path="/history">{() => <ProtectedRoute component={History} />}</Route>
<Route path="/settings">{() => <ProtectedRoute component={Settings} adminOnly />}</Route>
<Route path="/sql">{() => <ProtectedRoute component={SqlAdmin} adminOnly />}</Route>
<Route path="/users">{() => <ProtectedRoute component={UsersAdmin} adminOnly />}</Route>
<Route component={NotFound} />
</Switch>
);
}
function App() {
return (
<QueryClientProvider client={queryClient}>
<TooltipProvider>
<div>
<Toaster />
<Router />
</div>
</TooltipProvider>
</QueryClientProvider>
);
}
export default App;