diff --git a/src/pages/workorders/view/WorkOrderViewPage.js b/src/pages/workorders/view/WorkOrderViewPage.js index 4d83973e..46672da8 100644 --- a/src/pages/workorders/view/WorkOrderViewPage.js +++ b/src/pages/workorders/view/WorkOrderViewPage.js @@ -16,19 +16,22 @@ function formatDateTime(value) { function CommentTimeline({ comments }) { const bottomRef = useRef(null); + const sorted = [...(comments || [])].sort((a, b) => + new Date(a.createdDate) - new Date(b.createdDate) + ); useEffect(() => { bottomRef.current?.scrollIntoView(); - }, [comments?.length]); + }, [sorted.length]); - if (!comments || comments.length === 0) { + if (!sorted.length) { return

No comments yet.

; } return (
- {comments.map((c) => ( + {sorted.map((c) => (
{c.userName || c.commenter || "System"} @@ -46,14 +49,23 @@ function CommentTimeline({ comments }) { } function AuditTimeline({ entries }) { - if (!entries || entries.length === 0) { + const bottomRef = useRef(null); + const sorted = [...(entries || [])].sort((a, b) => + new Date(a.createdAt) - new Date(b.createdAt) + ); + + useEffect(() => { + bottomRef.current?.scrollIntoView(); + }, [sorted.length]); + + if (!sorted.length) { return

No changes recorded.

; } return (
- {entries.map((e) => ( + {sorted.map((e) => (
{e.userName || "System"} @@ -69,6 +81,7 @@ function AuditTimeline({ entries }) {
))} +
);