Merge pull request 'Worked on the Charge stations section according to the figma design' (#11) from dev-bansh into develop

Reviewed-on: DigiMantra/digiev_frontend#11
This commit is contained in:
Mohit kalshan 2025-02-25 07:03:33 +00:00
commit 4c63007072
9 changed files with 786 additions and 180 deletions

BIN
public/Bell.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,008 B

BIN
public/avatar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

View file

@ -1,63 +1,89 @@
import * as React from "react";
import Stack from "@mui/material/Stack";
import NotificationsRoundedIcon from "@mui/icons-material/NotificationsRounded";
import CustomDatePicker from "../CustomDatePicker";
import NavbarBreadcrumbs from "../NavbarBreadcrumbs";
import MenuButton from "../MenuButton";
import ColorModeIconDropdown from "../../shared-theme/ColorModeIconDropdown";
import Avatar from "@mui/material/Avatar";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import Search from "../Search";
import InputBase from "@mui/material/InputBase";
import SearchIcon from "@mui/icons-material/Search";
import Divider from "@mui/material/Divider";
import MenuButton from "../MenuButton";
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
export default function Header() {
const [showNotifications, setShowNotifications] = React.useState(false);
const toggleNotifications = () => {
setShowNotifications((prev) => !prev);
};
return (
<Stack
direction="row"
<Box
sx={{
display: { xs: "none", md: "flex" },
width: "100%",
alignItems: { xs: "flex-start", md: "center" },
height: "84px",
backgroundColor: "#202020",
padding: "20px 24px",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
maxWidth: { sm: "100%", md: "1700px" },
pt: 1.5,
}}
spacing={2}
>
<NavbarBreadcrumbs />
<Stack direction="row" sx={{ gap: 1 }}>
<Search />
<CustomDatePicker />
<MenuButton
showBadge
aria-label="Open notifications"
onClick={toggleNotifications}
>
<NotificationsRoundedIcon />
</MenuButton>
<ColorModeIconDropdown />
</Stack>
{showNotifications && (
<Box sx={{ flexGrow: 1 }} />
<Stack
direction="row"
spacing={3}
alignItems="center"
justifyContent="flex-end"
>
{/* Search Bar */}
<Box
sx={{
p: 2,
position: "absolute",
top: "55px", // Adjust this value according to your AppBar height
right: "66px",
bgcolor: "lightblue",
boxShadow: 1,
borderRadius: 1,
zIndex: 1300,
width: "360px",
height: "44px",
backgroundColor: "#303030",
borderRadius: "8px",
border: "1px solid #424242",
display: "flex",
alignItems: "center",
padding: "0 12px",
}}
>
<Typography variant="body2" color="text.secondary">
No notifications yet
</Typography>
<SearchIcon sx={{ color: "#FFFFFF" }} />
<InputBase
sx={{ marginLeft: 1, flex: 1, color: "#FFFFFF" }}
/>
</Box>
)}
</Stack>
{/* Notification and Profile Section */}
<Stack direction="row" spacing={2} alignItems="center">
<MenuButton
onClick={toggleNotifications}
aria-label="Open notifications"
>
{/* Custom Bell Icon */}
<Box
component="img"
src="/Bell.jpg"
alt="Notification Icon"
sx={{ width: 24, height: 24 }}
/>
</MenuButton>
<Divider flexItem sx={{ backgroundColor: "#424242" }} />
<Stack direction="row" spacing={1.5} alignItems="center">
<Avatar
alt="User Avatar"
src="/avatar.png"
sx={{ width: 36, height: 36 }}
/>
<Typography variant="body1" sx={{ color: "#FFFFFF" }}>
Momah
</Typography>
{/* Dropdown Icon */}
<ArrowDropDownIcon
sx={{ color: "#FFFFFF", width: 16, height: 16 }}
/>
</Stack>
</Stack>
</Stack>
</Box>
);
}

View file

@ -22,7 +22,11 @@ const baseMenuItems = [
icon: <AnalyticsRoundedIcon />,
url: "/panel/admin-list",
},
{
text: "Users",
icon: <AnalyticsRoundedIcon />,
url: "/panel/user-list",
},
];
//Eknoor singh and Jaanvi

View file

@ -1,159 +1,355 @@
import React, { useEffect, useState } from "react";
import { Box, Button, Typography } from "@mui/material";
import AddEditCategoryModal from "../../components/AddEditCategoryModal";
import { useForm } from "react-hook-form";
import CustomTable, { Column } from "../../components/CustomTable";
import { useDispatch, useSelector } from "react-redux";
import { useEffect, useState } from "react";
import {
adminList,
updateAdmin,
createAdmin,
} from "../../redux/slices/adminSlice";
Box,
Button,
Typography,
TextField,
InputAdornment,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Pagination,
IconButton,
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
import TuneIcon from "@mui/icons-material/Tune";
import { useDispatch, useSelector } from "react-redux";
import { adminList } from "../../redux/slices/adminSlice";
import { AppDispatch, RootState } from "../../redux/store/store";
export default function AdminList() {
const [modalOpen, setModalOpen] = useState(false);
const { reset } = useForm();
const [deleteModal, setDeleteModal] = React.useState<boolean>(false);
const [viewModal, setViewModal] = React.useState<boolean>(false);
const [rowData, setRowData] = React.useState<any | null>(null);
const [searchQuery, setSearchQuery] = useState("");
const [currentPage, setCurrentPage] = useState(1);
const adminsPerPage = 10;
const dispatch = useDispatch<AppDispatch>();
const admins = useSelector((state: RootState) => state.adminReducer.admins);
useEffect(() => {
dispatch(adminList());
}, [dispatch]);
const handleClickOpen = () => {
setRowData(null); // Reset row data when opening for new admin
setModalOpen(true);
};
const handleCloseModal = () => {
setModalOpen(false);
setRowData(null);
reset();
};
const handleCreate = async (data: {
name: string;
email: string;
phone: string;
registeredAddress: string;
}) => {
try {
await dispatch(createAdmin(data));
await dispatch(adminList()); // Refresh the list after creation
handleCloseModal();
} catch (error) {
console.error("Creation failed", error);
}
};
const handleUpdate = async (
id: string,
name: string,
email: string,
phone: string,
registeredAddress: string
) => {
try {
await dispatch(
updateAdmin({
id,
name,
email,
phone,
registeredAddress,
})
);
await dispatch(adminList());
} catch (error) {
console.error("Update failed", error);
}
};
const categoryColumns: Column[] = [
{ id: "srno", label: "Sr No" },
{ id: "name", label: "Name" },
{ id: "email", label: "Email" },
{ id: "phone", label: "Phone" },
{ id: "registeredAddress", label: "Address" },
{ id: "action", label: "Action", align: "center" },
const staticAdmins = [
{
name: "John Doe",
location: "New York",
managerAssigned: "Alice Johnson",
vehicle: "Tesla Model S",
phone: "+1 234 567 8901",
},
{
name: "Jane Smith",
location: "Los Angeles",
managerAssigned: "Bob Brown",
vehicle: "Ford F-150",
phone: "+1 987 654 3210",
},
{
name: "Michael Brown",
location: "Chicago",
managerAssigned: "Sarah Lee",
vehicle: "Chevrolet Bolt",
phone: "+1 312 555 7890",
},
{
name: "Emily Davis",
location: "Houston",
managerAssigned: "Tom Wilson",
vehicle: "Nissan Leaf",
phone: "+1 713 444 5678",
},
{
name: "Daniel Martinez",
location: "Phoenix",
managerAssigned: "Jessica White",
vehicle: "BMW i3",
phone: "+1 602 999 4321",
},
{
name: "Sophia Miller",
location: "Philadelphia",
managerAssigned: "Mark Adams",
vehicle: "Audi e-tron",
phone: "+1 215 777 6543",
},
{
name: "James Anderson",
location: "San Antonio",
managerAssigned: "Emma Thomas",
vehicle: "Hyundai Kona EV",
phone: "+1 210 321 8765",
},
{
name: "James Anderson",
location: "San Antonio",
managerAssigned: "Emma Thomas",
vehicle: "Hyundai Kona EV",
phone: "+1 210 321 8765",
},
];
const categoryRows = admins?.length
? admins?.map(
(
admin: {
id: string;
name: string;
email: string;
phone: string;
registeredAddress: string;
},
index: number
) => ({
id: admin?.id,
srno: index + 1,
name: admin?.name,
email: admin?.email,
phone: admin?.phone,
registeredAddress: admin?.registeredAddress,
})
)
: [];
const adminData = admins.length ? admins : staticAdmins;
const filteredAdmins = adminData.filter((admin) =>
admin.name.toLowerCase().includes(searchQuery.toLowerCase())
);
const indexOfLastAdmin = currentPage * adminsPerPage;
const indexOfFirstAdmin = indexOfLastAdmin - adminsPerPage;
const currentAdmins = filteredAdmins.slice(
indexOfFirstAdmin,
indexOfLastAdmin
);
const handlePageChange = (event, value) => {
setCurrentPage(value);
};
return (
<>
<Box
sx={{
width: "calc(100% - 48px)",
margin: "0 auto",
padding: "24px",
backgroundColor: "#1C1C1C",
borderRadius: "12px",
}}
>
<Typography
sx={{
color: "#FFFFFF",
fontWeight: 500,
fontSize: "18px",
fontFamily: "Gilroy",
}}
>
Charge stations
</Typography>
{/* Search & Buttons Section */}
<Box
sx={{
width: "100%",
maxWidth: {
sm: "100%",
display: "flex",
gap: "16px",
marginTop: "16px",
alignItems: "center",
fontFamily: "Gilroy",
}}
>
<TextField
variant="outlined"
placeholder="Search Charge stations"
sx={{
width: "422px",
backgroundColor: "#272727",
borderRadius: "12px",
input: { color: "#FFFFFF" },
"& .MuiOutlinedInput-root": {
borderRadius: "12px",
"& fieldset": { borderColor: "#FFFFFF" },
"&:hover fieldset": { borderColor: "#FFFFFF" },
"&.Mui-focused fieldset": {
borderColor: "#52ACDF",
},
},
}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<SearchIcon sx={{ color: "#FFFFFF" }} />
</InputAdornment>
),
}}
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
},
justifyContent: "flex-end",
width: "100%",
}}
>
<Button
sx={{
backgroundColor: "#52ACDF",
color: "white",
borderRadius: "8px",
width: "184px",
"&:hover": {
backgroundColor: "#439BC1",
},
}}
>
Add Charge Stations
</Button>
</Box>
<IconButton
sx={{
width: "44px",
height: "44px",
borderRadius: "8px",
backgroundColor: "#272727",
color: "#52ACDF",
"&:hover": { backgroundColor: "#333333" },
}}
>
<TuneIcon />
</IconButton>
</Box>
{/* Table Section */}
<TableContainer
component={Paper}
sx={{
marginTop: "24px",
backgroundColor: "#1C1C1C",
borderRadius: "12px",
overflow: "hidden",
}}
>
<Table>
<TableHead sx={{ backgroundColor: "#272727" }}>
<TableRow>
{[
"Name",
"Location",
"Manager Assigned",
"Vehicle",
"Phone Number",
"Action",
].map((header) => (
<TableCell
key={header}
sx={{
color: "#FFFFFF",
fontWeight: "bold",
}}
>
{header}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{currentAdmins.map((admin, index) => (
<TableRow
key={index}
sx={{ backgroundColor: "#1C1C1C" }}
>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{admin.name}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{admin.location || "N/A"}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{admin.managerAssigned || "N/A"}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{admin.vehicle || "N/A"}{" "}
<Typography
component="span"
sx={{
color: "#52ACDF",
cursor: "pointer",
textDecoration: "none",
"&:hover": {
textDecoration: "underline",
},
}}
>
+6 more
</Typography>
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{admin.phone}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
<IconButton size="small">
<MoreHorizIcon
sx={{ color: "#FFFFFF" }}
/>
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
{/* Pagination */}
<Box
sx={{
display: "flex",
justifyContent: "flex-end",
alignItems: "center",
marginTop: "16px",
width: "100%",
gap: "8px",
}}
>
<Typography
component="h2"
variant="h6"
sx={{ mt: 2, fontWeight: 600 }}
sx={{ color: "white", fontSize: "16px", fontWeight: 500 }}
>
Admins
Page Number :
</Typography>
<Button
variant="contained"
size="medium"
sx={{ textAlign: "right" }}
onClick={handleClickOpen}
>
Add Admin
</Button>
<Pagination
count={Math.ceil(filteredAdmins.length / adminsPerPage)}
page={currentPage}
onChange={handlePageChange}
siblingCount={0}
boundaryCount={0}
sx={{
"& .MuiPaginationItem-root": {
color: "white",
borderRadius: "0px",
},
"& .MuiPaginationItem-page.Mui-selected": {
backgroundColor: "transparent",
fontWeight: "bold",
color: "#FFFFFF",
},
}}
/>
</Box>
<CustomTable
columns={categoryColumns}
rows={categoryRows}
setDeleteModal={setDeleteModal}
deleteModal={deleteModal}
setViewModal={setViewModal}
viewModal={viewModal}
setRowData={setRowData}
setModalOpen={setModalOpen}
/>
<AddEditCategoryModal
open={modalOpen}
handleClose={handleCloseModal}
handleCreate={handleCreate}
handleUpdate={handleUpdate}
editRow={rowData}
/>
</>
</Box>
);
}

View file

@ -0,0 +1,313 @@
import { useEffect, useState } from "react";
import {
Box,
Button,
Typography,
TextField,
InputAdornment,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Pagination,
IconButton,
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
import TuneIcon from "@mui/icons-material/Tune";
import { useDispatch, useSelector } from "react-redux";
import { userList } from "../../redux/slices/userSlice"; // Make sure userSlice exists
import { AppDispatch, RootState } from "../../redux/store/store";
export default function UserList() {
const [searchQuery, setSearchQuery] = useState("");
const [currentPage, setCurrentPage] = useState(1);
const usersPerPage = 10;
const dispatch = useDispatch<AppDispatch>();
const users = useSelector((state: RootState) => state.userReducer.users);
useEffect(() => {
dispatch(userList());
}, [dispatch]);
const staticUsers = [
{
name: "Alice Johnson",
email: "alice@example.com",
role: "User",
phone: "+1 234 567 8901",
},
{
name: "Bob Brown",
email: "bob@example.com",
role: "Admin",
phone: "+1 987 654 3210",
},
{
name: "Charlie Davis",
email: "charlie@example.com",
role: "User",
phone: "+1 312 555 7890",
},
{
name: "Alice Johnson",
email: "alice@example.com",
role: "User",
phone: "+1 234 567 8901",
},
{
name: "Bob Brown",
email: "bob@example.com",
role: "Admin",
phone: "+1 987 654 3210",
},
{
name: "Charlie Davis",
email: "charlie@example.com",
role: "User",
phone: "+1 312 555 7890",
},
{
name: "Bob Brown",
email: "bob@example.com",
role: "Admin",
phone: "+1 987 654 3210",
},
{
name: "Charlie Davis",
email: "charlie@example.com",
role: "User",
phone: "+1 312 555 7890",
},
];
const userData = users.length ? users : staticUsers;
const filteredUsers = userData.filter((user) =>
user.name.toLowerCase().includes(searchQuery.toLowerCase())
);
const indexOfLastUser = currentPage * usersPerPage;
const indexOfFirstUser = indexOfLastUser - usersPerPage;
const currentUsers = filteredUsers.slice(indexOfFirstUser, indexOfLastUser);
const handlePageChange = (event, value) => {
setCurrentPage(value);
};
return (
<Box
sx={{
width: "calc(100% - 48px)",
margin: "0 auto",
padding: "24px",
backgroundColor: "#1C1C1C",
borderRadius: "12px",
}}
>
<Typography
sx={{
color: "#FFFFFF",
fontWeight: 500,
fontSize: "18px",
fontFamily: "Gilroy",
}}
>
User List
</Typography>
{/* Search & Buttons Section */}
<Box
sx={{
display: "flex",
gap: "16px",
marginTop: "16px",
alignItems: "center",
fontFamily: "Gilroy",
}}
>
<TextField
variant="outlined"
placeholder="Search Users"
sx={{
width: "422px",
backgroundColor: "#272727",
borderRadius: "12px",
input: { color: "#FFFFFF" },
"& .MuiOutlinedInput-root": {
borderRadius: "12px",
"& fieldset": { borderColor: "#FFFFFF" },
"&:hover fieldset": { borderColor: "#FFFFFF" },
"&.Mui-focused fieldset": {
borderColor: "#52ACDF",
},
},
}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<SearchIcon sx={{ color: "#FFFFFF" }} />
</InputAdornment>
),
}}
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
<Box
sx={{
display: "flex",
justifyContent: "flex-end",
width: "100%",
}}
>
<Button
sx={{
backgroundColor: "#52ACDF",
color: "white",
borderRadius: "8px",
width: "184px",
"&:hover": { backgroundColor: "#439BC1" },
}}
>
Add User
</Button>
</Box>
<IconButton
sx={{
width: "44px",
height: "44px",
borderRadius: "8px",
backgroundColor: "#272727",
color: "#52ACDF",
"&:hover": { backgroundColor: "#333333" },
}}
>
<TuneIcon />
</IconButton>
</Box>
{/* Table Section */}
<TableContainer
component={Paper}
sx={{
marginTop: "24px",
backgroundColor: "#1C1C1C",
borderRadius: "12px",
overflow: "hidden",
}}
>
<Table>
<TableHead sx={{ backgroundColor: "#272727" }}>
<TableRow>
{["Name", "Email", "Role", "Phone", "Action"].map(
(header) => (
<TableCell
key={header}
sx={{
color: "#FFFFFF",
fontWeight: "bold",
}}
>
{header}
</TableCell>
)
)}
</TableRow>
</TableHead>
<TableBody>
{currentUsers.map((user, index) => (
<TableRow
key={index}
sx={{ backgroundColor: "#1C1C1C" }}
>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{user.name}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{user.email}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{user.role}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
{user.phone}
</TableCell>
<TableCell
sx={{
color: "#FFFFFF",
borderBottom: "1px solid #2A2A2A",
}}
>
<IconButton size="small">
<MoreHorizIcon
sx={{ color: "#FFFFFF" }}
/>
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
{/* Pagination */}
<Box
sx={{
display: "flex",
justifyContent: "flex-end",
alignItems: "center",
marginTop: "16px",
}}
>
<Typography
sx={{ color: "white", fontSize: "16px", fontWeight: 500 }}
>
Page Number :
</Typography>
<Pagination
count={Math.ceil(filteredUsers.length / usersPerPage)}
page={currentPage}
onChange={handlePageChange}
siblingCount={0}
boundaryCount={0}
sx={{
"& .MuiPaginationItem-root": {
color: "white",
borderRadius: "0px",
},
"& .MuiPaginationItem-page.Mui-selected": {
backgroundColor: "transparent",
fontWeight: "bold",
color: "#FFFFFF",
},
}}
/>
</Box>
</Box>
);
}

View file

@ -3,11 +3,13 @@ import { combineReducers } from "@reduxjs/toolkit";
import authReducer from "./slices/authSlice";
import adminReducer from "./slices/adminSlice";
import profileReducer from "./slices/profileSlice";
import userReducer from "./slices/userSlice.ts";
const rootReducer = combineReducers({
authReducer,
adminReducer,
profileReducer
profileReducer,
userReducer,
});
export type RootState = ReturnType<typeof rootReducer>;

View file

@ -0,0 +1,59 @@
import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
import axios from "axios";
// Define TypeScript types
interface User {
id: number;
name: string;
email: string;
phone?: string;
location?: string;
managerAssigned?: string;
vehicle?: string;
}
interface UserState {
users: User[];
loading: boolean;
error: string | null;
}
// Initial state
const initialState: UserState = {
users: [],
loading: false,
error: null,
};
// Async thunk to fetch user list
export const userList = createAsyncThunk<User[]>("users/fetchUsers", async () => {
try {
const response = await axios.get<User[]>("/api/users"); // Adjust the API endpoint as needed
return response.data;
} catch (error: any) {
throw new Error(error.response?.data?.message || "Failed to fetch users");
}
});
const userSlice = createSlice({
name: "users",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(userList.pending, (state) => {
state.loading = true;
state.error = null;
})
.addCase(userList.fulfilled, (state, action: PayloadAction<User[]>) => {
state.loading = false;
state.users = action.payload;
})
.addCase(userList.rejected, (state, action) => {
state.loading = false;
state.error = action.error.message || "Failed to fetch users";
});
},
});
export default userSlice.reducer;

View file

@ -1,8 +1,4 @@
import {
Routes as BaseRoutes,
Navigate,
Route,
} from "react-router-dom";
import { Routes as BaseRoutes, Navigate, Route } from "react-router-dom";
import React, { lazy, Suspense } from "react";
import LoadingComponent from "./components/Loading";
import DashboardLayout from "./layouts/DashboardLayout";
@ -15,6 +11,7 @@ const Vehicles = lazy(() => import("./pages/Vehicles"));
const AdminList = lazy(() => import("./pages/AdminList"));
const ProfilePage = lazy(() => import("./pages/ProfilePage"));
const NotFoundPage = lazy(() => import("./pages/NotFound"));
const UserList = lazy(() => import("./pages/UserList"));
interface ProtectedRouteProps {
caps: string[];
@ -77,6 +74,15 @@ export default function AppRouter() {
/>
}
/>
<Route
path="user-list"
element={
<ProtectedRoute
caps={[]}
component={<UserList />}
/>
}
/>
<Route
path="profile"
@ -90,7 +96,7 @@ export default function AppRouter() {
</Route>
{/* Catch-all Route */}
<Route path="*" element={<NotFoundPage/>} />
<Route path="*" element={<NotFoundPage />} />
</BaseRoutes>
</Suspense>
);