import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { LOCALE_LABELS, LOCALES, type Locale } from '@barev/i18n';
import { Button, Center, Chip, Icon, Logo, Spinner, type IconName } from '@barev/ui';
import { I18nProvider, pickLocale, useI18n, useLocation, useTRPC } from '@barev/web';
import { useState, type ReactNode } from 'react';
import { Login } from './pages/Login.tsx';
import { Kanban } from './pages/Kanban.tsx';
import { Providers } from './pages/Providers.tsx';
import { Presets } from './pages/Presets.tsx';
import { Companies } from './pages/Companies.tsx';
import { Services } from './pages/Services.tsx';
import { Agencies } from './pages/Agencies.tsx';
import { Clients } from './pages/Clients.tsx';
import { Settings } from './pages/Settings.tsx';
import { WebRequests } from './pages/WebRequests.tsx';
import { Leads } from './pages/Leads.tsx';
import { Requests } from './pages/Requests.tsx';
import { Concierge } from './pages/Concierge.tsx';
import { Partners } from './pages/Partners.tsx';
import { Templates } from './pages/Templates.tsx';
import { Telegram } from './pages/Telegram.tsx';
const LOCALE_KEY = 'barev.admin.locale';
function savedLocale(): Locale {
try {
return pickLocale(localStorage.getItem(LOCALE_KEY), navigator.language);
} catch {
return 'ru';
}
}
export function App() {
const [locale] = useState(savedLocale);
return (
);
}
function Gate() {
const trpc = useTRPC();
const me = useQuery({ ...trpc.admin.auth.me.queryOptions(), retry: false });
if (me.isPending)
return (
);
if (!me.data || !me.data.verified) return ;
return ;
}
const NAV: { path: string; key: string; icon: IconName; owner?: boolean }[] = [
{ path: '/', key: 'admin.nav.orders', icon: 'grid' },
{ path: '/leads', key: 'admin.nav.leads', icon: 'globe' },
{ path: '/templates', key: 'admin.nav.templates', icon: 'docs' },
{ path: '/concierge', key: 'admin.nav.concierge', icon: 'chat' },
{ path: '/app-requests', key: 'admin.nav.requests', icon: 'star' },
{ path: '/requests', key: 'admin.nav.webRequests', icon: 'chat' },
{ path: '/clients', key: 'admin.nav.clients', icon: 'user' },
{ path: '/providers', key: 'admin.nav.providers', icon: 'star' },
{ path: '/presets', key: 'admin.nav.presets', icon: 'repeat' },
{ path: '/companies', key: 'admin.nav.companies', icon: 'home' },
{ path: '/services', key: 'admin.nav.services', icon: 'docs' },
{ path: '/agencies', key: 'admin.nav.agencies', icon: 'gift' },
{ path: '/partners', key: 'admin.nav.partners', icon: 'gift' },
{ path: '/telegram', key: 'admin.nav.telegram', icon: 'chat' },
{ path: '/settings', key: 'admin.nav.settings', icon: 'clock', owner: true },
];
function Shell({ role, name }: { role: 'OWNER' | 'OPERATOR'; name: string }) {
const { t, locale, setLocale } = useI18n();
const trpc = useTRPC();
const qc = useQueryClient();
const { path } = useLocation();
const logout = useMutation(trpc.admin.auth.logout.mutationOptions({ onSuccess: () => qc.invalidateQueries() }));
const isOwner = role === 'OWNER';
// новые заявки с сайта — счётчик в меню, обновляется сам
const openRequests = useQuery({ ...trpc.admin.webRequests.openCount.queryOptions(), refetchInterval: 30_000 });
const openLeads = useQuery({ ...trpc.admin.leads.openCount.queryOptions(), refetchInterval: 30_000 });
const openAppRequests = useQuery({ ...trpc.admin.requests.openCount.queryOptions(), refetchInterval: 30_000 });
const unreadChats = useQuery({ ...trpc.admin.concierge.unreadCount.queryOptions(), refetchInterval: 15_000 });
const counts: Record = { '/requests': openRequests.data, '/leads': openLeads.data, '/app-requests': openAppRequests.data, '/concierge': unreadChats.data };
let page: ReactNode;
if (path === '/leads') page = ;
else if (path === '/concierge') page = ;
else if (path === '/app-requests') page = ;
else if (path === '/partners') page = ;
else if (path === '/templates') page = ;
else if (path === '/telegram') page = ;
else if (path === '/requests') page = ;
else if (path === '/clients') page = ;
else if (path === '/providers') page = ;
else if (path === '/presets') page = ;
else if (path === '/companies') page = ;
else if (path === '/services') page = ;
else if (path === '/agencies') page = ;
else if (path === '/settings' && isOwner) page = ;
else page = ;
return (
{page}
);
}