Manager Station Details ApI Integration Completed

This commit is contained in:
jaanvi 2025-04-17 12:05:08 +05:30
parent 15fc16ffa9
commit 5f9f4960b1
4 changed files with 61 additions and 35 deletions

View file

@ -19,12 +19,18 @@ import { CustomIconButton, CustomTextField } from "../AddUserModal/styled.css";
import { AppDispatch } from "../../redux/store/store";
import { toast } from "sonner";
interface EditStationModalProps {
interface EditManagerStationModalProps {
open: boolean;
handleClose: () => void;
handleUpdate: (
id: string,
connectorType: string,
power: number,
price: number,
available: boolean
) => Promise<void>;
editRow: any; // Slot data including id
}
interface FormData {
connectorType: string;
power: number; // Changed to number
@ -32,7 +38,7 @@ interface FormData {
available: boolean;
}
const EditManagerStationModal: React.FC<EditStationModalProps> = ({
const EditManagerStationModal: React.FC<EditManagerStationModalProps> = ({
open,
handleClose,
editRow,
@ -59,10 +65,12 @@ const EditManagerStationModal: React.FC<EditStationModalProps> = ({
);
useEffect(() => {
if (editRow) {
setValue("connectorType", editRow.connectorType);
setValue("power", Number(editRow.power));
setValue("price", Number(editRow.price));
setValue("available", editRow.available);
setAvailable(editRow.available);
} else {
reset();

View file

@ -25,7 +25,7 @@ export default function EVSlotList() {
(state: RootState) => state?.slotReducer.availableSlots
);
const { user } = useSelector((state: RootState) => state?.profileReducer);
console.log("bjbjhjh", availableSlots);
useEffect(() => {
dispatch(fetchManagersSlots());
}, [dispatch]);

View file

@ -20,9 +20,9 @@ export default function ManagerStationDetails() {
const [rowData, setRowData] = useState<any | null>(null);
const dispatch = useDispatch<AppDispatch>();
const stationDetails = useSelector(
(state: RootState) => state.managerStationReducer.stationDetails
(state: RootState) => state?.managerStationReducer.stationDetails
);
console.log("-ghg", stationDetails);
useEffect(() => {
dispatch(stationDetailList());
}, [dispatch]);
@ -56,14 +56,20 @@ export default function ManagerStationDetails() {
};
const handleUpdate = async (
id: number,
id: string,
connectorType: string,
power: number,
price: number,
available: boolean
) => {
try {
console.log("Updating station with data:", { id, connectorType, power, price, available })
// console.log("Updating station with data:", {
// id,
// connectorType,
// power,
// price,
// available,
// });
if (!id) {
console.error("Error: id is missing!");
@ -98,16 +104,20 @@ export default function ManagerStationDetails() {
];
// Rows for the table
const categoryRows = stationDetails.map((station, index) => ({
...station, // Include all station properties
srno: index + 1,
stationName: station.stationName ?? "NA",
stationAddress: station.stationAddress ?? "NA",
connectorType: station.connectorType ?? "NA",
power: station.power ?? "NA",
price: station.price ?? "NA",
available: station.available ? "Yes" : "No",
}));
const categoryRows = stationDetails?.length
? stationDetails.map((station, index) => {
return {
srno: index + 1,
id: station?.id ?? "NA",
stationName: station?.stationName ?? "NA",
stationAddress: station?.stationAddress ?? "NA",
connectorType: station?.connectorType ?? "NA",
power: station?.power ?? "NA",
price: station?.price ?? "NA",
available: station?.available ? "Yes" : "No",
};
})
: [];
return (
<>

View file

@ -2,9 +2,9 @@ import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
import http from "../../lib/https";
import { toast } from "sonner";
interface StationDetails {
id: string;
stationAddress: string;
stationName: string;
id: number;
managerId?: number;
stationId?: number;
connectorType: string;
@ -75,7 +75,7 @@ export const addStationDetails = createAsyncThunk<
export const updateStationDetails = createAsyncThunk<
StationDetails,
{
id: number;
id: string;
connectorType: string;
power: number;
price: number;
@ -87,8 +87,9 @@ export const updateStationDetails = createAsyncThunk<
async ({ id, ...managerStationData }, { rejectWithValue }) => {
try {
const response = await http.patch(
`update-station-details/${id}`,
managerStationData
`/update-station-details/${id}`,
managerStationData,
);
toast.success("Station Details updated successfully");
return response.data; // Return the updated data
@ -106,9 +107,9 @@ export const deleteStationDetails = createAsyncThunk<
string,
string,
{ rejectValue: string }
>("deleteManager", async (id, { rejectWithValue }) => {
>("deleteManagerStationDetails", async (id, { rejectWithValue }) => {
try {
await http.delete(`remove-station-details/${id}`);
await http.delete(`/remove-station-details/${id}`);
toast.success("Station details deleted successfully!");
return id;
} catch (error: any) {
@ -176,10 +177,7 @@ const managerStationSlice = createSlice({
if (index !== -1) {
// Only update the fields that have changed
state.stationDetails[index] = {
...state.stationDetails[index],
...action.payload, // Merge the updated fields
};
state.stationDetails[index] = action.payload; // Merge the updated fields
}
}
)
@ -193,13 +191,23 @@ const managerStationSlice = createSlice({
.addCase(deleteStationDetails.pending, (state) => {
state.loading = true;
})
.addCase(deleteStationDetails.fulfilled, (state, action) => {
state.loading = false;
state.stationDetails = state.stationDetails.filter(
(stationDetail) =>
String(stationDetail.id) !== String(action.payload)
);
})
.addCase(
deleteStationDetails.fulfilled,
(state, action: PayloadAction<string>) => {
state.loading = false;
state.stationDetails = state.stationDetails.filter(
(station) =>
String(station.id) !== String(action.payload)
);
if (state.stationDetails) {
state.stationDetails = state.stationDetails.filter(
(station) =>
String(station.id) !== String(action.payload)
);
}
}
)
.addCase(deleteStationDetails.rejected, (state, action) => {
state.loading = false;
state.error =