Latest changes

This commit is contained in:
jaanvi 2025-03-28 11:48:44 +05:30
parent 0f33303a42
commit a6928b7db9
3 changed files with 35 additions and 40 deletions

View file

@ -57,7 +57,7 @@ const EditSlotModal: React.FC<EditSlotModalProps> = ({
// 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<EditSlotModalProps> = ({
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<EditSlotModalProps> = ({
{/* Input Fields */}
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 2 }}>
{/* Date */}
<Box sx={{ flex: "1 1 100%" }}>
{/* <Box sx={{ flex: "1 1 100%" }}>
<Typography variant="body2" fontWeight={500} mb={0.5}>
Date
</Typography>
@ -166,7 +163,7 @@ const EditSlotModal: React.FC<EditSlotModalProps> = ({
/>
)}
/>
</Box>
</Box> */}
{/* Start Time */}
<Box sx={{ flex: "1 1 48%" }}>

View file

@ -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<boolean>(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,

View file

@ -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";