diff --git a/src/components/EditManagerStationModal/editManagerStationModal.tsx b/src/components/EditManagerStationModal/editManagerStationModal.tsx index 2507a40..9e8976b 100644 --- a/src/components/EditManagerStationModal/editManagerStationModal.tsx +++ b/src/components/EditManagerStationModal/editManagerStationModal.tsx @@ -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; 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 = ({ +const EditManagerStationModal: React.FC = ({ open, handleClose, editRow, @@ -59,10 +65,12 @@ const EditManagerStationModal: React.FC = ({ ); 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(); diff --git a/src/pages/EvSlotList/index.tsx b/src/pages/EvSlotList/index.tsx index 09800b4..6cc5c29 100644 --- a/src/pages/EvSlotList/index.tsx +++ b/src/pages/EvSlotList/index.tsx @@ -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]); diff --git a/src/pages/ManagerStationDetails/index.tsx b/src/pages/ManagerStationDetails/index.tsx index c7a32cf..8d95be8 100644 --- a/src/pages/ManagerStationDetails/index.tsx +++ b/src/pages/ManagerStationDetails/index.tsx @@ -20,9 +20,9 @@ export default function ManagerStationDetails() { const [rowData, setRowData] = useState(null); const dispatch = useDispatch(); 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 ( <> diff --git a/src/redux/slices/managerStationSlice.ts b/src/redux/slices/managerStationSlice.ts index 1c32574..539b1e6 100644 --- a/src/redux/slices/managerStationSlice.ts +++ b/src/redux/slices/managerStationSlice.ts @@ -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) => { + 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 =