refactor: generalize method for getting doc link respecting locale and fix error link paths (#20801)

This commit is contained in:
Bowen Liang 2025-06-13 16:58:43 +08:00 • committed by GitHub
commit f4df759ba6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 149 additions and 136 deletions

View file

@ -1,7 +1,6 @@
'use client'
import {
useMemo,
useState,
} from 'react'
import { useTranslation } from 'react-i18next'
@ -23,13 +22,11 @@ import {
import { useProviderContext } from '@/context/provider-context'
import { useToastContext } from '@/app/components/base/toast'
import { EDUCATION_VERIFYING_LOCALSTORAGE_ITEM } from '@/app/education-apply/constants'
import { getLocaleOnClient } from '@/i18n'
import { noop } from 'lodash-es'
import DifyLogo from '../components/base/logo/dify-logo'
import { useDocLink } from '@/context/i18n'
const EducationApplyAge = () => {
const { t } = useTranslation()
const locale = getLocaleOnClient()
const [schoolName, setSchoolName] = useState('')
const [role, setRole] = useState('Student')
const [ageChecked, setAgeChecked] = useState(false)
@ -43,14 +40,7 @@ const EducationApplyAge = () => {
const updateEducationStatus = useInvalidateEducationStatus()
const { notify } = useToastContext()
const router = useRouter()
const docLink = useMemo(() => {
if (locale === 'zh-Hans')
return 'https://docs.dify.ai/zh-hans/getting-started/dify-for-education'
if (locale === 'ja-JP')
return 'https://docs.dify.ai/ja-jp/getting-started/dify-for-education'
return 'https://docs.dify.ai/getting-started/dify-for-education'
}, [locale])
const docLink = useDocLink()
const handleModalConfirm = () => {
setShowModal(undefined)
@ -167,7 +157,7 @@ const EducationApplyAge = () => {
<div className='mb-4 mt-5 h-[1px] bg-gradient-to-r from-[rgba(16,24,40,0.08)]'></div>
<a
className='system-xs-regular flex items-center text-text-accent'
href={docLink}
href={docLink('/getting-started/dify-for-education')}
target='_blank'
>
{t('education.learn')}

View file

@ -1,11 +1,11 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import { useTranslation } from 'react-i18next'
import {
RiExternalLinkLine,
} from '@remixicon/react'
import Button from '@/app/components/base/button'
import { getLocaleOnClient } from '@/i18n'
import { useDocLink } from '@/context/i18n'
export type IConfirm = {
className?: string
@ -30,20 +30,13 @@ function Confirm({
email,
}: IConfirm) {
const { t } = useTranslation()
const locale = getLocaleOnClient()
const docLink = useDocLink()
const dialogRef = useRef<HTMLDivElement>(null)
const [isVisible, setIsVisible] = useState(isShow)
const docLink = useMemo(() => {
if (locale === 'zh-Hans')
return 'https://docs.dify.ai/zh-hans/getting-started/dify-for-education'
if (locale === 'ja-JP')
return 'https://docs.dify.ai/ja-jp/getting-started/dify-for-education'
return 'https://docs.dify.ai/getting-started/dify-for-education'
}, [locale])
const eduDocLink = docLink('/getting-started/dify-for-education')
const handleClick = () => {
window.open(docLink, '_blank', 'noopener,noreferrer')
window.open(eduDocLink, '_blank', 'noopener,noreferrer')
}
useEffect(() => {
@ -106,7 +99,7 @@ function Confirm({
<div className='flex items-center gap-1'>
{showLink && (
<>
<a onClick={handleClick} href={docLink} target='_blank' className='system-xs-regular cursor-pointer text-text-accent'>{t('education.learn')}</a>
<a onClick={handleClick} href={eduDocLink} target='_blank' className='system-xs-regular cursor-pointer text-text-accent'>{t('education.learn')}</a>
<RiExternalLinkLine className='h-3 w-3 text-text-accent' />
</>
)}