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.tsxapps/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:
userfromgetUser()branchfromgetBranch()
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
Menu groups
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_ORDERMENU_ORDER_REVIEWMENU_BOOKINGMENU_INVOICEMENU_SHIPPINGMENU_STOREFRONTMENU_BORROWMENU_STOCKMENU_PRODUCTMENU_CUSTOMERMENU_TRANSPORTMENU_CUSTOMER_MANAGEMENTMENU_CAN_ACTIVE_CUSTOMERMENU_CREDIT_NOTEMENU_EMPLOYEEMENU_DEPOSITMENU_EXPENSE
Create-shortcut sets
CAN_CREATE_ORDERCAN_CREATE_SHIPPINGCAN_CREATE_TRANSPORTCAN_CREATE_DEPOSIT
Current department-specific note
deptCode20is currently included inMENU_ORDER,MENU_ORDER_REVIEW,MENU_BOOKING,MENU_INVOICE,MENU_STOREFRONT,MENU_BORROW,MENU_PRODUCT, andCAN_CREATE_ORDER.- In practice, department
20can seeใบสั่งขาย,ตรวจสอบใบสั่งขาย,ใบจองราคา,ใบแจ้งหนี้,ใบจัดส่งสินค้าหน้าร้าน, andสินค้า, and can use create shortcuts whereCAN_CREATE_ORDERapplies. ลูกค้าstill includesdeptCode20inMENU_CUSTOMER, and it is no longer gated byisMainBranch.isMainBranchis still enforced only forใบจัดส่งสินค้าสายส่ง,ขนส่ง, andบิลน้ำมัน.
Permission matrix
| Menu label | Visible when | Must be main branch | Shortcut rule |
|---|---|---|---|
ใบสั่งขาย | MENU_ORDER.has(deptCode) | No | CAN_CREATE_ORDER |
ตรวจสอบใบสั่งขาย | MENU_ORDER_REVIEW.has(deptCode) | No | None |
ใบจองราคา | MENU_BOOKING.has(deptCode) | No | CAN_CREATE_ORDER |
ใบแจ้งหนี้ | MENU_INVOICE.has(deptCode) | No | None |
ใบจัดส่งสินค้าสายส่ง | MENU_SHIPPING.has(deptCode) | Yes | CAN_CREATE_SHIPPING |
ใบจัดส่งสินค้าหน้าร้าน | MENU_STOREFRONT.has(deptCode) | No | None |
ใบเบิกยืมดูปลา | MENU_BORROW.has(deptCode) | No | CAN_CREATE_ORDER |
รับสินค้าเข้าตรง | `branch.isMain === false | MENU_STOCK.has(deptCode)` | |
โอนสินค้าไปสาขา | `branch.isMain === false | MENU_STOCK.has(deptCode)` | |
รับสินค้าจากสาขา | `branch.isMain === false | MENU_STOCK.has(deptCode)` | |
ย้ายสินค้าระหว่างคลัง | `branch.isMain === false | MENU_STOCK.has(deptCode)` | |
สินค้า | MENU_PRODUCT.has(deptCode) | No | None |
ลูกค้า | MENU_CUSTOMER.has(deptCode) | No | None |
ขนส่ง | MENU_TRANSPORT.has(deptCode) | Yes | CAN_CREATE_TRANSPORT |
การจัดการลูกค้า | MENU_CUSTOMER_MANAGEMENT.has(deptCode) | No | None |
เปิด/ปิด สถานะลูกค้า | MENU_CAN_ACTIVE_CUSTOMER.has(deptCode) | No | None |
ลดหนี้ / คืนสินค้า | MENU_CREDIT_NOTE.has(deptCode) | No | None |
ผู้ใช้ทั้งหมด | MENU_EMPLOYEE.has(deptCode) | No | None |
ยานพาหนะ | MENU_EMPLOYEE.has(deptCode) | No | None |
ฝากเงิน | MENU_DEPOSIT.has(deptCode) | No | CAN_CREATE_DEPOSIT |
บิลน้ำมัน | MENU_EXPENSE.has(deptCode) | Yes | None |
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.
Navigation mapping
Primary card press behavior
| Menu label | Navigation 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 label | Shortcut 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 becauseisMainBranchis 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: falseback to a main warehouse withisMain: true.
Logout behavior
Home delegates logout through HeaderHome.
On logout:
clearAllStorage()is calledonLogout?.()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 onPressnavigation mappingonShortcutPressnavigation mapping
When adding or changing a Home menu item, update all of the following together:
- menu definition
- visibility rule
- shortcut rule if any
- navigation target
- this wiki page
- the changelog if the behavior changed materially