'use client' import { useState } from 'react' import { CopyIcon, ExternalLinkIcon, Trash2Icon } from 'lucide-react' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Drawer, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, } from '@/components/ui/Drawer' import { Input } from '@/components/ui/input' import { useIsMobile } from '@/hooks/use-mobile' export type CalendarFeedSummary = { id: number label: string createdAt: string } export type CreateCalendarFeedResult = | { ok: true; feedUrl: string } | { ok: false; message: string } type CalendarFeedDialogProps = { open: boolean onOpenChange: (open: boolean) => void feeds: CalendarFeedSummary[] /** Whether the current agenda recorte can generate a feed (has filters). */ canGenerate: boolean onCreateFeed: (label: string) => Promise onRevokeFeed: (feedId: number) => Promise<{ ok: boolean }> } /** * Calendar feed dialog (nomear → copiar → revogar). Shared by the desktop * header icon and the mobile FAB quick action — rendered once per host, opened * by either trigger. Bottom sheet on mobile, dialog on desktop (C94). */ export const CalendarFeedDialog = ({ open, onOpenChange, feeds, canGenerate, onCreateFeed, onRevokeFeed, }: CalendarFeedDialogProps) => { const isMobile = useIsMobile() const [label, setLabel] = useState('') const [createdUrl, setCreatedUrl] = useState(null) const [isCreating, setIsCreating] = useState(false) const [error, setError] = useState(null) const [copied, setCopied] = useState(false) const handleCreate = async () => { if (!label.trim() || !canGenerate || isCreating) return setIsCreating(true) setError(null) const result = await onCreateFeed(label.trim()) setIsCreating(false) if (result.ok) { setCreatedUrl(result.feedUrl) setLabel('') } else { setError(result.message) } } const handleCopy = async () => { if (!createdUrl) return await navigator.clipboard.writeText(createdUrl) setCopied(true) setTimeout(() => setCopied(false), 2000) } const handleRevoke = async (feedId: number) => { await onRevokeFeed(feedId) } const handleClose = (next: boolean) => { if (next) return setCreatedUrl(null) setError(null) setCopied(false) onOpenChange(false) } const body = ( <> {createdUrl ? (
{copied &&

Link copiado!

}

Como adicionar ao Google Calendar:

  1. Abra o Google Calendar no computador
  2. No menu lateral, clique em {'"'} {'+'} {'"'} ao lado de {'"'}Outras agendas{'"'}
  3. Selecione {'"'}Por URL{'"'}
  4. Cole o link acima e clique em {'"'}Adicionar agenda{'"'}
{!isMobile ? ( ) : null}
) : (
{!canGenerate ? (

Aplique filtros à agenda para gerar um link de import.

) : null}
setLabel(e.target.value)} placeholder="Ex: Só deputado presente" maxLength={120} onKeyDown={(e) => e.key === 'Enter' && handleCreate()} />

Um nome para identificar este feed (ex: {'"'}Agenda do candidato{'"'}, {'"'} Reuniões em Salvador{'"'})

{error &&

{error}

} {feeds.length > 0 && (

Seus feeds ativos

    {feeds.map((feed) => (
  • {feed.label}
  • ))}
)}
{!isMobile ? ( ) : null}
)} ) if (isMobile) { return ( Sincronizar com Google Calendar Gere um link de import para sincronizar este recorte da agenda com o Google Calendar. Alterações em Teqo serão refletidas automaticamente.
{body}
Fechar
) } return ( Sincronizar com Google Calendar Gere um link de import para sincronizar este recorte da agenda com o Google Calendar. Alterações em Teqo serão refletidas automaticamente. {body} ) }