-
Notifications
You must be signed in to change notification settings - Fork 3
86b1vx0v2: Add Card and Avatar Components with Conditional Rendering for Login Page #25
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
base: development
Are you sure you want to change the base?
Changes from 14 commits
d7f3e6c
7667e5e
6cea914
4186b7c
d87a8ee
4f3a40b
59f46ce
5063490
dc2f06b
b8b8bb0
eabfa47
b248ef9
f7d0bf4
c172329
ae6ad1c
5df067f
f56a359
f1a0c25
4604ab2
c63bae5
0f92b49
f569066
d80bd87
9feb7d6
fefe3e2
9674436
eb4cfb0
a5bb525
7f0b682
2ae304c
57e513a
6a536cf
c3a828e
081a80d
12a473c
01f6928
fd76e9f
c58a27a
ba2f304
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use client'; | ||
|
|
||
| import { usePathname } from 'next/navigation'; // Import usePathname | ||
| import ProfileCard from "@/components/ProfileCard"; | ||
|
|
||
| const ConditionalLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
| const pathname = usePathname(); // Get the current pathname | ||
|
|
||
| const isLoginPage = pathname === '/login'; // Check if the current page is the login page | ||
|
|
||
| return ( | ||
| <> | ||
| {!isLoginPage && ( | ||
| <> | ||
| {/* Logo in the top-left corner */} | ||
| <div className="absolute top-4 left-4"> | ||
| <img | ||
| src="../t2t logo.png" // Ensure correct file path and name | ||
| alt="T2T Logo" | ||
| className="w-24 h-auto" // Adjust size as needed | ||
| /> | ||
| </div> | ||
|
|
||
| {/* ProfileCard component in the top-right corner */} | ||
| <div className="absolute top-4 right-4"> | ||
| <ProfileCard /> | ||
| </div> | ||
| </> | ||
| )} | ||
| <main className="p-4"> | ||
| {children} | ||
| </main> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default ConditionalLayout; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // src/components/ProfileCard.tsx | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import { useRouter } from 'next/navigation'; | ||
| import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
| import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; | ||
|
|
||
| export default function ProfileCard() { | ||
| const [isCardVisible, setIsCardVisible] = useState(false); | ||
| const router = useRouter(); | ||
|
|
||
| const toggleCardVisibility = () => { | ||
| setIsCardVisible(!isCardVisible); | ||
| }; | ||
|
|
||
| const handleLogout = async () => { | ||
|
||
| // Clear authentication tokens (adjust according to your storage method) | ||
| localStorage.removeItem('authToken'); | ||
| document.cookie = 'authToken=; expires=Thu, 01 Jan 1970 00:00:00 GMT;'; | ||
|
|
||
| // Redirect to the login page or home page after logout | ||
| router.push('/login'); // Adjust to your login route | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="absolute top-4 right-4"> | ||
| <button onClick={toggleCardVisibility}> | ||
| <Avatar> | ||
| <AvatarImage src="https://github.com/shadcn.png" /> | ||
| <AvatarFallback>CN</AvatarFallback> | ||
| </Avatar> | ||
| </button> | ||
| {isCardVisible && ( | ||
| <div className="absolute top-16 right-0 bg-light-green-100 p-4 border border-gray-200 rounded shadow-lg"> | ||
| <Card> | ||
| <CardHeader className="flex flex-col items-center bg-light-green-100 p-2"> | ||
| <Avatar> | ||
| <AvatarImage src="https://github.com/shadcn.png" /> | ||
| <AvatarFallback>CN</AvatarFallback> | ||
| </Avatar> | ||
| <CardTitle className="mt-2 text-lg font-semibold">Mohamed Asfik</CardTitle> | ||
| </CardHeader> | ||
| <CardContent className="bg-light-green-100 p-4"> | ||
| <p className="text-center text-sm text-gray-700">[email protected]</p> | ||
| </CardContent> | ||
| <CardFooter className="flex justify-center bg-light-green-100 p-2"> | ||
| <button | ||
| className="bg-red-500 text-white py-1 px-4 rounded" | ||
| onClick={handleLogout} | ||
| > | ||
| Logout | ||
| </button> | ||
| </CardFooter> | ||
| </Card> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| "use client" | ||
|
|
||
| import * as React from "react" | ||
| import * as AvatarPrimitive from "@radix-ui/react-avatar" | ||
|
|
||
| import { cn } from "@/lib/utils" | ||
|
|
||
| const Avatar = React.forwardRef< | ||
| React.ElementRef<typeof AvatarPrimitive.Root>, | ||
| React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> | ||
| >(({ className, ...props }, ref) => ( | ||
| <AvatarPrimitive.Root | ||
| ref={ref} | ||
| className={cn( | ||
| "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| Avatar.displayName = AvatarPrimitive.Root.displayName | ||
|
|
||
| const AvatarImage = React.forwardRef< | ||
| React.ElementRef<typeof AvatarPrimitive.Image>, | ||
| React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> | ||
| >(({ className, ...props }, ref) => ( | ||
| <AvatarPrimitive.Image | ||
| ref={ref} | ||
| className={cn("aspect-square h-full w-full", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| AvatarImage.displayName = AvatarPrimitive.Image.displayName | ||
|
|
||
| const AvatarFallback = React.forwardRef< | ||
| React.ElementRef<typeof AvatarPrimitive.Fallback>, | ||
| React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> | ||
| >(({ className, ...props }, ref) => ( | ||
| <AvatarPrimitive.Fallback | ||
| ref={ref} | ||
| className={cn( | ||
| "flex h-full w-full items-center justify-center rounded-full bg-muted", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName | ||
|
|
||
| export { Avatar, AvatarImage, AvatarFallback } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import * as React from "react" | ||
|
|
||
| import { cn } from "@/lib/utils" | ||
|
|
||
| const Card = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn( | ||
| "rounded-lg border bg-card text-card-foreground shadow-sm", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| Card.displayName = "Card" | ||
|
|
||
| const CardHeader = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn("flex flex-col space-y-1.5 p-6", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardHeader.displayName = "CardHeader" | ||
|
|
||
| const CardTitle = React.forwardRef< | ||
| HTMLParagraphElement, | ||
| React.HTMLAttributes<HTMLHeadingElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <h3 | ||
| ref={ref} | ||
| className={cn( | ||
| "text-2xl font-semibold leading-none tracking-tight", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardTitle.displayName = "CardTitle" | ||
|
|
||
| const CardDescription = React.forwardRef< | ||
| HTMLParagraphElement, | ||
| React.HTMLAttributes<HTMLParagraphElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <p | ||
| ref={ref} | ||
| className={cn("text-sm text-muted-foreground", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardDescription.displayName = "CardDescription" | ||
|
|
||
| const CardContent = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div ref={ref} className={cn("p-6 pt-0", className)} {...props} /> | ||
| )) | ||
| CardContent.displayName = "CardContent" | ||
|
|
||
| const CardFooter = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn("flex items-center p-6 pt-0", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardFooter.displayName = "CardFooter" | ||
|
|
||
| export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't query file path name. The common header should only be displayed if the user is authenticated. Use the session object here, and convert this to a server component. @thlurte please provide him guidance if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,