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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
'use client'
import type { Locale } from '@/i18n'
import { Button, buttonVariants } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
import { Field, FieldError, FieldLabel } from '@langgenius/dify-ui/field'
import { Form } from '@langgenius/dify-ui/form'
import { Input } from '@langgenius/dify-ui/input'
import {
Select,
SelectContent,
SelectItem,
SelectItemIndicator,
SelectItemText,
SelectLabel,
SelectTrigger,
} from '@langgenius/dify-ui/select'
import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query'
import { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useLocale } from '#i18n'
import { LoadingPlaceholder } from '@/app/components/base/loading-placeholder'
import { LICENSE_LINK } from '@/constants/link'
import { userProfileQueryOptions } from '@/features/account-profile/client'
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
import useDocumentTitle from '@/hooks/use-document-title'
import { i18n } from '@/i18n'
import { setLocaleOnClient } from '@/i18n/client'
import { languages } from '@/i18n/language'
import Link from '@/next/link'
import { useRouter, useSearchParams } from '@/next/navigation'
import { consoleClient, consoleQuery } from '@/service/console'
import { isUnauthorizedError } from '@/service/http-error'
import { replaceLoginRedirect } from '@/utils/login-redirect.client'
import { getBrowserTimezone, timezones } from '@/utils/timezone'
import { basePath } from '@/utils/var'
import { isInvitationForAccount } from '../utils/invitation-account'
import { resolvePostLoginRedirect } from '../utils/post-login-redirect'
type LanguageSelectOption = {
value: Locale
name: string
}
type TimezoneSelectOption = {
value: string
name: string
}
const LANGUAGE_OPTIONS: LanguageSelectOption[] = languages
.filter((item) => item.supported)
.map((item) => ({
value: item.value,
name: item.name,
}))
const TIMEZONE_OPTIONS: TimezoneSelectOption[] = timezones.map((item) => ({
value: String(item.value),
name: item.name,
}))
const getInitialLanguage = (locale: Locale): Locale => {
if (LANGUAGE_OPTIONS.some((item) => item.value === locale)) return locale
return i18n.defaultLocale
}
export default function InviteSettingsPage() {
const { t } = useTranslation(['common', 'login'])
const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions())
const router = useRouter()
const queryClient = useQueryClient()
const searchParams = useSearchParams()
const token = decodeURIComponent(searchParams.get('invite_token') as string)
const {
data: userResp,
isPending: isProfilePending,
error: profileError,
} = useQuery({
...userProfileQueryOptions(),
throwOnError: (err) => !isUnauthorizedError(err),
refetchOnWindowFocus: false,
})
const locale = useLocale()
const [name, setName] = useState('')
const [isActivating, setIsActivating] = useState(false)
const [language, setLanguage] = useState(() => getInitialLanguage(locale))
const [timezone, setTimezone] = useState(() => getBrowserTimezone() || 'America/Los_Angeles')
const selectedLanguage = LANGUAGE_OPTIONS.find((item) => item.value === language)
const selectedTimezone = TIMEZONE_OPTIONS.find((item) => item.value === timezone)
const handleLanguageChange = (nextValue: string | null) => {
const nextLanguage = LANGUAGE_OPTIONS.find((item) => item.value === nextValue)
if (nextLanguage) setLanguage(nextLanguage.value)
}
const handleTimezoneChange = (nextValue: string | null) => {
const nextTimezone = TIMEZONE_OPTIONS.find((item) => item.value === nextValue)
if (nextTimezone) setTimezone(nextTimezone.value)
}
const checkParams = {
url: '/activate/check',
params: {
token,
},
}
const { data: checkRes, refetch: recheck } = useQuery(
consoleQuery.activate.check.get.queryOptions({
input: { query: checkParams.params },
enabled: !!token,
retry: false,
}),
)
const isInvitationForCurrentAccount = isInvitationForAccount(
checkRes?.data?.email,
userResp?.profile.email,
)
const shouldReturnToSignIn =
!isProfilePending &&
Boolean(
checkRes?.is_valid &&
(isUnauthorizedError(profileError) || (userResp && !isInvitationForCurrentAccount)),
)
const requiresAccountSetup =
checkRes?.data?.requires_setup ?? checkRes?.data?.account_status === 'pending'
const setupAccountTitle = t(($) => $.setYourAccount, { ns: 'login' })
const workspaceInvitationTitle = checkRes?.data?.workspace_name
? t(($) => $.joinWorkspace, {
ns: 'login',
workspaceName: checkRes.data.workspace_name,
})
: setupAccountTitle
const documentTitle = !checkRes
? setupAccountTitle
: !checkRes.is_valid
? t(($) => $.invalid, { ns: 'login' })
: requiresAccountSetup || !checkRes.data?.workspace_name
? setupAccountTitle
: workspaceInvitationTitle
useDocumentTitle(documentTitle)
useEffect(() => {
if (!shouldReturnToSignIn) return
router.replace(`/signin?${searchParams.toString()}`)
}, [router, searchParams, shouldReturnToSignIn])
const handleActivate = useCallback(async () => {
try {
if (isActivating) return
if (!isInvitationForCurrentAccount) return
setIsActivating(true)
const body = requiresAccountSetup
? {
token,
name,
interface_language: language,
timezone,
}
: {
token,
}
const res = await consoleClient.activate.post({ body })
if (res.result === 'success') {
// Tokens are now stored in cookies by the backend
if (requiresAccountSetup) await setLocaleOnClient(language!)
await queryClient.resetQueries({ queryKey: consoleQuery.account.profile.get.key() })
replaceLoginRedirect(resolvePostLoginRedirect(searchParams), router.replace, basePath)
}
} catch {
recheck()
setIsActivating(false)
}
}, [
isInvitationForCurrentAccount,
isActivating,
language,
name,
queryClient,
recheck,
requiresAccountSetup,
searchParams,
timezone,
token,
router,
])
if (isProfilePending || shouldReturnToSignIn || !checkRes) return <LoadingPlaceholder />
if (!checkRes.is_valid) {
return (
<div className="flex flex-col">
<div className="mx-auto w-full">
<div className="mb-3 flex size-14 items-center justify-center rounded-2xl border border-components-panel-border-subtle text-2xl font-bold shadow-lg">
🤷♂️
</div>
<h1 className="title-4xl-semi-bold text-text-primary">
{t(($) => $.invalid, { ns: 'login' })}
</h1>
</div>
<div className="mx-auto mt-6 w-full">
<a
href="https://dify.ai"
className={cn(buttonVariants({ variant: 'primary' }), 'w-full text-sm!')}
>
{t(($) => $.explore, { ns: 'login' })}
</a>
</div>
</div>
)
}
return (
<div className="flex flex-col gap-3">
<div className="inline-flex size-14 items-center justify-center rounded-2xl border border-components-panel-border-subtle bg-background-default-dodge shadow-lg">
<span
className="i-ri-account-circle-line size-6 text-text-accent-light-mode-only"
aria-hidden="true"
/>
</div>
<div className="pt-2 pb-4">
<h1 className="title-4xl-semi-bold text-text-primary">
{requiresAccountSetup
? t(($) => $.setYourAccount, { ns: 'login' })
: workspaceInvitationTitle}
</h1>
</div>
<Form
onFormSubmit={() => {
void handleActivate()
}}
>
{requiresAccountSetup && (
<>
<Field
name="name"
validate={(value) => {
const nameValue = String(value)
return !nameValue || nameValue.trim()
? null
: t(($) => $.enterYourName, { ns: 'login' })
}}
className="mb-5"
>
<FieldLabel>{t(($) => $.name, { ns: 'login' })}</FieldLabel>
<Input
type="text"
required
value={name}
onValueChange={setName}
placeholder={t(($) => $.namePlaceholder, { ns: 'login' })}
/>
<FieldError>{t(($) => $.enterYourName, { ns: 'login' })}</FieldError>
</Field>
<Field name="interface_language" className="mb-5">
<Select value={selectedLanguage?.value ?? null} onValueChange={handleLanguageChange}>
<SelectLabel>{t(($) => $.interfaceLanguage, { ns: 'login' })}</SelectLabel>
<SelectTrigger size="large">
{selectedLanguage?.name ?? t(($) => $['placeholder.select'], { ns: 'common' })}
</SelectTrigger>
<SelectContent>
{LANGUAGE_OPTIONS.map((item) => (
<SelectItem key={item.value} value={item.value}>
<SelectItemText>{item.name}</SelectItemText>
<SelectItemIndicator />
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field name="timezone" className="mb-5">
<Select value={selectedTimezone?.value ?? null} onValueChange={handleTimezoneChange}>
<SelectLabel>{t(($) => $.timezone, { ns: 'login' })}</SelectLabel>
<SelectTrigger size="large">
{selectedTimezone?.name ?? t(($) => $['placeholder.select'], { ns: 'common' })}
</SelectTrigger>
<SelectContent>
{TIMEZONE_OPTIONS.map((item) => (
<SelectItem key={item.value} value={item.value}>
<SelectItemText>{item.name}</SelectItemText>
<SelectItemIndicator />
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
</>
)}
<Button type="submit" variant="primary" className="w-full" loading={isActivating}>
{workspaceInvitationTitle}
</Button>
</Form>
{!systemFeatures.branding.enabled && (
<div className="mt-2 block w-full system-xs-regular text-text-tertiary">
{t(($) => $['license.tip'], { ns: 'login' })}
<Link
className="system-xs-medium text-text-accent-secondary"
target="_blank"
rel="noopener noreferrer"
href={LICENSE_LINK}
>
{t(($) => $['license.link'], { ns: 'login' })}
</Link>
</div>
)}
</div>
)
}