Skip to content

feat: Account Hub admin page with smart search and account management (ENG-391)#26

Open
forge0x wants to merge 18 commits into
mainfrom
feat/eng-391-account-hub
Open

feat: Account Hub admin page with smart search and account management (ENG-391)#26
forge0x wants to merge 18 commits into
mainfrom
feat/eng-391-account-hub

Conversation

@forge0x
Copy link
Copy Markdown

@forge0x forge0x commented May 8, 2026

Summary

New Account Hub page at /app/account-hub for Flash support and admin staff to look up any customer account and perform management actions.

Features

  • Smart Search — single input auto-detects phone, email, username, or account ID and routes to the correct Flash admin GraphQL query with fallback
  • Split Panel — search on left (~30%), tabbed account detail on right (~70%)
  • 5 Tabs:
    1. Overview — identity (phone/email/username/npub), account state (level/status), actions (change level, lock/unlock, update phone)
    2. Wallets — USD balance (formatted .XX), USDT balance if present
    3. Documents — ID document viewer with pre-signed URL from DO Spaces
    4. Merchant — merchant info, validate/reject merchant map entries
    5. Upgrade History — linked AccountUpgradeRequest records from local DocType
  • Role Guard — restricted to Accounts Manager role

Files Changed

File Change
admin_panel/api/graphql_client.py +195/−28 — added account fragment, 4 search queries, 4 mutations, 7 client methods
admin_panel/api/admin_api.py +80 — added smart search, status/phone/merchant endpoints, upgrade requests by account
admin_panel/admin_panel/page/account_hub/ New page: __init__.py, account_hub.json, account_hub.js (1664 lines)
admin_panel/fixtures/workspace.json +37/−2 — added Account Hub shortcut and link

To Deploy

bench --site flashapp.me.localhost migrate

Then navigate to /app/account-hub.

Closes ENG-391

@linear
Copy link
Copy Markdown

linear Bot commented May 8, 2026

ENG-391

@forge0x
Copy link
Copy Markdown
Author

forge0x commented May 8, 2026

UAT Fixes (commit 638da4a)

Shortcut order — Account Hub shortcut now sits beside Alert Users and Account Management at the top (moved before Tools card in workspace content)

Default user list — On page load, recent upgrade requests now appear in the left panel. Searching filters this local list in real-time. Clicking a result fetches full account details via the API.

Network error resilience — The smart search backend now catches ValueError (missing Flash API config) and falls back to searching the local Account Upgrade Request DocType by username/phone/email. Upgrade requests will also appear as clickable results even without the Flash API connected.

To redeploy:

cd /Users/forgemini/dev/frappe-flash-admin
git checkout feat/eng-391-account-hub
git pull
bench --site flashapp.me.localhost migrate

Then visit /app/account-hub

Copy link
Copy Markdown
Collaborator

@brh28 brh28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing with Claude noticed some possible issues:

  • approve_upgrade_request: Sends DocType name instead of Flash UID to the mutation; never sets local status to "Approved" │
  • reject_upgrade_request: Writes "REJECTED" (uppercase) which isn't a valid Select option; should be "Rejected"

Comment thread admin_panel/api/admin_api.py Outdated

local_result = _search_local_doctype(query)
if local_result:
return local_result
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of returning the AccountUpgradeRequest when flash api fails. it could be outdated and therefore misleading.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the local Account Upgrade Request fallback from Account Hub search. search_account_smart now returns Flash GraphQL account data only; API misses return 404 and Flash API failures return 503 instead of synthesizing stale local data as an account.

@forge0x
Copy link
Copy Markdown
Author

forge0x commented May 11, 2026

Addressed the stale fallback concern in 1c330bc.

Change:

  • Removed _search_local_doctype from Account Hub search.
  • search_account_smart now returns only Flash GraphQL account data.
  • Flash API not found returns 404.
  • Flash API unavailable/config/error returns 503.

Verification:

  • python3 -m py_compile admin_panel/api/admin_api.py
  • git diff --check

patoo0x and others added 18 commits May 11, 2026 12:22
Task 2 — graphql_client.py:
- Add ACCOUNT_DETAIL_FRAGMENT reusable fragment with all account fields
  (id, uuid, username, npub, level, status, title, erpParty, owner, coordinates,
   wallets, merchants, createdAt)
- Update ACCOUNT_BY_PHONE_QUERY to use the fragment
- Add ACCOUNT_BY_USERNAME_QUERY (by username)
- Add ACCOUNT_BY_EMAIL_QUERY (by email via accountDetailsByUserEmail)
- Add ACCOUNT_BY_ID_QUERY (by account ID via accountDetailsByAccountId)
- Add UPDATE_STATUS_MUTATION (accountUpdateStatus)
- Add USER_UPDATE_PHONE_MUTATION (userUpdatePhone)
- Add MERCHANT_MAP_VALIDATE_MUTATION (merchantMapValidate)
- Add MERCHANT_MAP_DELETE_MUTATION (merchantMapDelete)
- Add client methods: get_account_by_username, get_account_by_email,
  get_account_by_id, update_account_status, update_user_phone,
  validate_merchant, delete_merchant

Task 3 — admin_api.py:
- Add search_account_smart: auto-detects phone/email/username/ID input
  and routes to the correct GraphQL query with fallback
- Add update_account_status_api: wrapper for account status mutation
- Add update_user_phone_api: wrapper for user phone update mutation
- Add validate_merchant_api: wrapper for merchant validation mutation
- Add delete_merchant_api: wrapper for merchant deletion mutation
- Add get_upgrade_requests_by_account: queries local Account Upgrade
  Request doctype by username

All endpoints follow existing patterns: @frappe.whitelist(), @handle_api_errors,
and GraphQLClient usage.
- New Account Hub page at /app/account-hub
- Split panel layout with search (left) and detail view (right)
- 5 tabs: Overview, Wallets, Documents, Merchant, Upgrade History
- Smart search via search_account_smart API
- Actions: Change Level, Lock/Activate Account, Update Phone
- Merchant validate/delete actions
- ID document viewer with pre-signed URL loading
- Wallet display with USD/USDT balances in cents format
- Upgrade history table from local DocType
- Role guard for Accounts Manager
- Consistent styling with existing Account Management page
1. Workspace: move Account Hub shortcut before Tools card so it
   appears beside Alert Users and Account Management at the top
2. Default user list: on page load, show recent upgrade requests
   in the left panel as clickable results. Search input filters
   this local list in real-time and also searches the Flash API
3. Network error resilience: backend search_account_smart now
   falls back to searching the local Account Upgrade Request
   DocType when the Flash API is unreachable or unconfigured.
   Also catches ValueError for missing config gracefully.
4. on_result_click: clicking a local upgrade request item
   triggers a full API search by username when available
5. show_search_error no longer clears previous results
6. show_search_result auto-selects the result item
- ACCOUNT_BY_EMAIL_QUERY: use 'accountDetailsByEmail' (not
  accountDetailsByUserEmail) to match the exported field name
  in Flash schema's queries.ts
- get_account_by_email: update extract path to match
- Merchant coordinates in fragment: nested under 'coordinates'
  object (lat/lng are sub-fields of Coordinates type, not
  top-level Merchant fields)
- account_hub.js: update merchant latitude/longitude access to
  use m.coordinates sub-object
…ists on click

- Documents tab: View button now opens the Account Upgrade Request
  DocType form directly (window.open to /app/account-upgrade-request/{name})
  instead of calling the failing get_id_document_url API
- Result list: on_result_click now calls fetch_account_details() which
  fetches full account data without replacing/re-rendering the result
  list. The list stays intact so users can switch between accounts.
- Added fetch_account_details() helper that populates the detail panel
  independently of the search results list
…details

this.$.detailPanel and this.$.detailLoading were never defined
in the page template, causing a silent TypeError when clicking
a result item.
fetch_account_details now accepts a fallback object built from
local DocType data. If the API returns 'not found' or a network
error occurs, the local data is shown silently instead of an
error dialog. This handles placeholder/seed records that only
exist in Frappe but not on the Flash API.
- Removed frappe.response['http_status_code'] from @handle_api_errors
  decorator — always returns 200 with {success: false, error: msg}
  so the frontend callback fires instead of the error handler
- Removed 400/404 status codes from search_account_smart for same
  reason
- Updated frontend error callback message to be more descriptive
- Cleaner error messages: 'Account not found...' and
  'Flash API unreachable. Search limited to local data.'
  instead of 'Network error. Please try again.'
Show the actual error message to the user and log the
traceback so we can identify root causes.
Account Upgrade Request has phone_number and email columns,
not phone and email_id. Fixed _search_local_doctype SQL
queries, return mapping, and all frontend references to
match the actual schema.
…requests

New /app/admin-dashboard page:
- 4 stat cards: pending, approved today, total approved, total requests
- 3 quick action cards: Account Hub, Account Management, Alert Users
- Recent upgrade requests table with clickable rows
- Responsive grid layout, auto-dark mode compatible

Backend: get_dashboard_stats endpoint for aggregated counts
Workspace: Dashboard is now the first shortcut in the Admin Panel workspace
Setup: syncs admin-dashboard page on after_migrate
- Added responsive breakpoints at 1024px, 768px, and 480px
- Stat cards compact at each breakpoint (smaller icons, padding, font)
- Tool cards switch to horizontal row layout on tablets (768px)
- Table gets horizontal scroll wrapper on mobile
- Added touch-friendly :active states for all clickable elements
- Removed hover-only interactions that don't work on touch
- Section spacing tightens on small screens
@forge0x forge0x force-pushed the feat/eng-391-account-hub branch from 1c330bc to afc5924 Compare May 11, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants