'use client' import { X } from 'lucide-react' import { useState } from 'react' import { createProperty } from '../lib/properties/actions' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/primitives/dialog' import { GoogleAddressSearch } from './google-address-search' interface NewPropertyDialogProps { open: boolean onOpenChange: (open: boolean) => void onSuccess?: (propertyId: string) => void } interface AddressData { streetNumber?: string route?: string city?: string state?: string postalCode?: string country?: string center: [number, number] formattedAddress: string } /** * NewPropertyDialog - Dialog for creating a new property with Google Maps address search */ export function NewPropertyDialog({ open, onOpenChange, onSuccess }: NewPropertyDialogProps) { const [address, setAddress] = useState(null) const [isCreating, setIsCreating] = useState(false) const [error, setError] = useState(null) const handleAddressSelect = (addressData: AddressData) => { setAddress(addressData) setError(null) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) if (!address) { setError('Please select an address') return } setIsCreating(true) try { // Use formatted address as property name (like monorepo) const result = await createProperty({ name: address.formattedAddress, center: address.center, streetNumber: address.streetNumber, route: address.route, city: address.city, state: address.state, postalCode: address.postalCode, country: address.country || 'US', }) if (result.success && result.data) { onOpenChange(false) setAddress(null) onSuccess?.(result.data.id) } else { setError(result.error || 'Failed to create property') } } catch (err) { setError(err instanceof Error ? err.message : 'An unexpected error occurred') } finally { setIsCreating(false) } } const handleClose = () => { if (!isCreating) { onOpenChange(false) setAddress(null) setError(null) } } return ( e.preventDefault()} > Add New Property
{/* Google Maps Address Search */} {/* Show selected address */} {address && (

Selected Address:

{address.formattedAddress}

)} {error && (
{error}
)}
) }