Skip to content

Commit

Permalink
Merge pull request #66 from vicheanath/update-prop
Browse files Browse the repository at this point in the history
update prop
  • Loading branch information
vicheanath authored Feb 8, 2024
2 parents 2316418 + 2ff8ab5 commit 2fc7e1e
Show file tree
Hide file tree
Showing 4 changed files with 455 additions and 29 deletions.
55 changes: 28 additions & 27 deletions frontend/src/pages/AddProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,29 @@ import { FaLocationDot } from "react-icons/fa6";
import { useNavigate } from "react-router-dom";

export const CATEGORY = ["House", "Apartment", "Condo","Land"];
const LAND_TYPES = ["Residential", "Commercial", "Agricultural"];
const HOUSE_TYPES = ["Single Family", "Multi Family", "Townhouse"];
const APARTMENT_TYPES = ["Studio", "Loft", "Duplex"];
const CONDO_TYPES = ["High Rise", "Low Rise", "Mid Rise"];
export const LAND_TYPES = ["Residential", "Commercial", "Agricultural"];
export const HOUSE_TYPES = ["Single Family", "Multi Family", "Townhouse"];
export const APARTMENT_TYPES = ["Studio", "Loft", "Duplex"];
export const CONDO_TYPES = ["High Rise", "Low Rise", "Mid Rise"];
export const handleChangePropertyType = (type, setPropertyType) => {
switch (type) {
case "House":
setPropertyType(HOUSE_TYPES);
break;
case "Apartment":
setPropertyType(APARTMENT_TYPES);
break;
case "Condo":
setPropertyType(CONDO_TYPES);
break;
case "Land":
setPropertyType(LAND_TYPES);
break;
default:
setPropertyType(HOUSE_TYPES);
break;
}
};

const AddProperty = () => {
const [propertyType, setPropertyType] = React.useState(HOUSE_TYPES);
Expand All @@ -34,25 +53,7 @@ const AddProperty = () => {
const [imageKeys, setImageKeys] = React.useState([]);
const [latLong, setLatLong] = React.useState(null);
const navigate = useNavigate();
const handleChangePropertyType = (type) => {
switch (type) {
case "House":
setPropertyType(HOUSE_TYPES);
break;
case "Apartment":
setPropertyType(APARTMENT_TYPES);
break;
case "Condo":
setPropertyType(CONDO_TYPES);
break;
case "Land":
setPropertyType(LAND_TYPES);
break;
default:
setPropertyType(HOUSE_TYPES);
break;
}
};

const PropertySchema = z.object({
type: z.string(),
title: z.string().min(3).max(150),
Expand Down Expand Up @@ -226,7 +227,7 @@ const AddProperty = () => {
<Form.Label>category</Form.Label>
<select
{...register("category")}
onChange={(e) => handleChangePropertyType(e.target.value)}
onChange={(e) => handleChangePropertyType(e.target.value, setPropertyType)}
className="form-select"
>
{CATEGORY.map((type, index) => {
Expand Down Expand Up @@ -321,7 +322,7 @@ const AddProperty = () => {

export default AddProperty;

const Map = ({ set }) => {
export const Map = ({ set, center = defaultCenter }) => {
const [map, setMap] = useState(null);
const [latLong, setLatLong] = useState(null);

Expand Down Expand Up @@ -360,14 +361,14 @@ const Map = ({ set }) => {
);
};

const center = [41.023248, -91.966827];
const defaultCenter = [41.023248, -91.966827];
const zoom = 15;

function DisplayPosition({ map, setLatLong }) {
const [position, setPosition] = useState(() => map.getCenter());

const onClick = useCallback(() => {
map.setView(center, zoom);
map.setView(defaultCenter, zoom);
}, [map]);

const onMove = useCallback(() => {
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/PropertyDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Alert,
} from "react-bootstrap";
import { MdOutlineLocalOffer } from "react-icons/md";
import { useParams } from "react-router-dom";
import { Link, Navigate, useParams } from "react-router-dom";
import { useQuery } from "react-query";
import Loading from "../components/Loading";
import { formatMoney } from "../utils/money";
Expand Down Expand Up @@ -93,9 +93,16 @@ const PropertyDetail = () => {
? "success"
: "danger"
}>{data.offerStatus}</Badge>

<div className="mt-4">
{
isOwner ? "": (
isOwner ? (
<Link to={"/update-property"}>
<Button className="w-25" variant="primary">
Edit
</Button>
</Link>
): (
<Button
variant="primary"
onClick={() => {
Expand Down
Loading

0 comments on commit 2fc7e1e

Please sign in to comment.