dev-jaanvi #1
|
@ -19,12 +19,18 @@ import { CustomIconButton, CustomTextField } from "../AddUserModal/styled.css";
|
||||||
import { AppDispatch } from "../../redux/store/store";
|
import { AppDispatch } from "../../redux/store/store";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
interface EditStationModalProps {
|
interface EditManagerStationModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
|
handleUpdate: (
|
||||||
|
id: string,
|
||||||
|
connectorType: string,
|
||||||
|
power: number,
|
||||||
|
price: number,
|
||||||
|
available: boolean
|
||||||
|
) => Promise<void>;
|
||||||
editRow: any; // Slot data including id
|
editRow: any; // Slot data including id
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
connectorType: string;
|
connectorType: string;
|
||||||
power: number; // Changed to number
|
power: number; // Changed to number
|
||||||
|
@ -32,7 +38,7 @@ interface FormData {
|
||||||
available: boolean;
|
available: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditManagerStationModal: React.FC<EditStationModalProps> = ({
|
const EditManagerStationModal: React.FC<EditManagerStationModalProps> = ({
|
||||||
open,
|
open,
|
||||||
handleClose,
|
handleClose,
|
||||||
editRow,
|
editRow,
|
||||||
|
@ -59,10 +65,12 @@ const EditManagerStationModal: React.FC<EditStationModalProps> = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (editRow) {
|
if (editRow) {
|
||||||
setValue("connectorType", editRow.connectorType);
|
setValue("connectorType", editRow.connectorType);
|
||||||
setValue("power", Number(editRow.power));
|
setValue("power", Number(editRow.power));
|
||||||
setValue("price", Number(editRow.price));
|
setValue("price", Number(editRow.price));
|
||||||
|
setValue("available", editRow.available);
|
||||||
setAvailable(editRow.available);
|
setAvailable(editRow.available);
|
||||||
} else {
|
} else {
|
||||||
reset();
|
reset();
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default function EVSlotList() {
|
||||||
(state: RootState) => state?.slotReducer.availableSlots
|
(state: RootState) => state?.slotReducer.availableSlots
|
||||||
);
|
);
|
||||||
const { user } = useSelector((state: RootState) => state?.profileReducer);
|
const { user } = useSelector((state: RootState) => state?.profileReducer);
|
||||||
|
console.log("bjbjhjh", availableSlots);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchManagersSlots());
|
dispatch(fetchManagersSlots());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
|
@ -20,9 +20,9 @@ export default function ManagerStationDetails() {
|
||||||
const [rowData, setRowData] = useState<any | null>(null);
|
const [rowData, setRowData] = useState<any | null>(null);
|
||||||
const dispatch = useDispatch<AppDispatch>();
|
const dispatch = useDispatch<AppDispatch>();
|
||||||
const stationDetails = useSelector(
|
const stationDetails = useSelector(
|
||||||
(state: RootState) => state.managerStationReducer.stationDetails
|
(state: RootState) => state?.managerStationReducer.stationDetails
|
||||||
);
|
);
|
||||||
|
console.log("-ghg", stationDetails);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(stationDetailList());
|
dispatch(stationDetailList());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
@ -56,14 +56,20 @@ export default function ManagerStationDetails() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdate = async (
|
const handleUpdate = async (
|
||||||
id: number,
|
id: string,
|
||||||
connectorType: string,
|
connectorType: string,
|
||||||
power: number,
|
power: number,
|
||||||
price: number,
|
price: number,
|
||||||
available: boolean
|
available: boolean
|
||||||
) => {
|
) => {
|
||||||
try {
|
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) {
|
if (!id) {
|
||||||
console.error("Error: id is missing!");
|
console.error("Error: id is missing!");
|
||||||
|
@ -98,16 +104,20 @@ export default function ManagerStationDetails() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Rows for the table
|
// Rows for the table
|
||||||
const categoryRows = stationDetails.map((station, index) => ({
|
const categoryRows = stationDetails?.length
|
||||||
...station, // Include all station properties
|
? stationDetails.map((station, index) => {
|
||||||
|
return {
|
||||||
srno: index + 1,
|
srno: index + 1,
|
||||||
stationName: station.stationName ?? "NA",
|
id: station?.id ?? "NA",
|
||||||
stationAddress: station.stationAddress ?? "NA",
|
stationName: station?.stationName ?? "NA",
|
||||||
connectorType: station.connectorType ?? "NA",
|
stationAddress: station?.stationAddress ?? "NA",
|
||||||
power: station.power ?? "NA",
|
connectorType: station?.connectorType ?? "NA",
|
||||||
price: station.price ?? "NA",
|
power: station?.power ?? "NA",
|
||||||
available: station.available ? "Yes" : "No",
|
price: station?.price ?? "NA",
|
||||||
}));
|
available: station?.available ? "Yes" : "No",
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -2,9 +2,9 @@ import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
|
||||||
import http from "../../lib/https";
|
import http from "../../lib/https";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
interface StationDetails {
|
interface StationDetails {
|
||||||
|
id: string;
|
||||||
stationAddress: string;
|
stationAddress: string;
|
||||||
stationName: string;
|
stationName: string;
|
||||||
id: number;
|
|
||||||
managerId?: number;
|
managerId?: number;
|
||||||
stationId?: number;
|
stationId?: number;
|
||||||
connectorType: string;
|
connectorType: string;
|
||||||
|
@ -75,7 +75,7 @@ export const addStationDetails = createAsyncThunk<
|
||||||
export const updateStationDetails = createAsyncThunk<
|
export const updateStationDetails = createAsyncThunk<
|
||||||
StationDetails,
|
StationDetails,
|
||||||
{
|
{
|
||||||
id: number;
|
id: string;
|
||||||
connectorType: string;
|
connectorType: string;
|
||||||
power: number;
|
power: number;
|
||||||
price: number;
|
price: number;
|
||||||
|
@ -87,8 +87,9 @@ export const updateStationDetails = createAsyncThunk<
|
||||||
async ({ id, ...managerStationData }, { rejectWithValue }) => {
|
async ({ id, ...managerStationData }, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
const response = await http.patch(
|
const response = await http.patch(
|
||||||
`update-station-details/${id}`,
|
`/update-station-details/${id}`,
|
||||||
managerStationData
|
managerStationData,
|
||||||
|
|
||||||
);
|
);
|
||||||
toast.success("Station Details updated successfully");
|
toast.success("Station Details updated successfully");
|
||||||
return response.data; // Return the updated data
|
return response.data; // Return the updated data
|
||||||
|
@ -106,9 +107,9 @@ export const deleteStationDetails = createAsyncThunk<
|
||||||
string,
|
string,
|
||||||
string,
|
string,
|
||||||
{ rejectValue: string }
|
{ rejectValue: string }
|
||||||
>("deleteManager", async (id, { rejectWithValue }) => {
|
>("deleteManagerStationDetails", async (id, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
await http.delete(`remove-station-details/${id}`);
|
await http.delete(`/remove-station-details/${id}`);
|
||||||
toast.success("Station details deleted successfully!");
|
toast.success("Station details deleted successfully!");
|
||||||
return id;
|
return id;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -176,10 +177,7 @@ const managerStationSlice = createSlice({
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// Only update the fields that have changed
|
// 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) => {
|
.addCase(deleteStationDetails.pending, (state) => {
|
||||||
state.loading = true;
|
state.loading = true;
|
||||||
})
|
})
|
||||||
.addCase(deleteStationDetails.fulfilled, (state, action) => {
|
.addCase(
|
||||||
|
deleteStationDetails.fulfilled,
|
||||||
|
(state, action: PayloadAction<string>) => {
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
state.stationDetails = state.stationDetails.filter(
|
state.stationDetails = state.stationDetails.filter(
|
||||||
(stationDetail) =>
|
(station) =>
|
||||||
String(stationDetail.id) !== String(action.payload)
|
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) => {
|
.addCase(deleteStationDetails.rejected, (state, action) => {
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
state.error =
|
state.error =
|
||||||
|
|
Loading…
Reference in a new issue