Skip to main content

Home Menu And Permissions

This page documents how the mobile Home screen decides which menu items are visible, which shortcuts are enabled, and where each action navigates.

Scope

This page is based on:

  • apps/mobile/src/screens/homeScreen/index.tsx
  • apps/mobile/src/navigation/RootNavigator.tsx

Role of the Home screen

The Home screen is not only a landing page. It acts as:

  • the first authenticated navigation hub
  • the first permission gate for downstream workflows
  • the place where branch-specific access is enforced
  • the logout entry point for the mobile app

Inputs used for menu decisions

The screen loads two pieces of stored state:

  • user from getUser()
  • branch from getBranch()

It then derives:

  • deptCode = Number(user?.deptCode ?? -999)
  • isMainBranch = branch?.isMain === true

These two values determine nearly all menu visibility and shortcut behavior, but isMainBranch is now applied only to a subset of menus.

Decision flow

The current Home screen renders four top-level groups:

  • การขาย (Sell)
  • คลังสินค้า (Stock)
  • ข้อมูล (Data)
  • อื่นๆ (Other)

Permission model

The implementation uses hard-coded Set<number> collections for visibility and create-shortcut rules.

Visibility sets

  • MENU_ORDER
  • MENU_ORDER_REVIEW
  • MENU_BOOKING
  • MENU_INVOICE
  • MENU_SHIPPING
  • MENU_STOREFRONT
  • MENU_BORROW
  • MENU_STOCK
  • MENU_PRODUCT
  • MENU_CUSTOMER
  • MENU_TRANSPORT
  • MENU_CUSTOMER_MANAGEMENT
  • MENU_CAN_ACTIVE_CUSTOMER
  • MENU_CREDIT_NOTE
  • MENU_EMPLOYEE
  • MENU_DEPOSIT
  • MENU_EXPENSE

Create-shortcut sets

  • CAN_CREATE_ORDER
  • CAN_CREATE_SHIPPING
  • CAN_CREATE_TRANSPORT
  • CAN_CREATE_DEPOSIT

Current department-specific note

  • deptCode 20 is currently included in MENU_ORDER, MENU_ORDER_REVIEW, MENU_BOOKING, MENU_INVOICE, MENU_STOREFRONT, MENU_BORROW, MENU_PRODUCT, and CAN_CREATE_ORDER.
  • In practice, department 20 can see ใบสั่งขาย, ตรวจสอบใบสั่งขาย, ใบจองราคา, ใบแจ้งหนี้, ใบจัดส่งสินค้าหน้าร้าน, and สินค้า, and can use create shortcuts where CAN_CREATE_ORDER applies.
  • ลูกค้า still includes deptCode 20 in MENU_CUSTOMER, and it is no longer gated by isMainBranch.
  • isMainBranch is still enforced only for ใบจัดส่งสินค้าสายส่ง, ขนส่ง, and บิลน้ำมัน.

Permission matrix

Menu labelVisible whenMust be main branchShortcut rule
ใบสั่งขายMENU_ORDER.has(deptCode)NoCAN_CREATE_ORDER
ตรวจสอบใบสั่งขายMENU_ORDER_REVIEW.has(deptCode)NoNone
ใบจองราคาMENU_BOOKING.has(deptCode)NoCAN_CREATE_ORDER
ใบแจ้งหนี้MENU_INVOICE.has(deptCode)NoNone
ใบจัดส่งสินค้าสายส่งMENU_SHIPPING.has(deptCode)YesCAN_CREATE_SHIPPING
ใบจัดส่งสินค้าหน้าร้านMENU_STOREFRONT.has(deptCode)NoNone
ใบเบิกยืมดูปลาMENU_BORROW.has(deptCode)NoCAN_CREATE_ORDER
รับสินค้าเข้าตรง`branch.isMain === falseMENU_STOCK.has(deptCode)`
โอนสินค้าไปสาขา`branch.isMain === falseMENU_STOCK.has(deptCode)`
รับสินค้าจากสาขา`branch.isMain === falseMENU_STOCK.has(deptCode)`
ย้ายสินค้าระหว่างคลัง`branch.isMain === falseMENU_STOCK.has(deptCode)`
สินค้าMENU_PRODUCT.has(deptCode)NoNone
ลูกค้าMENU_CUSTOMER.has(deptCode)NoNone
ขนส่งMENU_TRANSPORT.has(deptCode)YesCAN_CREATE_TRANSPORT
การจัดการลูกค้าMENU_CUSTOMER_MANAGEMENT.has(deptCode)NoNone
เปิด/ปิด สถานะลูกค้าMENU_CAN_ACTIVE_CUSTOMER.has(deptCode)NoNone
ลดหนี้ / คืนสินค้าMENU_CREDIT_NOTE.has(deptCode)NoNone
ผู้ใช้ทั้งหมดMENU_EMPLOYEE.has(deptCode)NoNone
ยานพาหนะMENU_EMPLOYEE.has(deptCode)NoNone
ฝากเงินMENU_DEPOSIT.has(deptCode)NoCAN_CREATE_DEPOSIT
บิลน้ำมันMENU_EXPENSE.has(deptCode)YesNone

For stock menus, non-main warehouse branches bypass the Home menu deptCode check. The stock list and detail screens do not add their own deptCode gate for existing actions; action availability is controlled by document state and data completeness instead.

Primary card press behavior

Menu labelNavigation target
ใบสั่งขายOrderList with { mode: 'default' }
ตรวจสอบใบสั่งขายOrderList with { mode: 'shipping-review' }
ใบจองราคาBookingPriceList
ใบเบิกยืมดูปลาBorrowList
สินค้าProductList
ใบแจ้งหนี้InvoiceList
ใบจัดส่งสินค้าสายส่งShippingList
ใบจัดส่งสินค้าหน้าร้านStorefrontList
ขนส่งTransportList
รับสินค้าเข้าตรงGoodsReceiptList
โอนสินค้าไปสาขาTransferOutList
รับสินค้าจากสาขาTransferInList
ย้ายสินค้าระหว่างคลังTransferWarehouseList
ฝากเงินDepositList
บิลน้ำมันExpenseBillList
ลดหนี้ / คืนสินค้าCreditNoteList
ลูกค้าCustomerList with { mode: 'default' }
เปิด/ปิด สถานะลูกค้าCustomerList with { mode: 'request' }
การจัดการลูกค้าCustomerManagementList
ผู้ใช้ทั้งหมดEmployeeList
ยานพาหนะVehicleList

Shortcut behavior

Shortcuts exist only for specific menus and only when the matching CAN_CREATE_* set allows it.

Menu labelShortcut target
ใบสั่งขายCustomerList with { mode: 'default', origin: { screen: 'Home' } }
ใบจองราคาCustomerList with { mode: 'booking', origin: { screen: 'Home' } }
ใบเบิกยืมดูปลาCustomerList with { mode: 'borrow', origin: { screen: 'Home' } }
ใบจัดส่งสินค้าสายส่งShippingDetail with { deliveryId: null, mode: 'create' }
ขนส่งTransportDetail with { transportId: null }
ฝากเงินDepositDetail with { depositId: null }

Access behavior to call out

  • Some menus are visible but do not expose a shortcut.
  • Only ใบจัดส่งสินค้าสายส่ง, ขนส่ง, and บิลน้ำมัน are still hidden completely for sub-branches because isMainBranch is required.
  • Shortcut visibility is independent from card visibility, so a user may see a card but still not get the create action.
  • The Home screen filters entire sections, then removes empty sections before rendering.
  • Home reloads the stored user and branch whenever the screen regains focus. This keeps menu visibility aligned with the latest selected warehouse, especially after switching from a sub-warehouse with isMain: false back to a main warehouse with isMain: true.

Logout behavior

Home delegates logout through HeaderHome.

On logout:

  • clearAllStorage() is called
  • onLogout?.() is called
  • the app returns to the unauthenticated navigation state

Maintenance risks

The current permission model is centralized in one screen file and spread across:

  • MENU_SECTIONS
  • visibility Sets
  • create-shortcut Sets
  • onPress navigation mapping
  • onShortcutPress navigation mapping

When adding or changing a Home menu item, update all of the following together:

  1. menu definition
  2. visibility rule
  3. shortcut rule if any
  4. navigation target
  5. this wiki page
  6. the changelog if the behavior changed materially