import type { FC } from 'react' import { useTranslation } from '#i18n' import { RiAlertFill } from '@remixicon/react' import { camelCase } from 'es-toolkit/string' import Link from 'next/link' import * as React from 'react' import { useMemo } from 'react' import { Trans } from 'react-i18next' import { cn } from '@/utils/classnames' type DeprecationNoticeProps = { status: 'deleted' | 'active' deprecatedReason: string alternativePluginId: string alternativePluginURL: string className?: string innerWrapperClassName?: string iconWrapperClassName?: string textClassName?: string } const i18nPrefix = 'detailPanel.deprecation' type DeprecatedReasonKey = 'businessAdjustments' | 'ownershipTransferred' | 'noMaintainer' const validReasonKeys: DeprecatedReasonKey[] = ['businessAdjustments', 'ownershipTransferred', 'noMaintainer'] function isValidReasonKey(key: string): key is DeprecatedReasonKey { return (validReasonKeys as string[]).includes(key) } const DeprecationNotice: FC = ({ status, deprecatedReason, alternativePluginId, alternativePluginURL, className, innerWrapperClassName, iconWrapperClassName, textClassName, }) => { const { t } = useTranslation('plugin') const deprecatedReasonKey = useMemo(() => { if (!deprecatedReason) return null const key = camelCase(deprecatedReason) if (isValidReasonKey(key)) return key return null }, [deprecatedReason]) // Check if the deprecatedReasonKey exists in i18n const hasValidDeprecatedReason = deprecatedReasonKey !== null if (status !== 'deleted') return null return (
{ hasValidDeprecatedReason && alternativePluginId && ( ), }} values={{ deprecatedReason: deprecatedReasonKey ? t(`${i18nPrefix}.reason.${deprecatedReasonKey}`, { ns: 'plugin' }) : '', alternativePluginId, }} /> ) } { hasValidDeprecatedReason && !alternativePluginId && ( {t(`${i18nPrefix}.onlyReason`, { ns: 'plugin', deprecatedReason: deprecatedReasonKey ? t(`${i18nPrefix}.reason.${deprecatedReasonKey}`, { ns: 'plugin' }) : '' })} ) } { !hasValidDeprecatedReason && ( {t(`${i18nPrefix}.noReason`, { ns: 'plugin' })} ) }
) } export default React.memo(DeprecationNotice)