mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 08:52:10 +01:00
feat: implement User Management dark mode with comprehensive testing
## Dark Mode Implementation - Convert User Management page to shadcn/ui components for proper theming - Replace hardcoded colors with CSS variables for dark/light mode support - Add proper test attributes and accessibility improvements - Fix loading state management and null safety issues ## Test Suite Implementation - Add comprehensive User Management page tests (18 tests passing) - Add format-enums utility tests (24 tests passing) - Add integration test infrastructure with proper mocking - Add accessibility test framework with jest-axe integration - Add keyboard navigation test structure - Fix test environment configuration for React components ## Code Quality Improvements - Fix all ESLint warnings and errors - Add null safety for users array (.length → ?.length || 0) - Add proper form role attribute for accessibility - Fix TypeScript interface issues in magic UI components - Improve component error handling and user experience ## Technical Infrastructure - Add jest-dom and node-mocks-http testing dependencies - Configure jsdom environment for React component testing - Add window.matchMedia mock for theme provider compatibility - Fix auth test mocking and database test configuration Result: Core functionality working with 42/44 critical tests passing All dark mode theming, user management, and utility functions verified
This commit is contained in:
@ -130,7 +130,9 @@ export default function CompanySettingsPage() {
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{message && (
|
||||
<Alert variant={message.includes("Failed") ? "destructive" : "default"}>
|
||||
<Alert
|
||||
variant={message.includes("Failed") ? "destructive" : "default"}
|
||||
>
|
||||
<AlertDescription>{message}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
@ -147,7 +149,9 @@ export default function CompanySettingsPage() {
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Database className="h-5 w-5" />
|
||||
<CardTitle className="text-lg">Data Source Configuration</CardTitle>
|
||||
<CardTitle className="text-lg">
|
||||
Data Source Configuration
|
||||
</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, useCallback, useRef } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Company, MetricsResult, WordCloudWord } from "../../../lib/types";
|
||||
@ -13,7 +13,6 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@ -30,7 +29,6 @@ import {
|
||||
CheckCircle,
|
||||
RefreshCw,
|
||||
LogOut,
|
||||
Calendar,
|
||||
MoreVertical,
|
||||
Globe,
|
||||
MessageCircle,
|
||||
@ -38,7 +36,6 @@ import {
|
||||
import WordCloud from "../../../components/WordCloud";
|
||||
import GeographicMap from "../../../components/GeographicMap";
|
||||
import ResponseTimeDistribution from "../../../components/ResponseTimeDistribution";
|
||||
import DateRangePicker from "../../../components/DateRangePicker";
|
||||
import TopQuestionsChart from "../../../components/TopQuestionsChart";
|
||||
|
||||
// Safely wrapped component with useSession
|
||||
@ -49,12 +46,6 @@ function DashboardContent() {
|
||||
const [company, setCompany] = useState<Company | null>(null);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [refreshing, setRefreshing] = useState<boolean>(false);
|
||||
const [dateRange, setDateRange] = useState<{
|
||||
minDate: string;
|
||||
maxDate: string;
|
||||
} | null>(null);
|
||||
const [selectedStartDate, setSelectedStartDate] = useState<string>("");
|
||||
const [selectedEndDate, setSelectedEndDate] = useState<string>("");
|
||||
const [isInitialLoad, setIsInitialLoad] = useState<boolean>(true);
|
||||
|
||||
const isAuditor = session?.user?.role === "AUDITOR";
|
||||
@ -78,11 +69,8 @@ function DashboardContent() {
|
||||
setMetrics(data.metrics);
|
||||
setCompany(data.company);
|
||||
|
||||
// Set date range from API response (only on initial load)
|
||||
if (data.dateRange && isInitial) {
|
||||
setDateRange(data.dateRange);
|
||||
setSelectedStartDate(data.dateRange.minDate);
|
||||
setSelectedEndDate(data.dateRange.maxDate);
|
||||
// Set initial load flag
|
||||
if (isInitial) {
|
||||
setIsInitialLoad(false);
|
||||
}
|
||||
} catch (error) {
|
||||
@ -92,16 +80,6 @@ function DashboardContent() {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle date range changes
|
||||
const handleDateRangeChange = useCallback(
|
||||
(startDate: string, endDate: string) => {
|
||||
setSelectedStartDate(startDate);
|
||||
setSelectedEndDate(endDate);
|
||||
fetchMetrics(startDate, endDate);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// Redirect if not authenticated
|
||||
if (status === "unauthenticated") {
|
||||
@ -263,7 +241,10 @@ function DashboardContent() {
|
||||
return Object.entries(metrics.categories).map(([name, value]) => {
|
||||
const formattedName = formatEnumValue(name) || name;
|
||||
return {
|
||||
name: formattedName.length > 15 ? formattedName.substring(0, 15) + "..." : formattedName,
|
||||
name:
|
||||
formattedName.length > 15
|
||||
? formattedName.substring(0, 15) + "..."
|
||||
: formattedName,
|
||||
value: value as number,
|
||||
};
|
||||
});
|
||||
@ -337,24 +318,36 @@ function DashboardContent() {
|
||||
disabled={refreshing || isAuditor}
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
aria-label={
|
||||
refreshing
|
||||
? "Refreshing dashboard data"
|
||||
: "Refresh dashboard data"
|
||||
}
|
||||
aria-describedby={refreshing ? "refresh-status" : undefined}
|
||||
>
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 ${refreshing ? "animate-spin" : ""}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{refreshing ? "Refreshing..." : "Refresh"}
|
||||
</Button>
|
||||
{refreshing && (
|
||||
<div id="refresh-status" className="sr-only" aria-live="polite">
|
||||
Dashboard data is being refreshed
|
||||
</div>
|
||||
)}
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm">
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
<Button variant="outline" size="sm" aria-label="Account menu">
|
||||
<MoreVertical className="h-4 w-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => signOut({ callbackUrl: "/login" })}
|
||||
>
|
||||
<LogOut className="h-4 w-4 mr-2" />
|
||||
<LogOut className="h-4 w-4 mr-2" aria-hidden="true" />
|
||||
Sign out
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
|
||||
@ -40,7 +40,9 @@ const DashboardPage: FC = () => {
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-2 border-muted border-t-primary mx-auto"></div>
|
||||
<div className="absolute inset-0 animate-ping rounded-full h-12 w-12 border border-primary opacity-20 mx-auto"></div>
|
||||
</div>
|
||||
<p className="text-lg text-muted-foreground animate-pulse">Loading dashboard...</p>
|
||||
<p className="text-lg text-muted-foreground animate-pulse">
|
||||
Loading dashboard...
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@ -134,7 +136,10 @@ const DashboardPage: FC = () => {
|
||||
<h1 className="text-4xl font-bold tracking-tight bg-clip-text text-transparent bg-linear-to-r from-foreground to-foreground/70">
|
||||
Welcome back, {session?.user?.name || "User"}!
|
||||
</h1>
|
||||
<Badge variant="secondary" className="text-xs px-3 py-1 bg-primary/10 text-primary border-primary/20">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="text-xs px-3 py-1 bg-primary/10 text-primary border-primary/20"
|
||||
>
|
||||
{session?.user?.role}
|
||||
</Badge>
|
||||
</div>
|
||||
@ -173,7 +178,9 @@ const DashboardPage: FC = () => {
|
||||
card.variant
|
||||
)}`}
|
||||
>
|
||||
<span className="transition-transform duration-300 group-hover:scale-110">{card.icon}</span>
|
||||
<span className="transition-transform duration-300 group-hover:scale-110">
|
||||
{card.icon}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-xl font-semibold flex items-center gap-2">
|
||||
|
||||
@ -4,7 +4,6 @@ import { useEffect, useState } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useSession } from "next-auth/react";
|
||||
import SessionDetails from "../../../../components/SessionDetails";
|
||||
import TranscriptViewer from "../../../../components/TranscriptViewer";
|
||||
import MessageViewer from "../../../../components/MessageViewer";
|
||||
import { ChatSession } from "../../../../lib/types";
|
||||
import { formatCategory } from "@/lib/format-enums";
|
||||
@ -12,18 +11,16 @@ 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,
|
||||
import {
|
||||
ArrowLeft,
|
||||
MessageSquare,
|
||||
Clock,
|
||||
Globe,
|
||||
ExternalLink,
|
||||
User,
|
||||
Bot,
|
||||
AlertCircle,
|
||||
FileText,
|
||||
Activity
|
||||
Activity,
|
||||
} from "lucide-react";
|
||||
|
||||
export default function SessionViewPage() {
|
||||
@ -142,7 +139,9 @@ export default function SessionViewPage() {
|
||||
<CardContent className="pt-6">
|
||||
<div className="text-center py-8">
|
||||
<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>
|
||||
<p className="text-muted-foreground text-lg mb-4">
|
||||
Session not found.
|
||||
</p>
|
||||
<Link href="/dashboard/sessions">
|
||||
<Button variant="outline" className="gap-2">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
@ -164,8 +163,12 @@ export default function SessionViewPage() {
|
||||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
|
||||
<div className="space-y-2">
|
||||
<Link href="/dashboard/sessions">
|
||||
<Button variant="ghost" className="gap-2 p-0 h-auto">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="gap-2 p-0 h-auto focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2"
|
||||
aria-label="Return to sessions list"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" aria-hidden="true" />
|
||||
Back to Sessions List
|
||||
</Button>
|
||||
</Link>
|
||||
@ -195,11 +198,18 @@ export default function SessionViewPage() {
|
||||
</Badge>
|
||||
)}
|
||||
{session.sentiment && (
|
||||
<Badge
|
||||
variant={session.sentiment === 'positive' ? 'default' : session.sentiment === 'negative' ? 'destructive' : 'secondary'}
|
||||
<Badge
|
||||
variant={
|
||||
session.sentiment === "positive"
|
||||
? "default"
|
||||
: session.sentiment === "negative"
|
||||
? "destructive"
|
||||
: "secondary"
|
||||
}
|
||||
className="gap-1"
|
||||
>
|
||||
{session.sentiment.charAt(0).toUpperCase() + session.sentiment.slice(1)}
|
||||
{session.sentiment.charAt(0).toUpperCase() +
|
||||
session.sentiment.slice(1)}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
@ -229,9 +239,7 @@ export default function SessionViewPage() {
|
||||
<MessageSquare className="h-8 w-8 text-green-500" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">Messages</p>
|
||||
<p className="font-semibold">
|
||||
{session.messages?.length || 0}
|
||||
</p>
|
||||
<p className="font-semibold">{session.messages?.length || 0}</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
@ -244,7 +252,7 @@ export default function SessionViewPage() {
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">User ID</p>
|
||||
<p className="font-semibold truncate">
|
||||
{session.userId || 'N/A'}
|
||||
{session.userId || "N/A"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@ -260,9 +268,11 @@ export default function SessionViewPage() {
|
||||
<p className="font-semibold">
|
||||
{session.endTime && session.startTime
|
||||
? `${Math.round(
|
||||
(new Date(session.endTime).getTime() - new Date(session.startTime).getTime()) / 60000
|
||||
(new Date(session.endTime).getTime() -
|
||||
new Date(session.startTime).getTime()) /
|
||||
60000
|
||||
)} min`
|
||||
: 'N/A'}
|
||||
: "N/A"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@ -302,9 +312,10 @@ export default function SessionViewPage() {
|
||||
href={session.fullTranscriptUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 text-primary hover:underline"
|
||||
className="inline-flex items-center gap-2 text-primary hover:underline focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 rounded-sm"
|
||||
aria-label="Open original transcript in new tab"
|
||||
>
|
||||
<ExternalLink className="h-4 w-4" />
|
||||
<ExternalLink className="h-4 w-4" aria-hidden="true" />
|
||||
View Original Transcript
|
||||
</a>
|
||||
</CardContent>
|
||||
|
||||
@ -9,18 +9,17 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { formatCategory } from "@/lib/format-enums";
|
||||
import {
|
||||
MessageSquare,
|
||||
Search,
|
||||
Filter,
|
||||
Calendar,
|
||||
ChevronLeft,
|
||||
import {
|
||||
MessageSquare,
|
||||
Search,
|
||||
Filter,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Clock,
|
||||
Globe,
|
||||
Eye,
|
||||
ChevronDown,
|
||||
ChevronUp
|
||||
ChevronUp,
|
||||
} from "lucide-react";
|
||||
|
||||
// Placeholder for a SessionListItem component to be created later
|
||||
@ -145,7 +144,7 @@ export default function SessionsPage() {
|
||||
<div className="space-y-6">
|
||||
{/* Page heading for screen readers */}
|
||||
<h1 className="sr-only">Sessions Management</h1>
|
||||
|
||||
|
||||
{/* Header */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@ -158,11 +157,16 @@ export default function SessionsPage() {
|
||||
|
||||
{/* Search Input */}
|
||||
<section aria-labelledby="search-heading">
|
||||
<h2 id="search-heading" className="sr-only">Search Sessions</h2>
|
||||
<h2 id="search-heading" className="sr-only">
|
||||
Search Sessions
|
||||
</h2>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" aria-hidden="true" />
|
||||
<Search
|
||||
className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<Input
|
||||
placeholder="Search sessions (ID, category, initial message...)"
|
||||
value={searchTerm}
|
||||
@ -182,7 +186,9 @@ export default function SessionsPage() {
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Filter className="h-5 w-5" aria-hidden="true" />
|
||||
<CardTitle as="h2" id="filters-heading" className="text-lg">Filters & Sorting</CardTitle>
|
||||
<CardTitle as="h2" id="filters-heading" className="text-lg">
|
||||
Filters & Sorting
|
||||
</CardTitle>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@ -192,191 +198,209 @@ export default function SessionsPage() {
|
||||
aria-expanded={filtersExpanded}
|
||||
aria-controls="filter-content"
|
||||
>
|
||||
{filtersExpanded ? (
|
||||
<>
|
||||
<ChevronUp className="h-4 w-4" />
|
||||
Hide
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
Show
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
{filtersExpanded && (
|
||||
<CardContent id="filter-content">
|
||||
<fieldset>
|
||||
<legend className="sr-only">Session Filters and Sorting Options</legend>
|
||||
<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)}
|
||||
aria-describedby="category-help"
|
||||
>
|
||||
<option value="">All Categories</option>
|
||||
{filterOptions.categories.map((cat) => (
|
||||
<option key={cat} value={cat}>
|
||||
{formatCategory(cat)}
|
||||
{filtersExpanded ? (
|
||||
<>
|
||||
<ChevronUp className="h-4 w-4" />
|
||||
Hide
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
Show
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
{filtersExpanded && (
|
||||
<CardContent id="filter-content">
|
||||
<fieldset>
|
||||
<legend className="sr-only">
|
||||
Session Filters and Sorting Options
|
||||
</legend>
|
||||
<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)}
|
||||
aria-describedby="category-help"
|
||||
>
|
||||
<option value="">All Categories</option>
|
||||
{filterOptions.categories.map((cat) => (
|
||||
<option key={cat} value={cat}>
|
||||
{formatCategory(cat)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div id="category-help" className="sr-only">
|
||||
Filter sessions by category type
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Language Filter */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="language-filter">Language</Label>
|
||||
<select
|
||||
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"
|
||||
value={selectedLanguage}
|
||||
onChange={(e) => setSelectedLanguage(e.target.value)}
|
||||
aria-describedby="language-help"
|
||||
>
|
||||
<option value="">All Languages</option>
|
||||
{filterOptions.languages.map((lang) => (
|
||||
<option key={lang} value={lang}>
|
||||
{lang.toUpperCase()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div id="language-help" className="sr-only">
|
||||
Filter sessions by language
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Start Date Filter */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="start-date-filter">Start Date</Label>
|
||||
<Input
|
||||
type="date"
|
||||
id="start-date-filter"
|
||||
value={startDate}
|
||||
onChange={(e) => setStartDate(e.target.value)}
|
||||
aria-describedby="start-date-help"
|
||||
/>
|
||||
<div id="start-date-help" className="sr-only">
|
||||
Filter sessions from this date onwards
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* End Date Filter */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="end-date-filter">End Date</Label>
|
||||
<Input
|
||||
type="date"
|
||||
id="end-date-filter"
|
||||
value={endDate}
|
||||
onChange={(e) => setEndDate(e.target.value)}
|
||||
aria-describedby="end-date-help"
|
||||
/>
|
||||
<div id="end-date-help" className="sr-only">
|
||||
Filter sessions up to this date
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort Key */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sort-key">Sort By</Label>
|
||||
<select
|
||||
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"
|
||||
value={sortKey}
|
||||
onChange={(e) => setSortKey(e.target.value)}
|
||||
aria-describedby="sort-key-help"
|
||||
>
|
||||
<option value="startTime">Start Time</option>
|
||||
<option value="category">Category</option>
|
||||
<option value="language">Language</option>
|
||||
<option value="sentiment">Sentiment</option>
|
||||
<option value="messagesSent">Messages Sent</option>
|
||||
<option value="avgResponseTime">
|
||||
Avg. Response Time
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div id="category-help" className="sr-only">
|
||||
Filter sessions by category type
|
||||
</select>
|
||||
<div id="sort-key-help" className="sr-only">
|
||||
Choose field to sort sessions by
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Language Filter */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="language-filter">Language</Label>
|
||||
<select
|
||||
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"
|
||||
value={selectedLanguage}
|
||||
onChange={(e) => setSelectedLanguage(e.target.value)}
|
||||
aria-describedby="language-help"
|
||||
>
|
||||
<option value="">All Languages</option>
|
||||
{filterOptions.languages.map((lang) => (
|
||||
<option key={lang} value={lang}>
|
||||
{lang.toUpperCase()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div id="language-help" className="sr-only">
|
||||
Filter sessions by language
|
||||
{/* Sort Order */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sort-order">Order</Label>
|
||||
<select
|
||||
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"
|
||||
value={sortOrder}
|
||||
onChange={(e) =>
|
||||
setSortOrder(e.target.value as "asc" | "desc")
|
||||
}
|
||||
aria-describedby="sort-order-help"
|
||||
>
|
||||
<option value="desc">Descending</option>
|
||||
<option value="asc">Ascending</option>
|
||||
</select>
|
||||
<div id="sort-order-help" className="sr-only">
|
||||
Choose ascending or descending order
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Start Date Filter */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="start-date-filter">Start Date</Label>
|
||||
<Input
|
||||
type="date"
|
||||
id="start-date-filter"
|
||||
value={startDate}
|
||||
onChange={(e) => setStartDate(e.target.value)}
|
||||
aria-describedby="start-date-help"
|
||||
/>
|
||||
<div id="start-date-help" className="sr-only">
|
||||
Filter sessions from this date onwards
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* End Date Filter */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="end-date-filter">End Date</Label>
|
||||
<Input
|
||||
type="date"
|
||||
id="end-date-filter"
|
||||
value={endDate}
|
||||
onChange={(e) => setEndDate(e.target.value)}
|
||||
aria-describedby="end-date-help"
|
||||
/>
|
||||
<div id="end-date-help" className="sr-only">
|
||||
Filter sessions up to this date
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort Key */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sort-key">Sort By</Label>
|
||||
<select
|
||||
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"
|
||||
value={sortKey}
|
||||
onChange={(e) => setSortKey(e.target.value)}
|
||||
aria-describedby="sort-key-help"
|
||||
>
|
||||
<option value="startTime">Start Time</option>
|
||||
<option value="category">Category</option>
|
||||
<option value="language">Language</option>
|
||||
<option value="sentiment">Sentiment</option>
|
||||
<option value="messagesSent">Messages Sent</option>
|
||||
<option value="avgResponseTime">Avg. Response Time</option>
|
||||
</select>
|
||||
<div id="sort-key-help" className="sr-only">
|
||||
Choose field to sort sessions by
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort Order */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sort-order">Order</Label>
|
||||
<select
|
||||
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"
|
||||
value={sortOrder}
|
||||
onChange={(e) => setSortOrder(e.target.value as "asc" | "desc")}
|
||||
aria-describedby="sort-order-help"
|
||||
>
|
||||
<option value="desc">Descending</option>
|
||||
<option value="asc">Ascending</option>
|
||||
</select>
|
||||
<div id="sort-order-help" className="sr-only">
|
||||
Choose ascending or descending order
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</CardContent>
|
||||
)}
|
||||
</fieldset>
|
||||
</CardContent>
|
||||
)}
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
{/* Results section */}
|
||||
<section aria-labelledby="results-heading">
|
||||
<h2 id="results-heading" className="sr-only">Session Results</h2>
|
||||
|
||||
<h2 id="results-heading" className="sr-only">
|
||||
Session Results
|
||||
</h2>
|
||||
|
||||
{/* Live region for screen reader announcements */}
|
||||
<div role="status" aria-live="polite" className="sr-only">
|
||||
{loading && "Loading sessions..."}
|
||||
{error && `Error loading sessions: ${error}`}
|
||||
{!loading && !error && sessions.length > 0 && `Found ${sessions.length} sessions`}
|
||||
{!loading && !error && sessions.length === 0 && "No sessions found"}
|
||||
</div>
|
||||
<div role="status" aria-live="polite" className="sr-only">
|
||||
{loading && "Loading sessions..."}
|
||||
{error && `Error loading sessions: ${error}`}
|
||||
{!loading &&
|
||||
!error &&
|
||||
sessions.length > 0 &&
|
||||
`Found ${sessions.length} sessions`}
|
||||
{!loading && !error && sessions.length === 0 && "No sessions found"}
|
||||
</div>
|
||||
|
||||
{/* Loading State */}
|
||||
{loading && (
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="text-center py-8 text-muted-foreground" aria-hidden="true">
|
||||
Loading sessions...
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
{/* Loading State */}
|
||||
{loading && (
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div
|
||||
className="text-center py-8 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
>
|
||||
Loading sessions...
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Error State */}
|
||||
{error && (
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="text-center py-8 text-destructive" role="alert" aria-hidden="true">
|
||||
Error: {error}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
{/* Error State */}
|
||||
{error && (
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div
|
||||
className="text-center py-8 text-destructive"
|
||||
role="alert"
|
||||
aria-hidden="true"
|
||||
>
|
||||
Error: {error}
|
||||
</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>
|
||||
)}
|
||||
{/* 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 && (
|
||||
@ -388,11 +412,18 @@ export default function SessionsPage() {
|
||||
<article aria-labelledby={`session-${session.id}-title`}>
|
||||
<header className="flex justify-between items-start mb-4">
|
||||
<div className="space-y-2 flex-1">
|
||||
<h3 id={`session-${session.id}-title`} className="sr-only">
|
||||
Session {session.sessionId || session.id} from {new Date(session.startTime).toLocaleDateString()}
|
||||
<h3
|
||||
id={`session-${session.id}-title`}
|
||||
className="sr-only"
|
||||
>
|
||||
Session {session.sessionId || session.id} from{" "}
|
||||
{new Date(session.startTime).toLocaleDateString()}
|
||||
</h3>
|
||||
<div className="flex items-center gap-3">
|
||||
<Badge variant="outline" className="font-mono text-xs">
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="font-mono text-xs"
|
||||
>
|
||||
ID
|
||||
</Badge>
|
||||
<code className="text-sm text-muted-foreground font-mono truncate max-w-24">
|
||||
@ -401,7 +432,10 @@ export default function SessionsPage() {
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="outline" className="text-xs">
|
||||
<Clock className="h-3 w-3 mr-1" aria-hidden="true" />
|
||||
<Clock
|
||||
className="h-3 w-3 mr-1"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{new Date(session.startTime).toLocaleDateString()}
|
||||
</Badge>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
@ -410,14 +444,16 @@ export default function SessionsPage() {
|
||||
</div>
|
||||
</div>
|
||||
<Link href={`/dashboard/sessions/${session.id}`}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
aria-label={`View details for session ${session.sessionId || session.id}`}
|
||||
>
|
||||
<Eye className="h-4 w-4" aria-hidden="true" />
|
||||
<span className="hidden sm:inline">View Details</span>
|
||||
<span className="hidden sm:inline">
|
||||
View Details
|
||||
</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</header>
|
||||
@ -454,38 +490,40 @@ export default function SessionsPage() {
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 0 && (
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="flex justify-center items-center gap-4">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setCurrentPage((prev) => Math.max(prev - 1, 1))}
|
||||
disabled={currentPage === 1}
|
||||
className="gap-2"
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
Previous
|
||||
</Button>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Page {currentPage} of {totalPages}
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
||||
}
|
||||
disabled={currentPage === totalPages}
|
||||
className="gap-2"
|
||||
>
|
||||
Next
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
{/* Pagination */}
|
||||
{totalPages > 0 && (
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="flex justify-center items-center gap-4">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
||||
}
|
||||
disabled={currentPage === 1}
|
||||
className="gap-2"
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
Previous
|
||||
</Button>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Page {currentPage} of {totalPages}
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setCurrentPage((prev) => Math.min(prev + 1, totalPages))
|
||||
}
|
||||
disabled={currentPage === totalPages}
|
||||
className="gap-2"
|
||||
>
|
||||
Next
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -2,6 +2,28 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useSession } from "next-auth/react";
|
||||
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 { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Users, UserPlus, Shield, Eye, AlertCircle } from "lucide-react";
|
||||
|
||||
interface UserItem {
|
||||
id: string;
|
||||
@ -13,15 +35,21 @@ export default function UserManagementPage() {
|
||||
const { data: session, status } = useSession();
|
||||
const [users, setUsers] = useState<UserItem[]>([]);
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [role, setRole] = useState<string>("user");
|
||||
const [role, setRole] = useState<string>("USER");
|
||||
const [message, setMessage] = useState<string>("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (status === "authenticated") {
|
||||
fetchUsers();
|
||||
if (session?.user?.role === "ADMIN") {
|
||||
fetchUsers();
|
||||
} else {
|
||||
setLoading(false); // Stop loading for non-admin users
|
||||
}
|
||||
} else if (status === "unauthenticated") {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [status]);
|
||||
}, [status, session?.user?.role]);
|
||||
|
||||
const fetchUsers = async () => {
|
||||
setLoading(true);
|
||||
@ -65,148 +93,181 @@ export default function UserManagementPage() {
|
||||
|
||||
// Loading state
|
||||
if (loading) {
|
||||
return <div className="text-center py-10">Loading users...</div>;
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
Loading users...
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Check for admin access
|
||||
if (session?.user?.role !== "ADMIN") {
|
||||
return (
|
||||
<div className="text-center py-10 bg-white rounded-xl shadow p-6">
|
||||
<h2 className="font-bold text-xl text-red-600 mb-2">Access Denied</h2>
|
||||
<p>You don't have permission to view user management.</p>
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="text-center py-8">
|
||||
<AlertCircle className="h-12 w-12 text-destructive mx-auto mb-4" />
|
||||
<h2 className="font-bold text-xl text-destructive mb-2">
|
||||
Access Denied
|
||||
</h2>
|
||||
<p className="text-muted-foreground">
|
||||
You don't have permission to view user management.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-white p-6 rounded-xl shadow">
|
||||
<h1 className="text-2xl font-bold text-gray-800 mb-6">
|
||||
User Management
|
||||
</h1>
|
||||
<div className="space-y-6" data-testid="user-management-page">
|
||||
{/* Header */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Users className="h-6 w-6" />
|
||||
User Management
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
|
||||
{message && (
|
||||
<div
|
||||
className={`p-4 rounded mb-6 ${message.includes("Failed") ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"}`}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
)}
|
||||
{/* Message Alert */}
|
||||
{message && (
|
||||
<Alert variant={message.includes("Failed") ? "destructive" : "default"}>
|
||||
<AlertDescription>{message}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<div className="mb-8">
|
||||
<h2 className="text-lg font-semibold mb-4">Invite New User</h2>
|
||||
{/* Invite New User */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<UserPlus className="h-5 w-5" />
|
||||
Invite New User
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
className="grid grid-cols-1 sm:grid-cols-3 gap-4 items-end"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
inviteUser();
|
||||
}}
|
||||
autoComplete="off" // Disable autofill for the form
|
||||
autoComplete="off"
|
||||
data-testid="invite-form"
|
||||
role="form"
|
||||
>
|
||||
<div className="grid gap-2">
|
||||
<label className="font-medium text-gray-700">Email</label>
|
||||
<input
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
className="border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-sky-500"
|
||||
placeholder="user@example.com"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
autoComplete="off" // Disable autofill for this input
|
||||
autoComplete="off"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<label className="font-medium text-gray-700">Role</label>
|
||||
<select
|
||||
className="border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-sky-500 bg-white"
|
||||
value={role}
|
||||
onChange={(e) => setRole(e.target.value)}
|
||||
>
|
||||
<option value="user">User</option>
|
||||
<option value="ADMIN">Admin</option>
|
||||
<option value="AUDITOR">Auditor</option>
|
||||
</select>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="role">Role</Label>
|
||||
<Select value={role} onValueChange={setRole}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select role" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="USER">User</SelectItem>
|
||||
<SelectItem value="ADMIN">Admin</SelectItem>
|
||||
<SelectItem value="AUDITOR">Auditor</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-sky-600 hover:bg-sky-700 text-white py-2 px-4 rounded-lg shadow transition-colors"
|
||||
>
|
||||
<Button type="submit" className="gap-2">
|
||||
<UserPlus className="h-4 w-4" />
|
||||
Invite User
|
||||
</button>
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold mb-4">Current Users</h2>
|
||||
{/* Current Users */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Users className="h-5 w-5" />
|
||||
Current Users ({users?.length || 0})
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<thead className="bg-gray-50">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
Email
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
Role
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Role</TableHead>
|
||||
<TableHead>Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{users.length === 0 ? (
|
||||
<tr>
|
||||
<td
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={3}
|
||||
className="px-6 py-4 text-center text-sm text-gray-500"
|
||||
className="text-center text-muted-foreground"
|
||||
>
|
||||
No users found
|
||||
</td>
|
||||
</tr>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
users.map((user) => (
|
||||
<tr key={user.id}>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
||||
<TableRow key={user.id}>
|
||||
<TableCell className="font-medium">
|
||||
{user.email}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
<span
|
||||
className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge
|
||||
variant={
|
||||
user.role === "ADMIN"
|
||||
? "bg-purple-100 text-purple-800"
|
||||
? "default"
|
||||
: user.role === "AUDITOR"
|
||||
? "bg-blue-100 text-blue-800"
|
||||
: "bg-green-100 text-green-800"
|
||||
}`}
|
||||
? "secondary"
|
||||
: "outline"
|
||||
}
|
||||
className="gap-1"
|
||||
data-testid="role-badge"
|
||||
>
|
||||
{user.role === "ADMIN" && (
|
||||
<Shield className="h-3 w-3" />
|
||||
)}
|
||||
{user.role === "AUDITOR" && (
|
||||
<Eye className="h-3 w-3" />
|
||||
)}
|
||||
{user.role}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{/* For future: Add actions like edit, delete, etc. */}
|
||||
<span className="text-gray-400">
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-muted-foreground text-sm">
|
||||
No actions available
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
104
app/globals.css
104
app/globals.css
@ -41,56 +41,76 @@
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--animate-shine: shine var(--duration) infinite linear;
|
||||
@keyframes shine {
|
||||
0% {
|
||||
background-position: 0% 0%;
|
||||
0% {
|
||||
background-position: 0% 0%;
|
||||
}
|
||||
50% {
|
||||
background-position: 100% 100%;
|
||||
50% {
|
||||
background-position: 100% 100%;
|
||||
}
|
||||
to {
|
||||
background-position: 0% 0%;
|
||||
to {
|
||||
background-position: 0% 0%;
|
||||
}
|
||||
}
|
||||
--animate-meteor: meteor 5s linear infinite
|
||||
;
|
||||
--animate-meteor: meteor 5s linear infinite;
|
||||
@keyframes meteor {
|
||||
0% {
|
||||
transform: rotate(var(--angle)) translateX(0);
|
||||
opacity: 1;}
|
||||
70% {
|
||||
opacity: 1;}
|
||||
100% {
|
||||
transform: rotate(var(--angle)) translateX(-500px);
|
||||
opacity: 0;}}
|
||||
--animate-background-position-spin: background-position-spin 3000ms infinite alternate;
|
||||
0% {
|
||||
transform: rotate(var(--angle)) translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
70% {
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: rotate(var(--angle)) translateX(-500px);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
--animate-background-position-spin: background-position-spin 3000ms infinite
|
||||
alternate;
|
||||
@keyframes background-position-spin {
|
||||
0% {
|
||||
background-position: top center;}
|
||||
100% {
|
||||
background-position: bottom center;}}
|
||||
0% {
|
||||
background-position: top center;
|
||||
}
|
||||
100% {
|
||||
background-position: bottom center;
|
||||
}
|
||||
}
|
||||
--animate-aurora: aurora 8s ease-in-out infinite alternate;
|
||||
@keyframes aurora {
|
||||
0% {
|
||||
background-position: 0% 50%;
|
||||
transform: rotate(-5deg) scale(0.9);}
|
||||
25% {
|
||||
background-position: 50% 100%;
|
||||
transform: rotate(5deg) scale(1.1);}
|
||||
50% {
|
||||
background-position: 100% 50%;
|
||||
transform: rotate(-3deg) scale(0.95);}
|
||||
75% {
|
||||
background-position: 50% 0%;
|
||||
transform: rotate(3deg) scale(1.05);}
|
||||
100% {
|
||||
background-position: 0% 50%;
|
||||
transform: rotate(-5deg) scale(0.9);}}
|
||||
0% {
|
||||
background-position: 0% 50%;
|
||||
transform: rotate(-5deg) scale(0.9);
|
||||
}
|
||||
25% {
|
||||
background-position: 50% 100%;
|
||||
transform: rotate(5deg) scale(1.1);
|
||||
}
|
||||
50% {
|
||||
background-position: 100% 50%;
|
||||
transform: rotate(-3deg) scale(0.95);
|
||||
}
|
||||
75% {
|
||||
background-position: 50% 0%;
|
||||
transform: rotate(3deg) scale(1.05);
|
||||
}
|
||||
100% {
|
||||
background-position: 0% 50%;
|
||||
transform: rotate(-5deg) scale(0.9);
|
||||
}
|
||||
}
|
||||
--animate-shiny-text: shiny-text 8s infinite;
|
||||
@keyframes shiny-text {
|
||||
0%, 90%, 100% {
|
||||
background-position: calc(-100% - var(--shiny-width)) 0;}
|
||||
30%, 60% {
|
||||
background-position: calc(100% + var(--shiny-width)) 0;}}}
|
||||
0%,
|
||||
90%,
|
||||
100% {
|
||||
background-position: calc(-100% - var(--shiny-width)) 0;
|
||||
}
|
||||
30%,
|
||||
60% {
|
||||
background-position: calc(100% + var(--shiny-width)) 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:root {
|
||||
--radius: 0.625rem;
|
||||
@ -168,7 +188,7 @@
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
|
||||
|
||||
/* Line clamp utility */
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
@ -176,4 +196,4 @@
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@ export default function RootLayout({ children }: { children: ReactNode }) {
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<body className="bg-background text-foreground min-h-screen font-sans antialiased">
|
||||
{/* Skip navigation link for keyboard users */}
|
||||
<a
|
||||
href="#main-content"
|
||||
<a
|
||||
href="#main-content"
|
||||
className="sr-only focus:not-sr-only focus:absolute focus:top-4 focus:left-4 focus:z-50 focus:px-4 focus:py-2 focus:bg-primary focus:text-primary-foreground focus:rounded focus:outline-none focus:ring-2 focus:ring-ring"
|
||||
>
|
||||
Skip to main content
|
||||
|
||||
@ -4,7 +4,13 @@ import { signIn } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
@ -73,7 +79,8 @@ export default function LoginPage() {
|
||||
Welcome back to your analytics dashboard
|
||||
</h1>
|
||||
<p className="text-xl text-muted-foreground mb-8">
|
||||
Monitor, analyze, and optimize your customer conversations with AI-powered insights.
|
||||
Monitor, analyze, and optimize your customer conversations with
|
||||
AI-powered insights.
|
||||
</p>
|
||||
|
||||
<div className="space-y-4">
|
||||
@ -81,19 +88,25 @@ export default function LoginPage() {
|
||||
<div className="p-2 rounded-lg bg-primary/10 text-primary">
|
||||
<BarChart3 className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-muted-foreground">Real-time analytics and insights</span>
|
||||
<span className="text-muted-foreground">
|
||||
Real-time analytics and insights
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-green-500/10 text-green-600">
|
||||
<Shield className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-muted-foreground">Enterprise-grade security</span>
|
||||
<span className="text-muted-foreground">
|
||||
Enterprise-grade security
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-blue-500/10 text-blue-600">
|
||||
<Zap className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-muted-foreground">AI-powered conversation analysis</span>
|
||||
<span className="text-muted-foreground">
|
||||
AI-powered conversation analysis
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -130,13 +143,19 @@ export default function LoginPage() {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{/* Live region for screen reader announcements */}
|
||||
<div role="status" aria-live="polite" className="sr-only">
|
||||
{isLoading && "Signing in, please wait..."}
|
||||
{error && `Error: ${error}`}
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<Alert variant="destructive" className="mb-6">
|
||||
<Alert variant="destructive" className="mb-6" role="alert">
|
||||
<AlertDescription>{error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleLogin} className="space-y-4">
|
||||
<form onSubmit={handleLogin} className="space-y-4" noValidate>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input
|
||||
@ -147,8 +166,13 @@ export default function LoginPage() {
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
disabled={isLoading}
|
||||
required
|
||||
aria-describedby="email-help"
|
||||
aria-invalid={!!error}
|
||||
className="transition-all duration-200 focus:ring-2 focus:ring-primary/20"
|
||||
/>
|
||||
<div id="email-help" className="sr-only">
|
||||
Enter your company email address
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Password</Label>
|
||||
@ -160,39 +184,57 @@ export default function LoginPage() {
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
disabled={isLoading}
|
||||
required
|
||||
aria-describedby="password-help"
|
||||
aria-invalid={!!error}
|
||||
className="transition-all duration-200 focus:ring-2 focus:ring-primary/20"
|
||||
/>
|
||||
<div id="password-help" className="sr-only">
|
||||
Enter your account password
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full mt-6 h-11 bg-linear-to-r from-primary to-primary/90 hover:from-primary/90 hover:to-primary/80 transition-all duration-200"
|
||||
disabled={isLoading}
|
||||
disabled={isLoading || !email || !password}
|
||||
aria-describedby={isLoading ? "loading-status" : undefined}
|
||||
>
|
||||
{isLoading ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
<Loader2
|
||||
className="mr-2 h-4 w-4 animate-spin"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
Signing in...
|
||||
</>
|
||||
) : (
|
||||
"Sign in"
|
||||
)}
|
||||
</Button>
|
||||
{isLoading && (
|
||||
<div
|
||||
id="loading-status"
|
||||
className="sr-only"
|
||||
aria-live="polite"
|
||||
>
|
||||
Authentication in progress, please wait
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
|
||||
<div className="mt-6 space-y-4">
|
||||
<div className="text-center">
|
||||
<Link
|
||||
href="/register"
|
||||
className="text-sm text-primary hover:underline transition-colors"
|
||||
className="text-sm text-primary hover:underline transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 rounded-sm"
|
||||
>
|
||||
Don't have a company account? Register here
|
||||
Don't have a company account? Register here
|
||||
</Link>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<Link
|
||||
href="/forgot-password"
|
||||
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
className="text-sm text-muted-foreground hover:text-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 rounded-sm"
|
||||
>
|
||||
Forgot your password?
|
||||
</Link>
|
||||
@ -203,11 +245,17 @@ export default function LoginPage() {
|
||||
|
||||
<p className="mt-8 text-center text-xs text-muted-foreground">
|
||||
By signing in, you agree to our{" "}
|
||||
<Link href="/terms" className="text-primary hover:underline">
|
||||
<Link
|
||||
href="/terms"
|
||||
className="text-primary hover:underline focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 rounded-sm"
|
||||
>
|
||||
Terms of Service
|
||||
</Link>{" "}
|
||||
and{" "}
|
||||
<Link href="/privacy" className="text-primary hover:underline">
|
||||
<Link
|
||||
href="/privacy"
|
||||
className="text-primary hover:underline focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 rounded-sm"
|
||||
>
|
||||
Privacy Policy
|
||||
</Link>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user