Skip to content

Commit

Permalink
Merge pull request #67 from vicheanath/update-property
Browse files Browse the repository at this point in the history
Update property
  • Loading branch information
vicheanath authored Feb 8, 2024
2 parents 2fc7e1e + df4cff0 commit d73789e
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 451 deletions.
6 changes: 3 additions & 3 deletions backend/pms/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ VALUES (
'House for Sell in Iowa',
'RENT',
'2024-02-07 00:29:48.576972',
3
2
),
(
'Land',
Expand All @@ -106,7 +106,7 @@ VALUES (
'Great Building Site Right off Hwy 34',
'RENT',
'2024-02-07 00:44:43.55343',
3
2
),
(
'House',
Expand All @@ -123,7 +123,7 @@ VALUES (
'1,000',
'RENT',
'2024-02-07 01:04:03.030894',
3
2
);


Expand Down
72 changes: 41 additions & 31 deletions frontend/src/components/Property.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MdFavoriteBorder, MdOutlineFavorite } from "react-icons/md";
import { Link } from "react-router-dom";
import { formatMoney } from "../utils/money";
import { api } from "../libs/api";
import { FiEdit2, FiEye } from "react-icons/fi";
const Property = ({
price,
numberOfRoom,
Expand All @@ -15,21 +16,23 @@ const Property = ({
favorite,
refetch,
viewOffer,
updateProperty,
unFav,
}) => {
const addFavorite = async (id) => {
api.post(`favorites/${id}`).then((res) => {
console.log(res);
refetch();
setIsFav(true);
});
};
const removeFavorite = (id) => {
api.delete(`favorites/${id}`).then((res) => {
console.log(res);
refetch();
setIsFav(false);
});
};

const [isFav, setIsFav] = useState(favorite);
const [isFav, setIsFav] = useState(favorite || unFav);

return (
<Card>
Expand All @@ -40,41 +43,48 @@ const Property = ({
</Link>
<Card.Text className="d-flex justify-content-between">
<span>Location: {location} </span>

</Card.Text>
<div className="d-flex justify-content-between">
<span>
<span className="me-3">
Rooms: {numberOfRoom}</span>
<Badge bg={
offerStatus === "PENDING"
? "warning"
: offerStatus === "APPROVED"
? "success"
: "danger"
}>{offerStatus}</Badge>
<span className="me-3">Rooms: {numberOfRoom}</span>
<Badge
bg={
offerStatus === "PENDING"
? "warning"
: offerStatus === "APPROVED"
? "success"
: "danger"
}
>
{offerStatus}
</Badge>
</span>


<Button
variant={isFav ? "danger" : "primary"}
onClick={() => {
isFav ? removeFavorite(id) : addFavorite(id);
refetch();
}}
>
{isFav ? <MdOutlineFavorite /> : <MdFavoriteBorder />}
</Button>
{
viewOffer && (
<div>
<Button
variant="secondary"
onClick={() => viewOffer(id)}
className="me-2"
variant={isFav ? "danger" : "primary"}
onClick={() => {
isFav ? removeFavorite(id) : addFavorite(id);
refetch();
}}
>
View Offer
{isFav ? <MdOutlineFavorite /> : <MdFavoriteBorder />}
</Button>
)
}
{updateProperty && (

<Link to={`/update-property/${id}`} className="btn btn-warning me-2">
<FiEdit2 />
</Link>
)}
{viewOffer && (
<Button
className="me-2"
variant="secondary" onClick={() => viewOffer(id)}>
<FiEye /> Offer
</Button>
)}

</div>
</div>
</Card.Body>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Favorite = () => {
{data.map((property) => {
return (
<Col md={4} key={property.id} className="mb-4">
<Property key={property.id} {...property} refetch={refetch}/>
<Property key={property.id} {...property} refetch={refetch} unFav={true} />
</Col>
)
})}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/MyProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const MyProperty = () => {
{...property}
refetch={refetch}
viewOffer={handleViewOffer}
updateProperty={true}
/>
</div>
);
Expand Down
50 changes: 21 additions & 29 deletions frontend/src/pages/PropertyDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import { api } from "../libs/api";

const PropertyDetail = () => {
const { id } = useParams();
const { user } = useSelector((state) => state.auth);
const isOwner = user?.roles.map((role) => role.role).includes("Owner");
console.log(isOwner);

const { data, isLoading, isError } = useQuery(`properties/${id}`);
const navigate = useNavigate();
const [show, setShow] = React.useState(false);
Expand Down Expand Up @@ -86,33 +84,27 @@ const PropertyDetail = () => {
<h3>{formatMoney(data.price)}</h3>
<p>{data.location}</p>
<p> Rooms: {data.numberOfRoom}</p>
Status :<Badge bg={
data.offerStatus === "PENDING"
? "warning"
: data.offerStatus === "APPROVED"
? "success"
: "danger"
}>{data.offerStatus}</Badge>

<div className="mt-4">
{
isOwner ? (
<Link to={"/update-property"}>
<Button className="w-25" variant="primary">
Edit
</Button>
</Link>
): (
<Button
variant="primary"
onClick={() => {
setShow(true);
}}
>
<MdOutlineLocalOffer /> Request Offer
</Button>
)
Status :
<Badge
bg={
data.offerStatus === "PENDING"
? "warning"
: data.offerStatus === "APPROVED"
? "success"
: "danger"
}
>
{data.offerStatus}
</Badge>
<div className="mt-4">
<Button
variant="primary"
onClick={() => {
setShow(true);
}}
>
<MdOutlineLocalOffer /> Request Offer
</Button>
</div>
</div>
</Col>
Expand Down
Loading

0 comments on commit d73789e

Please sign in to comment.