-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Build Client Dashboard for Project Tracking, Updates, and Payments (#63) #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8ac394d
feat: build client dashboard for project tracking, updates, and payments
hrx01-dev 177ff86
fix: address CodeRabbit review — signOut error handling, displayName …
hrx01-dev 5c982c0
Merge pull request #69 from hrx01-dev/devin/1781968928-coderabbit-fixes
hrx01-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| import { useState } from "react"; | ||
| import { Link, Outlet, useLocation, useNavigate } from "react-router-dom"; | ||
| import { motion, AnimatePresence } from "motion/react"; | ||
| import { signOut } from "firebase/auth"; | ||
| import { auth } from "../../Firebase/firebase"; | ||
| import { useAuth } from "../../Firebase/useAuth"; | ||
| import { | ||
| LayoutDashboard, | ||
| GitBranch, | ||
| Bell, | ||
| CreditCard, | ||
| FileText, | ||
| FolderOpen, | ||
| LogOut, | ||
| Menu, | ||
| X, | ||
| Home, | ||
| } from "lucide-react"; | ||
| import { Avatar, AvatarFallback, AvatarImage } from "../../app/components/ui/avatar"; | ||
| import { Button } from "../../app/components/ui/button"; | ||
| import { Separator } from "../../app/components/ui/separator"; | ||
|
|
||
| const NAV_ITEMS = [ | ||
| { to: "/dashboard", icon: LayoutDashboard, label: "Overview", end: true }, | ||
| { to: "/dashboard/progress", icon: GitBranch, label: "Progress" }, | ||
| { to: "/dashboard/updates", icon: Bell, label: "Updates" }, | ||
| { to: "/dashboard/payments", icon: CreditCard, label: "Payments" }, | ||
| { to: "/dashboard/invoices", icon: FileText, label: "Invoices" }, | ||
| { to: "/dashboard/resources", icon: FolderOpen, label: "Resources" }, | ||
| ]; | ||
|
|
||
| function NavLink({ | ||
| to, | ||
| icon: Icon, | ||
| label, | ||
| active, | ||
| onClick, | ||
| }: { | ||
| to: string; | ||
| icon: React.ComponentType<{ className?: string }>; | ||
| label: string; | ||
| active: boolean; | ||
| onClick?: () => void; | ||
| }) { | ||
| return ( | ||
| <Link | ||
| to={to} | ||
| onClick={onClick} | ||
| className={`flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors ${ | ||
| active | ||
| ? "bg-indigo-50 text-indigo-700 dark:bg-indigo-950/50 dark:text-indigo-300" | ||
| : "text-gray-600 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-slate-800 dark:hover:text-gray-200" | ||
| }`} | ||
| > | ||
| <Icon className="h-5 w-5 shrink-0" /> | ||
| {label} | ||
| </Link> | ||
| ); | ||
| } | ||
|
|
||
| export function DashboardLayout() { | ||
| const [sidebarOpen, setSidebarOpen] = useState(false); | ||
| const location = useLocation(); | ||
| const navigate = useNavigate(); | ||
| const { currentUser } = useAuth(); | ||
|
|
||
| const handleSignOut = async () => { | ||
| try { | ||
| await signOut(auth); | ||
| navigate("/"); | ||
| } catch (error) { | ||
| console.error("Sign out failed:", error); | ||
| } | ||
| }; | ||
|
|
||
| const initials = currentUser?.displayName | ||
| ? currentUser.displayName | ||
| .split(" ") | ||
| .filter((n) => n.length > 0) | ||
| .map((n) => n[0]) | ||
| .join("") | ||
| .toUpperCase() | ||
| .slice(0, 2) | ||
| : currentUser?.email?.slice(0, 2).toUpperCase() ?? "U"; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const isActive = (to: string, end?: boolean) => { | ||
| if (end) return location.pathname === to; | ||
| return location.pathname.startsWith(to); | ||
| }; | ||
|
|
||
| const sidebarContent = ( | ||
| <div className="flex h-full flex-col"> | ||
| <div className="flex items-center gap-2 px-4 py-5"> | ||
| <Link to="/" className="flex items-center gap-2 group"> | ||
| <div className="flex h-8 w-8 items-center justify-center rounded-lg bg-gradient-to-br from-indigo-600 to-purple-600 text-white text-sm font-bold"> | ||
| S | ||
| </div> | ||
| <span className="text-lg font-bold bg-gradient-to-r from-indigo-600 via-purple-600 to-cyan-500 bg-clip-text text-transparent"> | ||
| Servio | ||
| </span> | ||
| </Link> | ||
| </div> | ||
|
|
||
| <Separator /> | ||
|
|
||
| <nav className="flex-1 space-y-1 px-3 py-4"> | ||
| {NAV_ITEMS.map((item) => ( | ||
| <NavLink | ||
| key={item.to} | ||
| {...item} | ||
| active={isActive(item.to, item.end)} | ||
| onClick={() => setSidebarOpen(false)} | ||
| /> | ||
| ))} | ||
| </nav> | ||
|
|
||
| <Separator /> | ||
|
|
||
| <div className="p-4 space-y-3"> | ||
| <Link | ||
| to="/" | ||
| className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium text-gray-600 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-slate-800 dark:hover:text-gray-200 transition-colors" | ||
| > | ||
| <Home className="h-5 w-5 shrink-0" /> | ||
| Back to Home | ||
| </Link> | ||
| <div className="flex items-center gap-3 rounded-lg px-3 py-2"> | ||
| <Avatar className="h-8 w-8"> | ||
| <AvatarImage src={currentUser?.photoURL ?? undefined} /> | ||
| <AvatarFallback className="text-xs bg-indigo-100 text-indigo-700 dark:bg-indigo-900 dark:text-indigo-300"> | ||
| {initials} | ||
| </AvatarFallback> | ||
| </Avatar> | ||
| <div className="flex-1 min-w-0"> | ||
| <p className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate"> | ||
| {currentUser?.displayName ?? "Client"} | ||
| </p> | ||
| <p className="text-xs text-gray-500 dark:text-gray-400 truncate"> | ||
| {currentUser?.email} | ||
| </p> | ||
| </div> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={handleSignOut} | ||
| aria-label="Sign out" | ||
| className="shrink-0" | ||
| > | ||
| <LogOut className="h-4 w-4" /> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="min-h-screen bg-slate-50 dark:bg-slate-950"> | ||
| {/* Desktop sidebar */} | ||
| <aside className="fixed inset-y-0 left-0 z-30 hidden w-64 border-r border-gray-200 bg-white dark:border-slate-800 dark:bg-slate-900 lg:block"> | ||
| {sidebarContent} | ||
| </aside> | ||
|
|
||
| {/* Mobile sidebar overlay */} | ||
| <AnimatePresence> | ||
| {sidebarOpen && ( | ||
| <> | ||
| <motion.div | ||
| initial={{ opacity: 0 }} | ||
| animate={{ opacity: 0.5 }} | ||
| exit={{ opacity: 0 }} | ||
| className="fixed inset-0 z-40 bg-black lg:hidden" | ||
| onClick={() => setSidebarOpen(false)} | ||
| /> | ||
| <motion.aside | ||
| initial={{ x: "-100%" }} | ||
| animate={{ x: 0 }} | ||
| exit={{ x: "-100%" }} | ||
| transition={{ type: "spring", stiffness: 300, damping: 30 }} | ||
| className="fixed inset-y-0 left-0 z-50 w-64 border-r border-gray-200 bg-white dark:border-slate-800 dark:bg-slate-900 lg:hidden" | ||
| > | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| className="absolute top-4 right-4" | ||
| onClick={() => setSidebarOpen(false)} | ||
| aria-label="Close sidebar" | ||
| > | ||
| <X className="h-5 w-5" /> | ||
| </Button> | ||
| {sidebarContent} | ||
| </motion.aside> | ||
| </> | ||
| )} | ||
| </AnimatePresence> | ||
|
|
||
| {/* Main content */} | ||
| <div className="lg:pl-64"> | ||
| {/* Top bar (mobile) */} | ||
| <header className="sticky top-0 z-20 flex h-14 items-center gap-4 border-b border-gray-200 bg-white/80 backdrop-blur-md px-4 dark:border-slate-800 dark:bg-slate-900/80 lg:hidden"> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={() => setSidebarOpen(true)} | ||
| aria-label="Open sidebar" | ||
| > | ||
| <Menu className="h-5 w-5" /> | ||
| </Button> | ||
| <span className="text-sm font-semibold bg-gradient-to-r from-indigo-600 via-purple-600 to-cyan-500 bg-clip-text text-transparent"> | ||
| Servio Dashboard | ||
| </span> | ||
| </header> | ||
|
|
||
| <main className="p-4 md:p-6 lg:p-8"> | ||
| <Outlet /> | ||
| </main> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { Navigate } from "react-router-dom"; | ||
| import { useAuth } from "../../Firebase/useAuth"; | ||
|
|
||
| interface ProtectedRouteProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export function ProtectedRoute({ children }: ProtectedRouteProps) { | ||
| const { currentUser, loading } = useAuth(); | ||
|
|
||
| if (loading) { | ||
| return ( | ||
| <div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-950"> | ||
| <div className="flex flex-col items-center gap-4"> | ||
| <div className="h-8 w-8 animate-spin rounded-full border-4 border-indigo-500 border-t-transparent" /> | ||
| <p className="text-sm text-gray-500 dark:text-gray-400">Loading...</p> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (!currentUser) { | ||
| return <Navigate to="/signin" replace />; | ||
| } | ||
|
|
||
| return <>{children}</>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { useAuth } from "../../Firebase/useAuth"; | ||
| import { fetchClientProjects } from "../services/dashboardService"; | ||
| import { DEMO_PROJECT } from "../services/demoData"; | ||
| import type { Project } from "../types"; | ||
|
|
||
| export function useProjects() { | ||
| const { currentUser } = useAuth(); | ||
| const [projects, setProjects] = useState<Project[]>([]); | ||
| const [loading, setLoading] = useState(true); | ||
| const [isDemo, setIsDemo] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!currentUser) { | ||
| setLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| let cancelled = false; | ||
|
|
||
| async function load() { | ||
| try { | ||
| const data = await fetchClientProjects(currentUser!.uid); | ||
| if (cancelled) return; | ||
| if (data.length > 0) { | ||
| setProjects(data); | ||
| setIsDemo(false); | ||
| } else { | ||
| setProjects([DEMO_PROJECT]); | ||
| setIsDemo(true); | ||
| } | ||
| } catch { | ||
| if (cancelled) return; | ||
| setProjects([DEMO_PROJECT]); | ||
| setIsDemo(true); | ||
| } finally { | ||
| if (!cancelled) setLoading(false); | ||
| } | ||
| } | ||
|
|
||
| load(); | ||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, [currentUser]); | ||
|
|
||
| return { projects, loading, isDemo }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.