2025-08-08 21:12:28 -07:00
|
|
|
"use client";
|
2025-04-07 23:47:06 -07:00
|
|
|
|
2025-11-11 04:02:04 +02:00
|
|
|
import { useAtom } from "jotai";
|
|
|
|
|
import { Loader2, PanelRight } from "lucide-react";
|
2025-10-10 00:50:29 -07:00
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
import { useTranslations } from "next-intl";
|
2025-10-27 20:30:10 -07:00
|
|
|
import type React from "react";
|
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
2025-11-11 04:02:04 +02:00
|
|
|
import { ChatPanelContainer } from "@/components/chat/ChatPanel/ChatPanelContainer";
|
2025-08-02 22:46:15 -07:00
|
|
|
import { DashboardBreadcrumb } from "@/components/dashboard-breadcrumb";
|
2025-10-27 20:30:10 -07:00
|
|
|
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
2025-07-27 10:05:37 -07:00
|
|
|
import { AppSidebarProvider } from "@/components/sidebar/AppSidebarProvider";
|
2025-07-27 11:46:34 -07:00
|
|
|
import { ThemeTogglerComponent } from "@/components/theme/theme-toggle";
|
2025-10-10 00:50:29 -07:00
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
2025-07-27 11:46:34 -07:00
|
|
|
import { Separator } from "@/components/ui/separator";
|
|
|
|
|
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
|
2025-10-10 00:50:29 -07:00
|
|
|
import { useLLMPreferences } from "@/hooks/use-llm-configs";
|
2025-11-11 04:02:04 +02:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
import { chatUIAtom } from "@/stores/chat/chat-ui.atom";
|
2025-04-07 23:47:06 -07:00
|
|
|
|
2025-08-11 10:49:36 -07:00
|
|
|
export function DashboardClientLayout({
|
2025-07-27 10:05:37 -07:00
|
|
|
children,
|
|
|
|
|
searchSpaceId,
|
|
|
|
|
navSecondary,
|
|
|
|
|
navMain,
|
2025-04-07 23:47:06 -07:00
|
|
|
}: {
|
2025-07-27 10:05:37 -07:00
|
|
|
children: React.ReactNode;
|
|
|
|
|
searchSpaceId: string;
|
|
|
|
|
navSecondary: any[];
|
|
|
|
|
navMain: any[];
|
2025-04-07 23:47:06 -07:00
|
|
|
}) {
|
2025-10-27 20:30:10 -07:00
|
|
|
const t = useTranslations("dashboard");
|
2025-10-10 00:50:29 -07:00
|
|
|
const router = useRouter();
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const searchSpaceIdNum = Number(searchSpaceId);
|
|
|
|
|
|
2025-11-11 04:02:04 +02:00
|
|
|
const [chatUIState, setChatUIState] = useAtom(chatUIAtom);
|
|
|
|
|
|
|
|
|
|
const { isChatPannelOpen } = chatUIState;
|
|
|
|
|
|
2025-10-10 00:50:29 -07:00
|
|
|
const { loading, error, isOnboardingComplete } = useLLMPreferences(searchSpaceIdNum);
|
|
|
|
|
const [hasCheckedOnboarding, setHasCheckedOnboarding] = useState(false);
|
|
|
|
|
|
|
|
|
|
// Skip onboarding check if we're already on the onboarding page
|
|
|
|
|
const isOnboardingPage = pathname?.includes("/onboard");
|
|
|
|
|
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
// Translate navigation items
|
2025-10-27 20:30:10 -07:00
|
|
|
const tNavMenu = useTranslations("nav_menu");
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
const translatedNavMain = useMemo(() => {
|
|
|
|
|
return navMain.map((item) => ({
|
|
|
|
|
...item,
|
2025-10-27 20:30:10 -07:00
|
|
|
title: tNavMenu(item.title.toLowerCase().replace(/ /g, "_")),
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
items: item.items?.map((subItem: any) => ({
|
|
|
|
|
...subItem,
|
2025-10-27 20:30:10 -07:00
|
|
|
title: tNavMenu(subItem.title.toLowerCase().replace(/ /g, "_")),
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
})),
|
|
|
|
|
}));
|
|
|
|
|
}, [navMain, tNavMenu]);
|
|
|
|
|
|
|
|
|
|
const translatedNavSecondary = useMemo(() => {
|
|
|
|
|
return navSecondary.map((item) => ({
|
|
|
|
|
...item,
|
2025-10-27 20:30:10 -07:00
|
|
|
title: item.title === "All Search Spaces" ? tNavMenu("all_search_spaces") : item.title,
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
}));
|
|
|
|
|
}, [navSecondary, tNavMenu]);
|
|
|
|
|
|
2025-08-11 10:49:36 -07:00
|
|
|
const [open, setOpen] = useState<boolean>(() => {
|
|
|
|
|
try {
|
|
|
|
|
const match = document.cookie.match(/(?:^|; )sidebar_state=([^;]+)/);
|
|
|
|
|
if (match) return match[1] === "true";
|
|
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2025-08-08 11:17:43 -07:00
|
|
|
|
2025-10-10 00:50:29 -07:00
|
|
|
useEffect(() => {
|
|
|
|
|
// Skip check if already on onboarding page
|
|
|
|
|
if (isOnboardingPage) {
|
|
|
|
|
setHasCheckedOnboarding(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only check once after preferences have loaded
|
|
|
|
|
if (!loading && !hasCheckedOnboarding) {
|
|
|
|
|
const onboardingComplete = isOnboardingComplete();
|
|
|
|
|
|
|
|
|
|
if (!onboardingComplete) {
|
|
|
|
|
router.push(`/dashboard/${searchSpaceId}/onboard`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setHasCheckedOnboarding(true);
|
|
|
|
|
}
|
|
|
|
|
}, [
|
|
|
|
|
loading,
|
|
|
|
|
isOnboardingComplete,
|
|
|
|
|
isOnboardingPage,
|
|
|
|
|
router,
|
|
|
|
|
searchSpaceId,
|
|
|
|
|
hasCheckedOnboarding,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Show loading screen while checking onboarding status (only on first load)
|
|
|
|
|
if (!hasCheckedOnboarding && loading && !isOnboardingPage) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
|
|
|
|
<Card className="w-[350px] bg-background/60 backdrop-blur-sm">
|
|
|
|
|
<CardHeader className="pb-2">
|
2025-10-27 20:30:10 -07:00
|
|
|
<CardTitle className="text-xl font-medium">{t("loading_config")}</CardTitle>
|
|
|
|
|
<CardDescription>{t("checking_llm_prefs")}</CardDescription>
|
2025-10-10 00:50:29 -07:00
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="flex justify-center py-6">
|
|
|
|
|
<Loader2 className="h-12 w-12 text-primary animate-spin" />
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Show error screen if there's an error loading preferences (but not on onboarding page)
|
|
|
|
|
if (error && !hasCheckedOnboarding && !isOnboardingPage) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
|
|
|
|
<Card className="w-[400px] bg-background/60 backdrop-blur-sm border-destructive/20">
|
|
|
|
|
<CardHeader className="pb-2">
|
|
|
|
|
<CardTitle className="text-xl font-medium text-destructive">
|
2025-10-27 20:30:10 -07:00
|
|
|
{t("config_error")}
|
2025-10-10 00:50:29 -07:00
|
|
|
</CardTitle>
|
2025-10-27 20:30:10 -07:00
|
|
|
<CardDescription>{t("failed_load_llm_config")}</CardDescription>
|
2025-10-10 00:50:29 -07:00
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
<p className="text-sm text-muted-foreground">{error}</p>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-27 10:05:37 -07:00
|
|
|
return (
|
2025-11-11 04:02:04 +02:00
|
|
|
<SidebarProvider
|
|
|
|
|
className="h-full bg-red-600 overflow-hidden"
|
|
|
|
|
open={open}
|
|
|
|
|
onOpenChange={setOpen}
|
|
|
|
|
>
|
2025-07-27 10:05:37 -07:00
|
|
|
{/* Use AppSidebarProvider which fetches user, search space, and recent chats */}
|
|
|
|
|
<AppSidebarProvider
|
|
|
|
|
searchSpaceId={searchSpaceId}
|
feat(i18n): Add next-intl framework with full bilingual support (EN/ZH)
- Implement next-intl framework for scalable i18n
- Add complete Chinese (Simplified) localization
- Support 400+ translated strings across all pages
- Add language switcher with persistent preference
- Zero breaking changes to existing functionality
Framework additions:
- i18n routing and middleware
- LocaleContext for client-side state
- LanguageSwitcher component
- Translation files (en.json, zh.json)
Translated components:
- Homepage: Hero, features, CTA, navbar
- Auth: Login, register
- Dashboard: Main page, layout
- Connectors: Management, add page (all categories)
- Documents: Upload, manage, filters
- Settings: LLM configs, role assignments
- Onboarding: Add provider, assign roles
- Logs: Task logs viewer
Adding a new language now requires only:
1. Create messages/<locale>.json
2. Add locale to i18n/routing.ts
2025-10-26 14:05:46 +08:00
|
|
|
navSecondary={translatedNavSecondary}
|
|
|
|
|
navMain={translatedNavMain}
|
2025-07-27 10:05:37 -07:00
|
|
|
/>
|
2025-11-11 04:02:04 +02:00
|
|
|
<SidebarInset className="h-full ">
|
|
|
|
|
<main className="flex h-full">
|
|
|
|
|
<div className="flex grow flex-col h-full border-r">
|
|
|
|
|
<header className="sticky top-0 z-50 flex h-16 shrink-0 items-center gap-2 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 border-b">
|
|
|
|
|
<div className="flex items-center justify-between w-full gap-2 px-4">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<SidebarTrigger className="-ml-1" />
|
|
|
|
|
<Separator orientation="vertical" className="h-6" />
|
|
|
|
|
<DashboardBreadcrumb />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<LanguageSwitcher />
|
|
|
|
|
<ThemeTogglerComponent />
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
setChatUIState((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
isChatPannelOpen: !isChatPannelOpen,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
className={cn(" shrink-0 rounded-full w-fit hover:bg-muted")}
|
|
|
|
|
>
|
|
|
|
|
<PanelRight className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
<div className="grow flex-1 overflow-auto">{children}</div>
|
2025-07-27 10:05:37 -07:00
|
|
|
</div>
|
2025-11-11 04:02:04 +02:00
|
|
|
<ChatPanelContainer />
|
|
|
|
|
</main>
|
2025-07-27 10:05:37 -07:00
|
|
|
</SidebarInset>
|
|
|
|
|
</SidebarProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|