-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic dashboard page setup and added profile page for user info
- Loading branch information
Showing
13 changed files
with
566 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import React from "react"; | ||
import { Metadata } from "next"; | ||
import { Sidebar } from "@/components/dashboard/Sidebar"; | ||
import { Topbar } from "@/components/dashboard/Topbar"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Dashboard - ML4E", | ||
description: | ||
"ML4E - Machine Learning for Everyone is a collection of resources to help you learn machine learning.", | ||
}; | ||
|
||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return <main>{children}</main>; | ||
export default function DashboardLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<div className="flex h-screen"> | ||
<Sidebar /> | ||
<div className="flex-1 flex flex-col overflow-hidden"> | ||
<Topbar /> | ||
<main className="flex-1 overflow-y-auto p-6">{children}</main> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains 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,120 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useForm } from "react-hook-form"; | ||
import * as z from "zod"; | ||
import { Loader2, User } from "lucide-react"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
import { useSupabase } from "@/components/providers/SupabaseProvider"; | ||
import { useToast } from "@/hooks/use-toast"; | ||
import { ToastAction } from "@/components/ui/toast"; | ||
|
||
const profileFormSchema = z.object({ | ||
fullName: z.string().min(2, "Name must be at least 2 characters"), | ||
email: z.string().email("Invalid email address"), | ||
}); | ||
|
||
export default function ProfilePage() { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const { supabase, user } = useSupabase(); | ||
const { toast } = useToast(); | ||
|
||
const form = useForm<z.infer<typeof profileFormSchema>>({ | ||
resolver: zodResolver(profileFormSchema), | ||
defaultValues: { | ||
fullName: user?.user_metadata?.full_name || "", | ||
email: user?.email || "", | ||
}, | ||
}); | ||
|
||
async function onSubmit(values: z.infer<typeof profileFormSchema>) { | ||
setIsLoading(true); | ||
try { | ||
const { error } = await supabase.auth.updateUser({ | ||
email: values.email, | ||
data: { full_name: values.fullName }, | ||
}); | ||
if (error) throw error; | ||
toast({ | ||
description: "Profile updated successfully", | ||
}); | ||
} catch (error) { | ||
toast({ | ||
variant: "destructive", | ||
title: "Uh oh! Error", | ||
description: "Error updating profile", | ||
action: <ToastAction altText="Try again">Try again</ToastAction>, | ||
}); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
} | ||
|
||
return ( | ||
<div className="max-w-2xl mx-auto space-y-6"> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Profile Settings</CardTitle> | ||
</CardHeader> | ||
<CardContent className="space-y-6"> | ||
<div className="flex items-center gap-4"> | ||
<Avatar className="h-20 w-20"> | ||
<AvatarImage src={user?.user_metadata?.avatar_url} /> | ||
<AvatarFallback> | ||
<User className="h-10 w-10" /> | ||
</AvatarFallback> | ||
</Avatar> | ||
<Button variant="outline">Change Avatar</Button> | ||
</div> | ||
|
||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> | ||
<FormField | ||
control={form.control} | ||
name="fullName" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Full Name</FormLabel> | ||
<FormControl> | ||
<Input placeholder="John Doe" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Email</FormLabel> | ||
<FormControl> | ||
<Input placeholder="[email protected]" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button type="submit" disabled={isLoading}> | ||
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />} | ||
Save Changes | ||
</Button> | ||
</form> | ||
</Form> | ||
</CardContent> | ||
</Card> | ||
</div> | ||
); | ||
} |
This file contains 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 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 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 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,59 @@ | ||
"use client"; | ||
|
||
import { useState } from 'react'; | ||
import Image from 'next/image'; | ||
import Link from 'next/link'; | ||
import { usePathname } from 'next/navigation'; | ||
import { LayoutDashboard, Users, Database, GraduationCap, Cpu } from 'lucide-react' | ||
import { cn } from '@/lib/utils'; | ||
import { Button } from '@/components/ui/button'; | ||
import { UserNav } from './UserNav'; | ||
|
||
const sidebarItems = [ | ||
{ icon: LayoutDashboard, label: 'Dashboard', href: '/dashboard' }, | ||
{ icon: Users, label: 'Community', href: '/dashboard/community' }, | ||
{ icon: Database, label: 'Datasets', href: '/dashboard/datasets' }, | ||
{ icon: GraduationCap, label: 'Learn', href: '/dashboard/learn' }, | ||
{ icon: Cpu, label: 'Models', href: '/dashboard/models' }, | ||
] | ||
|
||
export function Sidebar() { | ||
const pathname = usePathname(); | ||
const [isCollapsed] = useState(false); | ||
|
||
return ( | ||
<div className={cn( | ||
"flex flex-col h-screen border-r bg-card", | ||
isCollapsed ? "w-16" : "w-64" | ||
)}> | ||
<div className="p-4 flex items-center gap-2"> | ||
<Image src="/logo.png" alt="ML4E" width={32} height={32} /> | ||
{!isCollapsed && <span className="font-bold text-lg">ML4E</span>} | ||
</div> | ||
|
||
<nav className="flex-1 p-2 space-y-1"> | ||
{sidebarItems.map((item) => { | ||
const isActive = pathname.startsWith(item.href); | ||
return ( | ||
<Link key={item.href} href={item.href}> | ||
<Button | ||
variant={isActive ? "secondary" : "ghost"} | ||
className={cn( | ||
"w-full justify-start", | ||
isCollapsed && "justify-center" | ||
)} | ||
> | ||
<item.icon className="h-5 w-5" /> | ||
{!isCollapsed && <span className="ml-2">{item.label}</span>} | ||
</Button> | ||
</Link> | ||
); | ||
})} | ||
</nav> | ||
|
||
<div className="p-4 border-t"> | ||
<UserNav isCollapsed={isCollapsed} /> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.