Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.7 KB
Raw Blame
'use client'

import type { PropsWithChildren } from 'react'
import { Button } from '@langgenius/dify-ui/button'
import { useAtomValueRawSync } from 'jotai/react'
import dynamic from 'next/dynamic'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { LoadingPlaceholder } from '@/app/components/base/loading-placeholder'
import {
  appAccessStore,
  beginTrialAppAccess,
  endTrialAppAccess,
  trialAppAccessErrorAtom,
  trialAppAccessScopeAtom,
} from './state'

const AppNotAccessible = dynamic(() => import('./page'), {
  loading: () => <LoadingPlaceholder className="h-full" />,
})

export default function TrialAppAccessBoundary({
  appId,
  onClose,
  children,
}: PropsWithChildren<{ appId: string; onClose: () => void }>) {
  const { t } = useTranslation(['common'])
  const scope = useAtomValueRawSync(trialAppAccessScopeAtom, { store: appAccessStore })
  const error = useAtomValueRawSync(trialAppAccessErrorAtom, { store: appAccessStore })
  useEffect(() => {
    const visit = beginTrialAppAccess(appId)
    return () => endTrialAppAccess(visit)
  }, [appId])

  if (!scope || scope.key !== `trial:${appId}`) return <LoadingPlaceholder className="h-full" />
  if (error?.scope !== scope) return children
  return (
    <div className="relative h-full overflow-y-auto">
      <Button
        variant="tertiary"
        aria-label={t(($) => $['operation.close'])}
        className="absolute top-3 right-3 z-10"
        onClick={onClose}
      >
        <span aria-hidden className="i-ri-close-line size-5" />
      </Button>
      <div className="min-h-full pt-10">
        <AppNotAccessible embedded clientIp={error.clientIp} />
      </div>
    </div>
  )
}