Skip to main content

Users, Roles, and Organizations

Introduction

This document describes organization onboarding, user management, role and permission management, and organization profile behavior.


Main Files

FileResponsibility
pages/LoginPage.tsxLogin entry point
modules/onboarding/pages/OrganizationRegistrationPage.tsxPublic organization registration
modules/onboarding/pages/AdminUserRegistrationPage.tsxUser creation during onboarding
modules/users/pages/UserListPage.tsxOrganization user list route, permissions, and dialog orchestration
modules/users/partials/UserListTable.tsxUser table and row actions
modules/users/dialogs/CreateUserDialog.tsxCreate user dialog
modules/users/dialogs/EditUserDialog.tsxEdit user dialog
modules/roles/pages/RoleListPage.tsxRole list route, permissions, and dialog orchestration
modules/roles/partials/RoleListTable.tsxRole table and row actions
modules/roles/dialogs/CreateRoleDialog.tsxCreate role dialog with permissions
modules/roles/dialogs/EditRoleDialog.tsxEdit role dialog with permissions
modules/organizations/pages/OrganizationDetailPage.tsxCurrent organization detail page
modules/organizations/dialogs/EditOrganizationDialog.tsxOrganization edit dialog
modules/organizations/pages/ProfilePage.tsxCurrent user profile
modules/organizations/dialogs/EditProfileDialog.tsxCurrent user profile edit dialog
hooks/useApi.tsUser, role, organization, permission hooks
lib/api.tsuser, role, permission, organization, and location endpoint groups

Organization Onboarding

  • /register
  • /user-form
  1. Load Provinces: OrganizationForm loads provinces with api.location.getProvinces().
  2. Load Cities: When a province is selected, it loads cities with api.location.getCitiesByProvince(provinceId).
  3. Submit: The organization form submits to api.organization.create(...).
  4. Backend Response: The backend response is expected to include organization and adminRole.
  5. Navigation: The app navigates to /user-form and passes organization/admin role data in route state.
  6. User Creation: UserForm creates the initial user for that organization.

Organization create payload maps UI field names to backend field names:

UI FieldSubmitted Field
phone_numberphoneNumber
provinceprovince
citycity
oinkcodeoinkcode
parentIdnull

User Management

  • Route: /dashboard/user
  • Component: AllUser
  1. Context Initialization: Reads current organization/user IDs from auth cookies.
  2. Data Loading: Loads users with useOrganizationUsers([deletionFlag, createFlag, editFlag]).
  3. Permission Check: Loads permissions through useUserPermissions().
  4. Action Visibility: Shows create, edit, and delete actions according to permissions.
  5. Validation: Prevents deleting the current user in the UI.
  6. Form Handling: Uses CreateUser and EditUser inside dialogs.
  7. State Management: Toggles local flags after create/edit/delete to trigger hook refetch.

API endpoints:

OperationAPI Call
Listapi.user.getAll()
Paginated listapi.user.getPaginated(params)
Get oneapi.user.get(userId)
Createapi.user.create(data)
Updateapi.user.update(userId, data)
Deleteapi.user.delete(userId)

Role Management

  • Route: /dashboard/role
  • Component: AllRole
  1. Data Loading: Loads roles with useRoles([deletionFlag, createFlag, editFlag]).
  2. Context Check: Fetches current user through api.auth.me() to identify the current role ID.
  3. Action Visibility: Shows create, edit, and delete actions according to permissions.
  4. Validation: Prevents deleting the current user's active role in the UI.
  5. Form Handling: Uses CreateRole and EditRole inside dialogs.
  6. Metrics: Displays permission counts on the list.

Role forms load the permission catalog through api.permission.getAll() and submit selected permission IDs.

API endpoints:

OperationAPI Call
Listapi.role.getAll()
Paginated listapi.role.getPaginated(params)
Get oneapi.role.get(roleId)
Createapi.role.create(data)
Updateapi.role.update(roleId, data)
Deleteapi.role.delete(roleId)
Permissionsapi.permission.getAll()

Organization Detail

  • Route: /dashboard/organization
  • Component: OrganizationDetail
  1. Context Initialization: Reads current user ID from cookies.
  2. Data Loading: Calls useUser(userId, [editFlag]).
  3. Data Mapping: Reads user.organization.
  4. Render Details: Displays organization name, email, phone, address, province, and city.
  5. Action Visibility: Shows edit action only when the user has edit-organization.
  6. Form Handling: Opens EditOrganization in a dialog and refetches after closing.

Profile

  • Route: /dashboard/profile

The profile screen displays and edits the current user profile. It follows the same pattern as organization detail: fetch current user, render read-only details, open edit dialog, then refetch after successful edit.


Permissions

Management screens use these slugs:

AreaCreateEditDeleteRead
Userscreate-useredit-userdelete-userread-user
Rolescreate-roleedit-roledelete-roleread-role
Organizationn/aedit-organizationn/an/a

The backend remains the source of truth for authorization.


Failure Modes

ScenarioFrontend Behavior
Province/city load failsError alert is shown and form stays usable
Organization create returns invalid dataThrows an error and stops onboarding navigation
User/role list load failsHook logs error and exposes empty fallback arrays
Delete failsError alert is shown
Permission fetch failsAction buttons are hidden because permissions become empty
Current role/user ID is missingCurrent-user delete prevention may not apply