done
This commit is contained in:
parent
d02de3dafa
commit
5a1f3d8e7a
|
@ -1,47 +0,0 @@
|
||||||
|
|
||||||
import FundDetailsModal from "../models/fundDetails.js"
|
|
||||||
|
|
||||||
|
|
||||||
export const submitFundDetails = async (req, res) => {
|
|
||||||
|
|
||||||
const { propertyOwnerId, investorId, investmentAmount, ownershipPercentage, propertyId } = req.body;
|
|
||||||
|
|
||||||
const newFundDetail = new FundDetailsModal({
|
|
||||||
propertyOwnerId,
|
|
||||||
investorId,
|
|
||||||
investmentAmount,
|
|
||||||
ownershipPercentage,
|
|
||||||
propertyId
|
|
||||||
});
|
|
||||||
console.log("newFundDetail", newFundDetail)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const savedFundDetail = await newFundDetail.save();
|
|
||||||
res.status(201).json(savedFundDetail);
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getFundDetailsById = async (req, res) => {
|
|
||||||
const { id } = req.params;
|
|
||||||
try {
|
|
||||||
const fundDetails = await FundDetailsModal.findOne({ propertyId: id });
|
|
||||||
if (!fundDetails) {
|
|
||||||
return res.status(404).json({ message: "Fund details not found" });
|
|
||||||
}
|
|
||||||
res.status(200).json(fundDetails);
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAllFunds = async (req, res) => {
|
|
||||||
try {
|
|
||||||
// const allFunds = await FundDetailsModal.find();
|
|
||||||
const allFunds = await FundDetailsModal.findOne();
|
|
||||||
res.status(200).json(allFunds);
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ message: "Server error" });
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -80,10 +80,8 @@ export const getPropertyById = async (req, res) => {
|
||||||
export const updatePropertyById = async (req, res) => {
|
export const updatePropertyById = async (req, res) => {
|
||||||
const { id } = req.params; // This should be the propertyId
|
const { id } = req.params; // This should be the propertyId
|
||||||
const updateData = req.body;
|
const updateData = req.body;
|
||||||
const fundDetails=req.body
|
|
||||||
|
|
||||||
console.log("Received propertyId:", id); // Log the received propertyId
|
const { fundValue, fundPercentage } = req.body;
|
||||||
console.log("fundDetails", fundDetails);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find the property by propertyId instead of _id
|
// Find the property by propertyId instead of _id
|
||||||
|
@ -93,6 +91,17 @@ export const updatePropertyById = async (req, res) => {
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Push the new fund details into the existing fundDetails array
|
||||||
|
updatedProperty.fundDetails.push({
|
||||||
|
fundValue,
|
||||||
|
fundPercentage,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Save the updated document
|
||||||
|
await updatedProperty.save();
|
||||||
|
|
||||||
|
console.log("Received propertyId:", updatedProperty); // Log the received propertyId
|
||||||
|
|
||||||
if (!updatedProperty) {
|
if (!updatedProperty) {
|
||||||
return res.status(404).json({ message: "Property not found" });
|
return res.status(404).json({ message: "Property not found" });
|
||||||
}
|
}
|
||||||
|
@ -104,6 +113,72 @@ export const updatePropertyById = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Function to update fundDetails
|
||||||
|
export const addFundDetails = async (req, res) => {
|
||||||
|
const { id } = req.params; // This should be the propertyId
|
||||||
|
const { fundValue, fundPercentage } = req.body;
|
||||||
|
|
||||||
|
console.log("d", id, { fundValue, fundPercentage });
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Change findById to findOne with the correct field name
|
||||||
|
const property = await PropertyModal.findOne({ propertyId: id });
|
||||||
|
|
||||||
|
if (!property) {
|
||||||
|
return res.status(404).json({ message: 'Property not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new fund detail
|
||||||
|
const newFundDetail = {
|
||||||
|
fundValue,
|
||||||
|
fundPercentage,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add new fund detail to fundDetails array
|
||||||
|
property.fundDetails.push(newFundDetail);
|
||||||
|
|
||||||
|
// Save updated property
|
||||||
|
await property.save();
|
||||||
|
|
||||||
|
// Return success response with updated property
|
||||||
|
res.status(200).json({ message: 'Fund details added', property });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error adding fund details:", error); // Log error for debugging
|
||||||
|
res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Getting funds from the DB
|
||||||
|
export const getFundDetails = async (req, res) => {
|
||||||
|
const { id } = req.params; // Property ID
|
||||||
|
|
||||||
|
try {
|
||||||
|
const property = await PropertyModal.findOne({ propertyId: id }, 'fundDetails');
|
||||||
|
|
||||||
|
if (!property) {
|
||||||
|
return res.status(404).json({ message: 'Property not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return fund details
|
||||||
|
res.status(200).json({ fundDetails: property.fundDetails });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching fund details:", error);
|
||||||
|
res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// export const getProperties = async (req, res) => {
|
// export const getProperties = async (req, res) => {
|
||||||
// try {
|
// try {
|
||||||
// const properties = await PropertyModal.find(); // Fetch all properties from MongoDB
|
// const properties = await PropertyModal.find(); // Fetch all properties from MongoDB
|
||||||
|
|
|
@ -7,7 +7,6 @@ import session from "express-session";
|
||||||
import userRouter from "./routes/user.js";
|
import userRouter from "./routes/user.js";
|
||||||
import propertyRouter from "./routes/property.js";
|
import propertyRouter from "./routes/property.js";
|
||||||
import mysqlRouter from "./routes/mysqlproperty.js";
|
import mysqlRouter from "./routes/mysqlproperty.js";
|
||||||
import fundDetailsRouter from "./routes/fundDetails.js";
|
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
@ -35,7 +34,6 @@ app.use(
|
||||||
app.use("/users", userRouter);
|
app.use("/users", userRouter);
|
||||||
app.use("/properties", propertyRouter);
|
app.use("/properties", propertyRouter);
|
||||||
app.use("/mysql", mysqlRouter); // Use MySQL routes
|
app.use("/mysql", mysqlRouter); // Use MySQL routes
|
||||||
app.use("/fundDetails", fundDetailsRouter);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
|
|
||||||
import mongoose from "mongoose";
|
|
||||||
|
|
||||||
const fundDetailsSchema = new mongoose.Schema({
|
|
||||||
propertyOwnerId: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
investorId: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
investmentAmount: {
|
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
ownershipPercentage: {
|
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
propertyId:{
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
status: { type: Boolean, default: false },
|
|
||||||
}, { timestamps: true });
|
|
||||||
|
|
||||||
const FundDetailsModal = mongoose.model("FundDetails", fundDetailsSchema);
|
|
||||||
export default FundDetailsModal;
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ const propertyTaxInfoSchema = mongoose.Schema({
|
||||||
taxyear: { type: String },
|
taxyear: { type: String },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Schema for images
|
// Schema for images
|
||||||
const imageSchema = mongoose.Schema({
|
const imageSchema = mongoose.Schema({
|
||||||
title: { type: String }, // Title of the image
|
title: { type: String }, // Title of the image
|
||||||
|
@ -302,7 +303,18 @@ const propertySchema = mongoose.Schema({
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true, // Set to true if this field is mandatory
|
required: true, // Set to true if this field is mandatory
|
||||||
},
|
},
|
||||||
fundDetails:[],
|
fundDetails: [
|
||||||
|
{
|
||||||
|
fundValue: {
|
||||||
|
type: Number, // Adjust type if needed (String or Number)
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
fundPercentage: {
|
||||||
|
type: Number, // Adjust type if needed
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const PropertyModal = mongoose.model("property", propertySchema);
|
const PropertyModal = mongoose.model("property", propertySchema);
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
import express from 'express';
|
|
||||||
const router = express.Router();
|
|
||||||
import { submitFundDetails, getFundDetailsById } from '../controllers/fundDetails.js';
|
|
||||||
import { getAllFunds } from '../controllers/fundDetails.js';
|
|
||||||
|
|
||||||
|
|
||||||
router.post('/', submitFundDetails);
|
|
||||||
router.get("/allFunds", getAllFunds);
|
|
||||||
router.get("/:id", getFundDetailsById);
|
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
|
|
@ -1,12 +1,22 @@
|
||||||
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, getPropertyById, updatePropertyById, getProperties} from '../controllers/property.js';
|
import {
|
||||||
|
createProperty,
|
||||||
|
getUserProperties,
|
||||||
|
getPropertyById,
|
||||||
|
updatePropertyById,
|
||||||
|
getProperties,
|
||||||
|
addFundDetails,
|
||||||
|
getFundDetails,
|
||||||
|
} 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);
|
router.get("/:propertyId", getPropertyById);
|
||||||
router.put("/:id", updatePropertyById);
|
router.put("/:id", updatePropertyById);
|
||||||
router.get('/', getProperties);
|
router.get("/", getProperties);
|
||||||
|
router.put("/:id/fund-details", addFundDetails);
|
||||||
|
router.get("/:id/fund-details", getFundDetails);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -3,8 +3,8 @@ const router = express.Router();
|
||||||
|
|
||||||
import { signup, signin, verifyUser, showUser, forgotPassword, resetPassword, updateUser } from "../controllers/user.js";
|
import { signup, signin, verifyUser, showUser, forgotPassword, resetPassword, updateUser } from "../controllers/user.js";
|
||||||
|
|
||||||
router.post("/signin", signin);
|
|
||||||
router.post("/signup", signup);
|
router.post("/signup", signup);
|
||||||
|
router.post("/signin", signin);
|
||||||
router.get('/:id/verify/:token/', verifyUser);
|
router.get('/:id/verify/:token/', verifyUser);
|
||||||
router.get('/:userId', showUser);
|
router.get('/:userId', showUser);
|
||||||
router.post("/forgotpassword", forgotPassword);
|
router.post("/forgotpassword", forgotPassword);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script type="module" crossorigin src="/assets/index-CrKcgQxs.js"></script>
|
<script type="module" crossorigin src="/assets/index-DLb2856w.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-iEl-il0E.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-iEl-il0E.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -6,50 +6,58 @@ import propertydummy from "../img/propertydummy.jpg";
|
||||||
import Navbar from "./Navbar";
|
import Navbar from "./Navbar";
|
||||||
import Footer from "./Footer";
|
import Footer from "./Footer";
|
||||||
import { Modal, Button, Form } from "react-bootstrap"; // Importing Modal components
|
import { Modal, Button, Form } from "react-bootstrap"; // Importing Modal components
|
||||||
import {
|
import { addFundDetails } from "../redux/features/propertySlice";
|
||||||
submitFundDetails,
|
import { toast } from "react-toastify";
|
||||||
getFundDetailsById,
|
import { fetchFundDetails} from "../redux/features/fundSlice";
|
||||||
} from "../redux/features/fundDetailsSlice";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
const PropertyView = () => {
|
const PropertyView = () => {
|
||||||
const { id } = useParams(); // Extract the property ID from the route
|
const { id } = useParams(); // Extract the property ID from the route
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
|
||||||
const { selectedProperty, status, error } = useSelector(
|
const { selectedProperty, status, error } = useSelector(
|
||||||
(state) => state.property
|
(state) => state.property
|
||||||
);
|
);
|
||||||
const { user } = useSelector((state) => ({ ...state.auth }));
|
const { user } = useSelector((state) => ({ ...state.auth }));
|
||||||
const { fundDetails } = useSelector((state) => state.fundDetails);
|
|
||||||
|
|
||||||
console.log("funddetails", fundDetails);
|
// This also works !!
|
||||||
|
// const fundDetails = useSelector(selectFundDetails);
|
||||||
|
// console.log("fundDetailsa", fundDetails)
|
||||||
|
|
||||||
|
const {fundDetails} = useSelector((state) => state.fundDetails);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchFundDetails(id));
|
||||||
|
}, [dispatch, id]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState("propertydetails");
|
const [activeTab, setActiveTab] = useState("propertydetails");
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true); // Loader state
|
const [loading, setLoading] = useState(true); // Loader state
|
||||||
const [showModal, setShowModal] = useState(false); // Modal state
|
const [showModal, setShowModal] = useState(false); // Modal state
|
||||||
const [fundValue, setFundValue] = useState(""); // Fund value state
|
|
||||||
const [fundPercentage, setFundPercentage] = useState(""); // Fund percentage state
|
const [formData, setFormData] = useState({
|
||||||
|
fundValue: "0",
|
||||||
|
fundPercentage: "0",
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id) {
|
if (id) {
|
||||||
dispatch(fetchPropertyById(id));
|
dispatch(fetchPropertyById(id));
|
||||||
dispatch(getFundDetailsById(id));
|
|
||||||
}
|
}
|
||||||
}, [id, dispatch]);
|
}, [id, dispatch]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchFundDetails(id));
|
||||||
|
}, [dispatch, id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (status === "succeeded") {
|
if (status === "succeeded") {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [status]);
|
}, [status]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (fundDetails) {
|
|
||||||
setFundValue(fundDetails.investmentAmount);
|
|
||||||
setFundPercentage(fundDetails.ownershipPercentage);
|
|
||||||
}
|
|
||||||
}, [fundDetails]);
|
|
||||||
|
|
||||||
// if (status === "loading") {
|
// if (status === "loading") {
|
||||||
// return <p>Loading property details...</p>;
|
// return <p>Loading property details...</p>;
|
||||||
// }
|
// }
|
||||||
|
@ -70,24 +78,24 @@ const PropertyView = () => {
|
||||||
setShowModal(false); // Close the modal
|
setShowModal(false); // Close the modal
|
||||||
};
|
};
|
||||||
|
|
||||||
// Inside your PropertyView component
|
const handleChange = (e) => {
|
||||||
const handleSubmit = (e) => {
|
const { name, value } = e.target;
|
||||||
e.preventDefault();
|
setFormData({
|
||||||
if (fundValue <= 0 || fundPercentage <= 0 || fundPercentage > 100) {
|
...formData,
|
||||||
alert("Please enter valid values.");
|
[name]: value,
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
const fundDetails = {
|
|
||||||
propertyOwnerId: selectedProperty?.userId,
|
|
||||||
investorId: user?.result?.userId,
|
|
||||||
investmentAmount: fundValue,
|
|
||||||
ownershipPercentage: fundPercentage,
|
|
||||||
propertyId: selectedProperty?.propertyId || "defaultId", // Add a fallback
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch(submitFundDetails({ fundDetails, id, navigate }));
|
const handleSubmit = (e) => {
|
||||||
handleCloseModal(); // Close modal after submission
|
e.preventDefault();
|
||||||
|
|
||||||
|
const fundDetails = {
|
||||||
|
fundValue: Number(formData.fundValue), // Ensure number conversion if needed
|
||||||
|
fundPercentage: Number(formData.fundPercentage),
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatch(addFundDetails({ id, fundDetails, toast }));
|
||||||
|
handleCloseModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -381,18 +389,44 @@ const PropertyView = () => {
|
||||||
<div>
|
<div>
|
||||||
{activeTab === "Funding Details" && (
|
{activeTab === "Funding Details" && (
|
||||||
<div className="tab-pane active">
|
<div className="tab-pane active">
|
||||||
{fundDetails ? (
|
|
||||||
<div>
|
<div>
|
||||||
<p>Investment Amount: ${fundDetails.investmentAmount}</p>
|
{selectedProperty.fundDetails.length === 0 ? (
|
||||||
<p>
|
<p>No fund details available.</p>
|
||||||
Ownership Percentage: {fundDetails.ownershipPercentage}%
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<p>No funding details available.</p>
|
<ul>
|
||||||
|
{selectedProperty.fundDetails.map((detail, index) => (
|
||||||
|
<li key={index}>
|
||||||
|
Fund Value: {detail.fundValue}, Fund Percentage: {detail.fundPercentage}%
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
{fundDetails.length === 0 ? (
|
||||||
|
<p>No fund details available.</p>
|
||||||
|
) : (
|
||||||
|
<ul>
|
||||||
|
{fundDetails.map((detail, index) => (
|
||||||
|
<li key={index}>
|
||||||
|
Fund Value: {detail.fundValue}, Fund Percentage: {detail.fundPercentage}%
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -401,6 +435,7 @@ const PropertyView = () => {
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
{/* Modal for Investment/Funding */}
|
{/* Modal for Investment/Funding */}
|
||||||
|
{/* Modal for Investment/Funding */}
|
||||||
<Modal show={showModal} onHide={handleCloseModal}>
|
<Modal show={showModal} onHide={handleCloseModal}>
|
||||||
<Modal.Header closeButton>
|
<Modal.Header closeButton>
|
||||||
<Modal.Title>Investment/Funding Details</Modal.Title>
|
<Modal.Title>Investment/Funding Details</Modal.Title>
|
||||||
|
@ -411,16 +446,20 @@ const PropertyView = () => {
|
||||||
<Form.Label>Fund Value</Form.Label>
|
<Form.Label>Fund Value</Form.Label>
|
||||||
<Form.Control
|
<Form.Control
|
||||||
type="number"
|
type="number"
|
||||||
value={fundValue}
|
id="fundValue"
|
||||||
onChange={(e) => setFundValue(e.target.value)}
|
name="fundValue" // Added the name attribute
|
||||||
|
value={formData.fundValue}
|
||||||
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Group>
|
<Form.Group>
|
||||||
<Form.Label>Fund Percentage</Form.Label>
|
<Form.Label>Fund Percentage</Form.Label>
|
||||||
<Form.Control
|
<Form.Control
|
||||||
type="number"
|
type="number"
|
||||||
value={fundPercentage}
|
id="fundPercentage"
|
||||||
onChange={(e) => setFundPercentage(e.target.value)}
|
name="fundPercentage" // Added the name attribute
|
||||||
|
value={formData.fundPercentage}
|
||||||
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Button variant="primary" type="submit">
|
<Button variant="primary" type="submit">
|
||||||
|
|
|
@ -25,9 +25,9 @@ export const submitProperty = (propertyData) => API.post("/properties", property
|
||||||
export const fetchUserProperties = (userId, page, limit) => API.get( `/properties/user/${userId}?page=${page}&limit=${limit}`, userId);
|
export const fetchUserProperties = (userId, page, limit) => API.get( `/properties/user/${userId}?page=${page}&limit=${limit}`, userId);
|
||||||
export const fetchPropertyById = (id) => API.get(`/properties/${id}`, id);
|
export const fetchPropertyById = (id) => API.get(`/properties/${id}`, id);
|
||||||
export const updateProperty = (id, propertyData) => API.put(`/properties/${id}`, propertyData);
|
export const updateProperty = (id, propertyData) => API.put(`/properties/${id}`, propertyData);
|
||||||
|
|
||||||
export const showUser = (userId) => API.get(`/users/${userId}`);
|
export const showUser = (userId) => API.get(`/users/${userId}`);
|
||||||
export const submitFundDetails = (fundDetailsArray) => API.post(`/fundDetails`, fundDetailsArray);
|
|
||||||
export const getFundDetailsById = (fundDetails) => API.post(`/fundDetails`, fundDetails);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ export const register = createAsyncThunk(
|
||||||
async ({ formValue, navigate, toast }, { rejectWithValue }) => {
|
async ({ formValue, navigate, toast }, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
const response = await api.signUp(formValue);
|
const response = await api.signUp(formValue);
|
||||||
|
console.log("response", response)
|
||||||
toast.success("Register Successfully");
|
toast.success("Register Successfully");
|
||||||
navigate("/registrationsuccess");
|
navigate("/registrationsuccess");
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
||||||
import * as api from "../api";
|
|
||||||
import { toast } from "react-toastify"; // Import toast here
|
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export const submitFundDetails = createAsyncThunk(
|
|
||||||
"fundDetails/submit",
|
|
||||||
async ({ fundDetails,id,navigate }, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const response = await api.submitFundDetails(fundDetails, id);
|
|
||||||
toast.success("Details submitted successfully"); // Show toast on success
|
|
||||||
navigate(`/property/${id}`); // Navigate after successful submission
|
|
||||||
return response.data; // Assuming you return JSON data
|
|
||||||
} catch (error) {
|
|
||||||
toast.error("Failed to submit details"); // Show error toast
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
export const getFundDetailsById = createAsyncThunk(
|
|
||||||
"fundDetails/getFundDetailsById",
|
|
||||||
async (id, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const response = await axios.get(`http://localhost:3002/fundDetails/${id}`);
|
|
||||||
return response.data;
|
|
||||||
} catch (error) {
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
const fundDetailsSlice = createSlice({
|
|
||||||
name: "fundDetails",
|
|
||||||
initialState: {
|
|
||||||
fundDetails: null,
|
|
||||||
status: null,
|
|
||||||
error: null,
|
|
||||||
},
|
|
||||||
reducers: {},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
.addCase(getFundDetailsById.pending, (state) => {
|
|
||||||
state.status = "loading";
|
|
||||||
})
|
|
||||||
.addCase(getFundDetailsById.fulfilled, (state, action) => {
|
|
||||||
state.status = "succeeded";
|
|
||||||
state.fundDetails = action.payload;
|
|
||||||
})
|
|
||||||
.addCase(getFundDetailsById.rejected, (state, action) => {
|
|
||||||
state.status = "failed";
|
|
||||||
state.error = action.payload;
|
|
||||||
})
|
|
||||||
.addCase(submitFundDetails.fulfilled, (state, action) => {
|
|
||||||
state.fundDetails = action.payload;
|
|
||||||
})
|
|
||||||
.addCase(submitFundDetails.rejected, (state, action) => {
|
|
||||||
state.error = action.payload;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default fundDetailsSlice.reducer;
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
// fundDetailsSlice.js
|
||||||
|
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export const fetchFundDetails = createAsyncThunk(
|
||||||
|
'fundDetails/fetchFundDetails',
|
||||||
|
async (id, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`http://localhost:3002/properties/${id}/fund-details`);
|
||||||
|
return response.data.fundDetails;
|
||||||
|
} catch (error) {
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const fundDetailsSlice = createSlice({
|
||||||
|
name: 'fundDetails',
|
||||||
|
initialState: {
|
||||||
|
fundDetails: [],
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
},
|
||||||
|
reducers: {},
|
||||||
|
extraReducers: (builder) => {
|
||||||
|
builder
|
||||||
|
.addCase(fetchFundDetails.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
})
|
||||||
|
.addCase(fetchFundDetails.fulfilled, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
state.fundDetails = action.payload;
|
||||||
|
})
|
||||||
|
.addCase(fetchFundDetails.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
state.error = action.payload;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const selectFundDetails = (state) => state.fundDetails.fundDetails;
|
||||||
|
export const selectLoading = (state) => state.fundDetails.loading;
|
||||||
|
export const selectError = (state) => state.fundDetails.error;
|
||||||
|
|
||||||
|
export default fundDetailsSlice.reducer;
|
|
@ -58,14 +58,27 @@ export const updateProperty = createAsyncThunk(
|
||||||
try {
|
try {
|
||||||
const response = await api.updateProperty(id, propertyData);
|
const response = await api.updateProperty(id, propertyData);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return rejectWithValue(error.response.data);
|
return rejectWithValue(error.response.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const addFundDetails = createAsyncThunk(
|
||||||
|
'property/addFundDetails',
|
||||||
|
async ({ id, fundDetails, toast }, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await axios.put(
|
||||||
|
`http://localhost:3002/properties/${id}/fund-details`,
|
||||||
|
fundDetails);
|
||||||
|
toast.success("Submitted Successfully");
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
return rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// export const getProperties = createAsyncThunk("property/getProperties", async () => {
|
// export const getProperties = createAsyncThunk("property/getProperties", async () => {
|
||||||
|
@ -168,9 +181,17 @@ const propertySlice = createSlice({
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
state.error = action.error.message;
|
state.error = action.error.message;
|
||||||
})
|
})
|
||||||
|
.addCase(addFundDetails.pending, (state) => {
|
||||||
|
state.loading = true;
|
||||||
;
|
})
|
||||||
|
.addCase(addFundDetails.fulfilled, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
state.property = action.payload.property;
|
||||||
|
})
|
||||||
|
.addCase(addFundDetails.rejected, (state, action) => {
|
||||||
|
state.loading = false;
|
||||||
|
state.error = action.payload;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,17 @@ import { configureStore } from "@reduxjs/toolkit";
|
||||||
import AuthReducer from "./features/authSlice";
|
import AuthReducer from "./features/authSlice";
|
||||||
import userReducer from "./features/userSlice";
|
import userReducer from "./features/userSlice";
|
||||||
import propertyReducer from "./features/propertySlice";
|
import propertyReducer from "./features/propertySlice";
|
||||||
import fundReducer from "./features/fundDetailsSlice"
|
import fundDetailsReducer from "./features/fundSlice";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default configureStore({
|
export default configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
auth: AuthReducer,
|
auth: AuthReducer,
|
||||||
user: userReducer,
|
user: userReducer,
|
||||||
property: propertyReducer,
|
property: propertyReducer,
|
||||||
fundDetails:fundReducer,
|
fundDetails: fundDetailsReducer,
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue