latest
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import React, { useState, useRef, useEffect } from 'react'
|
||||
import { MessageCircle, X, Send, User, Bot, Heart } from 'lucide-react'
|
||||
import { useLanguage } from '@/components/providers/LanguageProvider'
|
||||
import { useAuth } from '@/components/providers/MockAuthProvider'
|
||||
|
||||
type Message = {
|
||||
id: string
|
||||
@@ -24,6 +25,7 @@ export const ChatWidget: React.FC = () => {
|
||||
const [surveyRating, setSurveyRating] = useState(0)
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null)
|
||||
const { t, dir } = useLanguage()
|
||||
const { user, userProfile } = useAuth()
|
||||
|
||||
useEffect(() => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })
|
||||
@@ -50,6 +52,19 @@ export const ChatWidget: React.FC = () => {
|
||||
setIsTyping(true)
|
||||
|
||||
try {
|
||||
// Create userContext if user is logged in
|
||||
const userContext = user ? {
|
||||
role: userProfile?.role || 'student',
|
||||
token: user.id,
|
||||
profile: userProfile ? {
|
||||
name: userProfile.name,
|
||||
email: userProfile.email,
|
||||
year: userProfile.year,
|
||||
faculty: userProfile.faculty,
|
||||
balance: userProfile.balance
|
||||
} : undefined
|
||||
} : undefined;
|
||||
|
||||
const response = await fetch('/api/chat', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -59,6 +74,7 @@ export const ChatWidget: React.FC = () => {
|
||||
message: userMessage,
|
||||
mode: chatMode,
|
||||
history: messages,
|
||||
userContext
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user