mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 11:32:13 +01:00
feat: make filters & sorting section collapsible
- Add collapsible filters section to save space on sessions page - Show/hide toggle button with chevron icons for better UX - Filters start collapsed by default for cleaner initial view - Improves mobile experience by reducing vertical space usage
This commit is contained in:
@ -3,6 +3,12 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { Company } from "../../../lib/types";
|
import { Company } from "../../../lib/types";
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
|
import { ShieldX, Settings, Save, Database, Bell } from "lucide-react";
|
||||||
|
|
||||||
export default function CompanySettingsPage() {
|
export default function CompanySettingsPage() {
|
||||||
const { data: session, status } = useSession();
|
const { data: session, status } = useSession();
|
||||||
@ -74,110 +80,161 @@ export default function CompanySettingsPage() {
|
|||||||
|
|
||||||
// Loading state
|
// Loading state
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <div className="text-center py-10">Loading settings...</div>;
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Settings className="h-6 w-6" />
|
||||||
|
<CardTitle>Company Settings</CardTitle>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
Loading settings...
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for ADMIN access
|
// Check for ADMIN access
|
||||||
if (session?.user?.role !== "ADMIN") {
|
if (session?.user?.role !== "ADMIN") {
|
||||||
return (
|
return (
|
||||||
<div className="text-center py-10 bg-white rounded-xl shadow p-6">
|
<div className="space-y-6">
|
||||||
<h2 className="font-bold text-xl text-red-600 mb-2">Access Denied</h2>
|
<Card>
|
||||||
<p>You don't have permission to view company settings.</p>
|
<CardHeader>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<ShieldX className="h-6 w-6 text-destructive" />
|
||||||
|
<CardTitle className="text-destructive">Access Denied</CardTitle>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-center py-8">
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
You don't have permission to view company settings.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="bg-white p-6 rounded-xl shadow">
|
<Card>
|
||||||
<h1 className="text-2xl font-bold text-gray-800 mb-6">
|
<CardHeader>
|
||||||
Company Settings
|
<div className="flex items-center gap-3">
|
||||||
</h1>
|
<Settings className="h-6 w-6" />
|
||||||
|
<CardTitle>Company Settings</CardTitle>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
{message && (
|
||||||
|
<Alert variant={message.includes("Failed") ? "destructive" : "default"}>
|
||||||
|
<AlertDescription>{message}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
{message && (
|
<form
|
||||||
<div
|
className="space-y-6"
|
||||||
className={`p-4 rounded mb-6 ${message.includes("Failed") ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"}`}
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleSave();
|
||||||
|
}}
|
||||||
|
autoComplete="off"
|
||||||
>
|
>
|
||||||
{message}
|
<div className="grid gap-6 md:grid-cols-2">
|
||||||
</div>
|
<Card>
|
||||||
)}
|
<CardHeader>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Database className="h-5 w-5" />
|
||||||
|
<CardTitle className="text-lg">Data Source Configuration</CardTitle>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="csvUrl">CSV Data Source URL</Label>
|
||||||
|
<Input
|
||||||
|
id="csvUrl"
|
||||||
|
type="text"
|
||||||
|
value={csvUrl}
|
||||||
|
onChange={(e) => setCsvUrl(e.target.value)}
|
||||||
|
placeholder="https://example.com/data.csv"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form
|
<div className="space-y-2">
|
||||||
className="grid gap-6"
|
<Label htmlFor="csvUsername">CSV Username</Label>
|
||||||
onSubmit={(e) => {
|
<Input
|
||||||
e.preventDefault();
|
id="csvUsername"
|
||||||
handleSave();
|
type="text"
|
||||||
}}
|
value={csvUsername}
|
||||||
autoComplete="off"
|
onChange={(e) => setCsvUsername(e.target.value)}
|
||||||
>
|
placeholder="Username for CSV access (if needed)"
|
||||||
<div className="grid gap-2">
|
autoComplete="off"
|
||||||
<label className="font-medium text-gray-700">
|
/>
|
||||||
CSV Data Source URL
|
</div>
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-sky-500"
|
|
||||||
value={csvUrl}
|
|
||||||
onChange={(e) => setCsvUrl(e.target.value)}
|
|
||||||
placeholder="https://example.com/data.csv"
|
|
||||||
autoComplete="off"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-2">
|
<div className="space-y-2">
|
||||||
<label className="font-medium text-gray-700">CSV Username</label>
|
<Label htmlFor="csvPassword">CSV Password</Label>
|
||||||
<input
|
<Input
|
||||||
type="text"
|
id="csvPassword"
|
||||||
className="border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-sky-500"
|
type="password"
|
||||||
value={csvUsername}
|
value={csvPassword}
|
||||||
onChange={(e) => setCsvUsername(e.target.value)}
|
onChange={(e) => setCsvPassword(e.target.value)}
|
||||||
placeholder="Username for CSV access (if needed)"
|
placeholder="Password will be updated only if provided"
|
||||||
autoComplete="off"
|
autoComplete="new-password"
|
||||||
/>
|
/>
|
||||||
</div>
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Leave blank to keep current password
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<div className="grid gap-2">
|
<Card>
|
||||||
<label className="font-medium text-gray-700">CSV Password</label>
|
<CardHeader>
|
||||||
<input
|
<div className="flex items-center gap-2">
|
||||||
type="password"
|
<Bell className="h-5 w-5" />
|
||||||
className="border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-sky-500"
|
<CardTitle className="text-lg">Alert Configuration</CardTitle>
|
||||||
value={csvPassword}
|
</div>
|
||||||
onChange={(e) => setCsvPassword(e.target.value)}
|
</CardHeader>
|
||||||
placeholder="Password will be updated only if provided"
|
<CardContent>
|
||||||
autoComplete="new-password"
|
<div className="space-y-2">
|
||||||
/>
|
<Label htmlFor="sentimentThreshold">
|
||||||
<p className="text-sm text-gray-500">
|
Sentiment Alert Threshold
|
||||||
Leave blank to keep current password
|
</Label>
|
||||||
</p>
|
<Input
|
||||||
</div>
|
id="sentimentThreshold"
|
||||||
|
type="number"
|
||||||
|
value={sentimentThreshold}
|
||||||
|
onChange={(e) => setSentimentThreshold(e.target.value)}
|
||||||
|
placeholder="Threshold value (0-100)"
|
||||||
|
min="0"
|
||||||
|
max="100"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Percentage of negative sentiment sessions to trigger alert (0-100)
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-2">
|
<div className="flex justify-end">
|
||||||
<label className="font-medium text-gray-700">
|
<Button type="submit" className="gap-2">
|
||||||
Sentiment Alert Threshold
|
<Save className="h-4 w-4" />
|
||||||
</label>
|
Save Settings
|
||||||
<input
|
</Button>
|
||||||
type="number"
|
</div>
|
||||||
className="border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-sky-500"
|
</form>
|
||||||
value={sentimentThreshold}
|
</CardContent>
|
||||||
onChange={(e) => setSentimentThreshold(e.target.value)}
|
</Card>
|
||||||
placeholder="Threshold value (0-100)"
|
|
||||||
min="0"
|
|
||||||
max="100"
|
|
||||||
autoComplete="off"
|
|
||||||
/>
|
|
||||||
<p className="text-sm text-gray-500">
|
|
||||||
Percentage of negative sentiment sessions to trigger alert (0-100)
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="bg-sky-600 hover:bg-sky-700 text-white py-2 px-4 rounded-lg shadow transition-colors w-full sm:w-auto"
|
|
||||||
>
|
|
||||||
Save Settings
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,29 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useParams, useRouter } from "next/navigation"; // Import useRouter
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useSession } from "next-auth/react"; // Import useSession
|
import { useSession } from "next-auth/react";
|
||||||
import SessionDetails from "../../../../components/SessionDetails";
|
import SessionDetails from "../../../../components/SessionDetails";
|
||||||
import TranscriptViewer from "../../../../components/TranscriptViewer";
|
import TranscriptViewer from "../../../../components/TranscriptViewer";
|
||||||
import MessageViewer from "../../../../components/MessageViewer";
|
import MessageViewer from "../../../../components/MessageViewer";
|
||||||
import { ChatSession } from "../../../../lib/types";
|
import { ChatSession } from "../../../../lib/types";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import {
|
||||||
|
ArrowLeft,
|
||||||
|
MessageSquare,
|
||||||
|
Clock,
|
||||||
|
Globe,
|
||||||
|
ExternalLink,
|
||||||
|
User,
|
||||||
|
Bot,
|
||||||
|
AlertCircle,
|
||||||
|
FileText,
|
||||||
|
Activity
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
export default function SessionViewPage() {
|
export default function SessionViewPage() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
@ -57,110 +73,242 @@ export default function SessionViewPage() {
|
|||||||
|
|
||||||
if (status === "loading") {
|
if (status === "loading") {
|
||||||
return (
|
return (
|
||||||
<div className="p-4 md:p-6 flex justify-center items-center min-h-screen">
|
<div className="space-y-6">
|
||||||
<p className="text-gray-600 text-lg">Loading session...</p>
|
<Card>
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
Loading session...
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status === "unauthenticated") {
|
if (status === "unauthenticated") {
|
||||||
return (
|
return (
|
||||||
<div className="p-4 md:p-6 flex justify-center items-center min-h-screen">
|
<div className="space-y-6">
|
||||||
<p className="text-gray-600 text-lg">Redirecting to login...</p>
|
<Card>
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
Redirecting to login...
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading && status === "authenticated") {
|
if (loading && status === "authenticated") {
|
||||||
return (
|
return (
|
||||||
<div className="p-4 md:p-6 flex justify-center items-center min-h-screen">
|
<div className="space-y-6">
|
||||||
<p className="text-gray-600 text-lg">Loading session details...</p>
|
<Card>
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
Loading session details...
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div className="p-4 md:p-6 min-h-screen">
|
<div className="space-y-6">
|
||||||
<p className="text-red-500 text-lg mb-4">Error: {error}</p>
|
<Card>
|
||||||
<Link
|
<CardContent className="pt-6">
|
||||||
href="/dashboard/sessions"
|
<div className="text-center py-8">
|
||||||
className="text-sky-600 hover:underline"
|
<AlertCircle className="h-12 w-12 text-destructive mx-auto mb-4" />
|
||||||
>
|
<p className="text-destructive text-lg mb-4">Error: {error}</p>
|
||||||
Back to Sessions List
|
<Link href="/dashboard/sessions">
|
||||||
</Link>
|
<Button variant="outline" className="gap-2">
|
||||||
|
<ArrowLeft className="h-4 w-4" />
|
||||||
|
Back to Sessions List
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return (
|
return (
|
||||||
<div className="p-4 md:p-6 min-h-screen">
|
<div className="space-y-6">
|
||||||
<p className="text-gray-600 text-lg mb-4">Session not found.</p>
|
<Card>
|
||||||
<Link
|
<CardContent className="pt-6">
|
||||||
href="/dashboard/sessions"
|
<div className="text-center py-8">
|
||||||
className="text-sky-600 hover:underline"
|
<MessageSquare className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
|
||||||
>
|
<p className="text-muted-foreground text-lg mb-4">Session not found.</p>
|
||||||
Back to Sessions List
|
<Link href="/dashboard/sessions">
|
||||||
</Link>
|
<Button variant="outline" className="gap-2">
|
||||||
|
<ArrowLeft className="h-4 w-4" />
|
||||||
|
Back to Sessions List
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-linear-to-br from-slate-50 to-sky-100 p-4 md:p-6">
|
<div className="space-y-6 max-w-6xl mx-auto">
|
||||||
<div className="max-w-4xl mx-auto">
|
{/* Header */}
|
||||||
<div className="mb-6">
|
<Card>
|
||||||
<Link
|
<CardContent className="pt-6">
|
||||||
href="/dashboard/sessions"
|
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
|
||||||
className="text-sky-700 hover:text-sky-900 hover:underline flex items-center"
|
<div className="space-y-2">
|
||||||
>
|
<Link href="/dashboard/sessions">
|
||||||
<svg
|
<Button variant="ghost" className="gap-2 p-0 h-auto">
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
<ArrowLeft className="h-4 w-4" />
|
||||||
className="h-5 w-5 mr-1"
|
Back to Sessions List
|
||||||
viewBox="0 0 20 20"
|
</Button>
|
||||||
fill="currentColor"
|
</Link>
|
||||||
>
|
<div className="space-y-2">
|
||||||
<path
|
<h1 className="text-3xl font-bold">Session Details</h1>
|
||||||
fillRule="evenodd"
|
<div className="flex items-center gap-3">
|
||||||
d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
|
<Badge variant="outline" className="font-mono text-xs">
|
||||||
clipRule="evenodd"
|
ID
|
||||||
/>
|
</Badge>
|
||||||
</svg>
|
<code className="text-sm text-muted-foreground font-mono">
|
||||||
Back to Sessions List
|
{(session.sessionId || session.id).slice(0, 8)}...
|
||||||
</Link>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-3xl font-bold text-gray-800 mb-6">
|
</div>
|
||||||
Session: {session.sessionId || session.id}
|
</div>
|
||||||
</h1>
|
<div className="flex flex-wrap gap-2">
|
||||||
<div className="grid grid-cols-1 gap-6">
|
{session.category && session.category !== 'UNRECOGNIZED_OTHER' && session.category !== 'ACCESS_LOGIN' && (
|
||||||
<div>
|
<Badge variant="secondary" className="gap-1">
|
||||||
<SessionDetails session={session} />
|
<Activity className="h-3 w-3" />
|
||||||
|
{session.category.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, l => l.toUpperCase())}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
{session.language && (
|
||||||
|
<Badge variant="outline" className="gap-1">
|
||||||
|
<Globe className="h-3 w-3" />
|
||||||
|
{session.language.toUpperCase()}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
{session.sentiment && (
|
||||||
|
<Badge
|
||||||
|
variant={session.sentiment === 'positive' ? 'default' : session.sentiment === 'negative' ? 'destructive' : 'secondary'}
|
||||||
|
className="gap-1"
|
||||||
|
>
|
||||||
|
{session.sentiment.charAt(0).toUpperCase() + session.sentiment.slice(1)}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
{/* Show parsed messages if available */}
|
{/* Session Overview */}
|
||||||
{session.messages && session.messages.length > 0 && (
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||||
<div>
|
<Card>
|
||||||
<MessageViewer messages={session.messages} />
|
<CardContent className="pt-6">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Clock className="h-8 w-8 text-blue-500" />
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Start Time</p>
|
||||||
|
<p className="font-semibold">
|
||||||
|
{new Date(session.startTime).toLocaleString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
{/* Show transcript URL if available */}
|
<Card>
|
||||||
{session.fullTranscriptUrl && (
|
<CardContent className="pt-6">
|
||||||
<div className="bg-white p-4 rounded-lg shadow">
|
<div className="flex items-center gap-3">
|
||||||
<h3 className="font-bold text-lg mb-3">Source Transcript</h3>
|
<MessageSquare className="h-8 w-8 text-green-500" />
|
||||||
<a
|
<div>
|
||||||
href={session.fullTranscriptUrl}
|
<p className="text-sm text-muted-foreground">Messages</p>
|
||||||
target="_blank"
|
<p className="font-semibold">
|
||||||
rel="noopener noreferrer"
|
{session.messages?.length || 0}
|
||||||
className="text-sky-600 hover:underline"
|
</p>
|
||||||
>
|
</div>
|
||||||
View Original Transcript
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</CardContent>
|
||||||
</div>
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<User className="h-8 w-8 text-purple-500" />
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">User ID</p>
|
||||||
|
<p className="font-semibold truncate">
|
||||||
|
{session.userId || 'N/A'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Activity className="h-8 w-8 text-orange-500" />
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Duration</p>
|
||||||
|
<p className="font-semibold">
|
||||||
|
{session.endTime && session.startTime
|
||||||
|
? `${Math.round(
|
||||||
|
(new Date(session.endTime).getTime() - new Date(session.startTime).getTime()) / 60000
|
||||||
|
)} min`
|
||||||
|
: 'N/A'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Session Details */}
|
||||||
|
<SessionDetails session={session} />
|
||||||
|
|
||||||
|
{/* Messages */}
|
||||||
|
{session.messages && session.messages.length > 0 && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<MessageSquare className="h-5 w-5" />
|
||||||
|
Conversation ({session.messages.length} messages)
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<MessageViewer messages={session.messages} />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Transcript URL */}
|
||||||
|
{session.fullTranscriptUrl && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<FileText className="h-5 w-5" />
|
||||||
|
Source Transcript
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<a
|
||||||
|
href={session.fullTranscriptUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline-flex items-center gap-2 text-primary hover:underline"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-4 w-4" />
|
||||||
|
View Original Transcript
|
||||||
|
</a>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,24 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { ChatSession } from "../../../lib/types";
|
import { ChatSession } from "../../../lib/types";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import {
|
||||||
|
MessageSquare,
|
||||||
|
Search,
|
||||||
|
Filter,
|
||||||
|
Calendar,
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
Clock,
|
||||||
|
Globe,
|
||||||
|
Eye,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
// Placeholder for a SessionListItem component to be created later
|
// Placeholder for a SessionListItem component to be created later
|
||||||
// For now, we'll display some basic info directly.
|
// For now, we'll display some basic info directly.
|
||||||
@ -43,6 +61,9 @@ export default function SessionsPage() {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
||||||
const [pageSize, setPageSize] = useState(10); // Or make this configurable
|
const [pageSize, setPageSize] = useState(10); // Or make this configurable
|
||||||
|
|
||||||
|
// UI states
|
||||||
|
const [filtersExpanded, setFiltersExpanded] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timerId = setTimeout(() => {
|
const timerId = setTimeout(() => {
|
||||||
setDebouncedSearchTerm(searchTerm);
|
setDebouncedSearchTerm(searchTerm);
|
||||||
@ -120,227 +141,282 @@ export default function SessionsPage() {
|
|||||||
}, [fetchFilterOptions]);
|
}, [fetchFilterOptions]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4 md:p-6">
|
<div className="space-y-6">
|
||||||
<h1 className="text-2xl font-semibold text-gray-800 mb-6">
|
{/* Header */}
|
||||||
Chat Sessions
|
<Card>
|
||||||
</h1>
|
<CardHeader>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<MessageSquare className="h-6 w-6" />
|
||||||
|
<CardTitle>Chat Sessions</CardTitle>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
</Card>
|
||||||
|
|
||||||
{/* Search Input */}
|
{/* Search Input */}
|
||||||
<div className="mb-4">
|
<Card>
|
||||||
<input
|
<CardContent className="pt-6">
|
||||||
type="text"
|
<div className="relative">
|
||||||
placeholder="Search sessions (ID, category, initial message...)"
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
<Input
|
||||||
value={searchTerm}
|
placeholder="Search sessions (ID, category, initial message...)"
|
||||||
onChange={(e) => setSearchTerm(e.target.value)}
|
value={searchTerm}
|
||||||
/>
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
</div>
|
className="pl-10"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
{/* Filter and Sort Controls */}
|
{/* Filter and Sort Controls */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6 p-4 bg-gray-50 rounded-lg shadow">
|
<Card>
|
||||||
{/* Category Filter */}
|
<CardHeader>
|
||||||
<div>
|
<div className="flex items-center justify-between">
|
||||||
<label
|
<div className="flex items-center gap-2">
|
||||||
htmlFor="category-filter"
|
<Filter className="h-5 w-5" />
|
||||||
className="block text-sm font-medium text-gray-700 mb-1"
|
<CardTitle className="text-lg">Filters & Sorting</CardTitle>
|
||||||
>
|
</div>
|
||||||
Category
|
<Button
|
||||||
</label>
|
variant="ghost"
|
||||||
<select
|
size="sm"
|
||||||
id="category-filter"
|
onClick={() => setFiltersExpanded(!filtersExpanded)}
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
className="gap-2"
|
||||||
value={selectedCategory}
|
>
|
||||||
onChange={(e) => setSelectedCategory(e.target.value)}
|
{filtersExpanded ? (
|
||||||
>
|
<>
|
||||||
<option value="">All Categories</option>
|
<ChevronUp className="h-4 w-4" />
|
||||||
{filterOptions.categories.map((cat) => (
|
Hide
|
||||||
<option key={cat} value={cat}>
|
</>
|
||||||
{cat}
|
) : (
|
||||||
</option>
|
<>
|
||||||
))}
|
<ChevronDown className="h-4 w-4" />
|
||||||
</select>
|
Show
|
||||||
</div>
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
{filtersExpanded && (
|
||||||
|
<CardContent>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-4">
|
||||||
|
{/* Category Filter */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="category-filter">Category</Label>
|
||||||
|
<select
|
||||||
|
id="category-filter"
|
||||||
|
className="w-full h-10 px-3 py-2 text-sm rounded-md border border-input bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||||
|
value={selectedCategory}
|
||||||
|
onChange={(e) => setSelectedCategory(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">All Categories</option>
|
||||||
|
{filterOptions.categories.map((cat) => (
|
||||||
|
<option key={cat} value={cat}>
|
||||||
|
{cat}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Language Filter */}
|
{/* Language Filter */}
|
||||||
<div>
|
<div className="space-y-2">
|
||||||
<label
|
<Label htmlFor="language-filter">Language</Label>
|
||||||
htmlFor="language-filter"
|
<select
|
||||||
className="block text-sm font-medium text-gray-700 mb-1"
|
id="language-filter"
|
||||||
>
|
className="w-full h-10 px-3 py-2 text-sm rounded-md border border-input bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||||
Language
|
value={selectedLanguage}
|
||||||
</label>
|
onChange={(e) => setSelectedLanguage(e.target.value)}
|
||||||
<select
|
>
|
||||||
id="language-filter"
|
<option value="">All Languages</option>
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
{filterOptions.languages.map((lang) => (
|
||||||
value={selectedLanguage}
|
<option key={lang} value={lang}>
|
||||||
onChange={(e) => setSelectedLanguage(e.target.value)}
|
{lang.toUpperCase()}
|
||||||
>
|
</option>
|
||||||
<option value="">All Languages</option>
|
))}
|
||||||
{filterOptions.languages.map((lang) => (
|
</select>
|
||||||
<option key={lang} value={lang}>
|
</div>
|
||||||
{lang.toUpperCase()}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Start Date Filter */}
|
{/* Start Date Filter */}
|
||||||
<div>
|
<div className="space-y-2">
|
||||||
<label
|
<Label htmlFor="start-date-filter">Start Date</Label>
|
||||||
htmlFor="start-date-filter"
|
<Input
|
||||||
className="block text-sm font-medium text-gray-700 mb-1"
|
type="date"
|
||||||
>
|
id="start-date-filter"
|
||||||
Start Date
|
value={startDate}
|
||||||
</label>
|
onChange={(e) => setStartDate(e.target.value)}
|
||||||
<input
|
/>
|
||||||
type="date"
|
</div>
|
||||||
id="start-date-filter"
|
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
|
||||||
value={startDate}
|
|
||||||
onChange={(e) => setStartDate(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* End Date Filter */}
|
{/* End Date Filter */}
|
||||||
<div>
|
<div className="space-y-2">
|
||||||
<label
|
<Label htmlFor="end-date-filter">End Date</Label>
|
||||||
htmlFor="end-date-filter"
|
<Input
|
||||||
className="block text-sm font-medium text-gray-700 mb-1"
|
type="date"
|
||||||
>
|
id="end-date-filter"
|
||||||
End Date
|
value={endDate}
|
||||||
</label>
|
onChange={(e) => setEndDate(e.target.value)}
|
||||||
<input
|
/>
|
||||||
type="date"
|
</div>
|
||||||
id="end-date-filter"
|
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
|
||||||
value={endDate}
|
|
||||||
onChange={(e) => setEndDate(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Sort Key */}
|
{/* Sort Key */}
|
||||||
<div>
|
<div className="space-y-2">
|
||||||
<label
|
<Label htmlFor="sort-key">Sort By</Label>
|
||||||
htmlFor="sort-key"
|
<select
|
||||||
className="block text-sm font-medium text-gray-700 mb-1"
|
id="sort-key"
|
||||||
>
|
className="w-full h-10 px-3 py-2 text-sm rounded-md border border-input bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||||
Sort By
|
value={sortKey}
|
||||||
</label>
|
onChange={(e) => setSortKey(e.target.value)}
|
||||||
<select
|
>
|
||||||
id="sort-key"
|
<option value="startTime">Start Time</option>
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
<option value="category">Category</option>
|
||||||
value={sortKey}
|
<option value="language">Language</option>
|
||||||
onChange={(e) => setSortKey(e.target.value)}
|
<option value="sentiment">Sentiment</option>
|
||||||
>
|
<option value="messagesSent">Messages Sent</option>
|
||||||
<option value="startTime">Start Time</option>
|
<option value="avgResponseTime">Avg. Response Time</option>
|
||||||
<option value="category">Category</option>
|
</select>
|
||||||
<option value="language">Language</option>
|
</div>
|
||||||
<option value="sentiment">Sentiment</option>
|
|
||||||
<option value="messagesSent">Messages Sent</option>
|
|
||||||
<option value="avgResponseTime">Avg. Response Time</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Sort Order */}
|
{/* Sort Order */}
|
||||||
<div>
|
<div className="space-y-2">
|
||||||
<label
|
<Label htmlFor="sort-order">Order</Label>
|
||||||
htmlFor="sort-order"
|
<select
|
||||||
className="block text-sm font-medium text-gray-700 mb-1"
|
id="sort-order"
|
||||||
>
|
className="w-full h-10 px-3 py-2 text-sm rounded-md border border-input bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||||
Order
|
value={sortOrder}
|
||||||
</label>
|
onChange={(e) => setSortOrder(e.target.value as "asc" | "desc")}
|
||||||
<select
|
>
|
||||||
id="sort-order"
|
<option value="desc">Descending</option>
|
||||||
className="w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-sky-500 focus:border-sky-500"
|
<option value="asc">Ascending</option>
|
||||||
value={sortOrder}
|
</select>
|
||||||
onChange={(e) => setSortOrder(e.target.value as "asc" | "desc")}
|
</div>
|
||||||
>
|
</div>
|
||||||
<option value="desc">Descending</option>
|
</CardContent>
|
||||||
<option value="asc">Ascending</option>
|
)}
|
||||||
</select>
|
</Card>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{loading && <p className="text-gray-600">Loading sessions...</p>}
|
{/* Loading State */}
|
||||||
{error && <p className="text-red-500">Error: {error}</p>}
|
{loading && (
|
||||||
|
<Card>
|
||||||
{!loading && !error && sessions.length === 0 && (
|
<CardContent className="pt-6">
|
||||||
<p className="text-gray-600">
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
{debouncedSearchTerm
|
Loading sessions...
|
||||||
? `No sessions found for "${debouncedSearchTerm}".`
|
</div>
|
||||||
: "No sessions found."}
|
</CardContent>
|
||||||
</p>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!loading && !error && sessions.length > 0 && (
|
{/* Error State */}
|
||||||
<div className="space-y-4">
|
{error && (
|
||||||
{sessions.map((session) => (
|
<Card>
|
||||||
<div
|
<CardContent className="pt-6">
|
||||||
key={session.id}
|
<div className="text-center py-8 text-destructive">
|
||||||
className="bg-white p-4 rounded-lg shadow hover:shadow-md transition-shadow"
|
Error: {error}
|
||||||
>
|
|
||||||
<h2 className="text-lg font-semibold text-sky-700 mb-1">
|
|
||||||
Session ID: {session.sessionId || session.id}
|
|
||||||
</h2>
|
|
||||||
<p className="text-sm text-gray-500 mb-1">
|
|
||||||
Start Time{/* (Local) */}:{" "}
|
|
||||||
{new Date(session.startTime).toLocaleString()}
|
|
||||||
</p>
|
|
||||||
{/* <p className="text-xs text-gray-400 mb-1">
|
|
||||||
Start Time (Raw API): {session.startTime.toString()}
|
|
||||||
</p> */}
|
|
||||||
{session.category && (
|
|
||||||
<p className="text-sm text-gray-700">
|
|
||||||
Category:{" "}
|
|
||||||
<span className="font-medium">{session.category}</span>
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{session.language && (
|
|
||||||
<p className="text-sm text-gray-700">
|
|
||||||
Language:{" "}
|
|
||||||
<span className="font-medium">
|
|
||||||
{session.language.toUpperCase()}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{session.initialMsg && (
|
|
||||||
<p className="text-sm text-gray-600 mt-1 truncate">
|
|
||||||
Initial Message: {session.initialMsg}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<Link
|
|
||||||
href={`/dashboard/sessions/${session.id}`}
|
|
||||||
className="mt-2 text-sm text-sky-600 hover:text-sky-800 hover:underline inline-block"
|
|
||||||
>
|
|
||||||
View Details
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Empty State */}
|
||||||
|
{!loading && !error && sessions.length === 0 && (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
{debouncedSearchTerm
|
||||||
|
? `No sessions found for "${debouncedSearchTerm}".`
|
||||||
|
: "No sessions found."}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Sessions List */}
|
||||||
|
{!loading && !error && sessions.length > 0 && (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
{sessions.map((session) => (
|
||||||
|
<Card key={session.id} className="hover:shadow-md transition-shadow">
|
||||||
|
<CardContent className="pt-6">
|
||||||
|
<div className="flex justify-between items-start mb-4">
|
||||||
|
<div className="space-y-2 flex-1">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Badge variant="outline" className="font-mono text-xs">
|
||||||
|
ID
|
||||||
|
</Badge>
|
||||||
|
<code className="text-sm text-muted-foreground font-mono">
|
||||||
|
{(session.sessionId || session.id).slice(0, 8)}...
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
|
<Clock className="h-4 w-4" />
|
||||||
|
{new Date(session.startTime).toLocaleString()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Link href={`/dashboard/sessions/${session.id}`}>
|
||||||
|
<Button variant="outline" size="sm" className="gap-2">
|
||||||
|
<Eye className="h-4 w-4" />
|
||||||
|
View Details
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-2 mb-3">
|
||||||
|
{session.category && session.category !== 'UNRECOGNIZED_OTHER' && session.category !== 'ACCESS_LOGIN' && (
|
||||||
|
<Badge variant="secondary" className="gap-1">
|
||||||
|
<Filter className="h-3 w-3" />
|
||||||
|
{session.category.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, l => l.toUpperCase())}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
{session.language && (
|
||||||
|
<Badge variant="outline" className="gap-1">
|
||||||
|
<Globe className="h-3 w-3" />
|
||||||
|
{session.language.toUpperCase()}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{session.summary ? (
|
||||||
|
<p className="text-sm text-muted-foreground line-clamp-2">
|
||||||
|
{session.summary}
|
||||||
|
</p>
|
||||||
|
) : session.initialMsg ? (
|
||||||
|
<p className="text-sm text-muted-foreground line-clamp-2">
|
||||||
|
{session.initialMsg}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Pagination */}
|
||||||
{totalPages > 0 && (
|
{totalPages > 0 && (
|
||||||
<div className="mt-6 flex justify-center items-center space-x-2">
|
<Card>
|
||||||
<button
|
<CardContent className="pt-6">
|
||||||
onClick={() => setCurrentPage((prev) => Math.max(prev - 1, 1))}
|
<div className="flex justify-center items-center gap-4">
|
||||||
disabled={currentPage === 1}
|
<Button
|
||||||
className="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50"
|
variant="outline"
|
||||||
>
|
onClick={() => setCurrentPage((prev) => Math.max(prev - 1, 1))}
|
||||||
Previous
|
disabled={currentPage === 1}
|
||||||
</button>
|
className="gap-2"
|
||||||
<span className="text-sm text-gray-700">
|
>
|
||||||
Page {currentPage} of {totalPages}
|
<ChevronLeft className="h-4 w-4" />
|
||||||
</span>
|
Previous
|
||||||
<button
|
</Button>
|
||||||
onClick={() =>
|
<span className="text-sm text-muted-foreground">
|
||||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
Page {currentPage} of {totalPages}
|
||||||
}
|
</span>
|
||||||
disabled={currentPage === totalPages}
|
<Button
|
||||||
className="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50"
|
variant="outline"
|
||||||
>
|
onClick={() =>
|
||||||
Next
|
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
||||||
</button>
|
}
|
||||||
</div>
|
disabled={currentPage === totalPages}
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -171,12 +171,20 @@
|
|||||||
|
|
||||||
/* Custom text selection colors */
|
/* Custom text selection colors */
|
||||||
::selection {
|
::selection {
|
||||||
background-color: hsl(var(--primary) / 0.2);
|
background-color: hsl(var(--primary) / 0.3);
|
||||||
color: hsl(var(--foreground));
|
color: hsl(var(--primary-foreground));
|
||||||
}
|
}
|
||||||
|
|
||||||
::-moz-selection {
|
::-moz-selection {
|
||||||
background-color: hsl(var(--primary) / 0.2);
|
background-color: hsl(var(--primary) / 0.3);
|
||||||
color: hsl(var(--foreground));
|
color: hsl(var(--primary-foreground));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Line clamp utility */
|
||||||
|
.line-clamp-2 {
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,10 @@
|
|||||||
import { ChatSession } from "../lib/types";
|
import { ChatSession } from "../lib/types";
|
||||||
import LanguageDisplay from "./LanguageDisplay";
|
import LanguageDisplay from "./LanguageDisplay";
|
||||||
import CountryDisplay from "./CountryDisplay";
|
import CountryDisplay from "./CountryDisplay";
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { ExternalLink } from "lucide-react";
|
||||||
|
|
||||||
interface SessionDetailsProps {
|
interface SessionDetailsProps {
|
||||||
session: ChatSession;
|
session: ChatSession;
|
||||||
@ -12,157 +16,175 @@ interface SessionDetailsProps {
|
|||||||
* Component to display session details with formatted country and language names
|
* Component to display session details with formatted country and language names
|
||||||
*/
|
*/
|
||||||
export default function SessionDetails({ session }: SessionDetailsProps) {
|
export default function SessionDetails({ session }: SessionDetailsProps) {
|
||||||
|
// Helper function to format category names
|
||||||
|
const formatCategory = (category: string) => {
|
||||||
|
if (category === 'UNRECOGNIZED_OTHER' || category === 'ACCESS_LOGIN') {
|
||||||
|
return null; // Don't show these internal enum values
|
||||||
|
}
|
||||||
|
return category.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, l => l.toUpperCase());
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white p-4 rounded-lg shadow">
|
<Card>
|
||||||
<h3 className="font-bold text-lg mb-3">Session Details</h3>
|
<CardHeader>
|
||||||
<div className="space-y-3">
|
<CardTitle>Session Information</CardTitle>
|
||||||
<div className="flex justify-between border-b pb-2">
|
</CardHeader>
|
||||||
<span className="text-gray-600">Session ID:</span>
|
<CardContent className="space-y-4">
|
||||||
<span className="font-medium font-mono text-sm">{session.id}</span>
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
</div>
|
<div className="space-y-3">
|
||||||
|
<div>
|
||||||
<div className="flex justify-between border-b pb-2">
|
<p className="text-sm text-muted-foreground">Session ID</p>
|
||||||
<span className="text-gray-600">Start Time:</span>
|
<code className="text-sm font-mono bg-muted px-2 py-1 rounded">
|
||||||
<span className="font-medium">
|
{session.id.slice(0, 8)}...
|
||||||
{new Date(session.startTime).toLocaleString()}
|
</code>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{session.endTime && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">End Time:</span>
|
|
||||||
<span className="font-medium">
|
|
||||||
{new Date(session.endTime).toLocaleString()}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.category && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Category:</span>
|
|
||||||
<span className="font-medium">{session.category}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.language && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Language:</span>
|
|
||||||
<span className="font-medium">
|
|
||||||
<LanguageDisplay languageCode={session.language} />
|
|
||||||
<span className="text-gray-400 text-xs ml-1">
|
|
||||||
({session.language.toUpperCase()})
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.country && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Country:</span>
|
|
||||||
<span className="font-medium">
|
|
||||||
<CountryDisplay countryCode={session.country} />
|
|
||||||
<span className="text-gray-400 text-xs ml-1">
|
|
||||||
({session.country})
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.sentiment !== null && session.sentiment !== undefined && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Sentiment:</span>
|
|
||||||
<span
|
|
||||||
className={`font-medium capitalize ${
|
|
||||||
session.sentiment === "POSITIVE"
|
|
||||||
? "text-green-500"
|
|
||||||
: session.sentiment === "NEGATIVE"
|
|
||||||
? "text-red-500"
|
|
||||||
: "text-orange-500"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{session.sentiment.toLowerCase()}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Messages Sent:</span>
|
|
||||||
<span className="font-medium">{session.messagesSent || 0}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{session.avgResponseTime !== null &&
|
|
||||||
session.avgResponseTime !== undefined && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Avg Response Time:</span>
|
|
||||||
<span className="font-medium">
|
|
||||||
{session.avgResponseTime.toFixed(2)}s
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
{session.escalated !== null && session.escalated !== undefined && (
|
<div>
|
||||||
<div className="flex justify-between border-b pb-2">
|
<p className="text-sm text-muted-foreground">Start Time</p>
|
||||||
<span className="text-gray-600">Escalated:</span>
|
<p className="font-medium">
|
||||||
<span
|
{new Date(session.startTime).toLocaleString()}
|
||||||
className={`font-medium ${session.escalated ? "text-red-500" : "text-green-500"}`}
|
</p>
|
||||||
>
|
|
||||||
{session.escalated ? "Yes" : "No"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.forwardedHr !== null && session.forwardedHr !== undefined && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">Forwarded to HR:</span>
|
|
||||||
<span
|
|
||||||
className={`font-medium ${session.forwardedHr ? "text-amber-500" : "text-green-500"}`}
|
|
||||||
>
|
|
||||||
{session.forwardedHr ? "Yes" : "No"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.ipAddress && (
|
|
||||||
<div className="flex justify-between border-b pb-2">
|
|
||||||
<span className="text-gray-600">IP Address:</span>
|
|
||||||
<span className="font-medium font-mono text-sm">
|
|
||||||
{session.ipAddress}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{session.initialMsg && (
|
|
||||||
<div className="border-b pb-2">
|
|
||||||
<span className="text-gray-600 block mb-1">Initial Message:</span>
|
|
||||||
<div className="bg-gray-50 p-2 rounded text-sm italic">
|
|
||||||
"{session.initialMsg}"
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{session.endTime && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">End Time</p>
|
||||||
|
<p className="font-medium">
|
||||||
|
{new Date(session.endTime).toLocaleString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{session.category && formatCategory(session.category) && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Category</p>
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{formatCategory(session.category)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{session.language && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Language</p>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<LanguageDisplay languageCode={session.language} />
|
||||||
|
<Badge variant="outline" className="text-xs">
|
||||||
|
{session.language.toUpperCase()}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{session.country && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Country</p>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<CountryDisplay countryCode={session.country} />
|
||||||
|
<Badge variant="outline" className="text-xs">
|
||||||
|
{session.country}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
{session.sentiment !== null && session.sentiment !== undefined && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Sentiment</p>
|
||||||
|
<Badge
|
||||||
|
variant={
|
||||||
|
session.sentiment === "positive"
|
||||||
|
? "default"
|
||||||
|
: session.sentiment === "negative"
|
||||||
|
? "destructive"
|
||||||
|
: "secondary"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{session.sentiment.charAt(0).toUpperCase() + session.sentiment.slice(1)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Messages Sent</p>
|
||||||
|
<p className="font-medium">{session.messagesSent || 0}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{session.avgResponseTime !== null && session.avgResponseTime !== undefined && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Avg Response Time</p>
|
||||||
|
<p className="font-medium">{session.avgResponseTime.toFixed(2)}s</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{session.escalated !== null && session.escalated !== undefined && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Escalated</p>
|
||||||
|
<Badge variant={session.escalated ? "destructive" : "default"}>
|
||||||
|
{session.escalated ? "Yes" : "No"}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{session.forwardedHr !== null && session.forwardedHr !== undefined && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">Forwarded to HR</p>
|
||||||
|
<Badge variant={session.forwardedHr ? "secondary" : "default"}>
|
||||||
|
{session.forwardedHr ? "Yes" : "No"}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{session.ipAddress && (
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-muted-foreground">IP Address</p>
|
||||||
|
<code className="text-sm font-mono bg-muted px-2 py-1 rounded">
|
||||||
|
{session.ipAddress}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{(session.summary || session.initialMsg) && <Separator />}
|
||||||
|
|
||||||
{session.summary && (
|
{session.summary && (
|
||||||
<div className="border-b pb-2">
|
<div>
|
||||||
<span className="text-gray-600 block mb-1">AI Summary:</span>
|
<p className="text-sm text-muted-foreground mb-2">AI Summary</p>
|
||||||
<div className="bg-blue-50 p-2 rounded text-sm">
|
<div className="bg-muted p-3 rounded-md text-sm">
|
||||||
{session.summary}
|
{session.summary}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{session.fullTranscriptUrl && (
|
{!session.summary && session.initialMsg && (
|
||||||
<div className="flex justify-between pt-2">
|
<div>
|
||||||
<span className="text-gray-600">Transcript:</span>
|
<p className="text-sm text-muted-foreground mb-2">Initial Message</p>
|
||||||
<a
|
<div className="bg-muted p-3 rounded-md text-sm italic">
|
||||||
href={session.fullTranscriptUrl}
|
"{session.initialMsg}"
|
||||||
target="_blank"
|
</div>
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="text-blue-500 hover:text-blue-700 underline"
|
|
||||||
>
|
|
||||||
View Full Transcript
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
</div>
|
{session.fullTranscriptUrl && (
|
||||||
|
<>
|
||||||
|
<Separator />
|
||||||
|
<div>
|
||||||
|
<a
|
||||||
|
href={session.fullTranscriptUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline-flex items-center gap-2 text-primary hover:underline"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-4 w-4" />
|
||||||
|
View Full Transcript
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user