mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 20:09:20 +08:00
fix: partner stack not recorded when not login (#34062)
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
import { render } from '@testing-library/react'
|
||||||
|
import PartnerStackCookieRecorder from '../cookie-recorder'
|
||||||
|
|
||||||
|
let isCloudEdition = true
|
||||||
|
|
||||||
|
const saveOrUpdate = vi.fn()
|
||||||
|
|
||||||
|
vi.mock('@/config', () => ({
|
||||||
|
get IS_CLOUD_EDITION() {
|
||||||
|
return isCloudEdition
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('../use-ps-info', () => ({
|
||||||
|
default: () => ({
|
||||||
|
saveOrUpdate,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('PartnerStackCookieRecorder', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
isCloudEdition = true
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should call saveOrUpdate once on mount when running in cloud edition', () => {
|
||||||
|
render(<PartnerStackCookieRecorder />)
|
||||||
|
|
||||||
|
expect(saveOrUpdate).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not call saveOrUpdate when not running in cloud edition', () => {
|
||||||
|
isCloudEdition = false
|
||||||
|
|
||||||
|
render(<PartnerStackCookieRecorder />)
|
||||||
|
|
||||||
|
expect(saveOrUpdate).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render null', () => {
|
||||||
|
const { container } = render(<PartnerStackCookieRecorder />)
|
||||||
|
|
||||||
|
expect(container.innerHTML).toBe('')
|
||||||
|
})
|
||||||
|
})
|
||||||
19
web/app/components/billing/partner-stack/cookie-recorder.tsx
Normal file
19
web/app/components/billing/partner-stack/cookie-recorder.tsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { IS_CLOUD_EDITION } from '@/config'
|
||||||
|
import usePSInfo from './use-ps-info'
|
||||||
|
|
||||||
|
const PartnerStackCookieRecorder = () => {
|
||||||
|
const { saveOrUpdate } = usePSInfo()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!IS_CLOUD_EDITION)
|
||||||
|
return
|
||||||
|
saveOrUpdate()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PartnerStackCookieRecorder
|
||||||
@@ -24,7 +24,7 @@ const usePSInfo = () => {
|
|||||||
}] = useBoolean(false)
|
}] = useBoolean(false)
|
||||||
const { mutateAsync } = useBindPartnerStackInfo()
|
const { mutateAsync } = useBindPartnerStackInfo()
|
||||||
// Save to top domain. cloud.dify.ai => .dify.ai
|
// Save to top domain. cloud.dify.ai => .dify.ai
|
||||||
const domain = globalThis.location.hostname.replace('cloud', '')
|
const domain = globalThis.location?.hostname.replace('cloud', '')
|
||||||
|
|
||||||
const saveOrUpdate = useCallback(() => {
|
const saveOrUpdate = useCallback(() => {
|
||||||
if (!psPartnerKey || !psClickId)
|
if (!psPartnerKey || !psClickId)
|
||||||
@@ -39,7 +39,7 @@ const usePSInfo = () => {
|
|||||||
path: '/',
|
path: '/',
|
||||||
domain,
|
domain,
|
||||||
})
|
})
|
||||||
}, [psPartnerKey, psClickId, isPSChanged])
|
}, [psPartnerKey, psClickId, isPSChanged, domain])
|
||||||
|
|
||||||
const bind = useCallback(async () => {
|
const bind = useCallback(async () => {
|
||||||
if (psPartnerKey && psClickId && !hasBind) {
|
if (psPartnerKey && psClickId && !hasBind) {
|
||||||
@@ -59,7 +59,7 @@ const usePSInfo = () => {
|
|||||||
Cookies.remove(PARTNER_STACK_CONFIG.cookieName, { path: '/', domain })
|
Cookies.remove(PARTNER_STACK_CONFIG.cookieName, { path: '/', domain })
|
||||||
setBind()
|
setBind()
|
||||||
}
|
}
|
||||||
}, [psPartnerKey, psClickId, mutateAsync, hasBind, setBind])
|
}, [psPartnerKey, psClickId, hasBind, domain, setBind, mutateAsync])
|
||||||
return {
|
return {
|
||||||
psPartnerKey,
|
psPartnerKey,
|
||||||
psClickId,
|
psClickId,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { getLocaleOnServer } from '@/i18n-config/server'
|
|||||||
import { ToastProvider } from './components/base/toast'
|
import { ToastProvider } from './components/base/toast'
|
||||||
import { ToastHost } from './components/base/ui/toast'
|
import { ToastHost } from './components/base/ui/toast'
|
||||||
import { TooltipProvider } from './components/base/ui/tooltip'
|
import { TooltipProvider } from './components/base/ui/tooltip'
|
||||||
|
import PartnerStackCookieRecorder from './components/billing/partner-stack/cookie-recorder'
|
||||||
import { AgentationLoader } from './components/devtools/agentation-loader'
|
import { AgentationLoader } from './components/devtools/agentation-loader'
|
||||||
import { ReactScanLoader } from './components/devtools/react-scan/loader'
|
import { ReactScanLoader } from './components/devtools/react-scan/loader'
|
||||||
import { I18nServerProvider } from './components/provider/i18n-server'
|
import { I18nServerProvider } from './components/provider/i18n-server'
|
||||||
@@ -67,6 +68,7 @@ const LocaleLayout = async ({
|
|||||||
<TanstackQueryInitializer>
|
<TanstackQueryInitializer>
|
||||||
<I18nServerProvider>
|
<I18nServerProvider>
|
||||||
<ToastHost timeout={5000} limit={3} />
|
<ToastHost timeout={5000} limit={3} />
|
||||||
|
<PartnerStackCookieRecorder />
|
||||||
<ToastProvider>
|
<ToastProvider>
|
||||||
<GlobalPublicStoreProvider>
|
<GlobalPublicStoreProvider>
|
||||||
<TooltipProvider delay={300} closeDelay={200}>
|
<TooltipProvider delay={300} closeDelay={200}>
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useEffect } from 'react'
|
|
||||||
import { useSearchParams } from '@/next/navigation'
|
import { useSearchParams } from '@/next/navigation'
|
||||||
import usePSInfo from '../components/billing/partner-stack/use-ps-info'
|
|
||||||
import NormalForm from './normal-form'
|
import NormalForm from './normal-form'
|
||||||
import OneMoreStep from './one-more-step'
|
import OneMoreStep from './one-more-step'
|
||||||
|
|
||||||
const SignIn = () => {
|
const SignIn = () => {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const step = searchParams.get('step')
|
const step = searchParams.get('step')
|
||||||
const { saveOrUpdate } = usePSInfo()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
saveOrUpdate()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
if (step === 'next')
|
if (step === 'next')
|
||||||
return <OneMoreStep />
|
return <OneMoreStep />
|
||||||
|
|||||||
Reference in New Issue
Block a user