import { memo, useMemo, } from 'react' import { useTranslation } from 'react-i18next' import { RiCheckLine, RiDeleteBinLine, RiEqualizer2Line, } from '@remixicon/react' import Indicator from '@/app/components/header/indicator' import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' import type { Credential } from '../../declarations' import Badge from '@/app/components/base/badge' type CredentialItemProps = { credential: Credential disabled?: boolean onDelete?: (credential: Credential) => void onEdit?: (credential?: Credential) => void onItemClick?: (credential: Credential) => void disableRename?: boolean disableEdit?: boolean disableDelete?: boolean showSelectedIcon?: boolean selectedCredentialId?: string } const CredentialItem = ({ credential, disabled, onDelete, onEdit, onItemClick, disableRename, disableEdit, disableDelete, showSelectedIcon, selectedCredentialId, }: CredentialItemProps) => { const { t } = useTranslation() const showAction = useMemo(() => { return !(disableRename && disableEdit && disableDelete) }, [disableRename, disableEdit, disableDelete]) const Item = (
{ if (disabled || credential.not_allowed_to_use) return onItemClick?.(credential) }} >
{ showSelectedIcon && (
{ selectedCredentialId === credential.credential_id && ( ) }
) }
{credential.credential_name}
{ credential.from_enterprise && ( Enterprise ) } { showAction && (
{ !disableEdit && !credential.not_allowed_to_use && !credential.from_enterprise && ( { e.stopPropagation() onEdit?.(credential) }} > ) } { !disableDelete && !credential.from_enterprise && ( { e.stopPropagation() onDelete?.(credential) }} > ) }
) }
) if (credential.not_allowed_to_use) { return ( {Item} ) } return Item } export default memo(CredentialItem)