dify/web/app/education/apply/applied-education-content.tsx
yyh 01460f681e
fix(web): render workspace plan badge during SSR (#40581)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-08-12 07:45:39 +00:00

95 lines
3.9 KiB
TypeScript

'use client'
import type { SubscriptionModel } from '@dify/contracts/api/console/features/types.gen'
import type {
GetWorkspacesCurrentSummaryResponse,
TenantListItemResponse,
} from '@dify/contracts/api/console/workspaces/types.gen'
import type { ReactNode } from 'react'
import { Select, SelectTrigger } from '@langgenius/dify-ui/select'
import { useTranslation } from 'react-i18next'
import { WorkplaceSelectorContent } from '@/app/components/header/account-dropdown/workplace-selector'
import { PlanBadge } from '@/app/components/header/plan-badge'
type AppliedEducationContentProps = {
workspaces: TenantListItemResponse[]
currentWorkspace: GetWorkspacesCurrentSummaryResponse
plan: SubscriptionModel['plan']
action: ReactNode
isSwitchingWorkspace: boolean
onSwitchWorkspace: (tenantId: string) => void
}
const AppliedEducationContent = ({
workspaces,
currentWorkspace,
plan,
action,
isSwitchingWorkspace,
onSwitchWorkspace,
}: AppliedEducationContentProps) => {
const { t } = useTranslation()
const currentWorkspaceInList = workspaces.find((workspace) => workspace.current)
const workspacePlan = currentWorkspaceInList?.plan ?? plan
const workspaceName = currentWorkspaceInList?.name || currentWorkspace?.name
const workspaceId = currentWorkspaceInList?.id || currentWorkspace?.id
return (
<div className="flex w-full flex-col gap-4">
<div className="rounded-lg border border-effects-highlight bg-background-default-subtle px-3">
<div className="flex items-center gap-2">
<div className="flex size-5 shrink-0 items-center justify-center rounded-full bg-state-success-solid text-text-primary-on-surface">
<span className="i-ri-check-line size-3.5" aria-hidden="true" />
</div>
<div>
<div className="text-text-secondary">
{t(($) => $['applied.step1.description'], { ns: 'education' })}
</div>
</div>
</div>
</div>
<div className="rounded-lg px-3">
<div className="mb-3.5 flex items-center gap-2">
<div className="flex size-5 shrink-0 items-center justify-center rounded-full bg-components-icon-bg-blue-solid system-xs-semibold text-text-primary-on-surface">
2
</div>
<div>
<div className="system-xl-medium text-text-secondary">
{t(($) => $['applied.step2.description'], { ns: 'education' })}
</div>
</div>
</div>
<div className="ml-7">
<Select
value={workspaceId ?? ''}
onValueChange={(value) => {
if (value) onSwitchWorkspace(value)
}}
>
<SelectTrigger
className="h-12! w-fit max-w-full min-w-70 cursor-pointer justify-between rounded-lg border-[0.5px] border-transparent bg-components-input-bg-normal px-3! py-1.5! hover:bg-state-base-hover"
disabled={isSwitchingWorkspace}
>
<span className="flex min-w-0 items-center gap-3">
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-components-icon-bg-blue-solid text-[14px]">
<span className="bg-linear-to-r from-components-avatar-shape-fill-stop-0 to-components-avatar-shape-fill-stop-100 bg-clip-text font-semibold text-shadow-shadow-1 uppercase opacity-90">
{workspaceName?.[0]?.toLocaleUpperCase()}
</span>
</span>
<span className="min-w-0 truncate system-md-semibold text-text-primary">
{workspaceName}
</span>
<PlanBadge plan={workspacePlan} />
</span>
</SelectTrigger>
<WorkplaceSelectorContent workspaces={workspaces} />
</Select>
<div className="mt-3 pr-5">{action}</div>
</div>
</div>
</div>
)
}
export default AppliedEducationContent