feat: update deprecation notice to use mixed translation and refactor URL handling

pull/22685/head
WTW0313 8 months ago
parent abd576bed9
commit 7ab66bdb48

@ -3,14 +3,16 @@ import type { FC } from 'react'
import Link from 'next/link' import Link from 'next/link'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { RiAlertFill } from '@remixicon/react' import { RiAlertFill } from '@remixicon/react'
import { Trans, useTranslation } from 'react-i18next' import { Trans } from 'react-i18next'
import { snakeCase2CamelCase } from '@/utils/format' import { snakeCase2CamelCase } from '@/utils/format'
import { useMixedTranslation } from '../marketplace/hooks'
type DeprecationNoticeProps = { type DeprecationNoticeProps = {
status: 'deleted' | 'active' status: 'deleted' | 'active'
deprecatedReason: string deprecatedReason: string
alternativePluginId: string alternativePluginId: string
urlPrefix: string alternativePluginURL: string
locale?: string
className?: string className?: string
innerWrapperClassName?: string innerWrapperClassName?: string
iconWrapperClassName?: string iconWrapperClassName?: string
@ -23,13 +25,14 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
status, status,
deprecatedReason, deprecatedReason,
alternativePluginId, alternativePluginId,
urlPrefix, alternativePluginURL,
locale,
className, className,
innerWrapperClassName, innerWrapperClassName,
iconWrapperClassName, iconWrapperClassName,
textClassName, textClassName,
}) => { }) => {
const { t } = useTranslation() const { t } = useMixedTranslation(locale)
const deprecatedReasonKey = useMemo(() => { const deprecatedReasonKey = useMemo(() => {
if (!deprecatedReason) return '' if (!deprecatedReason) return ''
@ -57,7 +60,7 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
components={{ components={{
CustomLink: ( CustomLink: (
<Link <Link
href={`${urlPrefix}/plugins/${alternativePluginId}`} href={alternativePluginURL}
target='_blank' target='_blank'
rel='noopener noreferrer' rel='noopener noreferrer'
className='underline' className='underline'

@ -29,11 +29,11 @@ import Toast from '@/app/components/base/toast'
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin' import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
import { Github } from '@/app/components/base/icons/src/public/common' import { Github } from '@/app/components/base/icons/src/public/common'
import { uninstallPlugin } from '@/service/plugins' import { uninstallPlugin } from '@/service/plugins'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage, useI18N } from '@/context/i18n'
import { useModalContext } from '@/context/modal-context' import { useModalContext } from '@/context/modal-context'
import { useProviderContext } from '@/context/provider-context' import { useProviderContext } from '@/context/provider-context'
import { useInvalidateAllToolProviders } from '@/service/use-tools' import { useInvalidateAllToolProviders } from '@/service/use-tools'
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config' import { API_PREFIX } from '@/config'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { getMarketplaceUrl } from '@/utils/var' import { getMarketplaceUrl } from '@/utils/var'
import { PluginAuth } from '@/app/components/plugins/plugin-auth' import { PluginAuth } from '@/app/components/plugins/plugin-auth'
@ -57,6 +57,7 @@ const DetailHeader = ({
const { t } = useTranslation() const { t } = useTranslation()
const { theme } = useTheme() const { theme } = useTheme()
const locale = useGetLanguage() const locale = useGetLanguage()
const { locale: currentLocale } = useI18N()
const { checkForUpdates, fetchReleases } = useGitHubReleases() const { checkForUpdates, fetchReleases } = useGitHubReleases()
const { setShowUpdatePluginModal } = useModalContext() const { setShowUpdatePluginModal } = useModalContext()
const { refreshModelProviders } = useProviderContext() const { refreshModelProviders } = useProviderContext()
@ -102,7 +103,7 @@ const DetailHeader = ({
if (isFromGitHub) if (isFromGitHub)
return `https://github.com/${meta!.repo}` return `https://github.com/${meta!.repo}`
if (isFromMarketplace) if (isFromMarketplace)
return getMarketplaceUrl(`/plugins/${author}/${name}`, { theme }) return getMarketplaceUrl(`/plugins/${author}/${name}`, { language: currentLocale, theme })
return '' return ''
}, [author, isFromGitHub, isFromMarketplace, meta, name, theme]) }, [author, isFromGitHub, isFromMarketplace, meta, name, theme])
@ -276,13 +277,15 @@ const DetailHeader = ({
</ActionButton> </ActionButton>
</div> </div>
</div> </div>
<DeprecationNotice {isFromMarketplace && (
status={status} <DeprecationNotice
deprecatedReason={deprecated_reason} status={status}
alternativePluginId={alternative_plugin_id} deprecatedReason={deprecated_reason}
urlPrefix={MARKETPLACE_URL_PREFIX} alternativePluginId={alternative_plugin_id}
className='mt-3' alternativePluginURL={getMarketplaceUrl(`/plugins/${alternative_plugin_id}`, { language: currentLocale, theme })}
/> className='mt-3'
/>
)}
<Description className='mb-2 mt-3 h-auto' text={description[locale]} descriptionLineRows={2}></Description> <Description className='mb-2 mt-3 h-auto' text={description[locale]} descriptionLineRows={2}></Description>
{ {
category === PluginType.tool && ( category === PluginType.tool && (

Loading…
Cancel
Save