diff --git a/web/app/(commonLayout)/layout.tsx b/web/app/(commonLayout)/layout.tsx index d4b9bc599e7..02302752df8 100644 --- a/web/app/(commonLayout)/layout.tsx +++ b/web/app/(commonLayout)/layout.tsx @@ -1,8 +1,9 @@ -import type { ReactNode } from 'react' +import * as React from 'react' import AmplitudeProvider from '@/app/components/base/amplitude' import { GoogleAnalyticsScripts } from '@/app/components/base/ga' import Zendesk from '@/app/components/base/zendesk' import { EducationVerifyActionRecorder } from '@/app/components/education-verify-action-recorder' +import MaintenanceNotice from '@/app/components/header/maintenance-notice' import MainNavLayout from '@/app/components/main-nav/layout' import { NextRouteStateBridge } from '@/app/components/next-route-state' import { OAuthRegistrationAnalytics } from '@/app/components/oauth-registration-analytics' @@ -17,32 +18,35 @@ export default async function Layout({ children, detailSidebar, }: { - children: ReactNode - detailSidebar: ReactNode + children: React.ReactNode + detailSidebar: React.ReactNode }) { return ( - <> + - - - - - - {children} - - - - - - +
+ + + + + + + {children} + + + + + + +
- +
) } diff --git a/web/app/account/(commonLayout)/layout.tsx b/web/app/account/(commonLayout)/layout.tsx index a97588d2030..9420503c08b 100644 --- a/web/app/account/(commonLayout)/layout.tsx +++ b/web/app/account/(commonLayout)/layout.tsx @@ -1,10 +1,10 @@ -import type { ReactNode } from 'react' import * as React from 'react' import { CommonLayoutHydrationBoundary } from '@/app/(commonLayout)/hydration-boundary' import AmplitudeProvider from '@/app/components/base/amplitude' import { GoogleAnalyticsScripts } from '@/app/components/base/ga' import { EducationVerifyActionRecorder } from '@/app/components/education-verify-action-recorder' import HeaderWrapper from '@/app/components/header/header-wrapper' +import MaintenanceNotice from '@/app/components/header/maintenance-notice' import { OAuthRegistrationAnalytics } from '@/app/components/oauth-registration-analytics' import { AppContextProvider } from '@/context/app-context-provider' import { EventEmitterContextProvider } from '@/context/event-emitter-provider' @@ -12,30 +12,32 @@ import { ModalContextProvider } from '@/context/modal-context-provider' import { ProviderContextProvider } from '@/context/provider-context-provider' import Header from './header' -const Layout = async ({ children }: { children: ReactNode }) => { +export default async function Layout({ children }: { children: React.ReactNode }) { return ( - <> + - - - - - -
- -
- {children} -
- - - - +
+ + + + + + +
+ +
+ {children} +
+ + + + +
- + ) } -export default Layout diff --git a/web/app/components/header/__tests__/maintenance-notice.spec.tsx b/web/app/components/header/__tests__/maintenance-notice.spec.tsx index bab8c014fc8..203dd55fa91 100644 --- a/web/app/components/header/__tests__/maintenance-notice.spec.tsx +++ b/web/app/components/header/__tests__/maintenance-notice.spec.tsx @@ -4,10 +4,18 @@ import { useLanguage } from '@/app/components/header/account-setting/model-provi import { NOTICE_I18N } from '@/i18n-config/language' import MaintenanceNotice from '../maintenance-notice' +const mockEnv = vi.hoisted(() => ({ + NEXT_PUBLIC_MAINTENANCE_NOTICE: 'true', +})) + vi.mock('@/app/components/base/icons/src/vender/line/general', () => ({ X: (props: React.SVGProps) => , })) +vi.mock('@/env', () => ({ + env: mockEnv, +})) + vi.mock( '@/app/components/header/account-setting/model-provider-page/hooks', () => ({ @@ -44,6 +52,7 @@ describe('MaintenanceNotice', () => { beforeEach(() => { vi.clearAllMocks() localStorage.clear() + mockEnv.NEXT_PUBLIC_MAINTENANCE_NOTICE = 'true' vi.mocked(useLanguage).mockReturnValue('en_US') setNoticeHref('#') }) @@ -71,6 +80,14 @@ describe('MaintenanceNotice', () => { const { container } = render() expect(container.firstChild).toBeNull() }) + + it('should not render when the notice env flag is disabled', () => { + mockEnv.NEXT_PUBLIC_MAINTENANCE_NOTICE = '' + + const { container } = render() + + expect(container.firstChild).toBeNull() + }) }) describe('User Interactions', () => { diff --git a/web/app/components/header/maintenance-notice.tsx b/web/app/components/header/maintenance-notice.tsx index 918c3ce78f4..fcfbb39e100 100644 --- a/web/app/components/header/maintenance-notice.tsx +++ b/web/app/components/header/maintenance-notice.tsx @@ -1,11 +1,21 @@ +'use client' + import { useState } from 'react' import { useTranslation } from 'react-i18next' import { X } from '@/app/components/base/icons/src/vender/line/general' import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks' +import { env } from '@/env' import { NOTICE_I18N } from '@/i18n-config/language' import { useHideMaintenanceNotice } from './storage' -const MaintenanceNotice = () => { +function MaintenanceNotice() { + if (!env.NEXT_PUBLIC_MAINTENANCE_NOTICE) + return null + + return +} + +function MaintenanceNoticeContent() { const { t } = useTranslation() const locale = useLanguage() diff --git a/web/context/app-context-provider.tsx b/web/context/app-context-provider.tsx index 2091f0818c2..509d36e3e59 100644 --- a/web/context/app-context-provider.tsx +++ b/web/context/app-context-provider.tsx @@ -2,14 +2,13 @@ import type { GetAccountProfileResponse } from '@dify/contracts/api/console/account/types.gen' import type { PostWorkspacesCurrentResponse } from '@dify/contracts/api/console/workspaces/types.gen' -import type { FC, ReactNode } from 'react' +import type { ReactNode } from 'react' import type { ICurrentWorkspace, LangGeniusVersionResponse } from '@/models/common' import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query' import { useCallback, useEffect, useMemo } from 'react' import { setUserId, setUserProperties } from '@/app/components/base/amplitude' import { flushRegistrationSuccess } from '@/app/components/base/amplitude/registration-tracking' import { setZendeskConversationFields } from '@/app/components/base/zendesk/utils' -import MaintenanceNotice from '@/app/components/header/maintenance-notice' import { ZENDESK_FIELD_IDS } from '@/config' import { AppContext, @@ -18,7 +17,6 @@ import { userProfilePlaceholder, useSelector, } from '@/context/app-context' -import { env } from '@/env' import { userProfileQueryOptions } from '@/features/account-profile/client' import { systemFeaturesQueryOptions } from '@/features/system-features/client' import { useWorkspacePermissionKeys } from '@/service/access-control/use-permission-keys' @@ -66,7 +64,7 @@ const normalizeCurrentWorkspace = (workspace?: PostWorkspacesCurrentResponse): I } } -export const AppContextProvider: FC = ({ children }) => { +export function AppContextProvider({ children }: AppContextProviderProps) { const queryClient = useQueryClient() const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions()) const { data: userProfileResp } = useSuspenseQuery(userProfileQueryOptions()) @@ -192,12 +190,7 @@ export const AppContextProvider: FC = ({ children }) => workspacePermissionKeys: workspacePermissionKeysQuery.data?.workspace.permission_keys ?? emptyWorkspacePermissionKeys, }} > -
- {env.NEXT_PUBLIC_MAINTENANCE_NOTICE && } -
- {children} -
-
+ {children} ) }