Files
supabase/apps/studio/components/ui/AdvisorPanel/NotificationDetail.tsx
Gildas GarciaandIvan Vasilov 96d43099bb chore: refactor Button API so that it can be used a standard button (#46880)
## Problem

Our `<Button>` component breaks the default `button` contract by
redefining the `type` prop to set its variant (`primary`, `default`,
etc) instead of the button type (`submit`, `button`, etc).
This is confusing and forces to write more code when using it with
shadcn components that expect/inject the standard button props.

## Solution

- rename the `type` prop to `variant`
- rename the `htmlType` prop to `type`
- propagate the changes where necessary
- format code

## How to test

As this is just prop renaming, if it builds it's ok

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2026-06-16 23:59:58 +02:00

119 lines
4.0 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-link"
>
{organization.name}
</Link>
)}
{project !== undefined && (
<Link title={project.name} href={`/project/${project.ref}`} className="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>
)
}