diff --git a/src/components/PetitionForm.tsx b/src/components/PetitionForm.tsx index bba66b94..ee97ccd8 100644 --- a/src/components/PetitionForm.tsx +++ b/src/components/PetitionForm.tsx @@ -11,7 +11,7 @@ import { import { Petition } from '@/payload-types' import { zodResolver } from '@hookform/resolvers/zod' import { FormProvider, type SubmitHandler, useForm } from 'react-hook-form' -import { useTransition } from 'react' +import { useState, useTransition } from 'react' import { Textarea } from './ui/textarea' import { Button } from './ui/button' import { petitionFormSchema, type PetitionFormInput } from '@/lib/schemas/petition-form' @@ -22,6 +22,7 @@ import { PhoneInput } from './PhoneInput' import { StateSelect } from './StateSelect' import { CitySelect } from './CitySelect' import { PostalCodeInput } from './PostalCodeInput' +import { PetitionSuccessDialog } from './PetitionSuccessDialog' interface PetitionFormProps { id: string @@ -44,6 +45,7 @@ export const PetitionForm = ({ id, petition, consentHTML }: PetitionFormProps) = }) const [isSubmitting, startTransition] = useTransition() + const [isSuccessOpen, setIsSuccessOpen] = useState(false) const onSubmit: SubmitHandler = (input) => { const consentId = @@ -57,6 +59,7 @@ export const PetitionForm = ({ id, petition, consentHTML }: PetitionFormProps) = consentId, }) methods.reset() + setIsSuccessOpen(true) } catch { methods.setError('root', { message: 'Falha ao enviar assinatura. Tente novamente.', @@ -67,6 +70,11 @@ export const PetitionForm = ({ id, petition, consentHTML }: PetitionFormProps) = return ( +
{petition.form.title ? {petition.form.title} : null} diff --git a/src/components/PetitionSuccessDialog.tsx b/src/components/PetitionSuccessDialog.tsx new file mode 100644 index 00000000..0bb625da --- /dev/null +++ b/src/components/PetitionSuccessDialog.tsx @@ -0,0 +1,73 @@ +'use client' + +import { useEffect, useState } from 'react' +import { Button } from '@/components/ui/button' +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogTitle, +} from '@/components/ui/dialog' +import { WhatsAppIcon } from '@/components/socialIcons' +import { XIcon } from 'lucide-react' + +interface PetitionSuccessDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + petitionTitle: string +} + +export const PetitionSuccessDialog = ({ + open, + onOpenChange, + petitionTitle, +}: PetitionSuccessDialogProps) => { + const [shareUrl, setShareUrl] = useState('') + + useEffect(() => { + if (typeof window !== 'undefined') { + setShareUrl(window.location.href) + } + }, []) + + const message = `Acabei de assinar o abaixo-assinado "${petitionTitle}". Some sua voz também: ${shareUrl}` + const whatsappHref = `https://wa.me/?text=${encodeURIComponent(message)}` + + return ( + + +
+ + + + + Obrigado por assinar! + +
+
+ + Sua assinatura foi registrada. Compartilhe o abaixo-assinado no WhatsApp para somar mais + apoiadores. + + +
+
+
+ ) +} diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx new file mode 100644 index 00000000..df51636c --- /dev/null +++ b/src/components/ui/dialog.tsx @@ -0,0 +1,132 @@ +'use client' + +import * as React from 'react' +import { Dialog as DialogPrimitive } from 'radix-ui' +import { XIcon } from 'lucide-react' + +import { cn } from '@/lib/utils' + +function Dialog({ ...props }: React.ComponentProps) { + return +} + +function DialogTrigger({ ...props }: React.ComponentProps) { + return +} + +function DialogPortal({ ...props }: React.ComponentProps) { + return +} + +function DialogClose({ ...props }: React.ComponentProps) { + return +} + +function DialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function DialogContent({ + className, + children, + showCloseButton = true, + ...props +}: React.ComponentProps & { + showCloseButton?: boolean +}) { + return ( + + + + {children} + {showCloseButton ? ( + + + + ) : null} + + + ) +} + +function DialogHeader({ className, ...props }: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function DialogFooter({ className, ...props }: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function DialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function DialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogOverlay, + DialogPortal, + DialogTitle, + DialogTrigger, +}