ReadOnlyBadge.tsx 530 B

1234567891011121314151617
  1. import { Badge } from 'ui'
  2. import { useProfile } from '@/lib/profile'
  3. import { useSqlEditorV2StateSnapshot } from '@/state/sql-editor-v2'
  4. export type ReadOnlyBadgeProps = { id: string }
  5. const ReadOnlyBadge = ({ id }: ReadOnlyBadgeProps) => {
  6. const { profile } = useProfile()
  7. const snapV2 = useSqlEditorV2StateSnapshot()
  8. const snippet = snapV2.snippets[id]
  9. const isSnippetOwner = profile?.id === snippet?.snippet.owner_id
  10. return <>{isSnippetOwner ? null : <Badge>Read-only</Badge>}</>
  11. }
  12. export default ReadOnlyBadge