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 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 | 'use client'; import { useState, useEffect, useMemo } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { CATEGORY_HIERARCHY_RULES } from '@/constants/dev-ticket'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { Icon } from '@/components/ui/icons'; // Collapsible Section Component interface CollapsibleSectionProps { id: string; title: string; count?: number; defaultExpanded?: boolean; children: React.ReactNode; } function CollapsibleSection({ id, title, count, defaultExpanded = true, children }: CollapsibleSectionProps) { const [isExpanded, setIsExpanded] = useState(defaultExpanded); return ( <div id={id} className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 scroll-mt-4"> <button onClick={() => setIsExpanded(!isExpanded)} className="w-full px-6 py-4 flex items-center justify-between text-left hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors" > <h3 className="text-lg font-medium text-gray-900 dark:text-gray-100"> {title}{count !== undefined && ` (${count})`} </h3> <Icon name="chevron-down" size={20} className={`text-gray-500 transition-transform ${isExpanded ? 'rotate-180' : ''}`} /> </button> {isExpanded && ( <div className="border-t border-gray-200 dark:border-gray-700"> {children} </div> )} </div> ); } import { DEV_TICKET_TYPE_CONFIG, DEV_TICKET_STATUS_CONFIG, DEV_TICKET_PRIORITY_CONFIG, DEV_TICKET_SEVERITY_CONFIG, DEV_TICKET_CATEGORY_CONFIG } from '@/constants/dev-ticket'; import type { DevTicketType, DevTicketStatus, DevTicketPriority, DevTicketSeverity, DevTicketCategory } from '@/types/dev-ticket'; interface TicketLabel { id: string; name: string; color: string; } interface TicketUser { id: number; name: string | null; email: string; image: string | null; } interface TicketProject { id: string; name: string; key: string; color: string; } interface TicketMilestone { id: string; name: string; } interface TicketSprint { id: string; name: string; } interface TicketComment { id: string; content: string; isInternal: boolean; createdAt: string; author: TicketUser; } interface TicketHistory { id: string; action: string; field: string | null; oldValue: string | null; newValue: string | null; createdAt: string; performedBy: TicketUser; } interface ParentTicket { id: string; ticketNumber: string; title: string; status: DevTicketStatus; category: DevTicketCategory; childCount: number; completedChildCount: number; } interface ChildTicket { id: string; ticketNumber: string; title: string; status: DevTicketStatus; category: DevTicketCategory; priority: DevTicketPriority; childCount: number; completedChildCount: number; assignee: TicketUser | null; } interface DevTicket { id: string; ticketNumber: string; title: string; description: string; type: DevTicketType; status: DevTicketStatus; priority: DevTicketPriority; severity: DevTicketSeverity | null; category: DevTicketCategory; parentId: string | null; projectId: string | null; objectives: string | null; definitionOfDone: string | null; hierarchyLevel: number; childCount: number; completedChildCount: number; estimatedHours: number | null; actualHours: number | null; storyPoints: number | null; dueDate: string | null; startedAt: string | null; completedAt: string | null; createdAt: string; updatedAt: string; branch: string | null; pullRequestUrl: string | null; deletedAt: string | null; deletedById: number | null; deletedBy?: TicketUser | null; reporter: TicketUser; assignee: TicketUser | null; project: TicketProject | null; milestone: TicketMilestone | null; sprint: TicketSprint | null; labels: TicketLabel[]; comments: TicketComment[]; history: TicketHistory[]; parent: ParentTicket | null; children: ChildTicket[]; _count: { comments: number; attachments: number; timeEntries: number; children: number; }; } interface DevTicketDetailProps { ticketId: string; } export default function DevTicketDetail({ ticketId }: DevTicketDetailProps) { const router = useRouter(); const [ticket, setTicket] = useState<DevTicket | null>(null); const [loading, setLoading] = useState(true); const [error, setError] = useState<string | null>(null); const [newComment, setNewComment] = useState(''); const [submittingComment, setSubmittingComment] = useState(false); const [showAttachModal, setShowAttachModal] = useState(false); const [attachableTickets, setAttachableTickets] = useState<ChildTicket[]>([]); const [attachSearchQuery, setAttachSearchQuery] = useState(''); const [attachingTicket, setAttachingTicket] = useState(false); useEffect(() => { fetchTicket(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [ticketId]); const fetchTicket = async () => { try { setLoading(true); const response = await fetch(`/api/dev/tickets/${ticketId}`); if (!response.ok) { if (response.status === 404) { setError('Ticket not found'); } else { setError('Failed to load ticket'); } return; } const data = await response.json(); setTicket(data.data); } catch (err) { setError('Failed to load ticket'); console.error('Error fetching ticket:', err); } finally { setLoading(false); } }; const handleStatusChange = async (newStatus: DevTicketStatus) => { if (!ticket) return; try { const response = await fetch(`/api/dev/tickets/${ticketId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ status: newStatus })}); if (response.ok) { fetchTicket(); } } catch (err) { console.error('Error updating status:', err); } }; const handleAddComment = async (e: React.FormEvent) => { e.preventDefault(); if (!newComment.trim() || submittingComment) return; try { setSubmittingComment(true); const response = await fetch(`/api/dev/tickets/${ticketId}/comments`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content: newComment })}); if (response.ok) { setNewComment(''); fetchTicket(); } } catch (err) { console.error('Error adding comment:', err); } finally { setSubmittingComment(false); } }; // Get allowed child categories for the current ticket const allowedChildCategories = useMemo(() => { if (!ticket) return []; // Find categories that can have this ticket's category as a parent const categories: DevTicketCategory[] = []; for (const [cat, allowedParents] of Object.entries(CATEGORY_HIERARCHY_RULES)) { if (allowedParents.includes(ticket.category)) { categories.push(cat as DevTicketCategory); } } return categories; }, [ticket]); // Fetch tickets that can be attached as children const fetchAttachableTickets = async () => { if (!ticket || allowedChildCategories.length === 0) return; try { // Fetch tickets with categories that can be children of this ticket // and that don't already have a parent const params = new URLSearchParams(); params.set('parentId', 'null'); params.set('limit', '100'); if (ticket.projectId) params.set('projectId', ticket.projectId); const response = await fetch(`/api/dev/tickets?${params}`); if (response.ok) { const data = await response.json(); // Filter to only tickets with allowed child categories and exclude this ticket const filtered = (data.data || []).filter( (t: ChildTicket) => t.id !== ticket.id && allowedChildCategories.includes(t.category) ); setAttachableTickets(filtered); } } catch (err) { console.error('Error fetching attachable tickets:', err); } }; // Handle opening attach modal const handleOpenAttachModal = () => { setShowAttachModal(true); fetchAttachableTickets(); }; // Handle attaching a ticket as a child const handleAttachTicket = async (childTicketId: string) => { if (attachingTicket) return; try { setAttachingTicket(true); const response = await fetch(`/api/dev/tickets/${childTicketId}/move`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ newParentId: ticketId })}); if (response.ok) { setShowAttachModal(false); setAttachSearchQuery(''); fetchTicket(); } else { const errorData = await response.json(); alert(errorData.error || 'Failed to attach ticket'); } } catch (err) { console.error('Error attaching ticket:', err); alert('Failed to attach ticket'); } finally { setAttachingTicket(false); } }; // Handle detaching a child ticket (making it a root-level ticket) const handleDetachTicket = async (childTicketId: string) => { if (!confirm('Are you sure you want to detach this child ticket? It will become a root-level ticket.')) { return; } try { const response = await fetch(`/api/dev/tickets/${childTicketId}/move`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ newParentId: null })}); if (response.ok) { fetchTicket(); } else { const errorData = await response.json(); alert(errorData.error || 'Failed to detach ticket'); } } catch (err) { console.error('Error detaching ticket:', err); alert('Failed to detach ticket'); } }; // Handle soft delete const handleSoftDelete = async () => { if (!confirm('Are you sure you want to delete this ticket? It will be moved to trash.')) { return; } try { const response = await fetch(`/api/dev/tickets/${ticketId}`, { method: 'DELETE'}); if (response.ok) { fetchTicket(); } else { const errorData = await response.json(); alert(errorData.error || 'Failed to delete ticket'); } } catch (err) { console.error('Error deleting ticket:', err); alert('Failed to delete ticket'); } }; // Handle restore const handleRestore = async () => { try { const response = await fetch(`/api/dev/tickets/${ticketId}/restore`, { method: 'POST'}); if (response.ok) { fetchTicket(); } else { const errorData = await response.json(); alert(errorData.error || 'Failed to restore ticket'); } } catch (err) { console.error('Error restoring ticket:', err); alert('Failed to restore ticket'); } }; // Handle permanent delete const handlePermanentDelete = async () => { if (!confirm('Are you sure you want to PERMANENTLY delete this ticket? This action cannot be undone.')) { return; } try { const response = await fetch(`/api/dev/tickets/${ticketId}?permanent=true`, { method: 'DELETE'}); if (response.ok) { router.push('/admin/dev/tickets'); } else { const errorData = await response.json(); alert(errorData.error || 'Failed to permanently delete ticket'); } } catch (err) { console.error('Error permanently deleting ticket:', err); alert('Failed to permanently delete ticket'); } }; // Filter attachable tickets by search query const filteredAttachableTickets = useMemo(() => { if (!attachSearchQuery) return attachableTickets; const query = attachSearchQuery.toLowerCase(); return attachableTickets.filter( (t) => t.title.toLowerCase().includes(query) || t.ticketNumber.toLowerCase().includes(query) ); }, [attachableTickets, attachSearchQuery]); if (loading) { return ( <div className="p-6"> <div className="animate-pulse"> <div className="h-8 bg-gray-200 dark:bg-gray-700 rounded w-1/3 mb-4"></div> <div className="h-4 bg-gray-200 dark:bg-gray-700 rounded w-2/3 mb-8"></div> <div className="space-y-4"> <div className="h-32 bg-gray-200 dark:bg-gray-700 rounded"></div> <div className="h-32 bg-gray-200 dark:bg-gray-700 rounded"></div> </div> </div> </div> ); } if (error || !ticket) { return ( <div className="p-6"> <div className="bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 rounded-lg p-6 text-center"> <h2 className="text-lg font-semibold text-red-800 dark:text-red-300 mb-2"> {error || 'Ticket not found'} </h2> <p className="text-red-600 dark:text-red-400 mb-4"> The ticket you're looking for doesn't exist or has been deleted. </p> <Link href="/admin/dev/tickets" className="text-indigo-600 hover:text-indigo-800 dark:text-indigo-400 dark:hover:text-indigo-300 font-medium" > Back to Tickets </Link> </div> </div> ); } const typeConfig = DEV_TICKET_TYPE_CONFIG[ticket.type]; const statusConfig = DEV_TICKET_STATUS_CONFIG[ticket.status]; const priorityConfig = DEV_TICKET_PRIORITY_CONFIG[ticket.priority]; const severityConfig = ticket.severity ? DEV_TICKET_SEVERITY_CONFIG[ticket.severity] : null; const categoryConfig = DEV_TICKET_CATEGORY_CONFIG[ticket.category]; // Calculate progress for parent tickets const progress = ticket.childCount > 0 ? Math.round((ticket.completedChildCount / ticket.childCount) * 100) : ticket.status === 'COMPLETED' ? 100 : 0; return ( <div className="p-6 w-full"> {/* Header */} <div className="mb-6"> {/* Breadcrumb with parent hierarchy */} <div className="flex items-center gap-2 text-sm text-gray-500 mb-2 flex-wrap"> <Link href="/admin/dev" className="hover:text-gray-700">Dev</Link> <span>/</span> <Link href="/admin/dev/tickets" className="hover:text-gray-700">Tickets</Link> {ticket.parent && ( <> <span>/</span> <Link href={`/admin/dev/tickets/${ticket.parent.id}`} className="hover:text-gray-700 inline-flex items-center gap-1" > <span>{DEV_TICKET_CATEGORY_CONFIG[ticket.parent.category]?.icon}</span> <span>{ticket.parent.ticketNumber}</span> </Link> </> )} <span>/</span> <span className="text-gray-900">{ticket.ticketNumber}</span> </div> <div className="flex items-start justify-between gap-4"> <div className="flex-1"> <div className="flex items-center gap-3 mb-2 flex-wrap"> {/* Category Badge */} <span className={`inline-flex items-center gap-1 px-2 py-1 rounded text-sm ${categoryConfig.bgColor} ${categoryConfig.color}`}> <span>{categoryConfig.icon}</span> <span>{categoryConfig.label}</span> </span> {/* Type Badge */} <span className={`inline-flex items-center gap-1 px-2 py-1 rounded text-sm ${typeConfig.bgColor} ${typeConfig.color}`}> <span>{typeConfig.icon}</span> <span>{typeConfig.label}</span> </span> <span className="text-gray-500 text-sm">{ticket.ticketNumber}</span> </div> <h1 className="text-2xl font-bold text-gray-900">{ticket.title}</h1> {/* Progress bar for parent tickets */} {ticket.childCount > 0 && ( <div className="mt-3 flex items-center gap-3"> <div className="flex-1 h-2 bg-gray-200 rounded-full overflow-hidden max-w-md"> <div className={`h-full rounded-full transition-all ${ progress === 100 ? 'bg-green-500' : progress > 50 ? 'bg-blue-500' : 'bg-yellow-500' }`} style={{ width: `${progress}%` }} /> </div> <span className="text-sm text-gray-600"> {progress}% ({ticket.completedChildCount}/{ticket.childCount} children) </span> </div> )} </div> <div className="flex items-center gap-2"> {!ticket.deletedAt ? ( <> <button onClick={() => router.push(`/admin/dev/tickets/${ticketId}/edit`)} className="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50" > Edit </button> <button onClick={handleSoftDelete} className="px-4 py-2 text-sm font-medium text-red-700 bg-white border border-red-300 rounded-lg hover:bg-red-50" > Delete </button> </> ) : ( <> <button onClick={handleRestore} className="px-4 py-2 text-sm font-medium text-green-700 bg-white border border-green-300 rounded-lg hover:bg-green-50" > Restore </button> <button onClick={handlePermanentDelete} className="px-4 py-2 text-sm font-medium text-red-700 bg-white border border-red-300 rounded-lg hover:bg-red-50" > Permanently Delete </button> </> )} </div> </div> {/* Deleted Warning Banner */} {ticket.deletedAt && ( <div className="mt-4 bg-red-50 border border-red-200 rounded-lg p-4 flex items-center gap-3"> <Icon name="trash" size={20} className="text-red-500" /> <div className="flex-1"> <p className="text-sm font-medium text-red-800">This ticket has been deleted</p> <p className="text-xs text-red-600"> Deleted on {new Date(ticket.deletedAt).toLocaleString()} {ticket.deletedBy && ` by ${ticket.deletedBy.name || ticket.deletedBy.email}`} </p> </div> </div> )} </div> <div className="flex flex-col lg:flex-row gap-6"> {/* Main Content */} <div className="flex-1 min-w-0 space-y-6"> {/* Section Navigation */} <nav className="flex gap-4 border-b border-gray-200 pb-3"> {[ { id: 'details', label: 'Details' }, { id: 'children', label: 'Children', count: ticket._count.children }, { id: 'comments', label: 'Comments', count: ticket._count.comments }, { id: 'history', label: 'History' }, ].map((section) => ( <a key={section.id} href={`#${section.id}`} className="text-sm font-medium text-gray-500 hover:text-indigo-600 transition-colors flex items-center gap-1" > {section.label} {section.count !== undefined && section.count > 0 && ( <span className="px-1.5 py-0.5 text-xs bg-gray-100 rounded-full"> {section.count} </span> )} </a> ))} </nav> {/* Details Section */} <CollapsibleSection id="details" title="Details"> <div className="p-6 space-y-6"> {/* Description */} <div> <h4 className="text-sm font-medium text-gray-500 mb-3">Description</h4> <div className="prose prose-sm max-w-none"> <ReactMarkdown remarkPlugins={[remarkGfm]} components={{ h1: ({ children }) => <h1 className="text-2xl font-bold mt-6 mb-4 first:mt-0">{children}</h1>, h2: ({ children }) => <h2 className="text-xl font-bold mt-5 mb-3">{children}</h2>, h3: ({ children }) => <h3 className="text-lg font-semibold mt-4 mb-2">{children}</h3>, h4: ({ children }) => <h4 className="text-base font-semibold mt-3 mb-2">{children}</h4>, p: ({ children }) => <p className="mb-3 text-gray-700">{children}</p>, ul: ({ children }) => <ul className="list-disc pl-6 mb-3 space-y-1">{children}</ul>, ol: ({ children }) => <ol className="list-decimal pl-6 mb-3 space-y-1">{children}</ol>, li: ({ children }) => <li className="text-gray-700">{children}</li>, a: ({ href, children }) => ( <a href={href} className="text-indigo-600 hover:text-indigo-800 underline" target="_blank" rel="noopener noreferrer"> {children} </a> ), code: ({ className, children }) => { const isInline = !className; if (isInline) { return <code className="bg-gray-100 px-1.5 py-0.5 rounded text-sm font-mono text-gray-800">{children}</code>; } return ( <code className="block bg-gray-900 text-gray-100 p-4 rounded-lg overflow-x-auto text-sm font-mono"> {children} </code> ); }, pre: ({ children }) => <pre className="bg-gray-900 rounded-lg overflow-x-auto mb-4">{children}</pre>, blockquote: ({ children }) => ( <blockquote className="border-l-4 border-gray-300 pl-4 italic text-gray-600 my-4">{children}</blockquote> ), table: ({ children }) => ( <div className="overflow-x-auto mb-4"> <table className="min-w-full divide-y divide-gray-200 border border-gray-200">{children}</table> </div> ), thead: ({ children }) => <thead className="bg-gray-50">{children}</thead>, th: ({ children }) => <th className="px-4 py-2 text-left text-sm font-semibold text-gray-900 border-b">{children}</th>, td: ({ children }) => <td className="px-4 py-2 text-sm text-gray-700 border-b">{children}</td>, hr: () => <hr className="my-6 border-gray-200" />, input: ({ checked, type }) => { if (type === 'checkbox') { return ( <input type="checkbox" checked={checked} readOnly className="mr-2 rounded border-gray-300" /> ); } return null; }}} > {ticket.description} </ReactMarkdown> </div> </div> {/* Objectives */} {ticket.objectives && ( <div> <h4 className="text-sm font-medium text-gray-500 mb-3">Objectives</h4> <div className="prose prose-sm max-w-none"> <ReactMarkdown remarkPlugins={[remarkGfm]}> {ticket.objectives} </ReactMarkdown> </div> </div> )} {/* Definition of Done */} {ticket.definitionOfDone && ( <div> <h4 className="text-sm font-medium text-gray-500 mb-3">Definition of Done</h4> <div className="prose prose-sm max-w-none"> <ReactMarkdown remarkPlugins={[remarkGfm]} components={{ input: ({ checked, type }) => { if (type === 'checkbox') { return ( <input type="checkbox" checked={checked} readOnly className="mr-2 rounded border-gray-300" /> ); } return null; }}} > {ticket.definitionOfDone} </ReactMarkdown> </div> </div> )} </div> </CollapsibleSection> {/* Children Section */} <CollapsibleSection id="children" title="Children" count={ticket._count.children} defaultExpanded={ticket._count.children > 0}> {/* Header with actions */} <div className="px-6 py-4 border-b border-gray-200 flex items-center justify-between"> <div> {allowedChildCategories.length > 0 && ( <p className="text-sm text-gray-500"> Can contain: {allowedChildCategories.map(cat => DEV_TICKET_CATEGORY_CONFIG[cat]?.label).join(', ')} </p> )} </div> <div className="flex items-center gap-2"> {allowedChildCategories.length > 0 && ( <> <button onClick={handleOpenAttachModal} className="px-3 py-1.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50" > Attach Existing </button> <Link href={`/admin/dev/tickets/new?parentId=${ticket.id}`} className="px-3 py-1.5 text-sm font-medium text-white bg-indigo-600 rounded-lg hover:bg-indigo-700" > + Create Child </Link> </> )} </div> </div> {/* Children Table */} {!ticket.children || ticket.children.length === 0 ? ( <div className="p-8 text-center"> <Icon name="clipboard-list" size={48} className="text-gray-300 mx-auto mb-4" /> <p className="text-gray-500 mb-4">No child tickets yet</p> {allowedChildCategories.length > 0 ? ( <div className="flex items-center justify-center gap-2"> <button onClick={handleOpenAttachModal} className="px-3 py-1.5 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50" > Attach Existing Ticket </button> <Link href={`/admin/dev/tickets/new?parentId=${ticket.id}`} className="px-3 py-1.5 text-sm font-medium text-white bg-indigo-600 rounded-lg hover:bg-indigo-700" > Create New Child </Link> </div> ) : ( <p className="text-sm text-gray-400"> This ticket category ({categoryConfig.label}) cannot have child tickets. </p> )} </div> ) : ( <div className="overflow-x-auto"> <table className="min-w-full divide-y divide-gray-200"> <thead className="bg-gray-50"> <tr> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Category</th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Ticket</th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Priority</th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Assignee</th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Progress</th> <th className="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase">Actions</th> </tr> </thead> <tbody className="bg-white divide-y divide-gray-200"> {ticket.children.map((child) => { const childCategoryConfig = DEV_TICKET_CATEGORY_CONFIG[child.category]; const childStatusConfig = DEV_TICKET_STATUS_CONFIG[child.status]; const childPriorityConfig = DEV_TICKET_PRIORITY_CONFIG[child.priority]; const childProgress = child.childCount > 0 ? Math.round((child.completedChildCount / child.childCount) * 100) : child.status === 'COMPLETED' ? 100 : null; return ( <tr key={child.id} className="hover:bg-gray-50"> {/* Category */} <td className="px-4 py-3 whitespace-nowrap"> <span className={`inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded ${childCategoryConfig.bgColor} ${childCategoryConfig.color}`}> {childCategoryConfig.icon} {childCategoryConfig.label} </span> </td> {/* Ticket */} <td className="px-4 py-3"> <Link href={`/admin/dev/tickets/${child.id}`} className="group"> <p className="text-sm font-medium text-gray-500">{child.ticketNumber}</p> <p className="text-sm text-gray-900 group-hover:text-indigo-600">{child.title}</p> </Link> </td> {/* Status */} <td className="px-4 py-3 whitespace-nowrap"> <span className={`px-2 py-0.5 text-xs font-medium rounded-full ${childStatusConfig.bgColor} ${childStatusConfig.color}`}> {childStatusConfig.label} </span> </td> {/* Priority */} <td className="px-4 py-3 whitespace-nowrap"> <span className={`text-sm ${childPriorityConfig.color}`}> {childPriorityConfig.icon} {childPriorityConfig.label} </span> </td> {/* Assignee */} <td className="px-4 py-3 whitespace-nowrap"> {child.assignee ? ( <span className="text-sm text-gray-900">{child.assignee.name || child.assignee.email}</span> ) : ( <span className="text-sm text-gray-400 italic">Unassigned</span> )} </td> {/* Progress */} <td className="px-4 py-3 whitespace-nowrap"> {child.childCount > 0 ? ( <div className="flex items-center gap-2 min-w-[80px]"> <div className="flex-1 h-1.5 bg-gray-200 rounded-full overflow-hidden"> <div className={`h-full rounded-full ${childProgress === 100 ? 'bg-green-500' : 'bg-blue-500'}`} style={{ width: `${childProgress || 0}%` }} /> </div> <span className="text-xs text-gray-500">{childProgress}%</span> </div> ) : ( <span className="text-xs text-gray-400">-</span> )} </td> {/* Actions */} <td className="px-4 py-3 whitespace-nowrap text-right"> <button onClick={() => handleDetachTicket(child.id)} className="text-xs text-gray-500 hover:text-red-600" title="Detach from parent" > Detach </button> </td> </tr> ); })} </tbody> </table> </div> )} </CollapsibleSection> {/* Attach Existing Ticket Modal */} {showAttachModal && ( <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"> <div className="bg-white rounded-lg shadow-xl max-w-2xl w-full mx-4 max-h-[80vh] flex flex-col"> <div className="px-6 py-4 border-b border-gray-200 flex items-center justify-between"> <h3 className="text-lg font-medium text-gray-900">Attach Existing Ticket</h3> <button onClick={() => { setShowAttachModal(false); setAttachSearchQuery(''); }} className="text-gray-400 hover:text-gray-600" > <Icon name="close" size={20} /> </button> </div> <div className="px-6 py-4 border-b border-gray-200"> <input type="text" value={attachSearchQuery} onChange={(e) => setAttachSearchQuery(e.target.value)} placeholder="Search by ticket number or title..." className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" autoFocus /> <p className="text-xs text-gray-500 mt-2"> Showing tickets that can be attached ({allowedChildCategories.map(c => DEV_TICKET_CATEGORY_CONFIG[c]?.label).join(', ')}) </p> </div> <div className="flex-1 overflow-y-auto px-6 py-4"> {filteredAttachableTickets.length === 0 ? ( <div className="text-center text-gray-500 py-8"> {attachSearchQuery ? 'No matching tickets found' : 'No available tickets to attach'} </div> ) : ( <div className="space-y-2"> {filteredAttachableTickets.map((t) => { const tCategoryConfig = DEV_TICKET_CATEGORY_CONFIG[t.category]; const tStatusConfig = DEV_TICKET_STATUS_CONFIG[t.status]; return ( <div key={t.id} className="flex items-center justify-between p-3 rounded-lg border border-gray-200 hover:border-indigo-300 hover:bg-indigo-50 cursor-pointer" onClick={() => handleAttachTicket(t.id)} > <div className="flex items-center gap-3 flex-1 min-w-0"> <span className={`${tCategoryConfig.color}`}> {tCategoryConfig.icon} </span> <span className="text-sm font-medium text-gray-600">{t.ticketNumber}</span> <span className="text-sm text-gray-900 truncate">{t.title}</span> </div> <div className="flex items-center gap-2 ml-4"> <span className={`px-2 py-0.5 text-xs rounded ${tStatusConfig.bgColor} ${tStatusConfig.color}`}> {tStatusConfig.label} </span> <button onClick={(e) => { e.stopPropagation(); handleAttachTicket(t.id); }} disabled={attachingTicket} className="px-3 py-1 text-xs font-medium text-white bg-indigo-600 rounded hover:bg-indigo-700 disabled:opacity-50" > {attachingTicket ? '...' : 'Attach'} </button> </div> </div> ); })} </div> )} </div> </div> </div> )} {/* Comments Section */} <CollapsibleSection id="comments" title="Comments" count={ticket._count.comments} defaultExpanded={ticket._count.comments > 0}> <div className="p-6 space-y-4"> {/* Add Comment Form */} <form onSubmit={handleAddComment}> <textarea value={newComment} onChange={(e) => setNewComment(e.target.value)} placeholder="Add a comment..." rows={3} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" /> <div className="mt-2 flex justify-end"> <button type="submit" disabled={!newComment.trim() || submittingComment} className="px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-lg hover:bg-indigo-700 disabled:opacity-50" > {submittingComment ? 'Adding...' : 'Add Comment'} </button> </div> </form> {/* Comments List */} {ticket.comments.length === 0 ? ( <p className="text-center text-gray-500 py-4">No comments yet</p> ) : ( <div className="space-y-4"> {ticket.comments.map((comment) => ( <div key={comment.id} className="border border-gray-200 rounded-lg p-4"> <div className="flex items-center gap-2 mb-2"> <span className="font-medium text-gray-900"> {comment.author.name || comment.author.email} </span> <span className="text-gray-400 text-sm"> {new Date(comment.createdAt).toLocaleString()} </span> {comment.isInternal && ( <span className="px-2 py-0.5 text-xs bg-yellow-100 text-yellow-700 rounded"> Internal </span> )} </div> <p className="text-gray-700 whitespace-pre-wrap">{comment.content}</p> </div> ))} </div> )} </div> </CollapsibleSection> {/* History Section - collapsed by default */} <CollapsibleSection id="history" title="History" count={ticket.history.length} defaultExpanded={false}> {ticket.history.length === 0 ? ( <div className="p-6 text-center text-gray-500">No history yet</div> ) : ( <div className="divide-y divide-gray-100"> {ticket.history.map((entry) => ( <div key={entry.id} className="p-4 flex items-start gap-3"> <div className="flex-1"> <p className="text-sm text-gray-700"> <span className="font-medium"> {entry.performedBy.name || entry.performedBy.email} </span>{' '} {entry.action} {entry.field && entry.oldValue && entry.newValue && ( <span> {' '}<span className="text-gray-500">from</span>{' '} <span className="font-medium">{entry.oldValue}</span>{' '} <span className="text-gray-500">to</span>{' '} <span className="font-medium">{entry.newValue}</span> </span> )} </p> <p className="text-xs text-gray-400 mt-1"> {new Date(entry.createdAt).toLocaleString()} </p> </div> </div> ))} </div> )} </CollapsibleSection> </div> {/* Sidebar */} <div className="w-full lg:w-72 xl:w-80 flex-shrink-0 space-y-6"> {/* Status */} <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4"> <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-3">Status</h3> <select value={ticket.status} onChange={(e) => handleStatusChange(e.target.value as DevTicketStatus)} className={`w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 font-medium ${statusConfig.bgColor} ${statusConfig.color}`} > {Object.entries(DEV_TICKET_STATUS_CONFIG).map(([value, config]) => ( <option key={value} value={value}> {config.label} </option> ))} </select> </div> {/* Hierarchy */} <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4"> <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-3">Hierarchy</h3> <dl className="space-y-3"> <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Category</dt> <dd className={`text-sm font-medium ${categoryConfig.color}`}> {categoryConfig.icon} {categoryConfig.label} </dd> </div> {ticket.parent && ( <div className="flex justify-between items-start"> <dt className="text-sm text-gray-500 dark:text-gray-400">Parent</dt> <dd className="text-sm text-right"> <Link href={`/admin/dev/tickets/${ticket.parent.id}`} className="text-indigo-600 hover:text-indigo-800 dark:text-indigo-400 dark:hover:text-indigo-300" > {ticket.parent.ticketNumber} </Link> </dd> </div> )} {ticket.childCount > 0 && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Children</dt> <dd className="text-sm text-gray-900 dark:text-gray-100"> {ticket.completedChildCount}/{ticket.childCount} complete </dd> </div> )} </dl> </div> {/* Details */} <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4"> <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-3">Details</h3> <dl className="space-y-3"> <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Priority</dt> <dd className={`text-sm font-medium ${priorityConfig.color}`}> {priorityConfig.icon} {priorityConfig.label} </dd> </div> {severityConfig && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Severity</dt> <dd className={`text-sm font-medium ${severityConfig.color}`}> {severityConfig.icon} {severityConfig.label} </dd> </div> )} <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Reporter</dt> <dd className="text-sm text-gray-900 dark:text-gray-100"> {ticket.reporter.name || ticket.reporter.email} </dd> </div> <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Assignee</dt> <dd className="text-sm text-gray-900 dark:text-gray-100"> {ticket.assignee ? (ticket.assignee.name || ticket.assignee.email) : 'Unassigned'} </dd> </div> {ticket.project && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Project</dt> <dd className="text-sm"> <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium" style={{ backgroundColor: ticket.project.color + '20', color: ticket.project.color }} > {ticket.project.key} </span> </dd> </div> )} {ticket.sprint && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Sprint</dt> <dd className="text-sm text-gray-900 dark:text-gray-100">{ticket.sprint.name}</dd> </div> )} {ticket.milestone && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Milestone</dt> <dd className="text-sm text-gray-900 dark:text-gray-100">{ticket.milestone.name}</dd> </div> )} {ticket.storyPoints && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Story Points</dt> <dd className="text-sm text-gray-900 dark:text-gray-100">{ticket.storyPoints}</dd> </div> )} {ticket.estimatedHours && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Estimated</dt> <dd className="text-sm text-gray-900 dark:text-gray-100">{ticket.estimatedHours}h</dd> </div> )} {ticket.actualHours && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Actual</dt> <dd className="text-sm text-gray-900 dark:text-gray-100">{ticket.actualHours}h</dd> </div> )} {ticket.dueDate && ( <div className="flex justify-between"> <dt className="text-sm text-gray-500 dark:text-gray-400">Due Date</dt> <dd className="text-sm text-gray-900 dark:text-gray-100"> {new Date(ticket.dueDate).toLocaleDateString()} </dd> </div> )} </dl> </div> {/* Labels */} {ticket.labels.length > 0 && ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4"> <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-3">Labels</h3> <div className="flex flex-wrap gap-2"> {ticket.labels.map((label) => ( <span key={label.id} className="px-2 py-1 rounded text-xs font-medium" style={{ backgroundColor: label.color + '20', color: label.color }} > {label.name} </span> ))} </div> </div> )} {/* Dates */} <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4"> <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-3">Dates</h3> <dl className="space-y-2 text-sm"> <div className="flex justify-between"> <dt className="text-gray-500 dark:text-gray-400">Created</dt> <dd className="text-gray-900 dark:text-gray-100">{new Date(ticket.createdAt).toLocaleDateString()}</dd> </div> <div className="flex justify-between"> <dt className="text-gray-500 dark:text-gray-400">Updated</dt> <dd className="text-gray-900 dark:text-gray-100">{new Date(ticket.updatedAt).toLocaleDateString()}</dd> </div> {ticket.startedAt && ( <div className="flex justify-between"> <dt className="text-gray-500 dark:text-gray-400">Started</dt> <dd className="text-gray-900 dark:text-gray-100">{new Date(ticket.startedAt).toLocaleDateString()}</dd> </div> )} {ticket.completedAt && ( <div className="flex justify-between"> <dt className="text-gray-500 dark:text-gray-400">Completed</dt> <dd className="text-gray-900 dark:text-gray-100">{new Date(ticket.completedAt).toLocaleDateString()}</dd> </div> )} </dl> </div> {/* Git Info */} {(ticket.branch || ticket.pullRequestUrl) && ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4"> <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-3">Development</h3> <dl className="space-y-2 text-sm"> {ticket.branch && ( <div> <dt className="text-gray-500 dark:text-gray-400">Branch</dt> <dd className="text-gray-900 dark:text-gray-100 font-mono text-xs mt-1">{ticket.branch}</dd> </div> )} {ticket.pullRequestUrl && ( <div> <dt className="text-gray-500 dark:text-gray-400">Pull Request</dt> <dd className="mt-1"> <a href={ticket.pullRequestUrl} target="_blank" rel="noopener noreferrer" className="text-indigo-600 hover:text-indigo-800 dark:text-indigo-400 dark:hover:text-indigo-300 text-xs" > View PR </a> </dd> </div> )} </dl> </div> )} </div> </div> </div> ); } |