diff --git a/src/food-market.web/src/components/AppLayout.tsx b/src/food-market.web/src/components/AppLayout.tsx index 643a947..490c683 100644 --- a/src/food-market.web/src/components/AppLayout.tsx +++ b/src/food-market.web/src/components/AppLayout.tsx @@ -37,10 +37,6 @@ function buildNav(): NavSection[] { { group: 'Контрагенты', items: [ { to: '/catalog/counterparties', icon: Users, label: 'Контрагенты' }, ]}, - { group: 'Склады', items: [ - { to: '/catalog/stores', icon: Warehouse, label: 'Склады' }, - { to: '/catalog/retail-points', icon: StoreIcon, label: 'Точки продаж' }, - ]}, { group: 'Остатки', items: [ { to: '/inventory/stock', icon: Boxes, label: 'Остатки' }, { to: '/inventory/movements', icon: History, label: 'Движения' }, @@ -57,8 +53,10 @@ function buildNav(): NavSection[] { { group: 'Импорт', items: [ { to: '/admin/import/moysklad', icon: Download, label: 'МойСклад' }, ]}, - { group: 'Настройки', items: [ - { to: '/settings/organization', icon: Settings, label: 'Организация' }, + { group: 'Настройки организации', items: [ + { to: '/settings/organization', icon: Settings, label: 'Общие' }, + { to: '/catalog/stores', icon: Warehouse, label: 'Склады' }, + { to: '/catalog/retail-points', icon: StoreIcon, label: 'Кассы' }, ]}, ] } diff --git a/src/food-market.web/src/lib/useOrgInfra.ts b/src/food-market.web/src/lib/useOrgInfra.ts new file mode 100644 index 0000000..51175d6 --- /dev/null +++ b/src/food-market.web/src/lib/useOrgInfra.ts @@ -0,0 +1,34 @@ +import { useStores } from '@/lib/useLookups' +import { useQuery } from '@tanstack/react-query' +import { api } from '@/lib/api' +import type { PagedResult, RetailPoint } from '@/lib/types' + +/** Инфраструктура организации (склады, кассы) для умного скрытия селекторов + * в формах документов: если у организации только 1 склад/касса — выбор не + * показывается, форма автоматически подставляет единственное значение. + * Появится 2-й — пикер вернётся. */ +export function useOrgInfra() { + const stores = useStores() + const cashRegisters = useQuery({ + queryKey: ['lookup:retail-points'], + queryFn: async () => + (await api.get>('/api/catalog/retail-points?pageSize=500')).data.items, + staleTime: 0, + refetchOnMount: 'always', + refetchOnWindowFocus: true, + }) + + const storesList = stores.data ?? [] + const cashList = cashRegisters.data ?? [] + const mainStore = storesList.find((s) => s.isMain) ?? storesList[0] + + return { + stores: storesList, + cashRegisters: cashList, + isLoading: stores.isLoading || cashRegisters.isLoading, + showStorePicker: storesList.length > 1, + showCashPicker: cashList.length > 1, + defaultStoreId: mainStore?.id ?? null, + defaultCashId: cashList[0]?.id ?? null, + } +} diff --git a/src/food-market.web/src/pages/RetailPointsPage.tsx b/src/food-market.web/src/pages/RetailPointsPage.tsx index 4f4a45e..38ed5b3 100644 --- a/src/food-market.web/src/pages/RetailPointsPage.tsx +++ b/src/food-market.web/src/pages/RetailPointsPage.tsx @@ -55,8 +55,8 @@ export function RetailPointsPage() { return ( <> @@ -96,12 +96,12 @@ export function RetailPointsPage() { setForm(null)} - title={form?.id ? 'Редактировать точку продаж' : 'Новая точка продаж'} + title={form?.id ? 'Редактировать кассу' : 'Новая касса'} footer={ <> {form?.id && (