new changes
This commit is contained in:
parent
b980f7a052
commit
3e6202f6d3
20
src/App.tsx
20
src/App.tsx
|
@ -6,6 +6,8 @@ import { ChatInterface } from './components/ChatInterface';
|
||||||
import { TicketConfirmation } from './components/TicketConfirmation';
|
import { TicketConfirmation } from './components/TicketConfirmation';
|
||||||
import { apiService } from './services/apiService';
|
import { apiService } from './services/apiService';
|
||||||
import { Ticket } from './types';
|
import { Ticket } from './types';
|
||||||
|
import { FilePlus } from 'lucide-react'; // Add this import at the top
|
||||||
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [activeTab, setActiveTab] = useState<'new' | 'history' | 'chat'>('new');
|
const [activeTab, setActiveTab] = useState<'new' | 'history' | 'chat'>('new');
|
||||||
|
@ -115,15 +117,25 @@ function App() {
|
||||||
{/* Main Content */}
|
{/* Main Content */}
|
||||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||||
{activeTab === 'new' && (
|
{activeTab === 'new' && (
|
||||||
<div>
|
<div className="flex items-center justify-center min-h-[80vh] px-4">
|
||||||
<div className="mb-8">
|
<div className="bg-gray-800 border border-gray-700 rounded-2xl shadow-2xl p-8 max-w-xl w-full text-center transition-all duration-300 hover:shadow-blue-700/30">
|
||||||
<h2 className="text-2xl font-bold text-white mb-2">Submit New Ticket</h2>
|
|
||||||
<p className="text-gray-400">Use voice or text to describe your IT issue</p>
|
{/* Header with icon */}
|
||||||
|
<div className="mb-6 flex flex-col items-center">
|
||||||
|
<div className="bg-gradient-to-r from-blue-600 to-purple-600 p-3 rounded-full shadow-lg mb-4">
|
||||||
|
<FilePlus className="w-6 h-6 text-white" />
|
||||||
</div>
|
</div>
|
||||||
|
<h2 className="text-3xl font-extrabold text-white mb-2">Submit a New Ticket</h2>
|
||||||
|
<p className="text-gray-400 text-sm">Describe your IT issue using voice or text — we’ll take it from here!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Ticket form */}
|
||||||
<TicketForm onTicketSubmit={handleTicketSubmit} />
|
<TicketForm onTicketSubmit={handleTicketSubmit} />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
{activeTab === 'history' && (
|
{activeTab === 'history' && (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-8 flex items-center justify-between">
|
<div className="mb-8 flex items-center justify-between">
|
||||||
|
|
|
@ -2,6 +2,7 @@ import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { Send, Bot, User, Loader, MessageSquare, UserPlus } from 'lucide-react';
|
import { Send, Bot, User, Loader, MessageSquare, UserPlus } from 'lucide-react';
|
||||||
import { ChatMessage } from '../types';
|
import { ChatMessage } from '../types';
|
||||||
import { ChatService } from '../services/chatService';
|
import { ChatService } from '../services/chatService';
|
||||||
|
import { Mic, MicOff } from 'lucide-react';
|
||||||
|
|
||||||
interface ChatInterfaceProps {
|
interface ChatInterfaceProps {
|
||||||
onCreateTicket?: (conversation: string) => void;
|
onCreateTicket?: (conversation: string) => void;
|
||||||
|
@ -23,22 +24,61 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
|
||||||
const [isCreatingTicket, setIsCreatingTicket] = useState(false);
|
const [isCreatingTicket, setIsCreatingTicket] = useState(false);
|
||||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||||
const [chatService] = useState(() => new ChatService());
|
const [chatService] = useState(() => new ChatService());
|
||||||
|
const [isListening, setIsListening] = useState(false);
|
||||||
|
const recognitionRef = useRef<SpeechRecognition | null>(null);
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
scrollToBottom();
|
const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
|
||||||
}, [messages]);
|
|
||||||
|
|
||||||
const handleSend = async () => {
|
if (SpeechRecognition) {
|
||||||
if (!input.trim() || isLoading) return;
|
const recognition = new SpeechRecognition();
|
||||||
|
recognition.lang = 'en-US';
|
||||||
|
recognition.interimResults = false;
|
||||||
|
recognition.maxAlternatives = 1;
|
||||||
|
|
||||||
|
recognition.onstart = () => setIsListening(true);
|
||||||
|
recognition.onend = () => setIsListening(false);
|
||||||
|
recognition.onerror = (e: any) => {
|
||||||
|
console.error('Speech recognition error', e);
|
||||||
|
setIsListening(false);
|
||||||
|
};
|
||||||
|
recognition.onresult = (event: SpeechRecognitionEvent) => {
|
||||||
|
const transcript = event.results[0][0].transcript;
|
||||||
|
setInput(transcript);
|
||||||
|
handleSend(transcript);
|
||||||
|
};
|
||||||
|
|
||||||
|
recognitionRef.current = recognition;
|
||||||
|
} else {
|
||||||
|
console.warn('SpeechRecognition is not supported in this browser.');
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const speak = (text: string) => {
|
||||||
|
if ('speechSynthesis' in window) {
|
||||||
|
const utterance = new SpeechSynthesisUtterance(text);
|
||||||
|
utterance.lang = 'en-US';
|
||||||
|
utterance.pitch = 1;
|
||||||
|
utterance.rate = 1;
|
||||||
|
utterance.volume = 1;
|
||||||
|
window.speechSynthesis.speak(utterance);
|
||||||
|
} else {
|
||||||
|
console.warn('Speech synthesis not supported in this browser.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSend = async (messageOverride?: string) => {
|
||||||
|
const messageToSend = messageOverride ?? input;
|
||||||
|
if (!messageToSend.trim() || isLoading) return;
|
||||||
|
|
||||||
const userMessage: ChatMessage = {
|
const userMessage: ChatMessage = {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: input,
|
content: messageToSend,
|
||||||
timestamp: new Date().toLocaleString()
|
timestamp: new Date().toLocaleString()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,12 +97,13 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
|
||||||
};
|
};
|
||||||
|
|
||||||
setMessages(prev => [...prev, assistantMessage]);
|
setMessages(prev => [...prev, assistantMessage]);
|
||||||
|
speak(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Chat error:', error);
|
console.error('Chat error:', error);
|
||||||
const errorMessage: ChatMessage = {
|
const errorMessage: ChatMessage = {
|
||||||
id: (Date.now() + 1).toString(),
|
id: (Date.now() + 1).toString(),
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: "I apologize, but I'm experiencing some technical difficulties. Please try again or create a support ticket if the issue persists.",
|
content: "I apologize, but I'm experiencing some technical difficulties.",
|
||||||
timestamp: new Date().toLocaleString()
|
timestamp: new Date().toLocaleString()
|
||||||
};
|
};
|
||||||
setMessages(prev => [...prev, errorMessage]);
|
setMessages(prev => [...prev, errorMessage]);
|
||||||
|
@ -71,6 +112,7 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleKeyPress = (e: React.KeyboardEvent) => {
|
const handleKeyPress = (e: React.KeyboardEvent) => {
|
||||||
if (e.key === 'Enter' && !e.shiftKey) {
|
if (e.key === 'Enter' && !e.shiftKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -78,6 +120,17 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMicClick = () => {
|
||||||
|
if (recognitionRef.current) {
|
||||||
|
if (isListening) {
|
||||||
|
recognitionRef.current.stop();
|
||||||
|
} else {
|
||||||
|
recognitionRef.current.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleCreateTicketFromChat = async () => {
|
const handleCreateTicketFromChat = async () => {
|
||||||
if (!ticketFormData.requester.trim() || !ticketFormData.email.trim()) {
|
if (!ticketFormData.requester.trim() || !ticketFormData.email.trim()) {
|
||||||
return;
|
return;
|
||||||
|
@ -260,13 +313,38 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ onCreateTicket })
|
||||||
rows={1}
|
rows={1}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
/>
|
/>
|
||||||
|
<div className="flex gap-3">
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={handleSend}
|
onClick={handleMicClick}
|
||||||
|
className={`relative flex items-center justify-center px-4 py-3 rounded-lg transition-all duration-200
|
||||||
|
${isListening ? 'bg-red-600 animate-pulse' : 'bg-gray-700 hover:bg-gray-600'}
|
||||||
|
text-white disabled:opacity-50 disabled:cursor-not-allowed hover:scale-105`}
|
||||||
|
disabled={isLoading}
|
||||||
|
title={isListening ? "Stop Listening" : "Start Voice Input"}
|
||||||
|
>
|
||||||
|
{isListening ? (
|
||||||
|
<MicOff className="w-5 h-5" />
|
||||||
|
) : (
|
||||||
|
<Mic className="w-5 h-5" />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isListening && (
|
||||||
|
<span className="absolute -bottom-6 text-xs text-red-400 animate-pulse">Listening...</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => handleSend()}
|
||||||
disabled={!input.trim() || isLoading}
|
disabled={!input.trim() || isLoading}
|
||||||
className="px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 text-white rounded-lg transition-all duration-200 hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100"
|
className="px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 text-white rounded-lg transition-all duration-200 hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
>
|
>
|
||||||
<Send className="w-5 h-5" />
|
<Send className="w-5 h-5" />
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -68,13 +68,7 @@ export const TicketForm: React.FC<TicketFormProps> = ({ onTicketSubmit }) => {
|
||||||
<div className="max-w-2xl mx-auto">
|
<div className="max-w-2xl mx-auto">
|
||||||
<div className="bg-gray-900 rounded-xl p-6 shadow-2xl border border-gray-800">
|
<div className="bg-gray-900 rounded-xl p-6 shadow-2xl border border-gray-800">
|
||||||
<div className="flex items-center gap-3 mb-6">
|
<div className="flex items-center gap-3 mb-6">
|
||||||
<div className="w-10 h-10 bg-blue-600 rounded-lg flex items-center justify-center">
|
|
||||||
<FileText className="w-5 h-5 text-white" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h2 className="text-xl font-semibold text-white">Create New Ticket</h2>
|
|
||||||
<p className="text-gray-400 text-sm">Submit your IT support request</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
|
@ -86,7 +80,7 @@ export const TicketForm: React.FC<TicketFormProps> = ({ onTicketSubmit }) => {
|
||||||
<form onSubmit={handleSubmit} className="space-y-6">
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
<label className="block text-sm font-medium text-gray-300 mb-2 text-left">
|
||||||
<User className="w-4 h-4 inline mr-2" />
|
<User className="w-4 h-4 inline mr-2" />
|
||||||
Your Name
|
Your Name
|
||||||
</label>
|
</label>
|
||||||
|
@ -102,10 +96,11 @@ export const TicketForm: React.FC<TicketFormProps> = ({ onTicketSubmit }) => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
<label className="block text-sm font-medium text-gray-300 mb-2 text-left flex items-center gap-2">
|
||||||
<Mail className="w-4 h-4 inline mr-2" />
|
<Mail className="w-4 h-4 text-gray-400" />
|
||||||
Email Address
|
Email Address
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
value={formData.email}
|
value={formData.email}
|
||||||
|
|
Loading…
Reference in a new issue