diff --git a/fe/src/components/PropertyAdd.js b/fe/src/components/PropertyAdd.js
index 47aa5f3..123ff2b 100644
--- a/fe/src/components/PropertyAdd.js
+++ b/fe/src/components/PropertyAdd.js
@@ -26,9 +26,13 @@ const PropertyAdd = () => {
apiRequest('PUT', '/property', { data: form, headers: { ...getAuthHeader() } })
.then((res) => {
console.log('Property added!', res.data);
+ alert('Property added!');
+ location.href = location.origin + '/property/list';
})
.catch((err) => {
console.error('There was an error adding the property!', err);
+ alert('There was an error adding the property!');
+ location.href = location.origin + '/property/list';
});
};
diff --git a/fe/src/components/PropertyDetail.js b/fe/src/components/PropertyDetail.js
index 0a0bcc0..c001a0b 100644
--- a/fe/src/components/PropertyDetail.js
+++ b/fe/src/components/PropertyDetail.js
@@ -10,6 +10,8 @@ import Header from "./Header";
const PropertyDetail = () => {
const [detail, setDetail] = useState([]);
+ const [whichView, setWhichView] = useState('show');
+
const getDetail = () => {
apiRequest('GET', location.pathname, { headers: { ...getAuthHeader() } })
.then((res) => {
@@ -24,16 +26,14 @@ const PropertyDetail = () => {
const handleLike = () => {
};
- const handleInterested = () => {
- return (
-
-
Name: {detail.user.firstName} {detail.user.lastName}
-
-
Email Address: {detail.user.email}
-
-
Phone Number: {detail.user.phoneNumber}
-
- );
+ const handleInterested = (e) => {
+ e.preventDefault();
+ if (sessionStorage.getItem('role') == null) {
+ alert('Please Login!');
+ location.href = location.origin + '/login';
+ }
+ setWhichView("user");
+ //location.reload();
};
const handleChange = (e) => {
@@ -43,14 +43,20 @@ const PropertyDetail = () => {
});
};
- const handleSubmit = (e) => {
+ const handleUpdate = (e) => {
e.preventDefault();
apiRequest('POST', location.pathname, { data: detail, headers: { ...getAuthHeader() } })
.then((res) => {
- console.log('Property updated!', res.data);
+ console.log("Property updated!", res.data);
+ alert("Property updated!");
+ setWhichView("show");
+ location.reload();
})
.catch((err) => {
- console.error('There was an error updating the property!', err);
+ console.error("There was an error updating the property!", err);
+ alert("There was an error updating the property!");
+ setWhichView("show");
+ location.reload();
});
};
@@ -58,41 +64,14 @@ const PropertyDetail = () => {
getDetail();
}, []);
- const editProperty = () => {
- return (
-
- );
+ const handleEdit = () => {
+ setWhichView("edit");
+ //location.reload();
};
- const deleteProperty = (e) => {
+ const handleDelete = (e) => {
e.preventDefault();
- apiRequest('DELETE', location.pathname, { headers: { ...getAuthHeader() } })
+ apiRequest("DELETE", location.pathname, { headers: { ...getAuthHeader() } })
.then((res) => {
console.log("Property deleted!", res.data);
alert("Property deleted!");
@@ -105,35 +84,89 @@ const PropertyDetail = () => {
});
};
- return (
-
-
-
Title: {detail.title}
-
-
Description: {detail.description}
-
-
Location: {detail.location}
-
-
Bedrooms: {detail.bedrooms}
-
-
Bathrooms: {detail.bathrooms}
-
-
Rent: {detail.rent}
-
- { (sessionStorage.getItem('role') === 'buyer')
- ? (
+ const renderView = () => {
+ if (whichView === 'show') {
+ return (
+
+
Title: {detail.title}
+
+
Description: {detail.description}
+
+
Location: {detail.location}
+
+
Bedrooms: {detail.bedrooms}
+
+
Bathrooms: {detail.bathrooms}
+
+
Rent: {detail.rent}
+
+ {(sessionStorage.getItem("role") === "seller")
+ ? (
+
+
+
+
+ )
+ : (
+
+
+
+
+ )
+ }
+
+ );
+ } else {
+ if (whichView === "edit") {
+ return (
- )
- : (
+ );
+ } else {
+ return (
-
-
+
Name: {detail.seller.firstName} {detail.seller.lastName}
+
+
Email Address: {detail.seller.email}
+
+
Phone Number: {detail.seller.phoneNumber}
- )
+ );
}
+ }
+ }
+
+ return (
+
+
+ {renderView()}
);
};