teqo-backup/src/components/campaign/shell/CampaignMobileTopBar.tsx
Cursor Agent 9b56b641a6
OH14 — remove OPS_HYBRID flag; sync always on for staff
Decision: remove compile-time OPS_HYBRID after OH11/OH13 green in CI/staging.
Staff hybrid sync is gated only by isStaffCampaignRole in the app layout;
OfflineBoundary swaps to Local when the browser is offline.

- Delete opsHybridFlag.ts and legacy formAction branches in staff controls
- E2e offline specs run in CI without OPS_HYBRID env
- Update ops-hibrido spec to implementado + offline write recipe

Closes #175

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-02 03:47:04 +00:00

184 lines
6.5 KiB
TypeScript

'use client'
import { ArrowLeft, X } from 'lucide-react'
import Link from 'next/link'
import 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 {
useCampaignWizardChrome,
useCampaignWizardRequestBack,
} 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 { CAMPAIGN_HOME } from '@/lib/campaignPaths'
import {
CAMPAIGN_HOME_TOP_BAR_LINK_ARIA_LABEL,
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 wizardSkipButtonClass =
'min-h-11 max-w-[9rem] px-2 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,
opsSyncStatus,
}: {
notificationBell?: ReactNode
/** OH5 — discreet sync chrome; staff layout only. */
opsSyncStatus?: ReactNode
}) => {
const chrome = useCampaignWizardChrome()
const requestWizardBack = useCampaignWizardRequestBack()
const homeSearchChrome = useCampaignHomeSearchChrome()
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
type="button"
variant="ghost"
size="sm"
className={wizardNavButtonClass}
disabled={isPending}
onClick={requestWizardBack}
>
<ArrowLeft className="size-4 shrink-0" aria-hidden />
Voltar
</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">
{chrome.skip ? (
<Button
variant="ghost"
size="sm"
className={wizardSkipButtonClass}
asChild
disabled={isPending}
>
<CampaignWizardNavLink href={chrome.skip.href} title={chrome.skip.label}>
{chrome.skip.label}
</CampaignWizardNavLink>
</Button>
) : (
<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>
) : (
<SidebarTrigger className="text-primary-foreground" />
)}
<div className="min-w-0 flex-1 leading-tight">
<Link
href={CAMPAIGN_HOME}
aria-label={CAMPAIGN_HOME_TOP_BAR_LINK_ARIA_LABEL}
className="block rounded-md outline-none focus-visible:ring-2 focus-visible:ring-primary-foreground/60"
>
<span className="block truncate text-sm font-semibold">Jorge Solla</span>
<span className="block truncate text-xs text-primary-foreground/80">
Campanha · Bahia
</span>
</Link>
{opsSyncStatus ? (
<div className="mt-0.5 text-primary-foreground/70 [&_[role=status]]:text-inherit">
{opsSyncStatus}
</div>
) : null}
</div>
{notificationBell ? <div className="shrink-0">{notificationBell}</div> : null}
</header>
)
}