11"use client" ;
22
3+ import { useState } from "react" ;
4+ import { useRouter } from "next/navigation" ;
35import { Card , CardContent , CardFooter , CardHeader } from "@/components/ui/card" ;
46import { Badge } from "@/components/ui/badge" ;
57import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar" ;
68import { Button } from "@/components/ui/button" ;
7- import { Briefcase , Linkedin , Clock , GraduationCap } from "lucide-react" ;
9+ import { Briefcase , Linkedin , MessageCircle , Loader2 } from "lucide-react" ;
810import { RequestDialog } from "./RequestDialog" ;
11+ import { conversationService } from "@/lib/services/conversationService" ;
12+ import { toast } from "sonner" ;
913
1014export interface Mentor {
1115 id : string ;
16+ user_id ?: string | null ;
1217 first_name : string ;
1318 last_name : string ;
1419 company : string ;
@@ -25,32 +30,34 @@ interface MentorCardProps {
2530 mentor : Mentor ;
2631}
2732
28- const EXPERTISE_LABELS : Record < string , string > = {
29- "web-development" : "Web Dev" ,
30- "mobile-development" : "Mobile Dev" ,
31- "ai-ml" : "AI & ML" ,
32- "data-science" : "Data Science" ,
33- "cybersecurity" : "Cybersecurity" ,
34- "blockchain" : "Blockchain" ,
35- "ui-ux" : "UI/UX" ,
36- "devops" : "DevOps" ,
37- "game-development" : "Game Dev" ,
38- "cloud-computing" : "Cloud" ,
39- "system-design" : "System Design" ,
40- "algorithms" : "Algorithms" ,
41- } ;
42-
4333const IMAGE_MAP : Record < string , string > = {
4434 "Deepak Pandey" : "/images/team/deepak.jpeg" ,
4535 "Parisha Sharma" : "/images/team/parisha.jpeg" ,
4636 "Akshay Kumar" : "/images/team/akshay.jpg" ,
4737} ;
4838
4939export function MentorCard ( { mentor } : MentorCardProps ) {
40+ const router = useRouter ( ) ;
41+ const [ loading , setLoading ] = useState ( false ) ;
5042 const initials = `${ mentor . first_name [ 0 ] } ${ mentor . last_name [ 0 ] } ` ;
5143 const fullName = `${ mentor . first_name } ${ mentor . last_name } ` ;
5244 const imageSrc = IMAGE_MAP [ fullName ] || `https://api.dicebear.com/7.x/avataaars/svg?seed=${ mentor . id } ` ;
5345
46+ const handleMessage = async ( ) => {
47+ if ( ! mentor . user_id ) return ;
48+
49+ setLoading ( true ) ;
50+ try {
51+ const conversation = await conversationService . getOrCreateMentorshipConversation ( mentor . user_id ) ;
52+ router . push ( `/protected/messages?conversation=${ conversation . id } ` ) ;
53+ } catch ( error ) {
54+ console . error ( "Failed to start conversation:" , error ) ;
55+ toast . error ( "Failed to start conversation. Please try again." ) ;
56+ } finally {
57+ setLoading ( false ) ;
58+ }
59+ } ;
60+
5461 return (
5562 < Card className = "flex flex-col h-full overflow-hidden border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-900/50 hover:shadow-lg transition-all duration-300 group" >
5663 < CardHeader className = "p-6 pb-4 space-y-4" >
@@ -63,77 +70,92 @@ export function MentorCard({ mentor }: MentorCardProps) {
6370 </ AvatarFallback >
6471 </ Avatar >
6572 < div >
66- < h3 className = "font-bold text-lg leading-none mb-1 group-hover:text-primary transition-colors" >
67- { fullName }
73+ < h3 className = "font-bold text-lg text-zinc-900 dark:text-zinc-100 group-hover:text-primary transition-colors" >
74+ { mentor . first_name } { mentor . last_name }
6875 </ h3 >
69- < div className = "flex items-center text-sm text-muted-foreground mb -1" >
70- < Briefcase className = "h -3.5 w -3.5 mr-1.5" />
76+ < div className = "flex items-center text-sm text-zinc-500 dark:text-zinc-400 mt -1" >
77+ < Briefcase className = "w -3.5 h -3.5 mr-1.5" />
7178 { mentor . occupation } at { mentor . company }
7279 </ div >
73- { mentor . linkedin && (
74- < a
75- href = { mentor . linkedin }
76- target = "_blank"
77- rel = "noopener noreferrer"
78- className = "inline-flex items-center text-xs text-blue-500 hover:underline"
79- >
80- < Linkedin className = "h-3 w-3 mr-1" />
81- LinkedIn Profile
82- </ a >
83- ) }
8480 </ div >
8581 </ div >
82+ { mentor . linkedin && (
83+ < a
84+ href = { mentor . linkedin }
85+ target = "_blank"
86+ rel = "noopener noreferrer"
87+ className = "text-zinc-400 hover:text-[#0077b5] transition-colors"
88+ >
89+ < Linkedin className = "w-5 h-5" />
90+ </ a >
91+ ) }
8692 </ div >
8793 </ CardHeader >
8894
89- < CardContent className = "p -6 pt-0 flex-grow space-y-4" >
90- < div className = "space-y-2" >
91- < p className = "text-sm text-muted-foreground line-clamp-3" >
95+ < CardContent className = "px -6 py-2 flex-grow space-y-4" >
96+ < div >
97+ < p className = "text-sm text-zinc-600 dark:text-zinc-300 line-clamp-2 mb -3" >
9298 { mentor . expertise }
9399 </ p >
94- </ div >
95-
96- < div className = "space-y-3" >
97100 < div className = "flex flex-wrap gap-1.5" >
98- { mentor . expertise_areas ? .slice ( 0 , 4 ) . map ( ( area ) => (
101+ { mentor . expertise_areas . slice ( 0 , 3 ) . map ( ( area ) => (
99102 < Badge
100103 key = { area }
101104 variant = "secondary"
102- className = "text-xs bg-primary/5 text-primary hover:bg-primary/10 border-transparent "
105+ className = "text-xs bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-300 hover:bg-zinc-200 dark:hover:bg-zinc-700 "
103106 >
104- { EXPERTISE_LABELS [ area ] || area }
107+ { area . replace ( "-" , " " ) }
105108 </ Badge >
106109 ) ) }
107- { mentor . expertise_areas ?. length > 4 && (
110+ { mentor . expertise_areas ?. length > 3 && (
108111 < Badge variant = "outline" className = "text-xs" >
109- +{ mentor . expertise_areas . length - 4 } more
112+ +{ mentor . expertise_areas . length - 3 } more
110113 </ Badge >
111114 ) }
112115 </ div >
113116 </ div >
114117
115- < div className = "flex items-center gap-4 text-xs text-muted-foreground pt-2 border-t border-border/50" >
116- < div className = "flex items-center" >
117- < Clock className = "h-3.5 w-3.5 mr-1.5" />
118- { mentor . availability }
119- </ div >
120- < div className = "flex items-center" >
121- < GraduationCap className = "h-3.5 w-3.5 mr-1.5" />
122- { mentor . mentoring_types ?. length || 0 } Types
118+ < div className = "pt-2 border-t border-zinc-100 dark:border-zinc-800" >
119+ < div className = "flex flex-wrap gap-2 text-xs text-zinc-500" >
120+ { mentor . mentoring_types . map ( ( type ) => (
121+ < span key = { type } className = "flex items-center" >
122+ • { type . replace ( "-" , " " ) }
123+ </ span >
124+ ) ) }
123125 </ div >
124126 </ div >
125127 </ CardContent >
126128
127- < CardFooter className = "p-6 pt-0 mt-auto" >
128- < RequestDialog
129- mentorName = { fullName }
130- mentorId = { mentor . id }
131- trigger = {
132- < Button className = "w-full bg-primary/10 text-primary hover:bg-primary/20 shadow-none border-0" >
133- Request Mentorship
134- </ Button >
135- }
136- />
129+ < CardFooter className = "p-6 pt-2" >
130+ { mentor . user_id ? (
131+ < Button
132+ className = "w-full bg-primary/10 hover:bg-primary/20 text-primary border-0 shadow-none"
133+ onClick = { handleMessage }
134+ disabled = { loading }
135+ >
136+ { loading ? (
137+ < >
138+ < Loader2 className = "w-4 h-4 mr-2 animate-spin" />
139+ Connecting...
140+ </ >
141+ ) : (
142+ < >
143+ < MessageCircle className = "w-4 h-4 mr-2" />
144+ Message Mentor
145+ </ >
146+ ) }
147+ </ Button >
148+ ) : (
149+ < RequestDialog
150+ mentorName = { fullName }
151+ mentorId = { mentor . id }
152+ trigger = {
153+ < Button className = "w-full bg-primary/10 text-primary hover:bg-primary/20 shadow-none border-0" >
154+ Request Mentorship
155+ </ Button >
156+ }
157+ />
158+ ) }
137159 </ CardFooter >
138160 </ Card >
139161 ) ;
0 commit comments