Files
Joshen Lim 74ddbc7453 Joshen/fe 3685 show a timestamp for failed restart messages in the (#47274)
## Context

For notifications which affect a specific project, there's currently no
indication of when the notification was created at all, so this PR
addresses that

## Changes involved
- For notifications, show created at timestamp in header description
- Was previously showing project ref if present in notification
metadata, but it's repeated information as the affected project is
mentioned in the context section
- It'll still show the project ref in the list view, change is only in
the detail view (after clicking on a notification)

### Before
<img width="400" alt="image"
src="https://github.com/user-attachments/assets/e8ce247c-afa4-46df-832f-856d34ce82fd"
/>
<img width="400" alt="image"
src="https://github.com/user-attachments/assets/2e0a6c8a-3bb4-4c05-ae13-36b8a92e7ff0"
/>

### After
No change for notifications list view

<img width="400" alt="image"
src="https://github.com/user-attachments/assets/e741b607-c5ef-4cd0-9985-5957f2b52bfc"
/>




<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved how advisor panel details are displayed, ensuring timestamps
and secondary text appear in the right situations.
* Hidden metadata when no relevant information is available, reducing
clutter in the panel.
  
* **Style**
* Updated a link layout in notification details for cleaner, more
consistent formatting.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-24 22:44:12 +08:00

123 lines
4.1 KiB
TypeScript

import { Archive, ArchiveRestoreIcon, ExternalLink } from 'lucide-react'
import Link from 'next/link'
import { Button } from 'ui'
import { Markdown } from '@/components/interfaces/Markdown'
import { Notification, NotificationData } from '@/data/notifications/notifications-v2-query'
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
import { useProjectDetailQuery } from '@/data/projects/project-detail-query'
interface NotificationDetailProps {
notification: Notification
onUpdateStatus: (id: string, status: 'archived' | 'seen') => void
}
export const NotificationDetail = ({ notification, onUpdateStatus }: NotificationDetailProps) => {
const data = notification.data as NotificationData
const { data: project } = useProjectDetailQuery({ ref: data.project_ref })
const { data: organizations } = useOrganizationsQuery()
const organization =
data.org_slug !== undefined
? organizations?.find((org) => org.slug === data.org_slug)
: project !== undefined
? organizations?.find((org) => org.id === project.organization_id)
: undefined
const onButtonAction = (type?: string) => {
// [Joshen] Implement accordingly - BE team will need to give us a heads up on this
console.log('Action', type)
}
return (
<div>
{(project !== undefined || organization !== undefined) && (
<>
<h3 className="text-sm mb-2">Context</h3>
<div className="flex items-center gap-2 flex-wrap mb-6">
{organization !== undefined && (
<Link
title={organization.name}
href={`/org/${organization.slug}/general`}
className="text-sm text-link"
>
{organization.name}
</Link>
)}
{project !== undefined && (
<Link
title={project.name}
href={`/project/${project.ref}`}
className="text-sm text-link"
>
{project.name}
</Link>
)}
</div>
</>
)}
{data.message !== undefined && (
<>
<h3 className="text-sm mb-2">Message</h3>
<Markdown
className="leading-6 text-sm text-foreground-light mb-6"
content={data.message}
/>
</>
)}
<h3 className="text-sm mb-2">Actions</h3>
<div className="flex items-center gap-2">
{(data.actions ?? []).map((action, idx) => {
const key = `${notification.id}-action-${idx}`
if (action.url !== undefined) {
const url = action.url.includes('[ref]')
? action.url.replace('[ref]', project?.ref ?? data.project_ref ?? '_')
: action.url.includes('[slug]')
? action.url.replace('[slug]', organization?.slug ?? data.org_slug ?? '_')
: action.url
return (
<Button key={key} variant="default" icon={<ExternalLink strokeWidth={1.5} />} asChild>
<Link href={url} target="_blank" rel="noreferrer">
{action.label}
</Link>
</Button>
)
} else if (action.action_type !== undefined) {
return (
<Button
key={key}
variant="default"
onClick={() => onButtonAction(action.action_type)}
>
{action.label}
</Button>
)
} else {
return null
}
})}
{notification.status === 'archived' ? (
<Button
variant="default"
icon={<ArchiveRestoreIcon size={14} strokeWidth={1.5} />}
onClick={() => onUpdateStatus(notification.id, 'seen')}
>
Unarchive
</Button>
) : (
<Button
variant="default"
icon={<Archive size={14} strokeWidth={1.5} />}
onClick={() => onUpdateStatus(notification.id, 'archived')}
>
Archive
</Button>
)}
</div>
</div>
)
}