teqo/src/components/campaign/shell/CampaignMobileTopBar.tsx
Francisco Solla f0dff330bd feat(C102): sem hamburger/sheet de sidebar no mobile staff — navegação pela barra + Mais
No mobile (<768px) staff perde o botão de abrir sidebar na top bar
(CampaignMobileTopBar role-gated via useCampaignPageChromeRole +
isStaffCampaignRole; leader mantém) e o sheet de navegação deixa de
montar (CampaignSidebar early-return quando isMobile && staff).
Filtros salvos de Municípios (B18) migram para o drawer Mais
(MunicipalityNavSavedFilters variant 'overflow', mesma store,
apagar/desfazer/sucessão de foco; drawer ganha overflow-y-auto).

Correção de bug pré-existente (D4): o Toaster vivia dentro do wrapper
[contain:layout_paint] do painel da AI, que vira containing block para
position:fixed e stacking context próprio — toasts com ação (ex.
Desfazer) ficavam inalcançáveis sob os portais z-50 de drawer/sheet.
Movido para o root layout (campaign).

Testes: unit top bar (staff sem trigger / leader com trigger) + e2e
(staff sem trigger/dialog, leader com sheet, B18 no drawer completo).
2026-08-09 19:13:43 -03:00

151 lines
5.7 KiB
TypeScript

'use client'
import { ArrowLeft, X } from 'lucide-react'
import { Fragment, type ReactNode } from 'react'
import { useCampaignListTransition } from '@/components/campaign/shared/CampaignListPending'
import { CampaignWizardNavLink } from '@/components/campaign/shared/CampaignWizardNavLink'
import { useCampaignHomeSearchChrome } from '@/components/campaign/shell/CampaignHomeSearchChromeContext'
import {
useCampaignHeaderActions,
useCampaignPageChromeRole,
} from '@/components/campaign/shell/CampaignPageChromeContext'
import { CampaignPageChromeDisplay } from '@/components/campaign/shell/CampaignPageChromeDisplay'
import { useCampaignWizardChrome } from '@/components/campaign/shell/CampaignWizardChromeContext'
import { Button } from '@/components/ui/button'
import { SidebarTrigger } from '@/components/ui/Sidebar'
import { Skeleton } from '@/components/ui/skeleton'
import { HOME_SEARCH_COLLAPSE_ARIA_LABEL } from '@/lib/campaignHomeSearchContract'
import { isStaffCampaignRole } from '@/lib/campaignRoles'
import {
WIZARD_APP_TOP_BAR_ARIA_LABEL,
WIZARD_DISMISS_ARIA_LABEL,
wizardFlowChromeAriaLabel,
wizardMunicipalityChromeAriaLabel,
} from '@/lib/campaignWizardCopy'
import { cn } from '@/lib/utils'
const wizardNavButtonClass =
'min-h-11 shrink-0 gap-1 px-2 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground'
const wizardDismissButtonClass =
'size-11 shrink-0 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground'
const wizardTitleSkeletonClass = 'mx-auto motion-reduce:animate-none bg-primary-foreground/20'
export const CampaignMobileTopBar = ({ notificationBell }: { notificationBell?: ReactNode }) => {
const chrome = useCampaignWizardChrome()
const homeSearchChrome = useCampaignHomeSearchChrome()
const headerActions = useCampaignHeaderActions()
const role = useCampaignPageChromeRole()
const { isPending } = useCampaignListTransition()
if (chrome) {
return (
<header
data-slot="campaign-mobile-top-bar"
data-mode="wizard"
aria-label={wizardFlowChromeAriaLabel(chrome.flowTitle)}
className={cn(
'flex min-h-14 shrink-0 items-center gap-2 bg-primary px-2 text-primary-foreground md:hidden print:hidden',
'pt-[max(0px,env(safe-area-inset-top))]',
)}
>
<div className="flex min-w-0 flex-1 items-center">
{chrome.stepKind === 'continue' && chrome.previousHref ? (
<Button
variant="ghost"
size="sm"
className={wizardNavButtonClass}
asChild
disabled={isPending}
>
<CampaignWizardNavLink href={chrome.previousHref} replace>
<ArrowLeft className="size-4 shrink-0" aria-hidden />
Voltar
</CampaignWizardNavLink>
</Button>
) : (
<div className="size-11 shrink-0" aria-hidden />
)}
<div className="min-w-0 flex-1 px-1 text-center leading-tight">
{isPending ? (
<>
<Skeleton className={cn(wizardTitleSkeletonClass, 'h-4 w-32 max-w-full')} />
{chrome.municipalityLabel ? (
<Skeleton className={cn(wizardTitleSkeletonClass, 'mt-1 h-3 w-24 max-w-full')} />
) : null}
</>
) : (
<>
<span className="block truncate text-sm font-semibold">{chrome.flowTitle}</span>
{chrome.municipalityLabel ? (
<span
className="block truncate text-xs text-primary-foreground/80"
aria-label={wizardMunicipalityChromeAriaLabel(chrome.municipalityLabel)}
>
{chrome.municipalityLabel}
</span>
) : null}
</>
)}
</div>
</div>
<div className="flex shrink-0 items-center">
<Button
variant="ghost"
size="icon"
className={wizardDismissButtonClass}
asChild
disabled={isPending}
>
<CampaignWizardNavLink href={chrome.dismissHref} aria-label={WIZARD_DISMISS_ARIA_LABEL}>
<X className="size-5" aria-hidden />
</CampaignWizardNavLink>
</Button>
</div>
</header>
)
}
return (
<header
data-slot="campaign-mobile-top-bar"
data-mode="app"
data-home-search-focused={homeSearchChrome?.focused || undefined}
aria-label={WIZARD_APP_TOP_BAR_ARIA_LABEL}
className={cn(
'flex min-h-14 shrink-0 items-center gap-3 bg-primary px-4 text-primary-foreground md:hidden print:hidden',
'pt-[max(0px,env(safe-area-inset-top))]',
)}
>
{homeSearchChrome?.focused ? (
<Button
type="button"
variant="ghost"
size="sm"
className={wizardNavButtonClass}
aria-label={HOME_SEARCH_COLLAPSE_ARIA_LABEL}
onClick={homeSearchChrome.collapse}
>
<ArrowLeft className="size-4 shrink-0" aria-hidden />
Voltar
</Button>
) : isStaffCampaignRole(role) ? null : (
// C102: staff navigates from the bottom bar + "Mais" — the hamburger is
// only the leader's (lockdown, no bottom nav). The sheet itself is
// unmounted for staff in CampaignSidebar.
<SidebarTrigger className="text-primary-foreground" />
)}
<CampaignPageChromeDisplay layout="mobile" />
<div className="ml-auto flex shrink-0 items-center gap-1">
{Object.entries(headerActions).map(([id, node]) => (
<Fragment key={id}>{node}</Fragment>
))}
{notificationBell ?? null}
</div>
</header>
)
}