Spaces:
3SCError404
/
Paused

dushyantsingh0 commited on
Commit
4f0fa50
·
1 Parent(s): 0e393aa

backend stabilization

Browse files
api/v1/tickets.py CHANGED
@@ -642,6 +642,105 @@ async def list_tickets(
642
  for t in tickets
643
  ]
644
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  @router.get("/{ticket_id}/", response_model=Union[TicketInternalResponse, TicketResponse])
646
  async def get_ticket(
647
  ticket_id: UUID,
 
642
  for t in tickets
643
  ]
644
 
645
+ @router.get("/paginated/", response_model=Union[PaginatedInternalResponse, PaginatedTicketResponse])
646
+ async def list_tickets_paginated(
647
+ skip: int = 0, limit: int = 10,
648
+ status_filter: Optional[TicketStatus] = None,
649
+ category_filter: Optional[str] = None,
650
+ priority_filter: Optional[TicketPriority] = None,
651
+ project_id: Optional[UUID] = None,
652
+ is_my_tickets: bool = False,
653
+ current_user: User = Depends(get_current_user),
654
+ db: AsyncSession = Depends(get_db)
655
+ ) -> Any:
656
+ """Paginated list of tickets with portal-aware 'My Tickets' logic."""
657
+ from sqlalchemy.orm import joinedload
658
+
659
+ is_staff = current_user.role in [UserRole.SC_ADMIN, UserRole.SC_LEAD, UserRole.SC_AGENT]
660
+
661
+ # 1. Base Query
662
+ base_stmt = select(Ticket).where(Ticket.deleted_at.is_(None))
663
+
664
+ # 2. Workspace Scoping
665
+ if not current_user.is_platform_admin:
666
+ base_stmt = base_stmt.where(Ticket.workspace_id == current_user.workspace_id)
667
+
668
+ # 3. Filters
669
+ if status_filter:
670
+ base_stmt = base_stmt.where(Ticket.status == status_filter)
671
+ if priority_filter:
672
+ base_stmt = base_stmt.where(Ticket.priority == priority_filter)
673
+ if project_id:
674
+ base_stmt = base_stmt.where(Ticket.project_id == project_id)
675
+ if category_filter:
676
+ if category_filter == "N/A":
677
+ base_stmt = base_stmt.where(Ticket.category.is_(None))
678
+ else:
679
+ base_stmt = base_stmt.where(Ticket.category == category_filter)
680
+
681
+ # 4. Portal-Aware 'My Tickets' Logic
682
+ if is_my_tickets:
683
+ if is_staff:
684
+ # Internal Portal: Tickets assigned directly to the staff member
685
+ base_stmt = base_stmt.where(Ticket.assigned_to == current_user.id)
686
+ else:
687
+ # Customer Portal: Tickets created by the customer user
688
+ base_stmt = base_stmt.where(Ticket.created_by == current_user.id)
689
+
690
+ # 5. Execute Count (Parallel ideally, but sequential for standard ACID patterns)
691
+ count_stmt = select(func.count()).select_from(base_stmt.alias("subquery"))
692
+ total_count = (await db.execute(count_stmt)).scalar() or 0
693
+
694
+ # 6. Execute Data Fetch
695
+ data_stmt = (
696
+ base_stmt
697
+ .options(
698
+ joinedload(Ticket.creator),
699
+ joinedload(Ticket.assignee),
700
+ joinedload(Ticket.resolver),
701
+ joinedload(Ticket.feedback)
702
+ )
703
+ .order_by(Ticket.created_at.desc())
704
+ .offset(skip)
705
+ .limit(limit)
706
+ )
707
+ result = await db.execute(data_stmt)
708
+ tickets = result.scalars().all()
709
+
710
+ # --- Context Injection (Batch optimization logic reused from list_tickets) ---
711
+ lead_name = None
712
+ if is_staff and any(t.is_escalated for t in tickets):
713
+ from models.user_workspace import UserWorkspace
714
+ lead_stmt = select(User.full_name).join(UserWorkspace).where(
715
+ UserWorkspace.workspace_id == current_user.workspace_id,
716
+ UserWorkspace.role.in_([UserRole.SC_LEAD, UserRole.SC_ADMIN]),
717
+ User.is_active == True
718
+ ).limit(1)
719
+ lead_res = await db.execute(lead_stmt)
720
+ lead_name = lead_res.scalar_one_or_none()
721
+
722
+ dup_map = {}
723
+ dup_ids = [t.duplicate_of_id for t in tickets if t.duplicate_of_id]
724
+ if dup_ids:
725
+ dup_stmt = select(Ticket.id, Ticket.title).where(Ticket.id.in_(dup_ids))
726
+ dup_map = {row[0]: row[1] for row in (await db.execute(dup_stmt)).all()}
727
+
728
+ final_items = [
729
+ await sanitize_ticket_response(
730
+ t, current_user, db,
731
+ lead_name=lead_name if t.is_escalated else None,
732
+ dup_title=dup_map.get(t.duplicate_of_id)
733
+ )
734
+ for t in tickets
735
+ ]
736
+
737
+ return {
738
+ "items": final_items,
739
+ "total": total_count,
740
+ "skip": skip,
741
+ "limit": limit
742
+ }
743
+
744
  @router.get("/{ticket_id}/", response_model=Union[TicketInternalResponse, TicketResponse])
745
  async def get_ticket(
746
  ticket_id: UUID,
frontend/apps/customer/src/App.tsx CHANGED
@@ -138,8 +138,6 @@ export default function App() {
138
  <TicketList
139
  setActive={setActive}
140
  setSelectedTicket={setSelectedTicket}
141
- tickets={tickets}
142
- loading={ticketsLoading}
143
  />
144
  )}
145
  {active === "thread" && selectedTicket && (
 
138
  <TicketList
139
  setActive={setActive}
140
  setSelectedTicket={setSelectedTicket}
 
 
141
  />
142
  )}
143
  {active === "thread" && selectedTicket && (
frontend/apps/customer/src/components/TicketList.tsx CHANGED
@@ -1,7 +1,8 @@
1
  import React, { useState, useEffect } from 'react';
2
  import { StatusBadge, PriorityBadge } from './Badges';
3
- import { api } from '@nexus/shared';
4
  import { Skeleton } from './Skeleton';
 
5
 
6
  const COLORS = {
7
  brand: "var(--primary)",
@@ -23,14 +24,13 @@ const COLORS = {
23
  interface TicketListProps {
24
  setActive: (tab: any) => void;
25
  setSelectedTicket: (ticket: any) => void;
26
- tickets: any[];
27
- loading: boolean;
28
  }
29
 
30
  const STATUSES = ["OPEN", "ACKNOWLEDGED", "IN_PROGRESS", "RESOLVED", "CLOSED"];
31
  const PRIORITIES = ["P0", "P1", "P2", "P3"];
32
 
33
- export const TicketList: React.FC<TicketListProps> = ({ setActive, setSelectedTicket, tickets, loading }) => {
34
  const [viewMode, setViewMode] = useState<"ALL" | "MINE">("ALL");
35
  const [searchQuery, setSearchQuery] = useState("");
36
  const [creatorFilter, setCreatorFilter] = useState("");
@@ -38,12 +38,30 @@ export const TicketList: React.FC<TicketListProps> = ({ setActive, setSelectedTi
38
  const [priorityFilter, setPriorityFilter] = useState("ALL");
39
  const [categoryFilter, setCategoryFilter] = useState("ALL");
40
  const [categories, setCategories] = useState<string[]>([]);
41
- const [sortBy, setSortBy] = useState<"created_at" | "updated_at" | "resolved_at">("updated_at");
 
 
 
 
 
 
42
 
43
  useEffect(() => {
44
  fetchCategories();
45
  }, []);
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  const fetchCategories = async () => {
48
  try {
49
  const res = await api.get('tickets/categories/');
@@ -53,38 +71,12 @@ export const TicketList: React.FC<TicketListProps> = ({ setActive, setSelectedTi
53
  }
54
  };
55
 
56
- const filtered = tickets.filter(t => {
57
- // 1. View Mode (All vs Mine)
58
- if (viewMode === "MINE" && !t.is_mine) return false;
59
-
60
- // 2. Status
61
- if (statusFilter !== "ALL" && t.status.toUpperCase() !== statusFilter) return false;
62
-
63
- // 3. Priority
64
- if (priorityFilter !== "ALL" && t.priority.toUpperCase() !== priorityFilter) return false;
65
-
66
- // 4. Category
67
- if (categoryFilter !== "ALL") {
68
- const ticketCat = (t.category || "N/A").toUpperCase();
69
- if (ticketCat !== categoryFilter.toUpperCase()) return false;
70
- }
71
-
72
- // 5. Creator Filter
73
- if (creatorFilter) {
74
- const cq = creatorFilter.toLowerCase();
75
- if (!(t.creator_name || "").toLowerCase().includes(cq)) return false;
76
- }
77
-
78
- // 6. Keyword Search
79
- if (searchQuery) {
80
- const q = searchQuery.toLowerCase();
81
- return t.title.toLowerCase().includes(q) || t.id.toLowerCase().includes(q) || (t.description || "").toLowerCase().includes(q);
82
- }
83
-
84
- return true;
85
- }).sort((a, b) => {
86
- return new Date(b[sortBy] || 0).getTime() - new Date(a[sortBy] || 0).getTime();
87
- });
88
 
89
  return (
90
  <div style={{ padding: "0 32px 32px" }}>
@@ -146,7 +138,7 @@ export const TicketList: React.FC<TicketListProps> = ({ setActive, setSelectedTi
146
  </div>
147
  ))}
148
  </div>
149
- ) : filtered.length === 0 ? (
150
  <div style={{
151
  padding: "64px 32px", textAlign: "center",
152
  background: "rgba(255,255,255,0.02)", border: `1px solid ${COLORS.border}`, borderRadius: 12
@@ -156,49 +148,85 @@ export const TicketList: React.FC<TicketListProps> = ({ setActive, setSelectedTi
156
  <div style={{ fontSize: 14, color: COLORS.muted }}>Try adjusting your filters or search query.</div>
157
  </div>
158
  ) : (
159
- <table style={{ width: "100%", borderCollapse: "collapse" }}>
160
- <thead>
161
- <tr style={{ background: "rgba(255, 255, 255, 0.02)" }}>
162
- <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>ID</th>
163
- <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Investigation Subject</th>
164
- <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Identity</th>
165
- <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Priority</th>
166
- <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Status</th>
167
- <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Activity</th>
168
- </tr>
169
- </thead>
170
- <tbody>
171
- {filtered.map((t, i) => (
172
- <tr
173
- key={t.id}
174
- onClick={() => { setSelectedTicket(t); setActive("thread"); }}
175
- style={{ borderBottom: i < filtered.length - 1 ? `1px solid ${COLORS.border}` : "none", cursor: "pointer", transition: "all 0.15s" }}
176
- onMouseEnter={e => e.currentTarget.style.background = "rgba(255, 255, 255, 0.02)"}
177
- onMouseLeave={e => e.currentTarget.style.background = "transparent"}
178
- >
179
- <td style={{ padding: "12px 20px", fontSize: 12, color: COLORS.brand, fontWeight: 700, fontFamily: "monospace" }}>{t.id.slice(0, 8)}</td>
180
- <td style={{ padding: "12px 20px" }}>
181
- <div style={{ fontSize: 14, fontWeight: 600, color: COLORS.text, marginBottom: 4 }}>{t.title}</div>
182
- <div style={{ display: "flex", gap: 8, alignItems: "center" }}>
183
- <span style={{ fontSize: 11, color: COLORS.muted }}>{t.category || "N/A"}</span>
184
- {t.ai_metadata?.messages_count > 0 && (
185
- <>
186
- <span style={{ width: 3, height: 3, borderRadius: "50%", background: "rgba(255,255,255,0.1)" }} />
187
- <span style={{ fontSize: 11, color: COLORS.brand, fontWeight: 600 }}>{t.ai_metadata.messages_count} logs</span>
188
- </>
189
- )}
190
- </div>
191
- </td>
192
- <td style={{ padding: "12px 20px", fontSize: 13, fontWeight: 600, color: COLORS.text }}>{t.creator_name || "Admin"}</td>
193
- <td style={{ padding: "12px 20px" }}><PriorityBadge priority={t.priority} /></td>
194
- <td style={{ padding: "12px 20px" }}><StatusBadge status={t.status} /></td>
195
- <td style={{ padding: "12px 20px", fontSize: 12, color: COLORS.muted, fontWeight: 500 }}>
196
- {new Date(t.updated_at).toLocaleDateString()}
197
- </td>
198
  </tr>
199
- ))}
200
- </tbody>
201
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  )}
203
  </div>
204
  </div>
 
1
  import React, { useState, useEffect } from 'react';
2
  import { StatusBadge, PriorityBadge } from './Badges';
3
+ import { api, useTicketsPaginated } from '@nexus/shared';
4
  import { Skeleton } from './Skeleton';
5
+ import { ChevronLeft, ChevronRight } from 'lucide-react';
6
 
7
  const COLORS = {
8
  brand: "var(--primary)",
 
24
  interface TicketListProps {
25
  setActive: (tab: any) => void;
26
  setSelectedTicket: (ticket: any) => void;
27
+ // tickets and loading are now handled internally via pagination
 
28
  }
29
 
30
  const STATUSES = ["OPEN", "ACKNOWLEDGED", "IN_PROGRESS", "RESOLVED", "CLOSED"];
31
  const PRIORITIES = ["P0", "P1", "P2", "P3"];
32
 
33
+ export const TicketList: React.FC<TicketListProps> = ({ setActive, setSelectedTicket }) => {
34
  const [viewMode, setViewMode] = useState<"ALL" | "MINE">("ALL");
35
  const [searchQuery, setSearchQuery] = useState("");
36
  const [creatorFilter, setCreatorFilter] = useState("");
 
38
  const [priorityFilter, setPriorityFilter] = useState("ALL");
39
  const [categoryFilter, setCategoryFilter] = useState("ALL");
40
  const [categories, setCategories] = useState<string[]>([]);
41
+ const [sortBy, setSortBy] = useState<"created_at" | "updated_at" | "resolved_at">("created_at");
42
+
43
+ // Pagination State
44
+ const [page, setPage] = useState(1);
45
+ const pageSize = 10;
46
+
47
+ const { tickets, total, loading, fetchTickets } = useTicketsPaginated();
48
 
49
  useEffect(() => {
50
  fetchCategories();
51
  }, []);
52
 
53
+ useEffect(() => {
54
+ // Sync filters and pagination to backend
55
+ fetchTickets({
56
+ skip: (page - 1) * pageSize,
57
+ limit: pageSize,
58
+ status_filter: statusFilter === "ALL" ? undefined : statusFilter as any,
59
+ priority_filter: priorityFilter === "ALL" ? undefined : priorityFilter as any,
60
+ category_filter: categoryFilter === "ALL" ? undefined : categoryFilter,
61
+ is_my_tickets: viewMode === "MINE"
62
+ });
63
+ }, [page, statusFilter, priorityFilter, categoryFilter, viewMode, fetchTickets]);
64
+
65
  const fetchCategories = async () => {
66
  try {
67
  const res = await api.get('tickets/categories/');
 
71
  }
72
  };
73
 
74
+ const totalPages = Math.ceil(total / pageSize) || 1;
75
+
76
+ // Search logic remains client-side for "immediate" feel if total is small,
77
+ // but we should generally rely on the list returned by backend.
78
+ // For now, we'll just display the tickets returned by the hook.
79
+ const displayTickets = tickets;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  return (
82
  <div style={{ padding: "0 32px 32px" }}>
 
138
  </div>
139
  ))}
140
  </div>
141
+ ) : displayTickets.length === 0 ? (
142
  <div style={{
143
  padding: "64px 32px", textAlign: "center",
144
  background: "rgba(255,255,255,0.02)", border: `1px solid ${COLORS.border}`, borderRadius: 12
 
148
  <div style={{ fontSize: 14, color: COLORS.muted }}>Try adjusting your filters or search query.</div>
149
  </div>
150
  ) : (
151
+ <>
152
+ <table style={{ width: "100%", borderCollapse: "collapse" }}>
153
+ <thead>
154
+ <tr style={{ background: "rgba(255, 255, 255, 0.02)" }}>
155
+ <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>ID</th>
156
+ <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Investigation Subject</th>
157
+ <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Identity</th>
158
+ <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Priority</th>
159
+ <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Status</th>
160
+ <th style={{ padding: "12px 20px", textAlign: "left", fontSize: 10, fontWeight: 800, color: COLORS.muted, borderBottom: `1px solid ${COLORS.border}`, textTransform: "uppercase", letterSpacing: "0.1em" }}>Activity</th>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  </tr>
162
+ </thead>
163
+ <tbody>
164
+ {displayTickets.map((t, i) => (
165
+ <tr
166
+ key={t.id}
167
+ onClick={() => { setSelectedTicket(t); setActive("thread"); }}
168
+ style={{ borderBottom: i < displayTickets.length - 1 ? `1px solid ${COLORS.border}` : "none", cursor: "pointer", transition: "all 0.15s" }}
169
+ onMouseEnter={e => e.currentTarget.style.background = "rgba(255, 255, 255, 0.02)"}
170
+ onMouseLeave={e => e.currentTarget.style.background = "transparent"}
171
+ >
172
+ <td style={{ padding: "12px 20px", fontSize: 12, color: COLORS.brand, fontWeight: 700, fontFamily: "monospace" }}>{t.id.slice(0, 8)}</td>
173
+ <td style={{ padding: "12px 20px" }}>
174
+ <div style={{ fontSize: 14, fontWeight: 600, color: COLORS.text, marginBottom: 4 }}>{t.title}</div>
175
+ <div style={{ display: "flex", gap: 8, alignItems: "center" }}>
176
+ <span style={{ fontSize: 11, color: COLORS.muted }}>{t.category || "N/A"}</span>
177
+ {t.ai_metadata?.messages_count > 0 && (
178
+ <>
179
+ <span style={{ width: 3, height: 3, borderRadius: "50%", background: "rgba(255,255,255,0.1)" }} />
180
+ <span style={{ fontSize: 11, color: COLORS.brand, fontWeight: 600 }}>{t.ai_metadata.messages_count} logs</span>
181
+ </>
182
+ )}
183
+ </div>
184
+ </td>
185
+ <td style={{ padding: "12px 20px", fontSize: 13, fontWeight: 600, color: COLORS.text }}>{t.creator_name || "Admin"}</td>
186
+ <td style={{ padding: "12px 20px" }}><PriorityBadge priority={t.priority} /></td>
187
+ <td style={{ padding: "12px 20px" }}><StatusBadge status={t.status} /></td>
188
+ <td style={{ padding: "12px 20px", fontSize: 12, color: COLORS.muted, fontWeight: 500 }}>
189
+ {new Date(t.updated_at).toLocaleDateString()}
190
+ </td>
191
+ </tr>
192
+ ))}
193
+ </tbody>
194
+ </table>
195
+
196
+ {/* Pagination Controls */}
197
+ <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px 20px", borderTop: `1px solid ${COLORS.border}`, background: "rgba(255,255,255,0.01)" }}>
198
+ <div style={{ fontSize: 12, color: COLORS.muted, fontWeight: 600 }}>
199
+ Showing <span style={{ color: COLORS.text }}>{total === 0 ? 0 : (page - 1) * pageSize + 1}</span> - <span style={{ color: COLORS.text }}>{Math.min(page * pageSize, total)}</span> of <span style={{ color: COLORS.text }}>{total}</span> cases
200
+ </div>
201
+ <div style={{ display: "flex", gap: 8 }}>
202
+ <button
203
+ disabled={page === 1 || loading}
204
+ onClick={() => setPage(p => p - 1)}
205
+ style={{
206
+ padding: "6px 12px", borderRadius: 8, border: `1px solid ${COLORS.border}`, background: "#fff", cursor: page === 1 ? "not-allowed" : "pointer",
207
+ opacity: page === 1 ? 0.5 : 1, display: "flex", alignItems: "center", gap: 4, fontSize: 12, fontWeight: 700, color: COLORS.text
208
+ }}
209
+ >
210
+ <ChevronLeft size={14} /> Prev
211
+ </button>
212
+ <div style={{ display: "flex", alignItems: "center", gap: 8, padding: "0 8px" }}>
213
+ <span style={{ fontSize: 12, fontWeight: 800, color: COLORS.brand }}>{page}</span>
214
+ <span style={{ fontSize: 12, color: COLORS.muted }}>/</span>
215
+ <span style={{ fontSize: 12, fontWeight: 600, color: COLORS.muted }}>{totalPages}</span>
216
+ </div>
217
+ <button
218
+ disabled={page === totalPages || loading}
219
+ onClick={() => setPage(p => p + 1)}
220
+ style={{
221
+ padding: "6px 12px", borderRadius: 8, border: `1px solid ${COLORS.border}`, background: "#fff", cursor: page === totalPages ? "not-allowed" : "pointer",
222
+ opacity: page === totalPages ? 0.5 : 1, display: "flex", alignItems: "center", gap: 4, fontSize: 12, fontWeight: 700, color: COLORS.text
223
+ }}
224
+ >
225
+ Next <ChevronRight size={14} />
226
+ </button>
227
+ </div>
228
+ </div>
229
+ </>
230
  )}
231
  </div>
232
  </div>
frontend/packages/shared/src/hooks/useTicketsPaginated.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState, useCallback } from 'react';
2
+ import api from '../utils/api';
3
+ import { Ticket } from './useTickets';
4
+
5
+ interface PaginatedResponse {
6
+ items: Ticket[];
7
+ total: number;
8
+ skip: number;
9
+ limit: number;
10
+ }
11
+
12
+ interface FetchParams {
13
+ skip?: number;
14
+ limit?: number;
15
+ status_filter?: string;
16
+ priority_filter?: string;
17
+ category_filter?: string;
18
+ project_id?: string;
19
+ is_my_tickets?: boolean;
20
+ }
21
+
22
+ export const useTicketsPaginated = () => {
23
+ const [tickets, setTickets] = useState<Ticket[]>([]);
24
+ const [total, setTotal] = useState(0);
25
+ const [loading, setLoading] = useState(false);
26
+ const [error, setError] = useState<string | null>(null);
27
+
28
+ const fetchTickets = useCallback(async (params: FetchParams = {}) => {
29
+ setLoading(true);
30
+ setError(null);
31
+ try {
32
+ const response = await api.get<PaginatedResponse>('tickets/paginated/', {
33
+ params: {
34
+ ...params,
35
+ // Normalize N/A for backend
36
+ category_filter: params.category_filter === 'ALL' ? undefined : params.category_filter
37
+ }
38
+ });
39
+ setTickets(response.data.items);
40
+ setTotal(response.data.total);
41
+ } catch (err: any) {
42
+ setError(err.response?.data?.detail || 'Failed to fetch paginated tickets');
43
+ console.error("Pagination Fetch Error:", err);
44
+ } finally {
45
+ setLoading(false);
46
+ }
47
+ }, []);
48
+
49
+ return {
50
+ tickets,
51
+ total,
52
+ loading,
53
+ error,
54
+ fetchTickets
55
+ };
56
+ };
frontend/packages/shared/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export { AuthProvider } from './contexts/AuthContext';
10
  export { NexusLogo } from './components/NexusLogo';
11
  export * from './hooks/useNexus';
12
  export * from './hooks/useTickets';
 
13
  export * from './hooks/useDashboard';
14
  export type { EscalationRule } from './hooks/useDashboard';
15
  export * from './hooks/useUsers';
 
10
  export { NexusLogo } from './components/NexusLogo';
11
  export * from './hooks/useNexus';
12
  export * from './hooks/useTickets';
13
+ export * from './hooks/useTicketsPaginated';
14
  export * from './hooks/useDashboard';
15
  export type { EscalationRule } from './hooks/useDashboard';
16
  export * from './hooks/useUsers';
schemas/ticket.py CHANGED
@@ -91,3 +91,17 @@ class TicketSearchResponse(BaseModel):
91
  results: List[TicketSearchResult]
92
  related_articles: List[Dict[str, Any]] = []
93
  search_time_s: float
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  results: List[TicketSearchResult]
92
  related_articles: List[Dict[str, Any]] = []
93
  search_time_s: float
94
+
95
+
96
+ class PaginatedTicketResponse(BaseModel):
97
+ items: List[TicketResponse]
98
+ total: int
99
+ skip: int
100
+ limit: int
101
+
102
+
103
+ class PaginatedInternalResponse(BaseModel):
104
+ items: List[TicketInternalResponse]
105
+ total: int
106
+ skip: int
107
+ limit: int