Add client dashboard ajax tabs v1
This commit is contained in:
@@ -914,6 +914,30 @@ def _active_financial_year(request: Request) -> str | None:
|
||||
value = (value or "").strip()
|
||||
return value or None
|
||||
|
||||
CLIENT_PORTAL_TABS = {
|
||||
"overview": "modules/clients/templates/clients/portal_partials/overview.html",
|
||||
"pending": "modules/clients/templates/clients/portal_partials/pending.html",
|
||||
"services": "modules/clients/templates/clients/portal_partials/services.html",
|
||||
"documents": "modules/clients/templates/clients/portal_partials/documents.html",
|
||||
"billing": "modules/clients/templates/clients/portal_partials/billing.html",
|
||||
"messages": "modules/clients/templates/clients/portal_partials/messages.html",
|
||||
"reports": "modules/clients/templates/clients/portal_partials/reports.html",
|
||||
}
|
||||
|
||||
|
||||
def _client_dashboard_payload(db, client_row, financial_year: str | None = None) -> dict:
|
||||
summary = build_client_portal_summary(db, client_row, financial_year=financial_year)
|
||||
billing_summary = build_client_billing_summary(db, client_row, financial_year=financial_year)
|
||||
return {
|
||||
"client_visible_comments": list_client_visible_comments(db, client_row, limit=20, financial_year=financial_year),
|
||||
"recent_documents": list_client_engagement_documents(db, client_row, financial_year=financial_year)[:12],
|
||||
"permanent_documents": list_client_permanent_documents(db, client_row),
|
||||
"auditor_card": build_client_auditor_card(db, client_row),
|
||||
**summary,
|
||||
**billing_summary,
|
||||
}
|
||||
|
||||
|
||||
def _portal_context(request: Request, db, current_user, **extra):
|
||||
ctx = {
|
||||
"request": request,
|
||||
@@ -964,6 +988,43 @@ def client_portal_dashboard(request: Request):
|
||||
db.close()
|
||||
|
||||
|
||||
@portal_router.get("/dashboard/tab/{tab_name}")
|
||||
def client_portal_dashboard_tab(request: Request, tab_name: str):
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
current_user = get_current_user(request, db=db)
|
||||
if not current_user:
|
||||
return RedirectResponse(url="/login", status_code=303)
|
||||
|
||||
client_row, redirect = _portal_client_or_redirect(request, db, current_user)
|
||||
if redirect:
|
||||
return redirect
|
||||
|
||||
active_tab = tab_name if tab_name in CLIENT_PORTAL_TABS else "overview"
|
||||
if not client_row:
|
||||
return templates.TemplateResponse(
|
||||
CLIENT_PORTAL_TABS["overview"],
|
||||
_portal_context(request, db, current_user, client_row=None, active_tab=active_tab),
|
||||
status_code=200,
|
||||
)
|
||||
financial_year = _active_financial_year(request)
|
||||
payload = _client_dashboard_payload(db, client_row, financial_year=financial_year)
|
||||
return templates.TemplateResponse(
|
||||
CLIENT_PORTAL_TABS[active_tab],
|
||||
_portal_context(
|
||||
request,
|
||||
db,
|
||||
current_user,
|
||||
client_row=client_row,
|
||||
active_tab=active_tab,
|
||||
active_financial_year=financial_year,
|
||||
**payload,
|
||||
),
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@portal_router.get("/billing")
|
||||
def client_portal_billing(request: Request, q: str = "", include_paid: str = "yes"):
|
||||
db = CommonSessionLocal()
|
||||
|
||||
Reference in New Issue
Block a user