diff --git a/src/components/EditSlotModal/index.tsx b/src/components/EditSlotModal/index.tsx index dbf581e..1365b1e 100644 --- a/src/components/EditSlotModal/index.tsx +++ b/src/components/EditSlotModal/index.tsx @@ -57,7 +57,7 @@ const EditSlotModal: React.FC = ({ // Set values if editRow is provided useEffect(() => { if (editRow) { - setValue("date", editRow.date); + // setValue("date", editRow.date); setValue("startTime", editRow.startTime); setValue("endTime", editRow.endTime); setIsAvailable(editRow.isAvailable); // Set the initial availability correctly @@ -76,13 +76,10 @@ const EditSlotModal: React.FC = ({ await dispatch( updateSlot({ - id: editRow.id, // Slot ID - slotData: { - date: data.date, - startTime: data.startTime, - endTime: data.endTime, - isAvailable: availabilityStatus, - }, + id: editRow.id, // Slot ID// date: data.date, + startTime: data.startTime, + endTime: data.endTime, + isAvailable: availabilityStatus, }) ).unwrap(); // Ensure that it throws an error if the update fails @@ -147,7 +144,7 @@ const EditSlotModal: React.FC = ({ {/* Input Fields */} {/* Date */} - + {/* Date @@ -166,7 +163,7 @@ const EditSlotModal: React.FC = ({ /> )} /> - + */} {/* Start Time */} diff --git a/src/pages/EvSlotList/index.tsx b/src/pages/EvSlotList/index.tsx index 4e34ad8..d1fbaa7 100644 --- a/src/pages/EvSlotList/index.tsx +++ b/src/pages/EvSlotList/index.tsx @@ -11,7 +11,6 @@ import { } from "../../redux/slices/slotSlice"; import AddSlotModal from "../../components/AddSlotModal"; import dayjs from "dayjs"; -import EditManagerModal from "../../components/EditManagerModal"; import EditSlotModal from "../../components/EditSlotModal"; export default function EVSlotList() { const [addModalOpen, setAddModalOpen] = useState(false); @@ -57,30 +56,28 @@ export default function EVSlotList() { } }; - const handleUpdate = async ( - id: string, - - startTime: string, - endTime: string, - isAvailable: boolean - ) => { - try { - // Update manager with stationId - await dispatch( - updateSlot({ - id, - - startTime, - endTime, - isAvailable, - }) - ); - await dispatch(fetchAvailableSlots()); // Refresh the list after update - handleCloseModal(); // Close modal after update - } catch (error) { - console.error("Update failed", error); - } - }; +const handleUpdate = async ( + id: string, + startTime: string, + endTime: string, + isAvailable: boolean +) => { + try { + await dispatch( + updateSlot({ + id, // Pass id separately, not inside slotData + startTime, + endTime, + isAvailable, + }) + ).unwrap(); // Ensure you unwrap the result so you can handle the error properly + await dispatch(fetchAvailableSlots()); // Refresh the list after update + handleCloseModal(); // Close modal after update + } catch (error) { + console.error("Update failed", error); + } +}; + const slotColumns: Column[] = [ { id: "srno", label: "Sr No" }, @@ -100,7 +97,7 @@ export default function EVSlotList() { const formattedDate = dayjs(slot?.date).format("YYYY-MM-DD"); const startTime = dayjs(slot?.startTime).format("HH:mm"); const endTime = dayjs(slot?.endTime).format("HH:mm"); - console.log("availability", availableSlots.isAvailable); + console.log("first", startTime); return { srno: index + 1, diff --git a/src/redux/slices/slotSlice.ts b/src/redux/slices/slotSlice.ts index 487d0ec..1dbc59b 100644 --- a/src/redux/slices/slotSlice.ts +++ b/src/redux/slices/slotSlice.ts @@ -88,16 +88,16 @@ export const createSlot = createAsyncThunk< // Update Slot details export const updateSlot = createAsyncThunk< Slot, - { id: string; startTime: string; endTime: string }, // Argument type (slot update data) + { id: string; startTime: string; endTime: string; isAvailable: boolean }, // Argument type (slot update data) { rejectValue: string } >("slots/updateSlot", async ({ id, ...slotData }, { rejectWithValue }) => { try { const response = await http.patch( `/update-availability/${id}`, - slotData + slotData // slotData is being sent here, but we should ensure its structure is correct ); toast.success("Slot updated successfully"); - console.log("Slots",response.data.data) + console.log("Slots", response.data.data); return response.data.data; // Return updated slot data } catch (error: any) { toast.error("Error updating the slot: " + error?.message); @@ -105,7 +105,7 @@ export const updateSlot = createAsyncThunk< error.response?.data?.message || "An error occurred" ); } -}); +}); export const deleteSlot = createAsyncThunk< string, // Return type (id of deleted slot) @@ -176,6 +176,7 @@ const slotSlice = createSlice({ } } ) + .addCase(updateSlot.rejected, (state, action) => { state.loading = false; state.error = action.payload || "Failed to update slot";