Update ClientPortal.tsx
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { Ticket, KBArticle, ChatMessage, TicketPriority, TicketStatus, SurveyResult, Attachment, ClientUser, TicketQueue } from '../types';
|
import { Ticket, KBArticle, ChatMessage, TicketPriority, TicketStatus, SurveyResult, Attachment, ClientUser, TicketQueue, AppSettings } from '../types';
|
||||||
import { getSupportResponse } from '../services/geminiService';
|
import { getSupportResponse } from '../services/geminiService';
|
||||||
import { ToastType } from './Toast';
|
import { ToastType } from './Toast';
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +28,7 @@ interface ClientPortalProps {
|
|||||||
currentUser: ClientUser;
|
currentUser: ClientUser;
|
||||||
articles: KBArticle[];
|
articles: KBArticle[];
|
||||||
queues: TicketQueue[];
|
queues: TicketQueue[];
|
||||||
|
settings: AppSettings; // Added settings prop
|
||||||
onCreateTicket: (ticket: Omit<Ticket, 'id' | 'createdAt' | 'messages' | 'status'>) => void;
|
onCreateTicket: (ticket: Omit<Ticket, 'id' | 'createdAt' | 'messages' | 'status'>) => void;
|
||||||
onReplyTicket: (ticketId: string, message: string) => void;
|
onReplyTicket: (ticketId: string, message: string) => void;
|
||||||
onSubmitSurvey: (survey: Omit<SurveyResult, 'id' | 'timestamp'>) => void;
|
onSubmitSurvey: (survey: Omit<SurveyResult, 'id' | 'timestamp'>) => void;
|
||||||
@@ -41,6 +41,7 @@ export const ClientPortal: React.FC<ClientPortalProps> = ({
|
|||||||
currentUser,
|
currentUser,
|
||||||
articles,
|
articles,
|
||||||
queues,
|
queues,
|
||||||
|
settings,
|
||||||
onCreateTicket,
|
onCreateTicket,
|
||||||
onReplyTicket,
|
onReplyTicket,
|
||||||
onSubmitSurvey,
|
onSubmitSurvey,
|
||||||
@@ -102,11 +103,20 @@ export const ClientPortal: React.FC<ClientPortalProps> = ({
|
|||||||
setInputMessage('');
|
setInputMessage('');
|
||||||
setIsTyping(true);
|
setIsTyping(true);
|
||||||
|
|
||||||
const aiResponseText = await getSupportResponse(
|
const apiKey = settings.aiConfig.apiKey;
|
||||||
userMsg.content,
|
|
||||||
chatMessages.map(m => m.content).slice(-5),
|
// Check if API Key exists before calling service
|
||||||
articles
|
let aiResponseText = '';
|
||||||
);
|
if (!apiKey) {
|
||||||
|
aiResponseText = "L'assistente AI non è disponibile al momento (Configurazione incompleta).";
|
||||||
|
} else {
|
||||||
|
aiResponseText = await getSupportResponse(
|
||||||
|
apiKey,
|
||||||
|
userMsg.content,
|
||||||
|
chatMessages.map(m => m.content).slice(-5),
|
||||||
|
articles
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const aiMsg: ChatMessage = {
|
const aiMsg: ChatMessage = {
|
||||||
id: (Date.now() + 1).toString(),
|
id: (Date.now() + 1).toString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user