Rebuild admin Topbar to match clinic-pro-tauri header: - Icon order: theme -> settings -> bell (was theme -> bell -> settings) - Settings gear now navigates to the role-based settings page instead of opening the personalization panel - Search placeholder changed to «جستجو», dropped the ⌘K hint - Add ProfileMenu: avatar + user name + context/role subtitle + caret, with a dropdown (profile / payments / settings / personalization / logout). Links are role-aware; personalization keeps the existing settings panel. Frontend-only, no API changes. Adds ProfileMenu.test + Topbar.test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
182 lines
7.6 KiB
TypeScript
182 lines
7.6 KiB
TypeScript
import React from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import {
|
|
BellIcon, SunIcon, MoonIcon, Bars3Icon, Cog6ToothIcon,
|
|
MagnifyingGlassIcon, XMarkIcon, CheckIcon,
|
|
} from '@heroicons/react/24/outline';
|
|
import { useUiStore, HUES, type BrandHue } from '../../stores/uiStore';
|
|
import { useAuthStore } from '../../stores/authStore';
|
|
import Portal from '../ui/Portal';
|
|
import ProfileMenu, { settingsPath } from './ProfileMenu';
|
|
|
|
export default function Topbar({ onMobileMenuOpen }: { onMobileMenuOpen?: () => void }) {
|
|
const navigate = useNavigate();
|
|
const primaryRole = useAuthStore((s) => s.primaryRole);
|
|
const toggleSidebar = useUiStore((s) => s.toggleSidebar);
|
|
const darkMode = useUiStore((s) => s.darkMode);
|
|
const toggleDarkMode = useUiStore((s) => s.toggleDarkMode);
|
|
const density = useUiStore((s) => s.density);
|
|
const setDensity = useUiStore((s) => s.setDensity);
|
|
const brandHue = useUiStore((s) => s.brandHue);
|
|
const setBrandHue = useUiStore((s) => s.setBrandHue);
|
|
const sidebarOpen = useUiStore((s) => s.sidebarOpen);
|
|
const settingsPanelOpen = useUiStore((s) => s.settingsPanelOpen);
|
|
const toggleSettingsPanel = useUiStore((s) => s.toggleSettingsPanel);
|
|
|
|
return (
|
|
<>
|
|
<header className="topbar">
|
|
{/* Sidebar toggle */}
|
|
<button
|
|
className="icon-btn"
|
|
onClick={typeof window !== 'undefined' && window.innerWidth < 1024 ? onMobileMenuOpen : toggleSidebar}
|
|
title={sidebarOpen ? 'جمع کردن منو' : 'باز کردن منو'}
|
|
>
|
|
<Bars3Icon style={{ width: 20, height: 20 }} />
|
|
</button>
|
|
|
|
{/* Search bar — placeholder «جستجو» مطابق clinic-pro-tauri */}
|
|
<div className="topbar-search">
|
|
<MagnifyingGlassIcon style={{ width: 17, height: 17, flexShrink: 0 }} />
|
|
<input placeholder="جستجو" readOnly />
|
|
</div>
|
|
|
|
<div style={{ flex: 1 }} />
|
|
|
|
{/* ترتیب آیکونها مطابق header در clinic-pro-tauri: تم → تنظیمات → اعلان */}
|
|
{/* Dark mode */}
|
|
<button className="icon-btn" onClick={toggleDarkMode} title={darkMode ? 'حالت روشن' : 'حالت تاریک'}>
|
|
{darkMode
|
|
? <SunIcon style={{ width: 18, height: 18, color: 'oklch(0.78 0.18 85)' }} />
|
|
: <MoonIcon style={{ width: 18, height: 18 }} />}
|
|
</button>
|
|
|
|
{/* Settings — به صفحه تنظیمات میرود (مثل tauri) */}
|
|
<button className="icon-btn" onClick={() => navigate(settingsPath(primaryRole))} title="تنظیمات">
|
|
<Cog6ToothIcon style={{ width: 18, height: 18 }} />
|
|
</button>
|
|
|
|
{/* Bell */}
|
|
<button className="icon-btn" title="اعلانها" style={{ position: 'relative' }}>
|
|
<BellIcon style={{ width: 18, height: 18 }} />
|
|
<span className="dot" />
|
|
</button>
|
|
|
|
{/* Profile menu — آواتار + نام + تخصص + منوی کشویی مطابق tauri */}
|
|
<ProfileMenu />
|
|
</header>
|
|
|
|
{/* Settings Panel */}
|
|
{settingsPanelOpen && (
|
|
<Portal>
|
|
<div
|
|
className="overlay"
|
|
style={{ placeItems: 'stretch', justifyContent: 'flex-start' }}
|
|
onClick={toggleSettingsPanel}
|
|
>
|
|
<div
|
|
className="modal settings-panel"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<div className="modal-head">
|
|
<h2>شخصیسازی</h2>
|
|
<button className="mini-btn" onClick={toggleSettingsPanel}>
|
|
<XMarkIcon style={{ width: 18, height: 18 }} />
|
|
</button>
|
|
</div>
|
|
<div className="modal-body" style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
|
|
|
|
{/* Theme */}
|
|
<div className="form-row">
|
|
<label>حالت نمایش</label>
|
|
<div className="seg" style={{ width: '100%' }}>
|
|
<button
|
|
className={!darkMode ? 'on' : ''}
|
|
style={{ flex: 1 }}
|
|
onClick={() => { if (darkMode) toggleDarkMode(); }}
|
|
>
|
|
<SunIcon style={{ width: 14, height: 14, display: 'inline', verticalAlign: 'middle', marginInlineEnd: 5 }} />
|
|
روشن
|
|
</button>
|
|
<button
|
|
className={darkMode ? 'on' : ''}
|
|
style={{ flex: 1 }}
|
|
onClick={() => { if (!darkMode) toggleDarkMode(); }}
|
|
>
|
|
<MoonIcon style={{ width: 14, height: 14, display: 'inline', verticalAlign: 'middle', marginInlineEnd: 5 }} />
|
|
تیره
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Brand color */}
|
|
<div className="form-row">
|
|
<label>رنگ اصلی</label>
|
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
|
{HUES.map((hue) => (
|
|
<button
|
|
key={hue.h}
|
|
onClick={() => setBrandHue(hue as BrandHue)}
|
|
title={hue.name}
|
|
style={{
|
|
width: 40, height: 40, borderRadius: 10,
|
|
background: hue.fixed?.primary ?? `oklch(0.55 ${hue.c} ${hue.h})`,
|
|
border: brandHue.h === hue.h ? '3px solid var(--text)' : '3px solid transparent',
|
|
display: 'grid', placeItems: 'center', color: '#fff', cursor: 'pointer',
|
|
}}
|
|
>
|
|
{brandHue.h === hue.h && <CheckIcon style={{ width: 16, height: 16 }} />}
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Density */}
|
|
<div className="form-row">
|
|
<label>تراکم اطلاعات</label>
|
|
<div className="seg" style={{ width: '100%' }}>
|
|
<button
|
|
className={density === 'comfortable' ? 'on' : ''}
|
|
style={{ flex: 1 }}
|
|
onClick={() => setDensity('comfortable')}
|
|
>جادار</button>
|
|
<button
|
|
className={density === 'compact' ? 'on' : ''}
|
|
style={{ flex: 1 }}
|
|
onClick={() => setDensity('compact')}
|
|
>فشرده</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Sidebar */}
|
|
<div className="form-row">
|
|
<label>سایدبار</label>
|
|
<div className="seg" style={{ width: '100%' }}>
|
|
<button
|
|
className={sidebarOpen ? 'on' : ''}
|
|
style={{ flex: 1 }}
|
|
onClick={() => { if (!sidebarOpen) toggleSidebar(); }}
|
|
>کامل</button>
|
|
<button
|
|
className={!sidebarOpen ? 'on' : ''}
|
|
style={{ flex: 1 }}
|
|
onClick={() => { if (sidebarOpen) toggleSidebar(); }}
|
|
>جمعشده</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div style={{
|
|
padding: 12, background: 'var(--surface-2)', borderRadius: 'var(--r)',
|
|
fontSize: 12, color: 'var(--text-2)', lineHeight: 1.9, marginTop: 8,
|
|
}}>
|
|
تنظیمات شما بهصورت خودکار ذخیره میشود.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Portal>
|
|
)}
|
|
</>
|
|
);
|
|
}
|