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." });
}
};

View File

@ -1,10 +1,11 @@
import express from "express";
const router = express.Router();
import { login } from "../controllers/admin.js"
import { adminUser, login } from "../controllers/admin.js"
router.post("/login", login);
router.get('/username', adminUser);
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-->
<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">
</head>

View File

@ -10,7 +10,7 @@ import PrivateRoute from "./components/PrivateRoute";
import VerifyUser from "./components/EmailVerify";
import ForgotPassword from "./components/ForgotPassword";
import ResetPassword from "./components/ResetPassword";
// import Addproperty from "./components/Addproperty";
import Addproperty from "./components/Addproperty";
import Registrationsuccess from "./components/Registrationsuccess";
import PropertyView from "./components/PropertyView";
import SearchMysqlProperties from "./components/SearchMysqlProperties";
@ -22,6 +22,7 @@ import ProfileView from "./components/ProfileView";
import AdminLogin from "./components/admin/AdminLogin";
import ProtectedRoute from "./components/admin/ProtectedRoute";
import AdminDashboard from "./components/admin/Dashboard";
import AdminInfo from "./components/admin/admininfo";
const App = () => {
return (
@ -61,7 +62,7 @@ const App = () => {
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="/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>
</BrowserRouter>
);

View File

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

View File

@ -11,7 +11,7 @@ const ProfileView = () => {
const { userId } = useParams(); // Extract the userId from the route
const dispatch = useDispatch();
const { user, loading } = useSelector((state) => state.user); // Access the loading state as well
console.log("user", user);
// console.log("user", user);
useEffect(() => {
// Fetch the user by ID when the component loads
@ -201,10 +201,7 @@ const ProfileView = () => {
me :
</h1>{" "}
<hr />
{user.aboutme}
</div>
</div>
</div>

View File

@ -109,7 +109,7 @@ const UserProperties = () => {
</button>
</NavLink>
<NavLink to={`/editproperty/${property.propertyId}`}>
<NavLink to={`/admineditproperty/${property.propertyId}`}>
<button
className="btn btn-outline-primary btn-sm mt-2"
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({
name: "user",
initialState: {
@ -55,19 +57,15 @@ const userSlice = createSlice({
state.loading = true;
state.error = null;
})
.addCase(verifyEmail.fulfilled, (state, action) => {
state.loading = false;
state.verified = action.payload === "Email verified successfully";
// state.verified = true;
})
.addCase(verifyEmail.rejected, (state, action) => {
state.loading = false;
state.error = action.error.message;
});
},
});

View File

@ -3,6 +3,7 @@ import AuthReducer from "./features/authSlice";
import userReducer from "./features/userSlice";
import propertyReducer from "./features/propertySlice";
import fundDetailsReducer from "./features/fundSlice";
import adminReducer from "./features/adminSlice"
@ -12,7 +13,7 @@ export default configureStore({
user: userReducer,
property: propertyReducer,
fundDetails: fundDetailsReducer,
admin:adminReducer,
},
});