Latest changes
This commit is contained in:
parent
0f33303a42
commit
a6928b7db9
|
@ -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%" }}>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue