done
This commit is contained in:
parent
4b228bc5b5
commit
97e3d6c3ab
|
@ -31,6 +31,7 @@ export const createProperty = async (req, res) => {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fetch property by userId
|
||||||
export const getUserProperties = async (req, res) => {
|
export const getUserProperties = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.params.userId;
|
const userId = req.params.userId;
|
||||||
|
@ -40,3 +41,16 @@ export const getUserProperties = async (req, res) => {
|
||||||
res.status(500).json({ message: "Error retrieving properties", error });
|
res.status(500).json({ message: "Error retrieving properties", error });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Fetch property by ID
|
||||||
|
export const getPropertyById = async (req, res) => {
|
||||||
|
const { propertyId } = req.params;
|
||||||
|
try {
|
||||||
|
const property = await PropertyModal.findOne({ propertyId });
|
||||||
|
res.status(200).json(property);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(404).json({ message: "Something went wrong" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
import auth from '../middleware/auth.js';
|
import auth from '../middleware/auth.js';
|
||||||
import { createProperty, getUserProperties } from '../controllers/property.js';
|
import { createProperty, getUserProperties, getPropertyById } from '../controllers/property.js';
|
||||||
|
|
||||||
router.post('/', auth, createProperty);
|
router.post('/', auth, createProperty);
|
||||||
router.get('/user/:userId', getUserProperties);
|
router.get('/user/:userId', getUserProperties);
|
||||||
|
router.get('/:propertyId', getPropertyById);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -42,7 +42,7 @@
|
||||||
<!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script> -->
|
<!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script> -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
<script type="module" crossorigin src="/assets/index-CzVE7_Kd.js"></script>
|
<script type="module" crossorigin src="/assets/index-BVD7tRJW.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-BrT2kTNU.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-BrT2kTNU.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@ import PrivateRoute from "./components/PrivateRoute";
|
||||||
import VerifyUser from "./components/EmailVerify";
|
import VerifyUser from "./components/EmailVerify";
|
||||||
import ForgotPassword from "./components/ForgotPassword";
|
import ForgotPassword from "./components/ForgotPassword";
|
||||||
import ResetPassword from "./components/ResetPassword";
|
import ResetPassword from "./components/ResetPassword";
|
||||||
import Addproperty from "./components/Addproperty";
|
// import Addproperty from "./components/Addproperty";
|
||||||
import Registrationsuccess from "./components/Registrationsuccess";
|
import Registrationsuccess from "./components/Registrationsuccess";
|
||||||
|
import PropertyView from "./components/PropertyView";
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
|
@ -48,6 +49,9 @@ const App = () => {
|
||||||
|
|
||||||
{/* <Route path="/addproperty" element={ <PrivateRoute><Addproperty /></PrivateRoute>}></Route> */}
|
{/* <Route path="/addproperty" element={ <PrivateRoute><Addproperty /></PrivateRoute>}></Route> */}
|
||||||
|
|
||||||
|
<Route path="/property/:id" element={<PropertyView />} />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
import { useState,useEffect } from "react";
|
import { useState } from "react";
|
||||||
import Footer from "./Footer";
|
import Footer from "./Footer";
|
||||||
import Navbar from "./Navbar";
|
import Navbar from "./Navbar";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import profilepic from "../img/samplepic.jpg";
|
import profilepic from "../img/samplepic.jpg";
|
||||||
import Addproperty from "./Addproperty";
|
import Addproperty from "./Addproperty";
|
||||||
import { fetchUserProperties } from "../redux/features/propertySlice";
|
import UserProperties from "./UserProperties";
|
||||||
|
// import { fetchUserProperties } from "../redux/features/propertySlice";
|
||||||
import "../dashboard.css";
|
import "../dashboard.css";
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
const dispatch = useDispatch();
|
// const dispatch = useDispatch();
|
||||||
const { user } = useSelector((state) => ({ ...state.auth }));
|
const { user } = useSelector((state) => ({ ...state.auth }));
|
||||||
const { userProperties} = useSelector((state) => state.property);
|
// const { userProperties} = useSelector((state) => state.property);
|
||||||
const [activeTab, setActiveTab] = useState("dashboard");
|
const [activeTab, setActiveTab] = useState("dashboard");
|
||||||
|
|
||||||
// Fetch user properties when "Active Properties" tab is selected
|
// Fetch user properties when "Active Properties" tab is selected
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (activeTab === "activeProperties") {
|
// if (activeTab === "activeProperties") {
|
||||||
dispatch(fetchUserProperties(user?.result?.userId));
|
// dispatch(fetchUserProperties(user?.result?.userId));
|
||||||
}
|
// }
|
||||||
}, [activeTab, dispatch, user?.result?.userId]);
|
// }, [activeTab, dispatch, user?.result?.userId]);
|
||||||
|
|
||||||
const renderTabContent = () => {
|
const renderTabContent = () => {
|
||||||
switch (activeTab) {
|
switch (activeTab) {
|
||||||
|
@ -27,7 +28,7 @@ const Dashboard = () => {
|
||||||
case "activeProperties":
|
case "activeProperties":
|
||||||
return <div>
|
return <div>
|
||||||
<h3>Active Properties</h3>
|
<h3>Active Properties</h3>
|
||||||
{userProperties.length > 0 ? (
|
{/* {userProperties.length > 0 ? (
|
||||||
<ul>
|
<ul>
|
||||||
{userProperties.map((property) => (
|
{userProperties.map((property) => (
|
||||||
<li key={property._id}>{property.title}</li>
|
<li key={property._id}>{property.title}</li>
|
||||||
|
@ -35,7 +36,9 @@ const Dashboard = () => {
|
||||||
</ul>
|
</ul>
|
||||||
) : (
|
) : (
|
||||||
<p>No active properties found.</p>
|
<p>No active properties found.</p>
|
||||||
)}
|
)} */}
|
||||||
|
|
||||||
|
<UserProperties />
|
||||||
</div>;
|
</div>;
|
||||||
case "closedProperties":
|
case "closedProperties":
|
||||||
return <p>These are your closed properties.</p>;
|
return <p>These are your closed properties.</p>;
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { fetchPropertyById } from "../redux/features/propertySlice";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const PropertyView = () => {
|
||||||
|
const { id } = useParams(); // Extract the property ID from the route
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const { selectedProperty, status, error } = useSelector((state) => state.property);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Fetch the property by ID when the component loads
|
||||||
|
if (id) {
|
||||||
|
dispatch(fetchPropertyById(id));
|
||||||
|
}
|
||||||
|
}, [id, dispatch]);
|
||||||
|
|
||||||
|
if (status === "loading") {
|
||||||
|
return <p>Loading property details...</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === "failed") {
|
||||||
|
return <p>Error loading property: {error}</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("selectedProperty", selectedProperty);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
|
||||||
|
<div className="container property-view">
|
||||||
|
{selectedProperty ? (
|
||||||
|
<div className="property-details">
|
||||||
|
<h1>{selectedProperty.title}</h1>
|
||||||
|
|
||||||
|
<p>Email: {selectedProperty.useremail}</p>
|
||||||
|
{/* Add more property details as needed */}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p>Property not found.</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PropertyView;
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { fetchUserProperties } from "../redux/features/propertySlice";
|
||||||
|
import { NavLink } from "react-router-dom";
|
||||||
|
|
||||||
|
|
||||||
|
const UserProperties = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const { user } = useSelector((state) => ({ ...state.auth }));
|
||||||
|
const { userProperties} = useSelector((state) => state.property);
|
||||||
|
|
||||||
|
// Fetch user properties when "Active Properties" tab is selected
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
dispatch(fetchUserProperties(user?.result?.userId));
|
||||||
|
|
||||||
|
}, [dispatch, user?.result?.userId]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{userProperties.length > 0 ? (
|
||||||
|
<ul>
|
||||||
|
{userProperties.map((property) => (
|
||||||
|
<li key={property._id}>
|
||||||
|
<NavLink to={`/property/${property.propertyId}`} target="_blank">
|
||||||
|
{property.title}
|
||||||
|
{"....."}
|
||||||
|
</NavLink>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : (
|
||||||
|
<p>No active properties found.</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserProperties
|
|
@ -27,6 +27,18 @@ export const fetchUserProperties = createAsyncThunk(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const fetchPropertyById = createAsyncThunk(
|
||||||
|
"property/fetchPropertyById",
|
||||||
|
async (id, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`http://localhost:3002/properties/${id}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const propertySlice = createSlice({
|
const propertySlice = createSlice({
|
||||||
name: 'property',
|
name: 'property',
|
||||||
initialState: {
|
initialState: {
|
||||||
|
@ -34,6 +46,7 @@ const propertySlice = createSlice({
|
||||||
status: 'idle',
|
status: 'idle',
|
||||||
error: null,
|
error: null,
|
||||||
userProperties: [],
|
userProperties: [],
|
||||||
|
selectedProperty: null,
|
||||||
},
|
},
|
||||||
reducers: {},
|
reducers: {},
|
||||||
extraReducers: (builder) => {
|
extraReducers: (builder) => {
|
||||||
|
@ -60,6 +73,18 @@ const propertySlice = createSlice({
|
||||||
.addCase(fetchUserProperties.rejected, (state, action) => {
|
.addCase(fetchUserProperties.rejected, (state, action) => {
|
||||||
state.status = 'failed';
|
state.status = 'failed';
|
||||||
state.error = action.payload;
|
state.error = action.payload;
|
||||||
|
})
|
||||||
|
|
||||||
|
.addCase(fetchPropertyById.pending, (state) => {
|
||||||
|
state.status = "loading";
|
||||||
|
})
|
||||||
|
.addCase(fetchPropertyById.fulfilled, (state, action) => {
|
||||||
|
state.status = "succeeded";
|
||||||
|
state.selectedProperty = action.payload;
|
||||||
|
})
|
||||||
|
.addCase(fetchPropertyById.rejected, (state, action) => {
|
||||||
|
state.status = "failed";
|
||||||
|
state.error = action.payload;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue