import { useState, useEffect } from "react"; import { useQuery, useMutation } from "@tanstack/react-query"; import { Card, CardContent } from "@/components/ui/card"; import { useToast } from "@/hooks/use-toast"; import { apiRequest, queryClient } from "@/lib/queryClient"; type OfficeContact = { id?: number; officeName?: string | null; receptionistName?: string | null; dentistName?: string | null; phoneNumber?: string | null; email?: string | null; fax?: string | null; streetAddress?: string | null; city?: string | null; state?: string | null; zipCode?: string | null; }; export function OfficeContactCard() { const { toast } = useToast(); const [officeName, setOfficeName] = useState(""); const [receptionistName, setReceptionistName] = useState(""); const [dentistName, setDentistName] = useState(""); const [phoneNumber, setPhoneNumber] = useState(""); const [email, setEmail] = useState(""); const [fax, setFax] = useState(""); const [streetAddress, setStreetAddress] = useState(""); const [city, setCity] = useState(""); const [state, setState] = useState(""); const [zipCode, setZipCode] = useState(""); const { data: contact, isLoading } = useQuery({ queryKey: ["/api/office-contact"], queryFn: async () => { const res = await apiRequest("GET", "/api/office-contact"); if (!res.ok) return null; return res.json(); }, }); useEffect(() => { if (contact) { setOfficeName(contact.officeName ?? ""); setReceptionistName(contact.receptionistName ?? ""); setDentistName(contact.dentistName ?? ""); setPhoneNumber(contact.phoneNumber ?? ""); setEmail(contact.email ?? ""); setFax(contact.fax ?? ""); setStreetAddress(contact.streetAddress ?? ""); setCity(contact.city ?? ""); setState(contact.state ?? ""); setZipCode(contact.zipCode ?? ""); } }, [contact]); const saveMutation = useMutation({ mutationFn: async (data: OfficeContact) => { const res = await apiRequest("PUT", "/api/office-contact", data); if (!res.ok) { const err = await res.json().catch(() => null); throw new Error(err?.message || "Failed to save office contact"); } return res.json(); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["/api/office-contact"] }); toast({ title: "Office Contact Saved", description: "Office contact information has been saved." }); }, onError: (err: any) => { toast({ title: "Error", description: err?.message || "Failed to save office contact", variant: "destructive" }); }, }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); saveMutation.mutate({ officeName, receptionistName, dentistName, phoneNumber, email, fax, streetAddress, city, state, zipCode }); }; return (

Office Contact

Contact information for your dental office staff and communications.

{isLoading ? (

Loading...

) : (
setOfficeName(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. Summit Dental Care" />
setReceptionistName(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. Jane Smith" />
setDentistName(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. Dr. John Doe" />
setPhoneNumber(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. (508) 555-0100" />
setEmail(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. office@dentalclinic.com" />
setFax(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. (508) 555-0199" />

Office Address

setStreetAddress(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. 123 Main Street" />
setCity(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. Framingham" />
setState(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. MA" />
setZipCode(e.target.value)} className="mt-1 p-2 border rounded w-full text-sm" placeholder="e.g. 01701" />
)}
); }