feat: multi-company dropdown in navigation menu

Replace single "Moja firma" link with a switchable company list for users
with multiple companies, using POST forms with CSRF and active-state highlighting.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-04-10 13:53:49 +02:00
parent 1598f93c58
commit 61204edd0c

View File

@ -230,7 +230,24 @@
</svg>
Moje konto
</a>
{% if current_user.company_id and current_user.can_manage_company(current_user.company_id) %}
{% if has_multiple_companies %}
<div class="user-menu-divider"></div>
<div style="padding: 4px 14px 2px; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;">Moja firma</div>
{% for uc in user_companies %}
{% if uc.company %}
<form method="POST" action="{{ url_for('public.switch_company', company_id=uc.company_id) }}" style="margin:0;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" class="user-menu-item" style="width:100%;text-align:left;background:{% if uc.company_id == active_company_id %}var(--bg-tertiary){% else %}none{% endif %};border:none;cursor:pointer;font:inherit;border-left:{% if uc.company_id == active_company_id %}3px solid var(--primary){% else %}3px solid transparent{% endif %};">
<svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/>
</svg>
{{ uc.company.name }}
{% if uc.company_id == active_company_id %}<span style="margin-left:auto;color:var(--primary);font-size:12px;"></span>{% endif %}
</button>
</form>
{% endif %}
{% endfor %}
{% elif current_user.company_id and current_user.can_manage_company(current_user.company_id) %}
<a href="{{ url_for('public.company_edit', company_id=current_user.company_id) }}" class="user-menu-item">
<svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/>