mirror of
https://github.com/langgenius/dify.git
synced 2026-03-28 23:00:25 -04:00
fix: ps not recorded when not login
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { render } from '@testing-library/react'
|
||||
import PartnerStackCookieRecorder from '../cookie-recorder'
|
||||
|
||||
const saveOrUpdate = vi.fn()
|
||||
|
||||
vi.mock('../use-ps-info', () => ({
|
||||
default: () => ({
|
||||
saveOrUpdate,
|
||||
}),
|
||||
}))
|
||||
|
||||
describe('PartnerStackCookieRecorder', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should call saveOrUpdate once on mount', () => {
|
||||
render(<PartnerStackCookieRecorder />)
|
||||
|
||||
expect(saveOrUpdate).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should render null', () => {
|
||||
const { container } = render(<PartnerStackCookieRecorder />)
|
||||
|
||||
expect(container.innerHTML).toBe('')
|
||||
})
|
||||
})
|
||||
16
web/app/components/billing/partner-stack/cookie-recorder.tsx
Normal file
16
web/app/components/billing/partner-stack/cookie-recorder.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import usePSInfo from './use-ps-info'
|
||||
|
||||
const PartnerStackCookieRecorder = () => {
|
||||
const { saveOrUpdate } = usePSInfo()
|
||||
|
||||
useEffect(() => {
|
||||
saveOrUpdate()
|
||||
}, [saveOrUpdate])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export default PartnerStackCookieRecorder
|
||||
@@ -24,13 +24,14 @@ const usePSInfo = () => {
|
||||
}] = useBoolean(false)
|
||||
const { mutateAsync } = useBindPartnerStackInfo()
|
||||
// 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(() => {
|
||||
if (!psPartnerKey || !psClickId)
|
||||
return
|
||||
if (!isPSChanged)
|
||||
return
|
||||
// console.log('set cookie')
|
||||
Cookies.set(PARTNER_STACK_CONFIG.cookieName, JSON.stringify({
|
||||
partnerKey: psPartnerKey,
|
||||
clickId: psClickId,
|
||||
@@ -39,7 +40,7 @@ const usePSInfo = () => {
|
||||
path: '/',
|
||||
domain,
|
||||
})
|
||||
}, [psPartnerKey, psClickId, isPSChanged])
|
||||
}, [psPartnerKey, psClickId, isPSChanged, domain])
|
||||
|
||||
const bind = useCallback(async () => {
|
||||
if (psPartnerKey && psClickId && !hasBind) {
|
||||
@@ -59,7 +60,7 @@ const usePSInfo = () => {
|
||||
Cookies.remove(PARTNER_STACK_CONFIG.cookieName, { path: '/', domain })
|
||||
setBind()
|
||||
}
|
||||
}, [psPartnerKey, psClickId, mutateAsync, hasBind, setBind])
|
||||
}, [psPartnerKey, psClickId, hasBind, domain, setBind, mutateAsync])
|
||||
return {
|
||||
psPartnerKey,
|
||||
psClickId,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { getLocaleOnServer } from '@/i18n-config/server'
|
||||
import { ToastProvider } from './components/base/toast'
|
||||
import { ToastHost } from './components/base/ui/toast'
|
||||
import { TooltipProvider } from './components/base/ui/tooltip'
|
||||
import PartnerStackCookieRecorder from './components/billing/partner-stack/cookie-recorder'
|
||||
import BrowserInitializer from './components/browser-initializer'
|
||||
import { ReactScanLoader } from './components/devtools/react-scan/loader'
|
||||
import { I18nServerProvider } from './components/provider/i18n-server'
|
||||
@@ -72,6 +73,7 @@ const LocaleLayout = async ({
|
||||
<TanstackQueryInitializer>
|
||||
<I18nServerProvider>
|
||||
<ToastHost timeout={5000} limit={3} />
|
||||
<PartnerStackCookieRecorder />
|
||||
<ToastProvider>
|
||||
<GlobalPublicStoreProvider>
|
||||
<TooltipProvider delay={300} closeDelay={200}>
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
'use client'
|
||||
import { useEffect } from 'react'
|
||||
import { useSearchParams } from '@/next/navigation'
|
||||
import usePSInfo from '../components/billing/partner-stack/use-ps-info'
|
||||
import NormalForm from './normal-form'
|
||||
import OneMoreStep from './one-more-step'
|
||||
|
||||
const SignIn = () => {
|
||||
const searchParams = useSearchParams()
|
||||
const step = searchParams.get('step')
|
||||
const { saveOrUpdate } = usePSInfo()
|
||||
|
||||
useEffect(() => {
|
||||
saveOrUpdate()
|
||||
}, [])
|
||||
|
||||
if (step === 'next')
|
||||
return <OneMoreStep />
|
||||
|
||||
Reference in New Issue
Block a user