dev-jaanvi #1

Open
jaanvi wants to merge 155 commits from dev-jaanvi into main
20 changed files with 173 additions and 144 deletions
Showing only changes of commit ef2e6a3b51 - Show all commits

View file

@ -14,7 +14,7 @@ import { useForm, Controller } from "react-hook-form";
import { import {
CustomIconButton, CustomIconButton,
CustomTextField, CustomTextField,
} from "../AddUserModel/styled.css.tsx"; } from "../AddEditUserModel/styled.css.tsx";
//By Jaanvi : Edit Model :: 11-feb-25 //By Jaanvi : Edit Model :: 11-feb-25
interface AddEditCategoryModalProps { interface AddEditCategoryModalProps {

View file

@ -30,7 +30,6 @@ interface AddUserModalProps {
id: string, id: string,
name: string, name: string,
email: string, email: string,
password: string,
phone: string, phone: string,
) => void; ) => void;
@ -50,24 +49,24 @@ const AddUserModal: React.FC<AddUserModalProps> = ({
handleSubmit, handleSubmit,
formState: { errors }, formState: { errors },
reset, reset,
setValue,
} = useForm<FormData>({ } = useForm<FormData>({
defaultValues: { defaultValues: {
name: "", name: "",
email: "", email: "",
password: "",
phone: "", phone: "",
}, },
}); });
// useEffect(() => {
// if (editRow) { useEffect(() => {
// setValue("name", editRow.name); if (editRow) {
// setValue("email", editRow.email); setValue("name", editRow.name);
// setValue("password", editRow.password); setValue("email", editRow.email);
// setValue("phone", editRow.phone); setValue("phone", editRow.phone);
// } else { } else {
// reset(); reset();
// } }
// }, [editRow, setValue, reset]); }, [editRow, setValue,reset]);
const onSubmit = (data: FormData) => { const onSubmit = (data: FormData) => {
if (editRow) { if (editRow) {
@ -75,7 +74,6 @@ const AddUserModal: React.FC<AddUserModalProps> = ({
editRow.id, editRow.id,
data.name, data.name,
data.email, data.email,
data.password,
data.phone data.phone
); );
} else { } else {
@ -234,7 +232,7 @@ const AddUserModal: React.FC<AddUserModalProps> = ({
{/* Second Row - Two Inputs */} {/* Second Row - Two Inputs */}
<Box sx={{ display: "flex", gap: 2 }}> <Box sx={{ display: "flex", gap: 2 }}>
<Box {!editRow && ( <Box
sx={{ sx={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
@ -304,7 +302,7 @@ const AddUserModal: React.FC<AddUserModalProps> = ({
/> />
)} )}
/> />
</Box> </Box>)}
<Box <Box
sx={{ sx={{
display: "flex", display: "flex",
@ -380,3 +378,7 @@ const AddUserModal: React.FC<AddUserModalProps> = ({
export default AddUserModal; export default AddUserModal;
function setValue(arg0: string, name: any) {
throw new Error("Function not implemented.");
}

View file

@ -14,7 +14,7 @@ import { addManager, managerList } from "../../redux/slices/managerSlice";
import { import {
CustomIconButton, CustomIconButton,
CustomTextField, CustomTextField,
} from "../AddUserModel/styled.css.tsx"; } from "../AddEditUserModel/styled.css.tsx";
import React, { useState, useRef } from "react"; import React, { useState, useRef } from "react";
export default function AddManagerModal({ export default function AddManagerModal({
@ -38,10 +38,9 @@ export default function AddManagerModal({
name: data.name, name: data.name,
email: data.email, email: data.email,
phone: data.phone, phone: data.phone,
registeredAddress: data.registeredAddress,
password: data.password, password: data.password,
stationId: data.stationId, // Send stationId here stationId: data.stationId, // Send stationId here
roleName: "Manager", // You can replace this with dynamic role if needed
}; };
try { try {
@ -274,26 +273,6 @@ export default function AddManagerModal({
/> />
</Box> </Box>
{/* Registered Address */}
<Box sx={{ flex: 1 }}>
<Typography variant="body2" fontWeight={500}>
Station Location
</Typography>
<CustomTextField
fullWidth
placeholder="Enter Registered Address"
size="small"
error={!!errors.registeredAddress}
helperText={
errors.registeredAddress
? errors.registeredAddress.message
: ""
}
{...register("registeredAddress", {
required: "Registered Address is required",
})}
/>
</Box>
</Box> </Box>
{/* Submit Button */} {/* Submit Button */}

View file

@ -4,7 +4,7 @@ import CloseIcon from "@mui/icons-material/Close";
import { import {
CustomIconButton, CustomIconButton,
CustomTextField, CustomTextField,
} from "../AddUserModel/styled.css.tsx"; // Assuming custom styled components } from "../AddEditUserModel/styled.css.tsx"; // Assuming custom styled components
export default function AddStationModal({ export default function AddStationModal({
open, open,
@ -125,7 +125,7 @@ export default function AddStationModal({
</Typography> </Typography>
<CustomTextField <CustomTextField
fullWidth fullWidth
placeholder="Enter Registered Address" placeholder="Enter Charging Station Address"
size="small" size="small"
error={!!errors.registeredAddress} error={!!errors.registeredAddress}
helperText={ helperText={

View file

@ -6,7 +6,10 @@ import {
Modal, Modal,
} from "@mui/material"; } from "@mui/material";
import CloseIcon from "@mui/icons-material/Close"; import CloseIcon from "@mui/icons-material/Close";
import { CustomIconButton, CustomTextField } from "../AddUserModel/styled.css.tsx"; import {
CustomIconButton,
CustomTextField,
} from "../AddEditUserModel/styled.css.tsx";
export default function AddVehicleModal({ export default function AddVehicleModal({
open, open,
handleClose, handleClose,

View file

@ -30,7 +30,7 @@ import VehicleViewModal from "../Modals/VehicleViewModal";
import SearchIcon from "@mui/icons-material/Search"; import SearchIcon from "@mui/icons-material/Search";
import TuneIcon from "@mui/icons-material/Tune"; import TuneIcon from "@mui/icons-material/Tune";
import { CustomIconButton } from "../AddUserModel/styled.css.tsx"; import { CustomIconButton } from "../AddEditUserModel/styled.css.tsx";
import ManagerViewModal from "../Modals/ViewManagerModal"; import ManagerViewModal from "../Modals/ViewManagerModal";
import UserViewModal from "../Modals/UserViewModal/index.tsx"; import UserViewModal from "../Modals/UserViewModal/index.tsx";
import { deleteUser, userList } from "../../redux/slices/userSlice.ts"; import { deleteUser, userList } from "../../redux/slices/userSlice.ts";

View file

@ -13,7 +13,7 @@ import { managerList, updateManager } from "../../redux/slices/managerSlice"; //
import { import {
CustomIconButton, CustomIconButton,
CustomTextField, CustomTextField,
} from "../AddUserModel/styled.css.tsx"; // Custom styled components } from "../AddEditUserModel/styled.css.tsx"; // Custom styled components
interface EditManagerModalProps { interface EditManagerModalProps {
open: boolean; open: boolean;
@ -25,6 +25,7 @@ interface FormData {
name: string; name: string;
email: string; email: string;
phone: string; phone: string;
stationId: string;
} }
const EditManagerModal: React.FC<EditManagerModalProps> = ({ const EditManagerModal: React.FC<EditManagerModalProps> = ({
@ -44,6 +45,7 @@ const EditManagerModal: React.FC<EditManagerModalProps> = ({
name: "", name: "",
email: "", email: "",
phone: "", phone: "",
stationId: "",
}, },
}); });
@ -55,6 +57,7 @@ const EditManagerModal: React.FC<EditManagerModalProps> = ({
setValue("name", editRow.name); setValue("name", editRow.name);
setValue("email", editRow.email); setValue("email", editRow.email);
setValue("phone", editRow.phone); setValue("phone", editRow.phone);
setValue("stationId", editRow.stationId);
} else { } else {
reset(); reset();
} }
@ -70,6 +73,8 @@ const EditManagerModal: React.FC<EditManagerModalProps> = ({
name: data.name, name: data.name,
email: data.email, email: data.email,
phone: data.phone, phone: data.phone,
stationId: data.stationId,
}, },
}) })
).unwrap(); // Ensure that it throws an error if the update fails ).unwrap(); // Ensure that it throws an error if the update fails
@ -212,6 +217,26 @@ const EditManagerModal: React.FC<EditManagerModalProps> = ({
)} )}
/> />
</Box> </Box>
{/* <Box sx={{ flex: "1 1 48%" }}>
<Typography variant="body2" fontWeight={500} mb={0.5}>
StationId
</Typography>
<Controller
name="stationId"
control={control}
rules={{ required: "StationId is required" }}
render={({ field }) => (
<CustomTextField
{...field}
fullWidth
placeholder="Enter Station Id"
size="small"
error={!!errors.stationId}
helperText={errors.stationId?.message}
/>
)}
/>
</Box> */}
</Box> </Box>
{/* Submit Button */} {/* Submit Button */}
@ -240,5 +265,4 @@ const EditManagerModal: React.FC<EditManagerModalProps> = ({
</Modal> </Modal>
); );
}; };
export default EditManagerModal; export default EditManagerModal;

View file

@ -5,7 +5,7 @@ import { useForm, Controller } from "react-hook-form";
import { import {
CustomIconButton, CustomIconButton,
CustomTextField, CustomTextField,
} from "../AddUserModel/styled.css.tsx"; } from "../AddEditUserModel/styled.css.tsx";
interface EditStationModalProps { interface EditStationModalProps {
open: boolean; open: boolean;
@ -15,7 +15,7 @@ interface EditStationModalProps {
name: string, name: string,
registeredAddress: string, registeredAddress: string,
totalSlots: number, totalSlots: number,
imageUrl: string status: number
) => void; ) => void;
editRow: any; editRow: any;
} }
@ -24,7 +24,7 @@ interface FormData {
name: string; name: string;
registeredAddress: string; registeredAddress: string;
totalSlots: number; totalSlots: number;
imageUrl: string; status: number;
} }
const EditStationModal: React.FC<EditStationModalProps> = ({ const EditStationModal: React.FC<EditStationModalProps> = ({
@ -44,7 +44,7 @@ const EditStationModal: React.FC<EditStationModalProps> = ({
name: "", name: "",
registeredAddress: "", registeredAddress: "",
totalSlots: 0, totalSlots: 0,
imageUrl: "", status: 1,
}, },
}); });
@ -54,7 +54,7 @@ const EditStationModal: React.FC<EditStationModalProps> = ({
setValue("name", editRow.name); setValue("name", editRow.name);
setValue("registeredAddress", editRow.registeredAddress); setValue("registeredAddress", editRow.registeredAddress);
setValue("totalSlots", editRow.totalSlots); setValue("totalSlots", editRow.totalSlots);
setValue("imageUrl", editRow.imageUrl); setValue("status", editRow.number);
} else { } else {
reset(); reset();
} }
@ -67,7 +67,7 @@ const EditStationModal: React.FC<EditStationModalProps> = ({
data.name, data.name,
data.registeredAddress, data.registeredAddress,
data.totalSlots, data.totalSlots,
data.imageUrl data.status
); );
} }
handleClose(); // Close the modal handleClose(); // Close the modal

View file

@ -11,7 +11,7 @@ import { updateVehicle } from "../../redux/slices/VehicleSlice";
import { import {
CustomIconButton, CustomIconButton,
CustomTextField, CustomTextField,
} from "../AddUserModel/styled.css.tsx"; } from "../AddEditUserModel/styled.css.tsx";
interface EditVehicleModalProps { interface EditVehicleModalProps {
open: boolean; open: boolean;
handleClose: () => void; handleClose: () => void;

View file

@ -35,6 +35,7 @@ export default function ManagerViewModal({ open, setViewModal, id }: Props) {
useEffect(() => { useEffect(() => {
if (id) { if (id) {
const manager = managers.find((manager) => manager.id === id); const manager = managers.find((manager) => manager.id === id);
setSelectedManager(manager || null); setSelectedManager(manager || null);
} }
@ -107,7 +108,7 @@ export default function ManagerViewModal({ open, setViewModal, id }: Props) {
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>
<Typography variant="body1"> <Typography variant="body1">
<strong>Registered Address:</strong> <strong>Station Location:</strong>
<Typography variant="body2"> <Typography variant="body2">
{selectedManager.registeredAddress} {selectedManager.registeredAddress}
</Typography> </Typography>

View file

@ -107,7 +107,8 @@ export default function ViewModal({ open, setViewModal, id }: Props) {
<strong>Address:</strong> <strong>Address:</strong>
<Typography variant="body2"> <Typography variant="body2">
{selectedAdmin.registeredAddress ?? "N/A"} {selectedAdmin?.Admins?.[0]
?.registeredAddress ?? "N/A"}
</Typography> </Typography>
</Typography> </Typography>
</Grid> </Grid>

View file

@ -20,9 +20,7 @@ import { useDispatch, useSelector } from "react-redux";
import { createRole } from "../../redux/slices/roleSlice"; // Import the createRole action import { createRole } from "../../redux/slices/roleSlice"; // Import the createRole action
import { AppDispatch, RootState } from "../../redux/store/store"; // Assuming this is the path to your store file import { AppDispatch, RootState } from "../../redux/store/store"; // Assuming this is the path to your store file
import { toast } from "sonner"; import { toast } from "sonner";
import { import { CustomTextField } from "../../components/AddEditUserModel/styled.css.tsx";
CustomTextField,
} from "../../components/AddUserModel/styled.css.tsx";
// Define the data structure for permission // Define the data structure for permission
interface Permission { interface Permission {
module: string; module: string;

View file

@ -69,7 +69,6 @@ export default function AdminList() {
email, email,
phone, phone,
registeredAddress, registeredAddress,
}) })
); );
await dispatch(adminList()); await dispatch(adminList());
@ -86,15 +85,6 @@ export default function AdminList() {
{ id: "registeredAddress", label: "Address" }, { id: "registeredAddress", label: "Address" },
{ id: "action", label: "Action", align: "center" }, { id: "action", label: "Action", align: "center" },
]; ];
// const filteredAdmins = admins?.filter(
// (admin) =>
// admin.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
// admin.email.toLowerCase().includes(searchTerm.toLowerCase()) ||
// admin.phone.toLowerCase().includes(searchTerm.toLowerCase()) ||
// admin.registeredAddress
// .toLowerCase()
// .includes(searchTerm.toLowerCase())
// );
const categoryRows = admins?.map( const categoryRows = admins?.map(
( (
@ -103,7 +93,7 @@ export default function AdminList() {
name: string; name: string;
email: string; email: string;
phone: string; phone: string;
registeredAddress: string; Admins: { registeredAddress: string }[]; // Adjusted to support array of Admins
}, },
index: number index: number
) => ({ ) => ({
@ -112,14 +102,13 @@ export default function AdminList() {
name: admin?.name, name: admin?.name,
email: admin?.email, email: admin?.email,
phone: admin?.phone, phone: admin?.phone,
registeredAddress: admin?.registeredAddress || "NA", registeredAddress: admin?.Admins?.[0]?.registeredAddress || "NA",
}) })
) );
;
return ( return (
<> <>
<CustomTable <CustomTable
columns={categoryColumns} columns={categoryColumns}
rows={categoryRows} rows={categoryRows}

View file

@ -22,9 +22,7 @@ import { toast } from "sonner";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Visibility, VisibilityOff } from "@mui/icons-material"; import { Visibility, VisibilityOff } from "@mui/icons-material";
import { Card, SignInContainer } from "./styled.css.tsx"; import { Card, SignInContainer } from "./styled.css.tsx";
import { import { CustomIconButton } from "../../../components/AddEditUserModel/styled.css.tsx";
CustomIconButton,
} from "../../../components/AddUserModel/styled.css.tsx";
interface ILoginForm { interface ILoginForm {
email: string; email: string;
password: string; password: string;

View file

@ -12,7 +12,7 @@ import {
deleteManager, deleteManager,
} from "../../redux/slices/managerSlice"; } from "../../redux/slices/managerSlice";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import DeleteModal from "../../components/Modals/DeleteModal";
export default function ManagerList() { export default function ManagerList() {
const [addModalOpen, setAddModalOpen] = useState<boolean>(false); const [addModalOpen, setAddModalOpen] = useState<boolean>(false);
@ -53,7 +53,6 @@ export default function ManagerList() {
name: string; name: string;
email: string; email: string;
phone: string; phone: string;
registeredAddress: string;
stationId: string; stationId: string;
}) => { }) => {
try { try {
@ -72,7 +71,6 @@ export default function ManagerList() {
name: string, name: string,
email: string, email: string,
phone: string, phone: string,
registeredAddress: string,
stationId: string stationId: string
) => { ) => {
try { try {
@ -83,7 +81,6 @@ export default function ManagerList() {
name, name,
email, email,
phone, phone,
registeredAddress,
stationId, stationId,
}) })
); );
@ -100,47 +97,70 @@ export default function ManagerList() {
{ id: "name", label: "Name" }, { id: "name", label: "Name" },
{ id: "email", label: "Email" }, { id: "email", label: "Email" },
{ id: "phone", label: "Phone" }, { id: "phone", label: "Phone" },
{ id: "registeredAddress", label: "Station Location" },
{ id: "stationName", label: "Station Name" }, { id: "stationName", label: "Station Name" },
{ id: "registeredAddress", label: "Station Location" },
{ id: "action", label: "Action", align: "center" }, { id: "action", label: "Action", align: "center" },
]; ];
// const categoryColumns: Column[] = [
// { id: "srno", label: "Sr No" },
// { id: "name", label: "Name" },
// { id: "email", label: "Email" },
// { id: "phone", label: "Phone" },
// { id: "stationName", label: "Station Name" }, // Added station name column
// { id: "stationAddress", label: "Station Location" }, // Added station address column
// { id: "action", label: "Action", align: "center" },
// ];
// Filter managers based on search term // Filter managers based on search term
const filteredManagers = managers?.filter( const filteredManagers = managers?.filter(
(manager) => (manager) =>
manager.name?.toLowerCase().includes(searchTerm.toLowerCase()) || manager.name?.toLowerCase().includes(searchTerm.toLowerCase()) ||
manager.email?.toLowerCase().includes(searchTerm.toLowerCase()) || manager.email?.toLowerCase().includes(searchTerm.toLowerCase()) ||
manager.phone?.toLowerCase().includes(searchTerm.toLowerCase()) || manager.phone?.toLowerCase().includes(searchTerm.toLowerCase())
manager.registeredAddress
?.toLowerCase()
.includes(searchTerm.toLowerCase())
); );
// Format rows to display manager details // Format rows to display manager details
const categoryRows = filteredManagers?.length // const categoryRows = filteredManagers?.length
? filteredManagers?.map( // ? filteredManagers?.map(
( // (
manager: { // manager: {
id: number; // id: number;
name: string; // name: string;
email: string; // email: string;
phone: string; // phone: string;
registeredAddress: string;
stationName: string;
}, // },
index: number // index: number
) => ({ // ) => ({
id: manager?.id, // id: manager?.id,
// srno: index + 1,
// name: manager?.name,
// email: manager?.email,
// phone: manager.phone ?? "NA",
// })
// )
// : [];
const categoryRows = filteredManagers?.length
? filteredManagers.map((manager, index) => {
const station = manager?.ChargingStation; // Correct access to the ChargingStation data
return {
id: manager.id,
srno: index + 1, srno: index + 1,
name: manager?.name, name: manager.name,
email: manager?.email, email: manager.email,
phone: manager.phone ?? "NA", phone: manager.phone ?? "NA",
registeredAddress: manager?.registeredAddress ?? "NA", stationName: station?.name ?? "NA", // Corrected station name
stationName: manager?.stationName ?? "NA", registeredAddress: station?.registeredAddress ?? "NA", // Corrected station address
};
}) })
)
: []; : [];
return ( return (
<> <>
{/* Custom Table to show manager list */} {/* Custom Table to show manager list */}

View file

@ -4,16 +4,12 @@ import CustomTable, { Column } from "../../components/CustomTable";
import { RootState } from "../../redux/reducers"; import { RootState } from "../../redux/reducers";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { AppDispatch } from "../../redux/store/store"; import { AppDispatch } from "../../redux/store/store";
import {
addVehicle,
updateVehicle,
vehicleList,
} from "../../redux/slices/VehicleSlice";
import AddStationModal from "../../components/AddStationModal"; import AddStationModal from "../../components/AddStationModal";
import EditStationModal from "../../components/EditStationModal"; import EditStationModal from "../../components/EditStationModal";
import { import {
createStation, createStation,
stationList, stationList,
toggleStatus,
updateStation, updateStation,
} from "../../redux/slices/stationSlice"; } from "../../redux/slices/stationSlice";
import { Chip, Switch } from "@mui/material"; import { Chip, Switch } from "@mui/material";
@ -76,6 +72,7 @@ export default function StationList() {
name, name,
registeredAddress, registeredAddress,
totalSlots, totalSlots,
}) })
); );
await dispatch(stationList()); await dispatch(stationList());
@ -85,16 +82,23 @@ export default function StationList() {
} }
}; };
const handleStatusToggle = async(id: string, newStatus: number) => {
await dispatch(toggleStatus({ id, status: newStatus }));
};
// Toggle station status // Toggle station status
// const handleStatusToggle = async (id: string, currentStatus: number) => { // const handleStatusToggle = async (id: string, currentStatus: number) => {
// try { // try {
// const newStatus = currentStatus === 1 ? 0 : 1; // Toggle between Active(1) and Inactive(0) // const newStatus = currentStatus === 1 ? 0 : 1; // Toggle between Active(1) and Inactive(0)
// await dispatch(updateStation({ // await dispatch(
// id, status: newStatus, // updateStation({
// name: "", // id,
// registeredAddress: "", // status: newStatus,
// totalSlots: "" // name: stations.name,
// })); // registeredAddress: stations.registeredAddress,
// totalSlots: stations.totalSlots,
// })
// );
// await dispatch(stationList()); // await dispatch(stationList());
// } catch (error) { // } catch (error) {
// console.error("Error toggling status", error); // console.error("Error toggling status", error);
@ -109,6 +113,8 @@ export default function StationList() {
id: station.id, id: station.id,
srno: index + 1, srno: index + 1,
name: station.name, name: station.name,
registeredAddress:station.registeredAddress,
totalSlots:station.totalSlots,
status: ( status: (
<Chip <Chip
label={ label={
@ -130,10 +136,11 @@ export default function StationList() {
const categoryColumns: Column[] = [ const categoryColumns: Column[] = [
{ id: "srno", label: "Sr No" }, { id: "srno", label: "Sr No" },
{ id: "id", label: "Station ID" },
{ id: "name", label: "Station Name" }, { id: "name", label: "Station Name" },
{ id: "registeredAddress", label: "Station Location" }, { id: "registeredAddress", label: "Station Location" },
{ id: "totalSlots", label: "Total Slots" }, { id: "totalSlots", label: "Total Slots" },
{ id: "status", label: "Status" }, //{ id: "status", label: "Status" },
{ id: "action", label: "Action", align: "center" }, { id: "action", label: "Action", align: "center" },
]; ];
@ -173,6 +180,7 @@ export default function StationList() {
viewModal={viewModal} viewModal={viewModal}
setRowData={setRowData} setRowData={setRowData}
setModalOpen={() => setEditModalOpen(true)} setModalOpen={() => setEditModalOpen(true)}
handleStatusToggle={handleStatusToggle}
tableType="station" tableType="station"
handleClickOpen={handleClickOpen} handleClickOpen={handleClickOpen}
/> />

View file

@ -8,7 +8,7 @@ import { createUser, updateUser, userList } from "../../redux/slices/userSlice";
import { AppDispatch, RootState } from "../../redux/store/store"; import { AppDispatch, RootState } from "../../redux/store/store";
import { string } from "prop-types"; import { string } from "prop-types";
import { adminList, updateAdmin } from "../../redux/slices/adminSlice"; import { adminList, updateAdmin } from "../../redux/slices/adminSlice";
import AddUserModal from "../../components/AddUserModel"; import AddUserModal from "../../components/AddEditUserModel";
export default function UserList() { export default function UserList() {
const [modalOpen, setModalOpen] = useState(false); const [modalOpen, setModalOpen] = useState(false);

View file

@ -5,11 +5,11 @@ import { toast } from "sonner";
// Define the Manager interface based on the payload // Define the Manager interface based on the payload
interface Manager { interface Manager {
Manager: any;
id: number; id: number;
name: string; name: string;
email: string; email: string;
phone: string; phone: string;
registeredAddress: string;
stationId: string; stationId: string;
} }
@ -36,7 +36,7 @@ export const managerList = createAsyncThunk<
const token = localStorage?.getItem("authToken"); const token = localStorage?.getItem("authToken");
if (!token) throw new Error("No token found"); if (!token) throw new Error("No token found");
const response = await http.get("manager-list"); const response = await http.get("/manager-list");
if (!response.data?.data) throw new Error("Invalid API response"); if (!response.data?.data) throw new Error("Invalid API response");
return response.data.data; return response.data.data;
} catch (error: any) { } catch (error: any) {
@ -50,6 +50,12 @@ export const managerList = createAsyncThunk<
// Create Manager (Async Thunk) // Create Manager (Async Thunk)
export const addManager = createAsyncThunk< export const addManager = createAsyncThunk<
Manager, Manager,
{
name: string;
email: string;
phone: string;
stationId: string;
},
{ rejectValue: string } { rejectValue: string }
>("addManager", async (data, { rejectWithValue }) => { >("addManager", async (data, { rejectWithValue }) => {
try { try {

View file

@ -32,7 +32,7 @@ export const stationList = createAsyncThunk<any, void, { rejectValue: string }>(
const token = localStorage?.getItem("authToken"); const token = localStorage?.getItem("authToken");
if (!token) throw new Error("No token found"); if (!token) throw new Error("No token found");
const response = await http.get("/get-station"); const response = await http.get("/get-stations");
if (!response.data) throw new Error("Invalid API response"); if (!response.data) throw new Error("Invalid API response");
@ -97,8 +97,8 @@ export const deleteStation = createAsyncThunk<
{ rejectValue: string } { rejectValue: string }
>("deleteStation", async (id, { rejectWithValue }) => { >("deleteStation", async (id, { rejectWithValue }) => {
try { try {
const response = await http.delete(`/delete-station/${id}`); await http.delete(`/delete-station/${id}`);
toast.success(response.data?.message); toast.success("Station deleted successfully!");
return id; return id;
} catch (error: any) { } catch (error: any) {
toast.error("Error deleting the Station" + error); toast.error("Error deleting the Station" + error);
@ -113,9 +113,9 @@ export const toggleStatus = createAsyncThunk<
any, any,
{ id: string; status: number }, { id: string; status: number },
{ rejectValue: string } { rejectValue: string }
>("Station/toggleStatus", async ({ id, status }, { rejectWithValue }) => { >("station/toggleStatus", async ({ id, status }, { rejectWithValue }) => {
try { try {
const response = await http.patch(`${id}`, { status }); const response = await http.patch(`/update-station/${id}`, { status });
if (response.data.statusCode === 200) { if (response.data.statusCode === 200) {
toast.success( toast.success(