108 lines
4.7 KiB
JavaScript
108 lines
4.7 KiB
JavaScript
/**
|
|
* What the assistant knows about where the operator is standing.
|
|
*
|
|
* Every page offers every question. The assistant answers about orders, riders,
|
|
* hubs and the rest regardless of which screen is open, so hiding a question
|
|
* because you happen to be on Dispatch made it look narrower than it is. The
|
|
* page decides the ORDER — its own questions lead — not the membership.
|
|
*
|
|
* Every suggestion here must actually resolve against the intent catalog. A
|
|
* chip that comes back "I can't answer that yet" is worse than no chip.
|
|
*/
|
|
|
|
const CATALOG = [
|
|
'How many orders today?',
|
|
'How many orders are cancelled?',
|
|
'Morning batch orders',
|
|
'Revenue this week',
|
|
'How many riders are active?',
|
|
'How many clients do we have?',
|
|
'How many hubs?',
|
|
'How many vehicles?',
|
|
'Any open exceptions?',
|
|
'How many tripsheets are dispatched?',
|
|
'How many customers?',
|
|
'How many pricing rules?',
|
|
'Track consignment DM-CN-1',
|
|
'Assign a rider to an order',
|
|
"Repeat yesterday's run",
|
|
'Compare orders today vs yesterday',
|
|
'Status of hub Chennai',
|
|
'Find vehicle TN01AB1234',
|
|
'How many competitor branches are tracked?',
|
|
'How many carrier pricing entries do we have?',
|
|
];
|
|
|
|
const BY_ROUTE = [
|
|
[
|
|
// Matches both spellings: the board moved to /doormile/control-x, and
|
|
// /doormile/dispatch still resolves through the redirect in App.jsx, so a
|
|
// bookmark that lands there should still get this page's suggestions
|
|
// rather than the default set.
|
|
/^\/doormile\/(control-x|dispatch)/,
|
|
'Control X',
|
|
['Morning batch orders', 'How many riders are active?', "Repeat yesterday's run", 'How many orders today?'],
|
|
],
|
|
[
|
|
/^\/doormile\/orders/,
|
|
'Orders',
|
|
['How many orders today?', 'Assign a rider to an order', 'How many orders are cancelled?', 'Revenue this week'],
|
|
],
|
|
[/^\/doormile\/deliveries/, 'Deliveries', ['How many orders are delivered?', 'Track consignment DM-CN-1', 'Morning batch orders']],
|
|
[/^\/doormile\/riders/, 'Riders', ['How many riders are active?', 'Where is Murali?']],
|
|
[/^\/doormile\/tenants/, 'Clients', ['How many clients do we have?', 'How many pricing rules?']],
|
|
[/^\/doormile\/customers/, 'Customers', ['How many customers?', 'Create a customer']],
|
|
[/^\/doormile\/pricing/, 'Pricing', ['How many pricing rules?', 'Revenue this week']],
|
|
[/^\/doormile\/hubs/, 'Hubs', ['How many hubs?', 'Status of hub Chennai', 'How many vehicles?']],
|
|
[/^\/doormile\/vehicles/, 'Vehicles', ['How many vehicles?', 'Find vehicle TN01AB1234', 'How many hubs?']],
|
|
[/^\/doormile\/tripsheets/, 'Tripsheets', ['How many tripsheets are dispatched?', 'How many consignments?']],
|
|
[/^\/doormile\/exceptions/, 'Exceptions', ['Any open exceptions?', 'How many consignments?']],
|
|
[
|
|
/^\/doormile\/competitive-intel/,
|
|
'Competitive Intel',
|
|
['How many competitor branches are tracked?', 'How many carrier pricing entries do we have?'],
|
|
],
|
|
[/^\/doormile\/reports/, 'Reports', ['Revenue this week', 'Compare orders today vs yesterday', 'How many orders today?']],
|
|
];
|
|
|
|
/** `{ label, suggestions }` for a route — its own questions first, then the rest. */
|
|
export const getPageContext = (pathname) => {
|
|
const hit = BY_ROUTE.find(([pattern]) => pattern.test(pathname || ''));
|
|
const label = hit ? hit[1] : 'Console';
|
|
const leading = hit ? hit[2] : [];
|
|
/* Deduplicated, leading questions first — one flat list means one place a
|
|
question can live. */
|
|
const suggestions = [...new Set([...leading, ...CATALOG])];
|
|
return { label, suggestions };
|
|
};
|
|
|
|
export const CHIP_LABELS = {
|
|
'How many orders today?': 'Orders today',
|
|
'How many orders are cancelled?': 'Cancelled',
|
|
'Morning batch orders': 'Morning batch',
|
|
'Revenue this week': 'Revenue',
|
|
'How many riders are active?': 'Active riders',
|
|
'How many clients do we have?': 'Clients',
|
|
'How many hubs?': 'Hubs',
|
|
'How many vehicles?': 'Vehicles',
|
|
'Any open exceptions?': 'Exceptions',
|
|
'How many tripsheets are dispatched?': 'Tripsheets',
|
|
'How many customers?': 'Customers',
|
|
'How many pricing rules?': 'Pricing rules',
|
|
'How many orders are delivered?': 'Delivered',
|
|
'Where is Murali?': 'Locate Murali',
|
|
'Create a customer': 'New customer',
|
|
'How many consignments?': 'Consignments',
|
|
'Track consignment DM-CN-1': 'Track DM-CN-1',
|
|
'Assign a rider to an order': 'Assign rider',
|
|
'Repeat yesterday\'s run': 'Repeat run',
|
|
'Compare orders today vs yesterday': 'Compare orders',
|
|
'Status of hub Chennai': 'Chennai hub',
|
|
'Find vehicle TN01AB1234': 'Find vehicle',
|
|
'How many competitor branches are tracked?': 'Competitor branches',
|
|
'How many carrier pricing entries do we have?': 'Carrier pricing'
|
|
};
|
|
|
|
export const ORDER_CREATED = '__orderCreated';
|
|
export const ORDER_CREATED_ASSIGNED = '__orderCreatedAssigned';
|