Skip to content

bug: Dine-in order requires two clicks + ID type mismatch breaks table selection for manually created tables #27

Closed

Description

@khaira777

Problem

Two related issues prevent dine-in orders from working correctly:

  1. Two-click "Place Order" flow — After selecting a table, the order is NOT placed. User must click "Place Order" a second time.
  2. 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)

  1. Open POS page (restaurant mode)
  2. Add items to cart
  3. Ensure order type is Dine-In and no table is selected
  4. Click "Place Order"
  5. Table picker modal opens → select a table
  6. Modal closes → nothing happens (order not placed)
  7. Must click "Place Order" again to submit

Issue 2: Manual tables vs auto-seeded tables

  1. With auto-seeded tables (seed endpoint): Tables show light grey border, blue on hover, yellow on occupied. Selection works correctly.
  2. 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 number

TablePickerModal (frontend/src/components/pos/TablePickerModal.tsx:69):

const isSelected = selectedTableId === table.id;  -- ← Strict equality

The 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

  1. After selecting a table, the order should be automatically placed (no second click required).
  2. 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 are available, occupied, reserved, cleaning
  • Frontend (frontend/src/lib/types.ts:99): Expects available, occupied, reserved, maintenance
  • Tables in cleaning status are clickable but handleClick does 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

  1. added theissue type on Jul 6, 2026
  2. pinned this issue on Jul 6, 2026
  3. volkkov commented on Jul 6, 2026

    @volkkov

    Good catch. This is related to the RFC change in how trailing slashes are normalized. PR incoming.

  4. added 6 commits that reference this issue on Jul 6, 2026
    230679a
    29ee5fb
    925c632
    bf1b771
    393b632
    a97cacf
  5. khaira777 commented on Jul 6, 2026

    @khaira777
    ContributorAuthor

    Fixed in commits 5fc59a4..c50f47a

    All changes have been pushed to main.

    Changes Made

    Backend:

    • : Generate string IDs () for new tables
    • : Add migrations v12-v13 to convert existing integer/NULL IDs to strings and update order references

    Frontend:

    • : Update type to
    • : Update type to
    • : Update to , status to
    • : Add Hold Table and Place Order action buttons
    • : Wire up modal callbacks
    • : Fix status and type mismatches

    Testing

    • TypeScript compiles with zero errors
    • New tables get string IDs
    • Existing tables with NULL/integer IDs are migrated
    • Existing orders reference updated table IDs
    • Table picker shows Hold/Place Order buttons
    • Security audit passed (no critical/high findings)

    Closes #27

  6. added 9 commits that reference this issue on Jul 6, 2026
    be0f602
    7e7c31c
    50f575b
    3dc33d6
    627b3f3
    d89a061
    432f346
    a2c4b8c
    e6404c6
  7. unpinned this issue on Jul 6, 2026
  8. self-assigned this
    on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions