"use client" import { useEffect, useState } from "react" import type { DocumentShareType } from "@garage/api" import { Button } from "@/shared/components/ui/button" import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog" import { Input } from "@/shared/components/ui/input" import { Label } from "@/shared/components/ui/label" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/shared/components/ui/tabs" import { Textarea } from "@/shared/components/ui/textarea" import { useDocumentShare } from "@/shared/hooks/use-document-share" interface ShareDocumentDialogProps { type: DocumentShareType id: string | number open: boolean onOpenChange: (open: boolean) => void } const DEFAULT_MESSAGES: Record = { estimate: { email: "Hello, please find your estimate at the link below. Kindly review the details and let us know if you'd like to proceed.", whatsapp: "Hello, here is your estimate. Please review and let us know if you'd like to proceed.", }, invoice: { email: "Hello, please find your invoice at the link below. Let us know once payment has been arranged.", whatsapp: "Hello, here is your invoice. Let us know once payment is arranged.", }, job_card: { email: "Hello, please find the job card for your vehicle at the link below.", whatsapp: "Hello, here is the job card for your vehicle.", }, inspection: { email: "Hello, please find your vehicle inspection report at the link below.", whatsapp: "Hello, here is your vehicle inspection report.", }, payment_received: { email: "Hello, please find your payment receipt at the link below. Thank you.", whatsapp: "Hello, here is your payment receipt. Thank you.", }, purchase_order: { email: "Hello, please find our purchase order at the link below. Kindly confirm receipt.", whatsapp: "Hello, here is our purchase order. Kindly confirm receipt.", }, bill: { email: "Hello, please find the bill at the link below for your reference.", whatsapp: "Hello, here is the bill for your reference.", }, expense: { email: "Hello, please find the expense document at the link below.", whatsapp: "Hello, here is the expense document.", }, payment_made: { email: "Hello, please find the payment confirmation at the link below.", whatsapp: "Hello, here is the payment confirmation.", }, } function getDefaultMessage(type: DocumentShareType, channel: "email" | "whatsapp"): string { return DEFAULT_MESSAGES[type as string]?.[channel] ?? "" } export function ShareDocumentDialog({ type, id, open, onOpenChange }: ShareDocumentDialogProps) { const { shareEmail, shareWhatsapp, isSharing } = useDocumentShare(type, id) const [email, setEmail] = useState("") const [phone, setPhone] = useState("") const [emailMessage, setEmailMessage] = useState("") const [whatsappMessage, setWhatsappMessage] = useState("") useEffect(() => { if (open) { setEmailMessage(getDefaultMessage(type, "email")) setWhatsappMessage(getDefaultMessage(type, "whatsapp")) } }, [open, type]) const close = () => { onOpenChange(false) setEmail("") setPhone("") setEmailMessage("") setWhatsappMessage("") } const handleEmail = async () => { if (!email) return await shareEmail({ email, message: emailMessage || undefined }) close() } const handleWhatsapp = async () => { await shareWhatsapp({ phone: phone || undefined, message: whatsappMessage || undefined }) close() } return ( Share document Email WhatsApp
setEmail(e.target.value)} placeholder="customer@example.com" />