import { useState, useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; import { fetchPropertyById } from "../redux/features/propertySlice"; import { updateProperty } from "../redux/features/propertySlice"; import { useParams } from "react-router-dom"; import Navbar from "./Navbar"; import Footer from "./Footer"; const EditProperty = () => { const { id } = useParams(); const dispatch = useDispatch(); const { selectedProperty } = useSelector((state) => state.property); const [formData, setFormData] = useState({ propertyType: "", yearBuild: "", totalSqft: "", }); useEffect(() => { dispatch(fetchPropertyById(id)); }, [dispatch, id]); useEffect(() => { if (selectedProperty) { setFormData({ propertyType: selectedProperty.propertyType, yearBuild: selectedProperty.yearBuild, totalSqft: selectedProperty.totalSqft, }); } }, [selectedProperty]); const handleChange = (e) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; const handleSubmit = (e) => { e.preventDefault(); dispatch(updateProperty({ id, propertyData: formData })); }; return ( <>





Edit Property