done
This commit is contained in:
parent
74ab432012
commit
b054298296
|
@ -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' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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." });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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 />} />
|
||||||
|
@ -90,6 +91,22 @@ const App = () => {
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<Route path="/AdminPLogin/admininfo" element={ <ProtectedRoute><AdminInfo /></ProtectedRoute>} />
|
||||||
|
|
||||||
|
<Route
|
||||||
|
path="/admineditproperty/:id"
|
||||||
|
element={
|
||||||
|
|
||||||
|
<EditProperty />
|
||||||
|
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
|
|
|
@ -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" && (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -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
|
||||||
|
@ -201,10 +201,7 @@ const ProfileView = () => {
|
||||||
me :
|
me :
|
||||||
</h1>{" "}
|
</h1>{" "}
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
{user.aboutme}
|
{user.aboutme}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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;
|
|
@ -42,3 +42,6 @@ export const investFunds = (formData) => API.patch(`/users/invest`, formData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
@ -24,6 +24,8 @@ export const verifyEmail = createAsyncThunk(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const userSlice = createSlice({
|
const userSlice = createSlice({
|
||||||
name: "user",
|
name: "user",
|
||||||
initialState: {
|
initialState: {
|
||||||
|
@ -55,19 +57,15 @@ const userSlice = createSlice({
|
||||||
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;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue