import { memo, useMemo, } from 'react' import { RiDeleteBinLine, RiEditLine, RiEqualizer2Line, } from '@remixicon/react' import Indicator from '@/app/components/header/indicator' import Badge from '@/app/components/base/badge' import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' import Button from '@/app/components/base/button' import type { Credential } from '../types' import { CredentialTypeEnum } from '../types' type ItemProps = { credential: Credential disabled?: boolean onDelete?: (id: string) => void onEdit?: (id: string, values: Record) => void onSetDefault?: (id: string) => void disableRename?: boolean disableEdit?: boolean disableDelete?: boolean disableSetDefault?: boolean onItemClick?: (id: string) => void } const Item = ({ credential, disabled, onDelete, onEdit, onSetDefault, disableRename, disableEdit, disableDelete, disableSetDefault, onItemClick, }: ItemProps) => { const isOAuth = credential.credential_type === CredentialTypeEnum.OAUTH2 const showAction = useMemo(() => { return !(disableRename && disableEdit && disableDelete && disableSetDefault) }, [disableRename, disableEdit, disableDelete, disableSetDefault]) return (
onItemClick?.(credential.id)} >
{credential.name}
{ credential.is_default && ( Default ) }
{ showAction && (
{ !credential.is_default && !disableSetDefault && ( ) } { isOAuth && !disableRename && ( ) } { !isOAuth && !disableEdit && ( { e.stopPropagation() onEdit?.( credential.id, { ...credential.credentials, __name__: credential.name, __credential_id__: credential.id, }, ) }} > ) } { !disableDelete && ( { e.stopPropagation() onDelete?.(credential.id) }} > ) }
) }
) } export default memo(Item)