|
2 | 2 |
|
3 | 3 | import { createElement, useMemo, useState } from 'react' |
4 | 4 | import { useParams } from 'next/navigation' |
5 | | -import { ArrowRight, ChevronDown, Expandable, ExpandableContent } from '@/components/emcn' |
| 5 | +import { |
| 6 | + ArrowRight, |
| 7 | + ChevronDown, |
| 8 | + Expandable, |
| 9 | + ExpandableContent, |
| 10 | + SecretReveal, |
| 11 | +} from '@/components/emcn' |
6 | 12 | import { cn } from '@/lib/core/utils/cn' |
7 | 13 | import { OAUTH_PROVIDERS } from '@/lib/oauth/oauth' |
8 | 14 | import { ContextMentionIcon } from '@/app/workspace/[workspaceId]/home/components/context-mention-icon' |
@@ -47,9 +53,10 @@ export const CREDENTIAL_TAG_TYPES = [ |
47 | 53 | export type CredentialTagType = (typeof CREDENTIAL_TAG_TYPES)[number] |
48 | 54 |
|
49 | 55 | export interface CredentialTagData { |
50 | | - value: string |
| 56 | + value?: string |
51 | 57 | type: CredentialTagType |
52 | 58 | provider?: string |
| 59 | + redacted?: boolean |
53 | 60 | } |
54 | 61 |
|
55 | 62 | export interface MothershipErrorTagData { |
@@ -140,12 +147,15 @@ function isUsageUpgradeTagData(value: unknown): value is UsageUpgradeTagData { |
140 | 147 |
|
141 | 148 | function isCredentialTagData(value: unknown): value is CredentialTagData { |
142 | 149 | if (!isRecord(value)) return false |
143 | | - return ( |
144 | | - typeof value.value === 'string' && |
145 | | - typeof value.type === 'string' && |
146 | | - (CREDENTIAL_TAG_TYPES as readonly string[]).includes(value.type) && |
147 | | - (value.provider === undefined || typeof value.provider === 'string') |
148 | | - ) |
| 150 | + if ( |
| 151 | + typeof value.type !== 'string' || |
| 152 | + !(CREDENTIAL_TAG_TYPES as readonly string[]).includes(value.type) |
| 153 | + ) { |
| 154 | + return false |
| 155 | + } |
| 156 | + if (value.provider !== undefined && typeof value.provider !== 'string') return false |
| 157 | + if (value.redacted === true) return value.value === undefined || typeof value.value === 'string' |
| 158 | + return typeof value.value === 'string' |
149 | 159 | } |
150 | 160 |
|
151 | 161 | function isMothershipErrorTagData(value: unknown): value is MothershipErrorTagData { |
@@ -595,24 +605,30 @@ const LockIcon = (props: { className?: string }) => ( |
595 | 605 | ) |
596 | 606 |
|
597 | 607 | function CredentialDisplay({ data }: { data: CredentialTagData }) { |
598 | | - if (data.type !== 'link' || !data.provider) return null |
| 608 | + if (data.type === 'link') { |
| 609 | + if (!data.provider) return null |
| 610 | + const Icon = getCredentialIcon(data.provider) ?? LockIcon |
| 611 | + return ( |
| 612 | + <a |
| 613 | + href={data.value} |
| 614 | + target='_blank' |
| 615 | + rel='noopener noreferrer' |
| 616 | + className='flex items-center gap-2 rounded-lg border border-[var(--divider)] px-3 py-2.5 transition-colors hover-hover:bg-[var(--surface-5)]' |
| 617 | + > |
| 618 | + {createElement(Icon, { className: 'h-[16px] w-[16px] shrink-0' })} |
| 619 | + <span className='flex-1 font-base text-[var(--text-body)] text-sm'> |
| 620 | + Connect {data.provider} |
| 621 | + </span> |
| 622 | + <ArrowRight className='h-[16px] w-[16px] shrink-0 text-[var(--text-icon)]' /> |
| 623 | + </a> |
| 624 | + ) |
| 625 | + } |
599 | 626 |
|
600 | | - const Icon = getCredentialIcon(data.provider) ?? LockIcon |
| 627 | + if (data.type === 'sim_key') { |
| 628 | + return <SecretReveal value={data.value} redacted={data.redacted || !data.value} /> |
| 629 | + } |
601 | 630 |
|
602 | | - return ( |
603 | | - <a |
604 | | - href={data.value} |
605 | | - target='_blank' |
606 | | - rel='noopener noreferrer' |
607 | | - className='flex items-center gap-2 rounded-lg border border-[var(--divider)] px-3 py-2.5 transition-colors hover-hover:bg-[var(--surface-5)]' |
608 | | - > |
609 | | - {createElement(Icon, { className: 'h-[16px] w-[16px] shrink-0' })} |
610 | | - <span className='flex-1 font-base text-[var(--text-body)] text-sm'> |
611 | | - Connect {data.provider} |
612 | | - </span> |
613 | | - <ArrowRight className='h-[16px] w-[16px] shrink-0 text-[var(--text-icon)]' /> |
614 | | - </a> |
615 | | - ) |
| 631 | + return null |
616 | 632 | } |
617 | 633 |
|
618 | 634 | function MothershipErrorDisplay({ data }: { data: MothershipErrorTagData }) { |
|
0 commit comments