This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -1,366 +1,438 @@
|
||||
"use client";
|
||||
|
||||
import { ArrowLeft, Calendar, Globe, Loader2, Mail, Send, Shield, User } from "lucide-react";
|
||||
import {
|
||||
ArrowLeft,
|
||||
Calendar,
|
||||
Globe,
|
||||
Loader2,
|
||||
Mail,
|
||||
Send,
|
||||
Shield,
|
||||
User,
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { adminReplyTicket, assignTicket, updateTicketPriority, updateTicketStatus } from "@/actions/tickets";
|
||||
import {
|
||||
adminReplyTicket,
|
||||
assignTicket,
|
||||
updateTicketPriority,
|
||||
updateTicketStatus,
|
||||
} from "@/actions/tickets";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
import { TICKET_PRIORITIES, TICKET_STATUSES } from "@/lib/validators/ticket";
|
||||
|
||||
interface TicketMessage {
|
||||
id: number;
|
||||
message: string;
|
||||
isStaff: boolean;
|
||||
createdAt: string;
|
||||
user: { id: number; username: string; look: string; rank: number };
|
||||
id: number;
|
||||
message: string;
|
||||
isStaff: boolean;
|
||||
createdAt: string;
|
||||
user: { id: number; username: string; look: string; rank: number };
|
||||
}
|
||||
|
||||
interface TicketInfo {
|
||||
id: number;
|
||||
subject: string;
|
||||
category: string;
|
||||
priority: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
closedAt: string | null;
|
||||
creator: {
|
||||
id: number;
|
||||
username: string;
|
||||
look: string;
|
||||
rank: number;
|
||||
mail: string;
|
||||
ipRegister: string;
|
||||
accountCreated: number;
|
||||
};
|
||||
assignee: { id: number; username: string } | null;
|
||||
id: number;
|
||||
subject: string;
|
||||
category: string;
|
||||
priority: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
closedAt: string | null;
|
||||
creator: {
|
||||
id: number;
|
||||
username: string;
|
||||
look: string;
|
||||
rank: number;
|
||||
mail: string;
|
||||
ipRegister: string;
|
||||
accountCreated: number;
|
||||
};
|
||||
assignee: { id: number; username: string } | null;
|
||||
}
|
||||
|
||||
interface StaffMember {
|
||||
id: number;
|
||||
username: string;
|
||||
id: number;
|
||||
username: string;
|
||||
}
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
open: "bg-[var(--admin-info-subtle)] text-[var(--admin-info)]",
|
||||
in_progress: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
waiting: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
closed: "bg-muted text-muted-foreground",
|
||||
open: "bg-[var(--admin-info-subtle)] text-[var(--admin-info)]",
|
||||
in_progress: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
waiting: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
closed: "bg-muted text-muted-foreground",
|
||||
};
|
||||
|
||||
const PRIORITY_COLORS: Record<string, string> = {
|
||||
low: "text-muted-foreground",
|
||||
normal: "text-[var(--admin-info)]",
|
||||
high: "text-[var(--admin-warning)]",
|
||||
urgent: "text-[var(--admin-error)]",
|
||||
low: "text-muted-foreground",
|
||||
normal: "text-[var(--admin-info)]",
|
||||
high: "text-[var(--admin-warning)]",
|
||||
urgent: "text-[var(--admin-error)]",
|
||||
};
|
||||
|
||||
export function AdminTicketDetail({
|
||||
ticket,
|
||||
messages: initialMessages,
|
||||
staffMembers,
|
||||
currentUserId,
|
||||
canEdit,
|
||||
ticket,
|
||||
messages: initialMessages,
|
||||
staffMembers,
|
||||
currentUserId,
|
||||
canEdit,
|
||||
}: {
|
||||
ticket: TicketInfo;
|
||||
messages: TicketMessage[];
|
||||
staffMembers: StaffMember[];
|
||||
currentUserId: number;
|
||||
canEdit: boolean;
|
||||
ticket: TicketInfo;
|
||||
messages: TicketMessage[];
|
||||
staffMembers: StaffMember[];
|
||||
currentUserId: number;
|
||||
canEdit: boolean;
|
||||
}) {
|
||||
const [messages] = useState(initialMessages);
|
||||
const [reply, setReply] = useState("");
|
||||
const { run, isPending } = useServerAction();
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
const [messages] = useState(initialMessages);
|
||||
const [reply, setReply] = useState("");
|
||||
const { run, isPending } = useServerAction();
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: explicitly chosen here, see surrounding code
|
||||
useEffect(() => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: explicitly chosen here, see surrounding code
|
||||
useEffect(() => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
|
||||
function handleReply() {
|
||||
if (!reply.trim() || isPending) return;
|
||||
run(() => adminReplyTicket({ ticketId: ticket.id, message: reply.trim() }), {
|
||||
successMessage: "Reply sent!",
|
||||
onSuccess: () => setReply(""),
|
||||
});
|
||||
}
|
||||
function handleReply() {
|
||||
if (!reply.trim() || isPending) return;
|
||||
run(
|
||||
() => adminReplyTicket({ ticketId: ticket.id, message: reply.trim() }),
|
||||
{
|
||||
successMessage: "Reply sent!",
|
||||
onSuccess: () => setReply(""),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function handleStatusChange(status: string) {
|
||||
run(
|
||||
() =>
|
||||
updateTicketStatus({
|
||||
ticketId: ticket.id,
|
||||
status: status as (typeof TICKET_STATUSES)[number],
|
||||
}),
|
||||
{
|
||||
successMessage: `Status changed to ${status}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
function handleStatusChange(status: string) {
|
||||
run(
|
||||
() =>
|
||||
updateTicketStatus({
|
||||
ticketId: ticket.id,
|
||||
status: status as (typeof TICKET_STATUSES)[number],
|
||||
}),
|
||||
{
|
||||
successMessage: `Status changed to ${status}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function handleAssign(assigneeId: string) {
|
||||
const id = assigneeId === "unassign" ? null : Number(assigneeId);
|
||||
run(() => assignTicket({ ticketId: ticket.id, assigneeId: id }), {
|
||||
successMessage: id ? "Ticket assigned" : "Ticket unassigned",
|
||||
});
|
||||
}
|
||||
function handleAssign(assigneeId: string) {
|
||||
const id = assigneeId === "unassign" ? null : Number(assigneeId);
|
||||
run(() => assignTicket({ ticketId: ticket.id, assigneeId: id }), {
|
||||
successMessage: id ? "Ticket assigned" : "Ticket unassigned",
|
||||
});
|
||||
}
|
||||
|
||||
function handlePriorityChange(priority: string) {
|
||||
run(
|
||||
() =>
|
||||
updateTicketPriority({
|
||||
ticketId: ticket.id,
|
||||
priority: priority as (typeof TICKET_PRIORITIES)[number],
|
||||
}),
|
||||
{
|
||||
successMessage: `Priority changed to ${priority}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
function handlePriorityChange(priority: string) {
|
||||
run(
|
||||
() =>
|
||||
updateTicketPriority({
|
||||
ticketId: ticket.id,
|
||||
priority: priority as (typeof TICKET_PRIORITIES)[number],
|
||||
}),
|
||||
{
|
||||
successMessage: `Priority changed to ${priority}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const isClosed = ticket.status === "closed";
|
||||
const isClosed = ticket.status === "closed";
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start gap-4">
|
||||
<Link href="/admin/tickets">
|
||||
<Button variant="ghost" size="icon">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="text-sm text-muted-foreground font-mono">#{ticket.id}</span>
|
||||
<Badge className={STATUS_COLORS[ticket.status]}>{ticket.status.replace("_", " ")}</Badge>
|
||||
<Badge variant="outline" className={`capitalize ${PRIORITY_COLORS[ticket.priority]}`}>
|
||||
{ticket.priority}
|
||||
</Badge>
|
||||
<Badge variant="outline" className="capitalize">
|
||||
{ticket.category}
|
||||
</Badge>
|
||||
</div>
|
||||
<h1 className="text-2xl font-bold">{ticket.subject}</h1>
|
||||
</div>
|
||||
</div>
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start gap-4">
|
||||
<Link href="/admin/tickets">
|
||||
<Button variant="ghost" size="icon">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="text-sm text-muted-foreground font-mono">
|
||||
#{ticket.id}
|
||||
</span>
|
||||
<Badge className={STATUS_COLORS[ticket.status]}>
|
||||
{ticket.status.replace("_", " ")}
|
||||
</Badge>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={`capitalize ${PRIORITY_COLORS[ticket.priority]}`}
|
||||
>
|
||||
{ticket.priority}
|
||||
</Badge>
|
||||
<Badge variant="outline" className="capitalize">
|
||||
{ticket.category}
|
||||
</Badge>
|
||||
</div>
|
||||
<h1 className="text-2xl font-bold">{ticket.subject}</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-[1fr_300px]">
|
||||
{/* Messages */}
|
||||
<div className="space-y-4">
|
||||
<Card className="overflow-hidden">
|
||||
<div className="max-h-[600px] overflow-y-auto p-4 space-y-4">
|
||||
{messages.map((msg) => (
|
||||
<div key={msg.id} className="flex gap-3">
|
||||
<div className="shrink-0">
|
||||
<div className="w-9 h-9 rounded-full bg-accent flex items-center justify-center text-xs font-bold">
|
||||
{msg.isStaff ? (
|
||||
<Shield className="h-4 w-4 text-primary" />
|
||||
) : (
|
||||
<User className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className={`text-xs font-semibold ${msg.isStaff ? "text-primary" : ""}`}>
|
||||
{msg.user.username}
|
||||
{msg.isStaff && " (Staff)"}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
{new Date(msg.createdAt).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className={`rounded-lg px-4 py-2.5 text-sm leading-relaxed ${
|
||||
msg.isStaff ? "bg-primary/10 border border-primary/20" : "bg-muted"
|
||||
}`}
|
||||
>
|
||||
<p className="whitespace-pre-wrap break-words">{msg.message}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div ref={messagesEndRef} />
|
||||
</div>
|
||||
<div className="grid gap-6 lg:grid-cols-[1fr_300px]">
|
||||
{/* Messages */}
|
||||
<div className="space-y-4">
|
||||
<Card className="overflow-hidden">
|
||||
<div className="max-h-[600px] overflow-y-auto p-4 space-y-4">
|
||||
{messages.map((msg) => (
|
||||
<div key={msg.id} className="flex gap-3">
|
||||
<div className="shrink-0">
|
||||
<div className="w-9 h-9 rounded-full bg-accent flex items-center justify-center text-xs font-bold">
|
||||
{msg.isStaff ? (
|
||||
<Shield className="h-4 w-4 text-primary" />
|
||||
) : (
|
||||
<User className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span
|
||||
className={`text-xs font-semibold ${msg.isStaff ? "text-primary" : ""}`}
|
||||
>
|
||||
{msg.user.username}
|
||||
{msg.isStaff && " (Staff)"}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
{new Date(msg.createdAt).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className={`rounded-lg px-4 py-2.5 text-sm leading-relaxed ${
|
||||
msg.isStaff
|
||||
? "bg-primary/10 border border-primary/20"
|
||||
: "bg-muted"
|
||||
}`}
|
||||
>
|
||||
<p className="whitespace-pre-wrap break-words">
|
||||
{msg.message}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div ref={messagesEndRef} />
|
||||
</div>
|
||||
|
||||
{/* Reply */}
|
||||
{canEdit && !isClosed && (
|
||||
<div className="border-t p-4">
|
||||
<div className="flex gap-2">
|
||||
<Textarea
|
||||
value={reply}
|
||||
onChange={(e) => setReply(e.target.value)}
|
||||
placeholder="Reply as staff..."
|
||||
rows={3}
|
||||
maxLength={5000}
|
||||
className="resize-none"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault();
|
||||
handleReply();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleReply}
|
||||
disabled={isPending || !reply.trim()}
|
||||
size="icon"
|
||||
className="shrink-0 h-auto"
|
||||
>
|
||||
{isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : <Send className="h-4 w-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-[10px] text-muted-foreground mt-1">
|
||||
Ctrl+Enter to send. Your reply will be marked as staff.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{/* Reply */}
|
||||
{canEdit && !isClosed && (
|
||||
<div className="border-t p-4">
|
||||
<div className="flex gap-2">
|
||||
<Textarea
|
||||
value={reply}
|
||||
onChange={(e) => setReply(e.target.value)}
|
||||
placeholder="Reply as staff..."
|
||||
rows={3}
|
||||
maxLength={5000}
|
||||
className="resize-none"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault();
|
||||
handleReply();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleReply}
|
||||
disabled={isPending || !reply.trim()}
|
||||
size="icon"
|
||||
className="shrink-0 h-auto"
|
||||
>
|
||||
{isPending ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Send className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-[10px] text-muted-foreground mt-1">
|
||||
Ctrl+Enter to send. Your reply will be marked as staff.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isClosed && (
|
||||
<div className="border-t p-4 text-center text-sm text-muted-foreground">
|
||||
Ticket closed {ticket.closedAt ? `on ${new Date(ticket.closedAt).toLocaleDateString()}` : ""}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
{isClosed && (
|
||||
<div className="border-t p-4 text-center text-sm text-muted-foreground">
|
||||
Ticket closed{" "}
|
||||
{ticket.closedAt
|
||||
? `on ${new Date(ticket.closedAt).toLocaleDateString()}`
|
||||
: ""}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<div className="space-y-4">
|
||||
{/* Actions */}
|
||||
{canEdit && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Actions</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">Status</span>
|
||||
<Select value={ticket.status} onValueChange={handleStatusChange}>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{TICKET_STATUSES.map((s) => (
|
||||
<SelectItem key={s} value={s} className="text-xs capitalize">
|
||||
{s.replace("_", " ")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{/* Sidebar */}
|
||||
<div className="space-y-4">
|
||||
{/* Actions */}
|
||||
{canEdit && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Actions</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">
|
||||
Status
|
||||
</span>
|
||||
<Select
|
||||
value={ticket.status}
|
||||
onValueChange={handleStatusChange}
|
||||
>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{TICKET_STATUSES.map((s) => (
|
||||
<SelectItem
|
||||
key={s}
|
||||
value={s}
|
||||
className="text-xs capitalize"
|
||||
>
|
||||
{s.replace("_", " ")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">Priority</span>
|
||||
<Select value={ticket.priority} onValueChange={handlePriorityChange}>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{TICKET_PRIORITIES.map((p) => (
|
||||
<SelectItem key={p} value={p} className="text-xs capitalize">
|
||||
{p}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">
|
||||
Priority
|
||||
</span>
|
||||
<Select
|
||||
value={ticket.priority}
|
||||
onValueChange={handlePriorityChange}
|
||||
>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{TICKET_PRIORITIES.map((p) => (
|
||||
<SelectItem
|
||||
key={p}
|
||||
value={p}
|
||||
className="text-xs capitalize"
|
||||
>
|
||||
{p}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">Assign to</span>
|
||||
<Select
|
||||
value={ticket.assignee ? String(ticket.assignee.id) : "unassign"}
|
||||
onValueChange={handleAssign}
|
||||
>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue placeholder="Unassigned" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="unassign" className="text-xs">
|
||||
Unassigned
|
||||
</SelectItem>
|
||||
{staffMembers.map((s) => (
|
||||
<SelectItem key={s.id} value={String(s.id)} className="text-xs">
|
||||
{s.username}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">
|
||||
Assign to
|
||||
</span>
|
||||
<Select
|
||||
value={
|
||||
ticket.assignee ? String(ticket.assignee.id) : "unassign"
|
||||
}
|
||||
onValueChange={handleAssign}
|
||||
>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue placeholder="Unassigned" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="unassign" className="text-xs">
|
||||
Unassigned
|
||||
</SelectItem>
|
||||
{staffMembers.map((s) => (
|
||||
<SelectItem
|
||||
key={s.id}
|
||||
value={String(s.id)}
|
||||
className="text-xs"
|
||||
>
|
||||
{s.username}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={() => {
|
||||
handleAssign(String(currentUserId));
|
||||
}}
|
||||
>
|
||||
Assign to me
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={() => {
|
||||
handleAssign(String(currentUserId));
|
||||
}}
|
||||
>
|
||||
Assign to me
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* User info */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Requester</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<Link
|
||||
href={`/admin/users/show/${ticket.creator.id}`}
|
||||
className="flex items-center gap-2 text-sm font-medium hover:text-primary"
|
||||
>
|
||||
<User className="h-3.5 w-3.5" />
|
||||
{ticket.creator.username}
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
Rank {ticket.creator.rank}
|
||||
</Badge>
|
||||
</Link>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Mail className="h-3 w-3" />
|
||||
{ticket.creator.mail}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Globe className="h-3 w-3" />
|
||||
{ticket.creator.ipRegister}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Calendar className="h-3 w-3" />
|
||||
Registered {new Date(ticket.creator.accountCreated * 1000).toLocaleDateString()}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* User info */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Requester</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<Link
|
||||
href={`/admin/users/show/${ticket.creator.id}`}
|
||||
className="flex items-center gap-2 text-sm font-medium hover:text-primary"
|
||||
>
|
||||
<User className="h-3.5 w-3.5" />
|
||||
{ticket.creator.username}
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
Rank {ticket.creator.rank}
|
||||
</Badge>
|
||||
</Link>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Mail className="h-3 w-3" />
|
||||
{ticket.creator.mail}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Globe className="h-3 w-3" />
|
||||
{ticket.creator.ipRegister}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Calendar className="h-3 w-3" />
|
||||
Registered{" "}
|
||||
{new Date(
|
||||
ticket.creator.accountCreated * 1000,
|
||||
).toLocaleDateString()}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Ticket info */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2 text-xs text-muted-foreground">
|
||||
<div className="flex justify-between">
|
||||
<span>Created</span>
|
||||
<span>{new Date(ticket.createdAt).toLocaleString()}</span>
|
||||
</div>
|
||||
{ticket.closedAt && (
|
||||
<div className="flex justify-between">
|
||||
<span>Closed</span>
|
||||
<span>{new Date(ticket.closedAt).toLocaleString()}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex justify-between">
|
||||
<span>Messages</span>
|
||||
<span>{messages.length}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
{/* Ticket info */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2 text-xs text-muted-foreground">
|
||||
<div className="flex justify-between">
|
||||
<span>Created</span>
|
||||
<span>{new Date(ticket.createdAt).toLocaleString()}</span>
|
||||
</div>
|
||||
{ticket.closedAt && (
|
||||
<div className="flex justify-between">
|
||||
<span>Closed</span>
|
||||
<span>{new Date(ticket.closedAt).toLocaleString()}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex justify-between">
|
||||
<span>Messages</span>
|
||||
<span>{messages.length}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,87 +3,95 @@ import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { AdminTicketDetail } from "./admin-ticket-detail";
|
||||
|
||||
export default async function AdminTicketDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.TICKETS_VIEW, session.user.rank)) {
|
||||
redirect("/admin");
|
||||
}
|
||||
export default async function AdminTicketDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.TICKETS_VIEW, session.user.rank)) {
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const ticketId = Number(id);
|
||||
if (Number.isNaN(ticketId)) notFound();
|
||||
const { id } = await params;
|
||||
const ticketId = Number(id);
|
||||
if (Number.isNaN(ticketId)) notFound();
|
||||
|
||||
const ticket = await prisma.websiteTicket.findUnique({
|
||||
where: { id: ticketId },
|
||||
include: {
|
||||
creator: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
look: true,
|
||||
rank: true,
|
||||
ipRegister: true,
|
||||
mail: true,
|
||||
accountCreated: true,
|
||||
},
|
||||
},
|
||||
assignee: { select: { id: true, username: true } },
|
||||
messages: {
|
||||
orderBy: { createdAt: "asc" },
|
||||
include: {
|
||||
user: { select: { id: true, username: true, look: true, rank: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const ticket = await prisma.websiteTicket.findUnique({
|
||||
where: { id: ticketId },
|
||||
include: {
|
||||
creator: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
look: true,
|
||||
rank: true,
|
||||
ipRegister: true,
|
||||
mail: true,
|
||||
accountCreated: true,
|
||||
},
|
||||
},
|
||||
assignee: { select: { id: true, username: true } },
|
||||
messages: {
|
||||
orderBy: { createdAt: "asc" },
|
||||
include: {
|
||||
user: {
|
||||
select: { id: true, username: true, look: true, rank: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!ticket) notFound();
|
||||
if (!ticket) notFound();
|
||||
|
||||
// Get staff members for assignment
|
||||
const staffMembers = await prisma.user.findMany({
|
||||
where: { rank: { gte: 4 } },
|
||||
select: { id: true, username: true },
|
||||
orderBy: { username: "asc" },
|
||||
});
|
||||
// Get staff members for assignment
|
||||
const staffMembers = await prisma.user.findMany({
|
||||
where: { rank: { gte: 4 } },
|
||||
select: { id: true, username: true },
|
||||
orderBy: { username: "asc" },
|
||||
});
|
||||
|
||||
const canEdit = canAccess(permissions, PERMS.TICKETS_EDIT, session.user.rank);
|
||||
const canEdit = canAccess(permissions, PERMS.TICKETS_EDIT, session.user.rank);
|
||||
|
||||
return (
|
||||
<AdminTicketDetail
|
||||
ticket={{
|
||||
id: ticket.id,
|
||||
subject: ticket.subject,
|
||||
category: ticket.category,
|
||||
priority: ticket.priority,
|
||||
status: ticket.status,
|
||||
createdAt: ticket.createdAt.toISOString(),
|
||||
closedAt: ticket.closedAt?.toISOString() ?? null,
|
||||
creator: {
|
||||
id: ticket.creator.id,
|
||||
username: ticket.creator.username,
|
||||
look: ticket.creator.look,
|
||||
rank: ticket.creator.rank,
|
||||
mail: ticket.creator.mail ?? "",
|
||||
ipRegister: ticket.creator.ipRegister,
|
||||
accountCreated: ticket.creator.accountCreated,
|
||||
},
|
||||
assignee: ticket.assignee ? { id: ticket.assignee.id, username: ticket.assignee.username } : null,
|
||||
}}
|
||||
messages={ticket.messages.map((m) => ({
|
||||
id: m.id,
|
||||
message: m.message,
|
||||
isStaff: m.isStaff === 1,
|
||||
createdAt: m.createdAt.toISOString(),
|
||||
user: {
|
||||
id: m.user.id,
|
||||
username: m.user.username,
|
||||
look: m.user.look,
|
||||
rank: m.user.rank,
|
||||
},
|
||||
}))}
|
||||
staffMembers={staffMembers}
|
||||
currentUserId={session.user.id}
|
||||
canEdit={canEdit}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<AdminTicketDetail
|
||||
ticket={{
|
||||
id: ticket.id,
|
||||
subject: ticket.subject,
|
||||
category: ticket.category,
|
||||
priority: ticket.priority,
|
||||
status: ticket.status,
|
||||
createdAt: ticket.createdAt.toISOString(),
|
||||
closedAt: ticket.closedAt?.toISOString() ?? null,
|
||||
creator: {
|
||||
id: ticket.creator.id,
|
||||
username: ticket.creator.username,
|
||||
look: ticket.creator.look,
|
||||
rank: ticket.creator.rank,
|
||||
mail: ticket.creator.mail ?? "",
|
||||
ipRegister: ticket.creator.ipRegister,
|
||||
accountCreated: ticket.creator.accountCreated,
|
||||
},
|
||||
assignee: ticket.assignee
|
||||
? { id: ticket.assignee.id, username: ticket.assignee.username }
|
||||
: null,
|
||||
}}
|
||||
messages={ticket.messages.map((m) => ({
|
||||
id: m.id,
|
||||
message: m.message,
|
||||
isStaff: m.isStaff === 1,
|
||||
createdAt: m.createdAt.toISOString(),
|
||||
user: {
|
||||
id: m.user.id,
|
||||
username: m.user.username,
|
||||
look: m.user.look,
|
||||
rank: m.user.rank,
|
||||
},
|
||||
}))}
|
||||
staffMembers={staffMembers}
|
||||
currentUserId={session.user.id}
|
||||
canEdit={canEdit}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+227
-192
@@ -1,4 +1,10 @@
|
||||
import { AlertCircle, CheckCircle2, Clock, Loader2, Ticket } from "lucide-react";
|
||||
import {
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
Loader2,
|
||||
Ticket,
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -7,215 +13,244 @@ import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
const STATUS_CONFIG = {
|
||||
open: { label: "Open", icon: AlertCircle, class: "bg-[var(--admin-info-subtle)] text-[var(--admin-info)]" },
|
||||
in_progress: {
|
||||
label: "In Progress",
|
||||
icon: Loader2,
|
||||
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
},
|
||||
waiting: {
|
||||
label: "Waiting",
|
||||
icon: Clock,
|
||||
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
},
|
||||
closed: { label: "Closed", icon: CheckCircle2, class: "bg-muted text-muted-foreground" },
|
||||
open: {
|
||||
label: "Open",
|
||||
icon: AlertCircle,
|
||||
class: "bg-[var(--admin-info-subtle)] text-[var(--admin-info)]",
|
||||
},
|
||||
in_progress: {
|
||||
label: "In Progress",
|
||||
icon: Loader2,
|
||||
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
},
|
||||
waiting: {
|
||||
label: "Waiting",
|
||||
icon: Clock,
|
||||
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
},
|
||||
closed: {
|
||||
label: "Closed",
|
||||
icon: CheckCircle2,
|
||||
class: "bg-muted text-muted-foreground",
|
||||
},
|
||||
} as const;
|
||||
|
||||
const PRIORITY_COLORS = {
|
||||
low: "",
|
||||
normal: "text-[var(--admin-info)]",
|
||||
high: "text-[var(--admin-warning)]",
|
||||
urgent: "text-[var(--admin-error)] font-bold",
|
||||
low: "",
|
||||
normal: "text-[var(--admin-info)]",
|
||||
high: "text-[var(--admin-warning)]",
|
||||
urgent: "text-[var(--admin-error)] font-bold",
|
||||
};
|
||||
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ status?: string; page?: string }>;
|
||||
searchParams: Promise<{ status?: string; page?: string }>;
|
||||
}
|
||||
|
||||
export default async function AdminTicketsPage({ searchParams }: PageProps) {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.TICKETS_VIEW, session.user.rank)) {
|
||||
redirect("/admin");
|
||||
}
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.TICKETS_VIEW, session.user.rank)) {
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const sp = await searchParams;
|
||||
const statusFilter = sp.status || "active";
|
||||
const page = Math.max(1, Number(sp.page) || 1);
|
||||
const perPage = 20;
|
||||
const sp = await searchParams;
|
||||
const statusFilter = sp.status || "active";
|
||||
const page = Math.max(1, Number(sp.page) || 1);
|
||||
const perPage = 20;
|
||||
|
||||
const where =
|
||||
statusFilter === "active"
|
||||
? { status: { not: "closed" } }
|
||||
: statusFilter === "all"
|
||||
? {}
|
||||
: { status: statusFilter };
|
||||
const where =
|
||||
statusFilter === "active"
|
||||
? { status: { not: "closed" } }
|
||||
: statusFilter === "all"
|
||||
? {}
|
||||
: { status: statusFilter };
|
||||
|
||||
const [tickets, total, stats] = await Promise.all([
|
||||
prisma.websiteTicket.findMany({
|
||||
where,
|
||||
orderBy: [{ createdAt: "desc" }],
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
include: {
|
||||
creator: { select: { id: true, username: true } },
|
||||
assignee: { select: { id: true, username: true } },
|
||||
_count: { select: { messages: true } },
|
||||
},
|
||||
}),
|
||||
prisma.websiteTicket.count({ where }),
|
||||
Promise.all([
|
||||
prisma.websiteTicket.count({ where: { status: "open" } }),
|
||||
prisma.websiteTicket.count({ where: { status: "in_progress" } }),
|
||||
prisma.websiteTicket.count({ where: { status: "waiting" } }),
|
||||
prisma.websiteTicket.count({ where: { status: "closed" } }),
|
||||
]),
|
||||
]);
|
||||
const [tickets, total, stats] = await Promise.all([
|
||||
prisma.websiteTicket.findMany({
|
||||
where,
|
||||
orderBy: [{ createdAt: "desc" }],
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
include: {
|
||||
creator: { select: { id: true, username: true } },
|
||||
assignee: { select: { id: true, username: true } },
|
||||
_count: { select: { messages: true } },
|
||||
},
|
||||
}),
|
||||
prisma.websiteTicket.count({ where }),
|
||||
Promise.all([
|
||||
prisma.websiteTicket.count({ where: { status: "open" } }),
|
||||
prisma.websiteTicket.count({ where: { status: "in_progress" } }),
|
||||
prisma.websiteTicket.count({ where: { status: "waiting" } }),
|
||||
prisma.websiteTicket.count({ where: { status: "closed" } }),
|
||||
]),
|
||||
]);
|
||||
|
||||
const [openCount, inProgressCount, waitingCount, closedCount] = stats;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
const [openCount, inProgressCount, waitingCount, closedCount] = stats;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Support Tickets</h1>
|
||||
<p className="text-muted-foreground">Manage user support requests</p>
|
||||
</div>
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Support Tickets</h1>
|
||||
<p className="text-muted-foreground">Manage user support requests</p>
|
||||
</div>
|
||||
|
||||
{/* Stats */}
|
||||
<div className="grid gap-4 grid-cols-2 lg:grid-cols-4">
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-[var(--admin-info)]">Open</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{openCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-[var(--admin-warning)]">In Progress</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{inProgressCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-[var(--admin-warning)]">Waiting</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{waitingCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">Closed</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{closedCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
{/* Stats */}
|
||||
<div className="grid gap-4 grid-cols-2 lg:grid-cols-4">
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-[var(--admin-info)]">
|
||||
Open
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{openCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-[var(--admin-warning)]">
|
||||
In Progress
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{inProgressCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-[var(--admin-warning)]">
|
||||
Waiting
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{waitingCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Closed
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{closedCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Filter tabs */}
|
||||
<div className="flex gap-2">
|
||||
{[
|
||||
{ key: "active", label: "Active" },
|
||||
{ key: "open", label: "Open" },
|
||||
{ key: "in_progress", label: "In Progress" },
|
||||
{ key: "waiting", label: "Waiting" },
|
||||
{ key: "closed", label: "Closed" },
|
||||
{ key: "all", label: "All" },
|
||||
].map(({ key, label }) => (
|
||||
<Link key={key} href={`/admin/tickets?status=${key}`}>
|
||||
<Badge variant={statusFilter === key ? "default" : "outline"} className="cursor-pointer">
|
||||
{label}
|
||||
</Badge>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
{/* Filter tabs */}
|
||||
<div className="flex gap-2">
|
||||
{[
|
||||
{ key: "active", label: "Active" },
|
||||
{ key: "open", label: "Open" },
|
||||
{ key: "in_progress", label: "In Progress" },
|
||||
{ key: "waiting", label: "Waiting" },
|
||||
{ key: "closed", label: "Closed" },
|
||||
{ key: "all", label: "All" },
|
||||
].map(({ key, label }) => (
|
||||
<Link key={key} href={`/admin/tickets?status=${key}`}>
|
||||
<Badge
|
||||
variant={statusFilter === key ? "default" : "outline"}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
{label}
|
||||
</Badge>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Ticket list */}
|
||||
<div className="rounded-lg border">
|
||||
<div className="grid grid-cols-[1fr_auto_auto_auto_auto] gap-4 p-3 bg-muted/50 text-xs font-medium text-muted-foreground border-b">
|
||||
<span>Ticket</span>
|
||||
<span>Status</span>
|
||||
<span>Priority</span>
|
||||
<span>Assigned</span>
|
||||
<span>Date</span>
|
||||
</div>
|
||||
{/* Ticket list */}
|
||||
<div className="rounded-lg border">
|
||||
<div className="grid grid-cols-[1fr_auto_auto_auto_auto] gap-4 p-3 bg-muted/50 text-xs font-medium text-muted-foreground border-b">
|
||||
<span>Ticket</span>
|
||||
<span>Status</span>
|
||||
<span>Priority</span>
|
||||
<span>Assigned</span>
|
||||
<span>Date</span>
|
||||
</div>
|
||||
|
||||
{tickets.length === 0 ? (
|
||||
<div className="p-8 text-center text-muted-foreground">
|
||||
<Ticket className="h-8 w-8 mx-auto mb-2" />
|
||||
No tickets found.
|
||||
</div>
|
||||
) : (
|
||||
tickets.map((ticket) => {
|
||||
const status = STATUS_CONFIG[ticket.status as keyof typeof STATUS_CONFIG] ?? STATUS_CONFIG.open;
|
||||
const StatusIcon = status.icon;
|
||||
{tickets.length === 0 ? (
|
||||
<div className="p-8 text-center text-muted-foreground">
|
||||
<Ticket className="h-8 w-8 mx-auto mb-2" />
|
||||
No tickets found.
|
||||
</div>
|
||||
) : (
|
||||
tickets.map((ticket) => {
|
||||
const status =
|
||||
STATUS_CONFIG[ticket.status as keyof typeof STATUS_CONFIG] ??
|
||||
STATUS_CONFIG.open;
|
||||
const StatusIcon = status.icon;
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={ticket.id}
|
||||
href={`/admin/tickets/${ticket.id}`}
|
||||
className="grid grid-cols-[1fr_auto_auto_auto_auto] gap-4 p-3 items-center hover:bg-accent/50 transition-all duration-150 border-b last:border-0 hover:pl-4"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground font-mono">#{ticket.id}</span>
|
||||
<span className="font-medium truncate">{ticket.subject}</span>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
by {ticket.creator.username} · {ticket._count.messages} msg ·{" "}
|
||||
{ticket.category}
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 text-xs font-medium px-2 py-0.5 rounded-full whitespace-nowrap ${status.class}`}
|
||||
>
|
||||
<StatusIcon className="h-3 w-3" />
|
||||
{status.label}
|
||||
</span>
|
||||
<span
|
||||
className={`text-xs capitalize whitespace-nowrap ${PRIORITY_COLORS[ticket.priority as keyof typeof PRIORITY_COLORS] ?? ""}`}
|
||||
>
|
||||
{ticket.priority}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{ticket.assignee?.username ?? "—"}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{new Date(ticket.createdAt).toLocaleDateString()}
|
||||
</span>
|
||||
</Link>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
return (
|
||||
<Link
|
||||
key={ticket.id}
|
||||
href={`/admin/tickets/${ticket.id}`}
|
||||
className="grid grid-cols-[1fr_auto_auto_auto_auto] gap-4 p-3 items-center hover:bg-accent/50 transition-all duration-150 border-b last:border-0 hover:pl-4"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground font-mono">
|
||||
#{ticket.id}
|
||||
</span>
|
||||
<span className="font-medium truncate">
|
||||
{ticket.subject}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
by {ticket.creator.username} ·{" "}
|
||||
{ticket._count.messages} msg · {ticket.category}
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 text-xs font-medium px-2 py-0.5 rounded-full whitespace-nowrap ${status.class}`}
|
||||
>
|
||||
<StatusIcon className="h-3 w-3" />
|
||||
{status.label}
|
||||
</span>
|
||||
<span
|
||||
className={`text-xs capitalize whitespace-nowrap ${PRIORITY_COLORS[ticket.priority as keyof typeof PRIORITY_COLORS] ?? ""}`}
|
||||
>
|
||||
{ticket.priority}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{ticket.assignee?.username ?? "—"}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{new Date(ticket.createdAt).toLocaleDateString()}
|
||||
</span>
|
||||
</Link>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
{page > 1 && (
|
||||
<Link href={`/admin/tickets?status=${statusFilter}&page=${page - 1}`}>
|
||||
<Badge variant="outline" className="cursor-pointer">
|
||||
Previous
|
||||
</Badge>
|
||||
</Link>
|
||||
)}
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Page {page} of {totalPages}
|
||||
</span>
|
||||
{page < totalPages && (
|
||||
<Link href={`/admin/tickets?status=${statusFilter}&page=${page + 1}`}>
|
||||
<Badge variant="outline" className="cursor-pointer">
|
||||
Next
|
||||
</Badge>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
{page > 1 && (
|
||||
<Link
|
||||
href={`/admin/tickets?status=${statusFilter}&page=${page - 1}`}
|
||||
>
|
||||
<Badge variant="outline" className="cursor-pointer">
|
||||
Previous
|
||||
</Badge>
|
||||
</Link>
|
||||
)}
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Page {page} of {totalPages}
|
||||
</span>
|
||||
{page < totalPages && (
|
||||
<Link
|
||||
href={`/admin/tickets?status=${statusFilter}&page=${page + 1}`}
|
||||
>
|
||||
<Badge variant="outline" className="cursor-pointer">
|
||||
Next
|
||||
</Badge>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,22 +4,24 @@ import { prisma } from "@/lib/prisma";
|
||||
import { TicketTemplatesManager } from "./templates-manager";
|
||||
|
||||
export default async function TicketTemplatesPage() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.TICKETS_EDIT, session.user.rank)) {
|
||||
redirect("/admin/tickets");
|
||||
}
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.TICKETS_EDIT, session.user.rank)) {
|
||||
redirect("/admin/tickets");
|
||||
}
|
||||
|
||||
const templates = await prisma.websiteTicketTemplate.findMany({
|
||||
orderBy: { sortOrder: "asc" },
|
||||
});
|
||||
const templates = await prisma.websiteTicketTemplate.findMany({
|
||||
orderBy: { sortOrder: "asc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Reply Templates</h1>
|
||||
<p className="text-muted-foreground">Pre-defined responses for common ticket situations</p>
|
||||
</div>
|
||||
<TicketTemplatesManager templates={templates} />
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Reply Templates</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Pre-defined responses for common ticket situations
|
||||
</p>
|
||||
</div>
|
||||
<TicketTemplatesManager templates={templates} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
import { Copy, Pencil, Plus, Trash2 } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { createTemplate, deleteTemplate, updateTemplate } from "@/actions/ticket-templates";
|
||||
import {
|
||||
createTemplate,
|
||||
deleteTemplate,
|
||||
updateTemplate,
|
||||
} from "@/actions/ticket-templates";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
@@ -11,155 +15,191 @@ import { Label } from "@/components/ui/label";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
|
||||
interface Template {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
category: string;
|
||||
sortOrder: number;
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
category: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
templates: Template[];
|
||||
templates: Template[];
|
||||
}
|
||||
|
||||
export function TicketTemplatesManager({ templates }: Props) {
|
||||
const { run, isPending } = useServerAction();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [form, setForm] = useState({ title: "", content: "", category: "general", sortOrder: 0 });
|
||||
const { run, isPending } = useServerAction();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [form, setForm] = useState({
|
||||
title: "",
|
||||
content: "",
|
||||
category: "general",
|
||||
sortOrder: 0,
|
||||
});
|
||||
|
||||
function resetForm() {
|
||||
setForm({ title: "", content: "", category: "general", sortOrder: 0 });
|
||||
setEditingId(null);
|
||||
setShowForm(false);
|
||||
}
|
||||
function resetForm() {
|
||||
setForm({ title: "", content: "", category: "general", sortOrder: 0 });
|
||||
setEditingId(null);
|
||||
setShowForm(false);
|
||||
}
|
||||
|
||||
function handleEdit(t: Template) {
|
||||
setForm({ title: t.title, content: t.content, category: t.category, sortOrder: t.sortOrder });
|
||||
setEditingId(t.id);
|
||||
setShowForm(true);
|
||||
}
|
||||
function handleEdit(t: Template) {
|
||||
setForm({
|
||||
title: t.title,
|
||||
content: t.content,
|
||||
category: t.category,
|
||||
sortOrder: t.sortOrder,
|
||||
});
|
||||
setEditingId(t.id);
|
||||
setShowForm(true);
|
||||
}
|
||||
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (editingId) {
|
||||
run(() => updateTemplate({ id: editingId, ...form }), {
|
||||
successMessage: "Template updated!",
|
||||
onSuccess: resetForm,
|
||||
});
|
||||
} else {
|
||||
run(() => createTemplate(form), { successMessage: "Template created!", onSuccess: resetForm });
|
||||
}
|
||||
}
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (editingId) {
|
||||
run(() => updateTemplate({ id: editingId, ...form }), {
|
||||
successMessage: "Template updated!",
|
||||
onSuccess: resetForm,
|
||||
});
|
||||
} else {
|
||||
run(() => createTemplate(form), {
|
||||
successMessage: "Template created!",
|
||||
onSuccess: resetForm,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
onClick={() => {
|
||||
resetForm();
|
||||
setShowForm(!showForm);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" /> New Template
|
||||
</Button>
|
||||
</div>
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
onClick={() => {
|
||||
resetForm();
|
||||
setShowForm(!showForm);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" /> New Template
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{showForm && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{editingId ? "Edit Template" : "New Template"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Title</Label>
|
||||
<Input
|
||||
value={form.title}
|
||||
onChange={(e) => setForm({ ...form, title: e.target.value })}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Category</Label>
|
||||
<Input
|
||||
value={form.category}
|
||||
onChange={(e) => setForm({ ...form, category: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Sort Order</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={form.sortOrder}
|
||||
onChange={(e) => setForm({ ...form, sortOrder: Number(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Content</Label>
|
||||
<textarea
|
||||
className="w-full rounded-md border bg-transparent px-3 py-2 text-sm min-h-[120px]"
|
||||
value={form.content}
|
||||
onChange={(e) => setForm({ ...form, content: e.target.value })}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2 justify-end">
|
||||
<Button type="button" variant="outline" onClick={resetForm}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isPending}>
|
||||
{editingId ? "Update" : "Create"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
{showForm && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>
|
||||
{editingId ? "Edit Template" : "New Template"}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Title</Label>
|
||||
<Input
|
||||
value={form.title}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, title: e.target.value })
|
||||
}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Category</Label>
|
||||
<Input
|
||||
value={form.category}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, category: e.target.value })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Sort Order</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={form.sortOrder}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, sortOrder: Number(e.target.value) })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Content</Label>
|
||||
<textarea
|
||||
className="w-full rounded-md border bg-transparent px-3 py-2 text-sm min-h-[120px]"
|
||||
value={form.content}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, content: e.target.value })
|
||||
}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2 justify-end">
|
||||
<Button type="button" variant="outline" onClick={resetForm}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isPending}>
|
||||
{editingId ? "Update" : "Create"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
{templates.length === 0 && (
|
||||
<p className="text-muted-foreground text-center py-8">No templates yet.</p>
|
||||
)}
|
||||
{templates.map((t) => (
|
||||
<Card key={t.id}>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="font-medium text-sm">{t.title}</span>
|
||||
<Badge variant="secondary">{t.category}</Badge>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground whitespace-pre-wrap">{t.content}</p>
|
||||
</div>
|
||||
<div className="flex gap-1 shrink-0 ml-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigator.clipboard.writeText(t.content)}
|
||||
>
|
||||
<Copy className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => handleEdit(t)}>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => run(() => deleteTemplate({ id: t.id }), { successMessage: "Deleted" })}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 text-destructive" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
<div className="space-y-2">
|
||||
{templates.length === 0 && (
|
||||
<p className="text-muted-foreground text-center py-8">
|
||||
No templates yet.
|
||||
</p>
|
||||
)}
|
||||
{templates.map((t) => (
|
||||
<Card key={t.id}>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="font-medium text-sm">{t.title}</span>
|
||||
<Badge variant="secondary">{t.category}</Badge>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground whitespace-pre-wrap">
|
||||
{t.content}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-1 shrink-0 ml-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigator.clipboard.writeText(t.content)}
|
||||
>
|
||||
<Copy className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => handleEdit(t)}
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() =>
|
||||
run(() => deleteTemplate({ id: t.id }), {
|
||||
successMessage: "Deleted",
|
||||
})
|
||||
}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 text-destructive" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user