feat: pricing on v2 (platform-v2 step 6.7)
- manager src/pages/pricing: price rules, price groups, deals, discounts on the tokens, English and Greek; the rules as data in pricingLogic.js (tests/pricing.test.mjs) - routers/pricing: set-up needs pricing.manage, broadcasts pricing.changed; incomplete conditions refused (pricing.bad_condition); venue discount settings saved again (the date-as-text bug) with empty = no limit (pricing.bad_limit), old "None" tolerated - nav: Offers & pricing needs pricing.manage - tests: test_pricing_setup.py (a happy-hour rule prices a counter quote), manager.mjs e2e Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// What the pricing rules can point at (plan step 6.7), loaded once and kept current: products,
|
||||
// categories (as a tree), prep zones, tags and price groups; and the colours a rule can have.
|
||||
import { useMemo } from 'react'
|
||||
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import { CATEGORY_COLOURS } from '../products/categoryColours'
|
||||
import { categoryTree, treeLabel } from '../products/productsLogic'
|
||||
import * as api from './pricingApi'
|
||||
|
||||
export const COLOURS = CATEGORY_COLOURS // the venue's colours (data, as the categories')
|
||||
|
||||
export function useCatalog() {
|
||||
const products = useLiveQuery({ queryKey: ['products-all'], queryFn: api.listProducts, events: ['products_changed'], staleTime: 60_000 })
|
||||
const categories = useLiveQuery({ queryKey: ['categories'], queryFn: api.listCategories, events: ['products_changed'], staleTime: 60_000 })
|
||||
const zones = useLiveQuery({ queryKey: ['prep-zones'], queryFn: api.listPrepZones, staleTime: 60_000 })
|
||||
const tags = useLiveQuery({ queryKey: ['product-tags'], queryFn: api.listTags, staleTime: 60_000 })
|
||||
const groups = useLiveQuery({ queryKey: ['pricing', 'groups'], queryFn: api.listGroups, events: api.PRICING_EVENTS })
|
||||
return useMemo(() => ({
|
||||
products: (products.data ?? []).filter(p => p.lifecycle_status !== 'archived' && !p.is_service_item)
|
||||
.sort((a, b) => a.name.localeCompare(b.name)).map(p => ({ id: p.id, name: p.name, price: p.base_price })),
|
||||
categories: categoryTree(categories.data ?? []).map(({ cat, depth }) => ({ id: cat.id, name: treeLabel(cat, depth), plain: cat.name })),
|
||||
zones: (zones.data ?? []).map(z => ({ id: z.id, name: z.name })),
|
||||
tags: tags.data ?? [],
|
||||
groups: groups.data ?? [],
|
||||
}), [products.data, categories.data, zones.data, tags.data, groups.data])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user