This commit is contained in:
Krikorios
2025-07-14 10:14:20 +04:00
parent 890acbd5bc
commit 868c9b252c
21 changed files with 615 additions and 97 deletions
+16
View File
@@ -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
}),
})