This commit is contained in:
omkieit 2024-11-07 20:59:39 +05:30
parent 74ab432012
commit b054298296
14 changed files with 170 additions and 51 deletions

View File

@ -28,5 +28,22 @@ export const login = async (req, res) => {
}; };
//To show Admin user
export const adminUser = async (req, res) => {
try {
const user = await adminModal.findOne({ username: "admin" });
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
return res.json(user);
} catch (error) {
return res.status(500).json({ message: 'Server Error' });
}
};

View File

@ -266,3 +266,10 @@ export const investFunds = async (req, res) => {
res.status(500).json({ message: "Something went wrong." }); res.status(500).json({ message: "Something went wrong." });
} }
}; };

View File

@ -1,10 +1,11 @@
import express from "express"; import express from "express";
const router = express.Router(); const router = express.Router();
import { login } from "../controllers/admin.js" import { adminUser, login } from "../controllers/admin.js"
router.post("/login", login); router.post("/login", login);
router.get('/username', adminUser);
export default router; export default router;

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,7 @@
<!-- Custom styles for this template--> <!-- Custom styles for this template-->
<link href="css/sb-admin-2.min.css" rel="stylesheet"> <link href="css/sb-admin-2.min.css" rel="stylesheet">
<script type="module" crossorigin src="/assets/index-C07R3o0W.js"></script> <script type="module" crossorigin src="/assets/index-BCe6aC64.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BH_0_em5.css"> <link rel="stylesheet" crossorigin href="/assets/index-BH_0_em5.css">
</head> </head>

View File

@ -10,7 +10,7 @@ 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"; import PropertyView from "./components/PropertyView";
import SearchMysqlProperties from "./components/SearchMysqlProperties"; import SearchMysqlProperties from "./components/SearchMysqlProperties";
@ -22,6 +22,7 @@ import ProfileView from "./components/ProfileView";
import AdminLogin from "./components/admin/AdminLogin"; import AdminLogin from "./components/admin/AdminLogin";
import ProtectedRoute from "./components/admin/ProtectedRoute"; import ProtectedRoute from "./components/admin/ProtectedRoute";
import AdminDashboard from "./components/admin/Dashboard"; import AdminDashboard from "./components/admin/Dashboard";
import AdminInfo from "./components/admin/admininfo";
const App = () => { const App = () => {
return ( return (
@ -61,7 +62,7 @@ const App = () => {
element={<ResetPassword />} element={<ResetPassword />}
/> />
{/* <Route path="/addproperty" element={ <PrivateRoute><Addproperty /></PrivateRoute>}></Route> */} <Route path="/addproperty" element={ <PrivateRoute><Addproperty /></PrivateRoute>}></Route>
<Route path="/property/:id" element={<PropertyView />} /> <Route path="/property/:id" element={<PropertyView />} />
<Route path="/properties/:house_id" element={<PropertyMysqlView />} /> <Route path="/properties/:house_id" element={<PropertyMysqlView />} />
@ -89,6 +90,22 @@ const App = () => {
} }
/> />
<Route path="/AdminPLogin/admininfo" element={ <ProtectedRoute><AdminInfo /></ProtectedRoute>} />
<Route
path="/admineditproperty/:id"
element={
<EditProperty />
}
/>
</Routes> </Routes>
</BrowserRouter> </BrowserRouter>

View File

@ -172,6 +172,17 @@ const Dashboard = () => {
{user.result.middleName} {user.result.lastName} {user.result.middleName} {user.result.lastName}
</NavLink> </NavLink>
</span> </span>
<span style={{ color: "#067ADC" }}>
<NavLink
to={`/addproperty`}
className="link-primary text-decoration-none"
>
add
</NavLink>
</span>
</span> </span>
{activeTab === "dashboard" && ( {activeTab === "dashboard" && (
<> <>

View File

@ -11,7 +11,7 @@ const ProfileView = () => {
const { userId } = useParams(); // Extract the userId from the route const { userId } = useParams(); // Extract the userId from the route
const dispatch = useDispatch(); const dispatch = useDispatch();
const { user, loading } = useSelector((state) => state.user); // Access the loading state as well const { user, loading } = useSelector((state) => state.user); // Access the loading state as well
console.log("user", user); // console.log("user", user);
useEffect(() => { useEffect(() => {
// Fetch the user by ID when the component loads // Fetch the user by ID when the component loads
@ -40,16 +40,16 @@ const ProfileView = () => {
<div className="card"> <div className="card">
<div className="card-body"> <div className="card-body">
<div className="d-flex flex-column align-items-center text-center"> <div className="d-flex flex-column align-items-center text-center">
<img <img
className="img-fluid" className="img-fluid"
src={user.profileImage || profilepic} src={user.profileImage || profilepic}
alt="ProfileImage" alt="ProfileImage"
style={{ style={{
marginTop: "0px", marginTop: "0px",
maxWidth: "300px", maxWidth: "300px",
maxHeight: "300px", maxHeight: "300px",
}} }}
/> />
<h4> <h4>
{user.title}. {user.firstName} {user.middleName}{" "} {user.title}. {user.firstName} {user.middleName}{" "}
@ -201,10 +201,7 @@ const ProfileView = () => {
me : me :
</h1>{" "} </h1>{" "}
<hr /> <hr />
{user.aboutme}
{user.aboutme}
</div> </div>
</div> </div>
</div> </div>

View File

@ -109,7 +109,7 @@ const UserProperties = () => {
</button> </button>
</NavLink> </NavLink>
<NavLink to={`/editproperty/${property.propertyId}`}> <NavLink to={`/admineditproperty/${property.propertyId}`}>
<button <button
className="btn btn-outline-primary btn-sm mt-2" className="btn btn-outline-primary btn-sm mt-2"
type="button" type="button"

View File

@ -0,0 +1,32 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchAdminUser } from '../../redux/features/adminSlice';
const AdminDetails = () => {
const dispatch = useDispatch();
const { adminuser, loading, error } = useSelector((state) => state.admin);
console.log("adminuser", adminuser)
useEffect(() => {
dispatch(fetchAdminUser());
}, [dispatch]);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
return (
<div>
{adminuser ? (
<div>
<p><strong>Username:</strong> {adminuser.username}</p>
{/* Add other fields here if available in the response */}
</div>
) : (
<p>No admin user details found. Thank you</p>
)}
</div>
);
};
export default AdminDetails;

View File

@ -42,3 +42,6 @@ export const investFunds = (formData) => API.patch(`/users/invest`, formData);

View File

@ -0,0 +1,35 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';
// Async thunk to fetch admin user details
export const fetchAdminUser = createAsyncThunk('admin/fetchAdminUser', async () => {
const response = await axios.get('http://localhost:3002/admin/username');
return response.data;
});
const adminSlice = createSlice({
name: 'admin',
initialState: {
user: null,
loading: false,
error: null,
},
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchAdminUser.pending, (state) => {
state.loading = true;
state.error = null;
})
.addCase(fetchAdminUser.fulfilled, (state, action) => {
state.loading = false;
state.user = action.payload;
})
.addCase(fetchAdminUser.rejected, (state, action) => {
state.loading = false;
state.error = action.error.message;
});
},
});
export default adminSlice.reducer;

View File

@ -24,6 +24,8 @@ export const verifyEmail = createAsyncThunk(
} }
); );
const userSlice = createSlice({ const userSlice = createSlice({
name: "user", name: "user",
initialState: { initialState: {
@ -51,23 +53,19 @@ const userSlice = createSlice({
state.loading = false; state.loading = false;
state.error = action.payload; state.error = action.payload;
}) })
.addCase(verifyEmail.pending, (state) => { .addCase(verifyEmail.pending, (state) => {
state.loading = true; state.loading = true;
state.error = null; state.error = null;
}) })
.addCase(verifyEmail.fulfilled, (state, action) => {
.addCase(verifyEmail.fulfilled, (state, action) => {
state.loading = false; state.loading = false;
state.verified = action.payload === "Email verified successfully"; state.verified = action.payload === "Email verified successfully";
// state.verified = true; // state.verified = true;
}) })
.addCase(verifyEmail.rejected, (state, action) => {
.addCase(verifyEmail.rejected, (state, action) => {
state.loading = false; state.loading = false;
state.error = action.error.message; state.error = action.error.message;
}); });
}, },
}); });

View File

@ -3,6 +3,7 @@ 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 fundDetailsReducer from "./features/fundSlice"; import fundDetailsReducer from "./features/fundSlice";
import adminReducer from "./features/adminSlice"
@ -12,7 +13,7 @@ export default configureStore({
user: userReducer, user: userReducer,
property: propertyReducer, property: propertyReducer,
fundDetails: fundDetailsReducer, fundDetails: fundDetailsReducer,
admin:adminReducer,
}, },
}); });