feat(loyalty): cross-persona page alignment with shared components

Align loyalty pages across admin, merchant, and store personas so each
sees the same page set scoped to their access level. Admin acts as a
superset of merchant with "on behalf" capabilities.

New pages:
- Store: Staff PINs management (CRUD)
- Merchant: Cards, Card Detail, Transactions, Staff PINs (CRUD), Settings (read-only)
- Admin: Merchant Cards, Card Detail, Transactions, PINs (read-only)

Architecture:
- 4 shared Jinja2 partials (cards-list, card-detail, transactions, pins)
- 4 shared JS factory modules parameterized by apiPrefix/scope
- Persona templates are thin wrappers including shared partials
- PinDetailResponse schema for cross-store PIN listings

API: 17 new endpoints (11 merchant, 6 admin on-behalf)
Tests: 38 new integration tests, arch-check green
i18n: ~130 new keys across en/fr/de/lb
Docs: pages-and-navigation.md with full page matrix

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-22 19:28:07 +01:00
parent f41f72b86f
commit 6161d69ba2
49 changed files with 4385 additions and 14 deletions

View File

@@ -124,6 +124,91 @@ async def admin_loyalty_program_edit(
)
@router.get(
"/merchants/{merchant_id}/cards",
response_class=HTMLResponse,
include_in_schema=False,
)
async def admin_loyalty_merchant_cards(
request: Request,
merchant_id: int = Path(..., description="Merchant ID"),
current_user: User = Depends(require_menu_access("loyalty-programs", FrontendType.ADMIN)),
db: Session = Depends(get_db),
):
"""
Render merchant loyalty cards list page.
Shows all loyalty cards for a specific merchant.
"""
return templates.TemplateResponse(
"loyalty/admin/merchant-cards.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id),
)
@router.get(
"/merchants/{merchant_id}/cards/{card_id}",
response_class=HTMLResponse,
include_in_schema=False,
)
async def admin_loyalty_merchant_card_detail(
request: Request,
merchant_id: int = Path(..., description="Merchant ID"),
card_id: int = Path(..., description="Card ID"),
current_user: User = Depends(require_menu_access("loyalty-programs", FrontendType.ADMIN)),
db: Session = Depends(get_db),
):
"""
Render merchant loyalty card detail page.
Shows detailed info for a specific loyalty card.
"""
return templates.TemplateResponse(
"loyalty/admin/merchant-card-detail.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id, card_id=card_id),
)
@router.get(
"/merchants/{merchant_id}/transactions",
response_class=HTMLResponse,
include_in_schema=False,
)
async def admin_loyalty_merchant_transactions(
request: Request,
merchant_id: int = Path(..., description="Merchant ID"),
current_user: User = Depends(require_menu_access("loyalty-programs", FrontendType.ADMIN)),
db: Session = Depends(get_db),
):
"""
Render merchant loyalty transactions list page.
Shows all loyalty transactions for a specific merchant.
"""
return templates.TemplateResponse(
"loyalty/admin/merchant-transactions.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id),
)
@router.get(
"/merchants/{merchant_id}/pins",
response_class=HTMLResponse,
include_in_schema=False,
)
async def admin_loyalty_merchant_pins(
request: Request,
merchant_id: int = Path(..., description="Merchant ID"),
current_user: User = Depends(require_menu_access("loyalty-programs", FrontendType.ADMIN)),
db: Session = Depends(get_db),
):
"""
Render merchant staff PINs page (read-only).
Shows all staff PINs for a specific merchant.
"""
return templates.TemplateResponse(
"loyalty/admin/merchant-pins.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id),
)
@router.get(
"/merchants/{merchant_id}/settings",
response_class=HTMLResponse,

View File

@@ -157,3 +157,125 @@ async def merchant_loyalty_analytics(
"loyalty/merchant/analytics.html",
context,
)
# ============================================================================
# LOYALTY CARDS
# ============================================================================
@router.get("/cards", response_class=HTMLResponse, include_in_schema=False)
async def merchant_loyalty_cards(
request: Request,
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
merchant: Merchant = Depends(get_merchant_for_current_user_page),
db: Session = Depends(get_db),
):
"""Render merchant loyalty cards list page."""
context = _get_merchant_context(
request,
db,
current_user,
merchant_id=merchant.id,
)
return templates.TemplateResponse(
"loyalty/merchant/cards.html",
context,
)
@router.get("/cards/{card_id}", response_class=HTMLResponse, include_in_schema=False)
async def merchant_loyalty_card_detail(
request: Request,
card_id: int,
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
merchant: Merchant = Depends(get_merchant_for_current_user_page),
db: Session = Depends(get_db),
):
"""Render merchant loyalty card detail page."""
context = _get_merchant_context(
request,
db,
current_user,
merchant_id=merchant.id,
card_id=card_id,
)
return templates.TemplateResponse(
"loyalty/merchant/card-detail.html",
context,
)
# ============================================================================
# LOYALTY TRANSACTIONS
# ============================================================================
@router.get("/transactions", response_class=HTMLResponse, include_in_schema=False)
async def merchant_loyalty_transactions(
request: Request,
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
merchant: Merchant = Depends(get_merchant_for_current_user_page),
db: Session = Depends(get_db),
):
"""Render merchant loyalty transactions page."""
context = _get_merchant_context(
request,
db,
current_user,
merchant_id=merchant.id,
)
return templates.TemplateResponse(
"loyalty/merchant/transactions.html",
context,
)
# ============================================================================
# LOYALTY STAFF PINS
# ============================================================================
@router.get("/pins", response_class=HTMLResponse, include_in_schema=False)
async def merchant_loyalty_pins(
request: Request,
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
merchant: Merchant = Depends(get_merchant_for_current_user_page),
db: Session = Depends(get_db),
):
"""Render merchant loyalty staff PINs page."""
context = _get_merchant_context(
request,
db,
current_user,
merchant_id=merchant.id,
)
return templates.TemplateResponse(
"loyalty/merchant/pins.html",
context,
)
# ============================================================================
# LOYALTY SETTINGS
# ============================================================================
@router.get("/settings", response_class=HTMLResponse, include_in_schema=False)
async def merchant_loyalty_settings(
request: Request,
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
merchant: Merchant = Depends(get_merchant_for_current_user_page),
db: Session = Depends(get_db),
):
"""Render merchant loyalty settings page (read-only)."""
context = _get_merchant_context(
request,
db,
current_user,
merchant_id=merchant.id,
)
return templates.TemplateResponse(
"loyalty/merchant/settings.html",
context,
)

View File

@@ -216,6 +216,32 @@ async def store_loyalty_analytics(
)
# ============================================================================
# STAFF PINS
# ============================================================================
@router.get(
"/loyalty/pins",
response_class=HTMLResponse,
include_in_schema=False,
)
async def store_loyalty_pins(
request: Request,
store_code: str = Depends(get_resolved_store_code),
current_user: User = Depends(get_current_store_from_cookie_or_header),
db: Session = Depends(get_db),
):
"""
Render staff PINs management page.
Allows store staff to manage staff PINs for loyalty transactions.
"""
return templates.TemplateResponse(
"loyalty/store/pins.html",
get_store_context(request, db, current_user, store_code),
)
# ============================================================================
# ENROLLMENT
# ============================================================================