import React, { useMemo } from 'react' import type { FC } from 'react' import Link from 'next/link' import cn from '@/utils/classnames' import { RiAlertFill } from '@remixicon/react' import { Trans } from 'react-i18next' import { useMixedTranslation } from '../marketplace/hooks' import { camelCase } from 'lodash-es' type DeprecationNoticeProps = { status: 'deleted' | 'active' deprecatedReason: string alternativePluginId: string alternativePluginURL: string locale?: string className?: string innerWrapperClassName?: string iconWrapperClassName?: string textClassName?: string } const i18nPrefix = 'plugin.detailPanel.deprecation' const DeprecationNotice: FC = ({ status, deprecatedReason, alternativePluginId, alternativePluginURL, locale, className, innerWrapperClassName, iconWrapperClassName, textClassName, }) => { const { t } = useMixedTranslation(locale) const deprecatedReasonKey = useMemo(() => { if (!deprecatedReason) return '' return camelCase(deprecatedReason) }, [deprecatedReason]) // Check if the deprecatedReasonKey exists in i18n const hasValidDeprecatedReason = useMemo(() => { if (!deprecatedReason || !deprecatedReasonKey) return false // Define valid reason keys that exist in i18n const validReasonKeys = ['businessAdjustments', 'ownershipTransferred', 'noMaintainer'] return validReasonKeys.includes(deprecatedReasonKey) }, [deprecatedReason, deprecatedReasonKey]) if (status !== 'deleted') return null return (
{ hasValidDeprecatedReason && alternativePluginId && ( ), }} values={{ deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`), alternativePluginId, }} /> ) } { hasValidDeprecatedReason && !alternativePluginId && ( {t(`${i18nPrefix}.onlyReason`, { deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`) })} ) } { !hasValidDeprecatedReason && ( {t(`${i18nPrefix}.noReason`)} ) }
) } export default React.memo(DeprecationNotice)