Repository navigation
Description
Problem
Two related issues prevent dine-in orders from working correctly:
- Two-click "Place Order" flow — After selecting a table, the order is NOT placed. User must click "Place Order" a second time.
- ID type mismatch — Auto-seeded tables have string IDs (
tbl-1), manually created tables have integer IDs (1). This causes the table selection to behave differently.
Additionally, the visual styling differs between auto-seeded and manually created tables in the picker, suggesting a state or type issue.
Steps to Reproduce
Issue 1: Two-click flow (all tables)
- Open POS page (restaurant mode)
- Add items to cart
- Ensure order type is Dine-In and no table is selected
- Click "Place Order"
- Table picker modal opens → select a table
- Modal closes → nothing happens (order not placed)
- Must click "Place Order" again to submit
Issue 2: Manual tables vs auto-seeded tables
- With auto-seeded tables (seed endpoint): Tables show light grey border, blue on hover, yellow on occupied. Selection works correctly.
- With manually created tables (via Tables page): Tables show blue outline. Selection appears broken — user cannot proceed with order.
Note: This was reported after clearing the auto-seeded DB and manually adding tables. The original auto-seeded tables (from commit 6cb5422 by Bankim) worked correctly.
Root Cause
Issue 1: Two-click flow
Location: frontend/src/app/(dashboard)/pos/page.tsx
Line 102-104 — Guard check:
if (isRestaurant && cart.orderType === 'dine_in' && !cart.tableId) {
setShowTablePicker(true);
return; // ← Returns early, order NOT placed
}Line 230-236 — Table selection handler:
const handleSelectAvailableTable = (tableId, customer?) => {
cart.setTableId(tableId); // Sets table ID
setShowTablePicker(false); // Closes modal
// ← Does NOT re-invoke handlePlaceOrder()
};After selecting a table, the function sets cart.tableId and closes the modal but does not auto-continue the order placement.
Issue 2: ID type mismatch (ROOT CAUSE of manual table issue)
Auto-seeded tables (from main/routes/auth.ts:536 — seed endpoint):
const tables = [['tbl-1', 'T1', 4], ['tbl-2', 'T2', 4], ['tbl-3', 'T3', 6]];
for (const [id, number, capacity] of tables) {
db.prepare('INSERT OR IGNORE INTO tables (id, number, capacity) VALUES (?, ?, ?)').run(id, number, capacity);
}→ Explicit string IDs: tbl-1, tbl-2, tbl-3
Manually created tables (from main/routes/tables.ts:72-80):
const result = db.prepare(`
INSERT INTO tables (number, capacity, floor, section, position_x, position_y, kitchen_station_id, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(tableNumber, capacity || 4, floor || null, section || null,
position_x || null, position_y || null, kitchen_station_id || null, now(), now());
const table = db.prepare('SELECT * FROM tables WHERE id = ?').get(result.lastInsertRowid);→ No id column in INSERT → SQLite auto-generates INTEGER ID from lastInsertRowid
Schema (main/db.ts:715):
CREATE TABLE IF NOT EXISTS tables (
id TEXT PRIMARY KEY, -- ← Expects TEXT
...
)Cart store (frontend/src/store/cart.ts:7):
tableId: number | null; -- ← Typed as numberTablePickerModal (frontend/src/components/pos/TablePickerModal.tsx:69):
const isSelected = selectedTableId === table.id; -- ← Strict equalityThe mismatch: Auto-seeded tables have string IDs ("tbl-1"), manually created tables have integer IDs (1). When the cart stores tableId as a number, comparisons with string IDs may silently fail or behave unexpectedly.
Expected Behavior
- After selecting a table, the order should be automatically placed (no second click required).
- Both auto-seeded and manually created tables should work identically in the picker.
Proposed Fix
Fix 1: Auto-continue after table selection
const handleSelectAvailableTable = (tableId, customer?) => {
cart.setTableId(tableId);
if (customer) { ... }
setShowTablePicker(false);
// Auto-continue: trigger order placement
handlePlaceOrder();
};Fix 2: Normalize table IDs in POST /tables
Generate string IDs for manually created tables to match auto-seeded tables:
// main/routes/tables.ts
import { v4 as uuidv4 } from 'uuid';
// or use generateShortId('tables')
const tableId = uuidv4();
db.prepare('INSERT INTO tables (id, number, capacity, ...) VALUES (?, ?, ?, ...)').run(tableId, ...);Fix 3: Normalize in GET /tables response
const tables = rows.map(t => ({ ...t, id: String(t.id), name: t.number }));Fix 4: Normalize cart.tableId type
// frontend/src/store/cart.ts
tableId: string | number | null;Or always convert to string when setting:
setTableId: (id) => set({ tableId: String(id) }),Additional Issues
Status mismatch: cleaning vs maintenance
- Backend (
main/routes/tables.ts:148): Valid statuses areavailable,occupied,reserved,cleaning - Frontend (
frontend/src/lib/types.ts:99): Expectsavailable,occupied,reserved,maintenance - Tables in
cleaningstatus are clickable buthandleClickdoes nothing
No backend validation for dine-in table requirement
The backend POST /api/orders accepts table_id as optional. A dine-in order can be placed without a table via direct API call.
Environment
- Version: 1.7.2
- Commit: 5cd6453
- Platforms: macOS, Windows, Linux (all affected)
Labels
bug, pos, ux, dine-in, data-integrity
Activity
volkkov commentedon Jul 6, 2026
Good catch. This is related to the RFC change in how trailing slashes are normalized. PR incoming.
fix(db): add migration to convert integer table IDs to strings
fix(cart): update tableId type to string | null
fix(held-orders): update tableId type to string
fix(types): update Table.id to string and status to cleaning
feat(TablePickerModal): add Hold Table and Place Order buttons
fix: address final review findings for issue #27
khaira777 commentedon Jul 6, 2026
Fixed in commits 5fc59a4..c50f47a
All changes have been pushed to main.
Changes Made
Backend:
Frontend:
Testing
Closes #27
fix(tables): generate string IDs for new tables to match schema
fix(db): add migration to convert integer table IDs to strings
fix(cart): update tableId type to string | null
fix(held-orders): update tableId type to string
fix(types): update Table.id to string and status to cleaning
feat(TablePickerModal): add Hold Table and Place Order buttons
fix: address final review findings for issue #27
test(tables): add integration test for string ID generation
fix: Dine-in order flow + ID type mismatch + status mismatch (#30)