refactor(dashboard): reorganize menu actions across sidebar/header/profile

Move shutdown into header popup + profile, move remote into sidebar above
settings, add flag-only language switcher in header, and add language card
plus shutdown/logout actions to the profile page.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-06 16:05:44 +07:00
parent 293cf40455
commit f161b295a5
6 changed files with 235 additions and 107 deletions

View File

@@ -1,13 +1,32 @@
"use client";
import { useState, useEffect, useRef } from "react";
import { useRouter } from "next/navigation";
import { Card, Button, Toggle, Input } from "@/shared/components";
import { ConfirmModal } from "@/shared/components/Modal";
import LanguageSwitcher from "@/shared/components/LanguageSwitcher";
import { useTheme } from "@/shared/hooks/useTheme";
import { cn } from "@/shared/utils/cn";
import { APP_CONFIG } from "@/shared/constants/config";
import { LOCALE_COOKIE, normalizeLocale } from "@/i18n/config";
import { LOCALE_FLAGS } from "@/shared/constants/locales";
function getLocaleFromCookie() {
if (typeof document === "undefined") return "en";
const cookie = document.cookie
.split(";")
.find((c) => c.trim().startsWith(`${LOCALE_COOKIE}=`));
const value = cookie ? decodeURIComponent(cookie.split("=")[1]) : "en";
return normalizeLocale(value);
}
export default function ProfilePage() {
const router = useRouter();
const { theme, setTheme, isDark } = useTheme();
const [locale, setLocale] = useState("en");
const [langOpen, setLangOpen] = useState(false);
const [shutdownOpen, setShutdownOpen] = useState(false);
const [isShuttingDown, setIsShuttingDown] = useState(false);
const [settings, setSettings] = useState({ fallbackStrategy: "fill-first" });
const [loading, setLoading] = useState(true);
const [passwords, setPasswords] = useState({ current: "", new: "", confirm: "" });
@@ -39,6 +58,10 @@ export default function ProfilePage() {
const [proxyLoading, setProxyLoading] = useState(false);
const [proxyTestLoading, setProxyTestLoading] = useState(false);
useEffect(() => {
setLocale(getLocaleFromCookie());
}, [langOpen]);
useEffect(() => {
fetch("/api/settings")
.then((res) => res.json())
@@ -515,6 +538,29 @@ export default function ProfilePage() {
const observabilityEnabled = settings.enableObservability === true;
const handleShutdown = async () => {
setIsShuttingDown(true);
try {
await fetch("/api/version/shutdown", { method: "POST" });
} catch (e) {
// Expected to fail as server shuts down; ignore error
}
setIsShuttingDown(false);
setShutdownOpen(false);
};
const handleLogout = async () => {
try {
const res = await fetch("/api/auth/logout", { method: "POST" });
if (res.ok) {
router.push("/login");
router.refresh();
}
} catch (err) {
console.error("Failed to logout:", err);
}
};
return (
<div className="max-w-2xl mx-auto px-4 sm:px-0">
<div className="flex flex-col gap-6">
@@ -593,6 +639,24 @@ export default function ProfilePage() {
</div>
</Card>
{/* Language */}
<Card>
<div className="flex items-center gap-3 mb-4">
<div className="size-10 rounded-lg bg-blue-500/10 text-blue-500 flex items-center justify-center shrink-0">
<span className="material-symbols-outlined text-[20px]">language</span>
</div>
<h3 className="text-base sm:text-lg font-semibold">Language</h3>
</div>
<button
onClick={() => setLangOpen(true)}
className="flex items-center justify-between w-full p-3 rounded-lg bg-bg border border-border hover:border-primary/50 transition-colors"
data-i18n-skip="true"
>
<span className="text-sm text-text-muted">Display language</span>
<span className="text-2xl">{LOCALE_FLAGS[locale] || "🌐"}</span>
</button>
</Card>
{/* Security */}
<Card>
<div className="flex items-center gap-3 mb-4">
@@ -1024,12 +1088,53 @@ export default function ProfilePage() {
</div>
</Card>
{/* Account actions */}
<div className="flex flex-col sm:flex-row gap-2">
<Button
variant="outline"
fullWidth
icon="power_settings_new"
onClick={() => setShutdownOpen(true)}
className="text-red-500 border-red-200 hover:bg-red-50 hover:border-red-300"
>
Shutdown
</Button>
<Button
variant="outline"
fullWidth
icon="logout"
onClick={handleLogout}
>
Logout
</Button>
</div>
{/* App Info */}
<div className="text-center text-xs sm:text-sm text-text-muted py-4">
<p>{APP_CONFIG.name} v{APP_CONFIG.version}</p>
<p className="mt-1">Local Mode - All data stored on your machine</p>
</div>
</div>
<LanguageSwitcher
hideTrigger
isOpen={langOpen}
onClose={(next) => {
setLangOpen(false);
setLocale(next);
}}
/>
<ConfirmModal
isOpen={shutdownOpen}
onClose={() => setShutdownOpen(false)}
onConfirm={handleShutdown}
title="Close Proxy"
message="Are you sure you want to close the proxy server?"
confirmText="Close"
cancelText="Cancel"
variant="danger"
loading={isShuttingDown}
/>
</div>
);
}