Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 2x 1x 1x 1x 1x 1x 4x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 4x 3x 3x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 4x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 2x 2x 3x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 34x 34x 1x 1x 34x 34x 1x 1x 1x 34x 34x 1x 1x 34x 34x 34x 34x 1x 1x 34x 34x 1x 1x 34x 34x 1x 1x 34x 34x 34x 34x 1x 1x 34x 34x 1x 1x 1x 34x 34x 1x 1x 34x 34x 34x 34x 1x 1x 34x 34x 1x 1x 1x 34x 34x 1x 1x 34x 34x 34x 34x 1x 1x 34x 34x 1x 1x 34x 34x 1x 1x 34x 34x 34x 34x 6x 6x 6x 6x 6x 6x 6x 6x 34x 34x 3x 3x 3x 3x 3x 3x 3x 3x 3x 34x 34x 1x 1x 1x 1x 1x 1x 1x 1x 34x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 4x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x | import { createAsyncThunk, createSelector, createSlice, PayloadAction } from "@reduxjs/toolkit";
import { RootState } from "../store";
import {
SupportTicketWithRelations,
SupportArticle,
ChatbotMessage,
SupportStats,
TicketFilters,
TicketListResponse,
ArticleListResponse,
ChatbotResponse,
TicketStatus,
TicketPriority} from "@/types/support";
/**
* Helper to extract data from API response wrapper
*/
function extractData<T>(result: { success?: boolean; data?: T } | T): T {
if (result && typeof result === 'object' && 'data' in result) {
return result.data as T;
}
return result as T;
}
// API functions
const supportApi = {
async getTickets(
filters?: TicketFilters,
page: number = 1,
limit: number = 10
): Promise<TicketListResponse> {
const params = new URLSearchParams();
params.append("page", page.toString());
params.append("limit", limit.toString());
if (filters) {
if (filters.status) {
if (Array.isArray(filters.status)) {
filters.status.forEach((s) => params.append("status", s));
} else {
params.append("status", filters.status);
}
}
if (filters.priority) {
if (Array.isArray(filters.priority)) {
filters.priority.forEach((p) => params.append("priority", p));
} else {
params.append("priority", filters.priority);
}
}
if (filters.category) {
if (Array.isArray(filters.category)) {
filters.category.forEach((c) => params.append("category", c));
} else {
params.append("category", filters.category);
}
}
if (filters.search) params.append("search", filters.search);
if (filters.assignedToId !== undefined) {
params.append("assignedToId", filters.assignedToId?.toString() || "null");
}
}
const response = await fetch(`/api/support/tickets?${params.toString()}`);
if (!response.ok) {
throw new Error("Failed to fetch tickets");
}
const result = await response.json();
return extractData<TicketListResponse>(result);
},
async getTicket(ticketId: string): Promise<SupportTicketWithRelations> {
const response = await fetch(`/api/support/tickets/${ticketId}`);
if (!response.ok) {
throw new Error("Failed to fetch ticket");
}
const result = await response.json();
return extractData<SupportTicketWithRelations>(result);
},
async getMyTickets(page: number = 1, limit: number = 10): Promise<TicketListResponse> {
const response = await fetch(`/api/support/my-tickets?page=${page}&limit=${limit}`);
if (!response.ok) {
throw new Error("Failed to fetch tickets");
}
const result = await response.json();
return extractData<TicketListResponse>(result);
},
async getArticles(
category?: string,
search?: string,
page: number = 1,
limit: number = 10
): Promise<ArticleListResponse> {
const params = new URLSearchParams();
params.append("page", page.toString());
params.append("limit", limit.toString());
if (category) params.append("category", category);
if (search) params.append("search", search);
const response = await fetch(`/api/support/articles?${params.toString()}`);
if (!response.ok) {
throw new Error("Failed to fetch articles");
}
const result = await response.json();
return extractData<ArticleListResponse>(result);
},
async getStats(): Promise<SupportStats> {
const response = await fetch("/api/admin/support/stats");
if (!response.ok) {
throw new Error("Failed to fetch stats");
}
const result = await response.json();
return extractData<SupportStats>(result);
},
async sendChatbotMessage(message: string): Promise<ChatbotResponse> {
const response = await fetch("/api/support/chatbot", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message })});
if (!response.ok) {
throw new Error("Failed to send message");
}
const result = await response.json();
return extractData<ChatbotResponse>(result);
}};
// State type
interface SupportState {
// Tickets
tickets: SupportTicketWithRelations[];
currentTicket: SupportTicketWithRelations | null;
ticketFilters: TicketFilters;
ticketPagination: {
page: number;
limit: number;
total: number;
totalPages: number;
};
ticketsLoading: boolean;
ticketLoading: boolean;
ticketsError: string | null;
// My tickets (customer view)
myTickets: SupportTicketWithRelations[];
myTicketsPagination: {
page: number;
limit: number;
total: number;
totalPages: number;
};
myTicketsLoading: boolean;
myTicketsError: string | null;
// Articles
articles: SupportArticle[];
articlesLoading: boolean;
articlesError: string | null;
articleFilters: {
category: string | null;
search: string;
};
articlePagination: {
page: number;
limit: number;
total: number;
totalPages: number;
};
// Chatbot
chatbotOpen: boolean;
chatbotMessages: ChatbotMessage[];
chatbotLoading: boolean;
chatbotError: string | null;
// Stats
stats: SupportStats | null;
statsLoading: boolean;
statsError: string | null;
// UI state
activeTicketId: string | null;
selectedTicketIds: string[];
unreadCount: number;
}
const initialState: SupportState = {
// Tickets
tickets: [],
currentTicket: null,
ticketFilters: {},
ticketPagination: {
page: 1,
limit: 10,
total: 0,
totalPages: 0},
ticketsLoading: false,
ticketLoading: false,
ticketsError: null,
// My tickets
myTickets: [],
myTicketsPagination: {
page: 1,
limit: 10,
total: 0,
totalPages: 0},
myTicketsLoading: false,
myTicketsError: null,
// Articles
articles: [],
articlesLoading: false,
articlesError: null,
articleFilters: {
category: null,
search: ""},
articlePagination: {
page: 1,
limit: 10,
total: 0,
totalPages: 0},
// Chatbot
chatbotOpen: false,
chatbotMessages: [],
chatbotLoading: false,
chatbotError: null,
// Stats
stats: null,
statsLoading: false,
statsError: null,
// UI state
activeTicketId: null,
selectedTicketIds: [],
unreadCount: 0};
// Async thunks
export const fetchTickets = createAsyncThunk(
"support/fetchTickets",
async (
params: { filters?: TicketFilters; page?: number; limit?: number } = {},
{ rejectWithValue }
) => {
try {
const response = await supportApi.getTickets(
params.filters,
params.page || 1,
params.limit || 10
);
return response;
} catch (error) {
return rejectWithValue(
error instanceof Error ? error.message : "Failed to fetch tickets"
);
}
}
);
export const fetchTicket = createAsyncThunk(
"support/fetchTicket",
async (ticketId: string, { rejectWithValue }) => {
try {
const ticket = await supportApi.getTicket(ticketId);
return ticket;
} catch (error) {
return rejectWithValue(
error instanceof Error ? error.message : "Failed to fetch ticket"
);
}
}
);
export const fetchMyTickets = createAsyncThunk(
"support/fetchMyTickets",
async (params: { page?: number; limit?: number } = {}, { rejectWithValue }) => {
try {
const response = await supportApi.getMyTickets(
params.page || 1,
params.limit || 10
);
return response;
} catch (error) {
return rejectWithValue(
error instanceof Error ? error.message : "Failed to fetch tickets"
);
}
}
);
export const fetchArticles = createAsyncThunk(
"support/fetchArticles",
async (
params: { category?: string; search?: string; page?: number; limit?: number } = {},
{ rejectWithValue }
) => {
try {
const response = await supportApi.getArticles(
params.category,
params.search,
params.page || 1,
params.limit || 10
);
return response;
} catch (error) {
return rejectWithValue(
error instanceof Error ? error.message : "Failed to fetch articles"
);
}
}
);
export const fetchStats = createAsyncThunk(
"support/fetchStats",
async (_, { rejectWithValue }) => {
try {
const stats = await supportApi.getStats();
return stats;
} catch (error) {
return rejectWithValue(
error instanceof Error ? error.message : "Failed to fetch stats"
);
}
}
);
export const sendChatbotMessage = createAsyncThunk(
"support/sendChatbotMessage",
async (message: string, { rejectWithValue }) => {
try {
const response = await supportApi.sendChatbotMessage(message);
return { userMessage: message, response };
} catch (error) {
return rejectWithValue(
error instanceof Error ? error.message : "Failed to send message"
);
}
}
);
// Slice
export const supportSlice = createSlice({
name: "support",
initialState,
reducers: {
// Chatbot actions
toggleChatbot: (state) => {
state.chatbotOpen = !state.chatbotOpen;
},
openChatbot: (state) => {
state.chatbotOpen = true;
},
closeChatbot: (state) => {
state.chatbotOpen = false;
},
addChatbotMessage: (state, action: PayloadAction<ChatbotMessage>) => {
state.chatbotMessages.push(action.payload);
},
clearChatbotMessages: (state) => {
state.chatbotMessages = [];
},
// Ticket filter actions
setTicketFilters: (state, action: PayloadAction<TicketFilters>) => {
state.ticketFilters = action.payload;
},
clearTicketFilters: (state) => {
state.ticketFilters = {};
},
setTicketPage: (state, action: PayloadAction<number>) => {
state.ticketPagination.page = action.payload;
},
// Article filter actions
setArticleCategory: (state, action: PayloadAction<string | null>) => {
state.articleFilters.category = action.payload;
},
setArticleSearch: (state, action: PayloadAction<string>) => {
state.articleFilters.search = action.payload;
},
clearArticleFilters: (state) => {
state.articleFilters = { category: null, search: "" };
},
setArticlePage: (state, action: PayloadAction<number>) => {
state.articlePagination.page = action.payload;
},
// UI actions
setActiveTicket: (state, action: PayloadAction<string | null>) => {
state.activeTicketId = action.payload;
},
selectTicket: (state, action: PayloadAction<string>) => {
if (!state.selectedTicketIds.includes(action.payload)) {
state.selectedTicketIds.push(action.payload);
}
},
deselectTicket: (state, action: PayloadAction<string>) => {
state.selectedTicketIds = state.selectedTicketIds.filter(
(id) => id !== action.payload
);
},
toggleTicketSelection: (state, action: PayloadAction<string>) => {
const index = state.selectedTicketIds.indexOf(action.payload);
if (index === -1) {
state.selectedTicketIds.push(action.payload);
} else {
state.selectedTicketIds.splice(index, 1);
}
},
selectAllTickets: (state) => {
state.selectedTicketIds = state.tickets.map((t) => t.id);
},
deselectAllTickets: (state) => {
state.selectedTicketIds = [];
},
setUnreadCount: (state, action: PayloadAction<number>) => {
state.unreadCount = action.payload;
},
incrementUnreadCount: (state) => {
state.unreadCount += 1;
},
decrementUnreadCount: (state) => {
if (state.unreadCount > 0) {
state.unreadCount -= 1;
}
},
clearUnreadCount: (state) => {
state.unreadCount = 0;
},
// Update ticket in list (for optimistic updates)
updateTicketInList: (
state,
action: PayloadAction<Partial<SupportTicketWithRelations> & { id: string }>
) => {
const index = state.tickets.findIndex((t) => t.id === action.payload.id);
if (index !== -1) {
state.tickets[index] = { ...state.tickets[index], ...action.payload };
}
if (state.currentTicket?.id === action.payload.id) {
state.currentTicket = { ...state.currentTicket, ...action.payload };
}
},
// Clear errors
clearTicketsError: (state) => {
state.ticketsError = null;
},
clearArticlesError: (state) => {
state.articlesError = null;
},
clearChatbotError: (state) => {
state.chatbotError = null;
},
clearStatsError: (state) => {
state.statsError = null;
},
// Reset state
resetSupport: () => initialState},
extraReducers: (builder) => {
// Fetch tickets
builder.addCase(fetchTickets.pending, (state) => {
state.ticketsLoading = true;
state.ticketsError = null;
});
builder.addCase(fetchTickets.fulfilled, (state, action) => {
state.ticketsLoading = false;
state.tickets = action.payload.tickets;
state.ticketPagination = action.payload.pagination;
});
builder.addCase(fetchTickets.rejected, (state, action) => {
state.ticketsLoading = false;
state.ticketsError = action.payload as string;
});
// Fetch single ticket
builder.addCase(fetchTicket.pending, (state) => {
state.ticketLoading = true;
state.ticketsError = null;
});
builder.addCase(fetchTicket.fulfilled, (state, action) => {
state.ticketLoading = false;
state.currentTicket = action.payload;
});
builder.addCase(fetchTicket.rejected, (state, action) => {
state.ticketLoading = false;
state.ticketsError = action.payload as string;
});
// Fetch my tickets
builder.addCase(fetchMyTickets.pending, (state) => {
state.myTicketsLoading = true;
state.myTicketsError = null;
});
builder.addCase(fetchMyTickets.fulfilled, (state, action) => {
state.myTicketsLoading = false;
state.myTickets = action.payload.tickets;
state.myTicketsPagination = action.payload.pagination;
});
builder.addCase(fetchMyTickets.rejected, (state, action) => {
state.myTicketsLoading = false;
state.myTicketsError = action.payload as string;
});
// Fetch articles
builder.addCase(fetchArticles.pending, (state) => {
state.articlesLoading = true;
state.articlesError = null;
});
builder.addCase(fetchArticles.fulfilled, (state, action) => {
state.articlesLoading = false;
state.articles = action.payload.articles;
state.articlePagination = action.payload.pagination;
});
builder.addCase(fetchArticles.rejected, (state, action) => {
state.articlesLoading = false;
state.articlesError = action.payload as string;
});
// Fetch stats
builder.addCase(fetchStats.pending, (state) => {
state.statsLoading = true;
state.statsError = null;
});
builder.addCase(fetchStats.fulfilled, (state, action) => {
state.statsLoading = false;
state.stats = action.payload;
});
builder.addCase(fetchStats.rejected, (state, action) => {
state.statsLoading = false;
state.statsError = action.payload as string;
});
// Send chatbot message
builder.addCase(sendChatbotMessage.pending, (state, action) => {
state.chatbotLoading = true;
state.chatbotError = null;
// Add user message immediately
state.chatbotMessages.push({
id: `user-${Date.now()}`,
type: "user",
content: action.meta.arg,
timestamp: new Date()});
});
builder.addCase(sendChatbotMessage.fulfilled, (state, action) => {
state.chatbotLoading = false;
// Add bot response
state.chatbotMessages.push({
id: `bot-${Date.now()}`,
type: "bot",
content: action.payload.response.message,
timestamp: new Date(),
suggestedArticles: action.payload.response.suggestedArticles,
quickActions: action.payload.response.quickActions});
});
builder.addCase(sendChatbotMessage.rejected, (state, action) => {
state.chatbotLoading = false;
state.chatbotError = action.payload as string;
// Add error message from bot
state.chatbotMessages.push({
id: `bot-error-${Date.now()}`,
type: "bot",
content: "Sorry, I encountered an error. Please try again.",
timestamp: new Date()});
});
}});
// Export actions
export const {
toggleChatbot,
openChatbot,
closeChatbot,
addChatbotMessage,
clearChatbotMessages,
setTicketFilters,
clearTicketFilters,
setTicketPage,
setArticleCategory,
setArticleSearch,
clearArticleFilters,
setArticlePage,
setActiveTicket,
selectTicket,
deselectTicket,
toggleTicketSelection,
selectAllTickets,
deselectAllTickets,
setUnreadCount,
incrementUnreadCount,
decrementUnreadCount,
clearUnreadCount,
updateTicketInList,
clearTicketsError,
clearArticlesError,
clearChatbotError,
clearStatsError,
resetSupport} = supportSlice.actions;
// Selectors
export const selectTickets = (state: RootState) => state.supportReducer.tickets;
export const selectCurrentTicket = (state: RootState) =>
state.supportReducer.currentTicket;
export const selectTicketFilters = (state: RootState) =>
state.supportReducer.ticketFilters;
export const selectTicketPagination = (state: RootState) =>
state.supportReducer.ticketPagination;
export const selectTicketsLoading = (state: RootState) =>
state.supportReducer.ticketsLoading;
export const selectTicketLoading = (state: RootState) =>
state.supportReducer.ticketLoading;
export const selectTicketsError = (state: RootState) =>
state.supportReducer.ticketsError;
export const selectMyTickets = (state: RootState) =>
state.supportReducer.myTickets;
export const selectMyTicketsPagination = (state: RootState) =>
state.supportReducer.myTicketsPagination;
export const selectMyTicketsLoading = (state: RootState) =>
state.supportReducer.myTicketsLoading;
export const selectMyTicketsError = (state: RootState) =>
state.supportReducer.myTicketsError;
export const selectArticles = (state: RootState) =>
state.supportReducer.articles;
export const selectArticlesLoading = (state: RootState) =>
state.supportReducer.articlesLoading;
export const selectArticlesError = (state: RootState) =>
state.supportReducer.articlesError;
export const selectArticleFilters = (state: RootState) =>
state.supportReducer.articleFilters;
export const selectArticlePagination = (state: RootState) =>
state.supportReducer.articlePagination;
export const selectChatbotOpen = (state: RootState) =>
state.supportReducer.chatbotOpen;
export const selectChatbotMessages = (state: RootState) =>
state.supportReducer.chatbotMessages;
export const selectChatbotLoading = (state: RootState) =>
state.supportReducer.chatbotLoading;
export const selectChatbotError = (state: RootState) =>
state.supportReducer.chatbotError;
export const selectStats = (state: RootState) => state.supportReducer.stats;
export const selectStatsLoading = (state: RootState) =>
state.supportReducer.statsLoading;
export const selectStatsError = (state: RootState) =>
state.supportReducer.statsError;
export const selectActiveTicketId = (state: RootState) =>
state.supportReducer.activeTicketId;
export const selectSelectedTicketIds = (state: RootState) =>
state.supportReducer.selectedTicketIds;
export const selectUnreadCount = (state: RootState) =>
state.supportReducer.unreadCount;
// Derived selectors
export const selectTicketById = (ticketId: string) =>
createSelector([selectTickets], (tickets) =>
tickets.find((t) => t.id === ticketId)
);
export const selectOpenTicketsCount = createSelector([selectTickets], (tickets) =>
tickets.filter(
(t) =>
t.status === TicketStatus.OPEN || t.status === TicketStatus.IN_PROGRESS
).length
);
export const selectHighPriorityTicketsCount = createSelector(
[selectTickets],
(tickets) =>
tickets.filter(
(t) =>
t.priority === TicketPriority.HIGH ||
t.priority === TicketPriority.URGENT
).length
);
export const selectSelectedTicketsCount = createSelector(
[selectSelectedTicketIds],
(ids) => ids.length
);
export const selectAllTicketsSelected = createSelector(
[selectTickets, selectSelectedTicketIds],
(tickets, selectedIds) =>
tickets.length > 0 && tickets.every((t) => selectedIds.includes(t.id))
);
export const selectHasActiveFilters = createSelector(
[selectTicketFilters],
(filters) =>
!!(
filters.status ||
filters.priority ||
filters.category ||
filters.search ||
filters.assignedToId !== undefined
)
);
export default supportSlice.reducer;
|