dev-jaanvi #1

Open
jaanvi wants to merge 155 commits from dev-jaanvi into main
3 changed files with 35 additions and 40 deletions
Showing only changes of commit a6928b7db9 - Show all commits

View file

@ -57,7 +57,7 @@ const EditSlotModal: React.FC<EditSlotModalProps> = ({
// Set values if editRow is provided // Set values if editRow is provided
useEffect(() => { useEffect(() => {
if (editRow) { if (editRow) {
setValue("date", editRow.date); // setValue("date", editRow.date);
setValue("startTime", editRow.startTime); setValue("startTime", editRow.startTime);
setValue("endTime", editRow.endTime); setValue("endTime", editRow.endTime);
setIsAvailable(editRow.isAvailable); // Set the initial availability correctly setIsAvailable(editRow.isAvailable); // Set the initial availability correctly
@ -76,13 +76,10 @@ const EditSlotModal: React.FC<EditSlotModalProps> = ({
await dispatch( await dispatch(
updateSlot({ updateSlot({
id: editRow.id, // Slot ID id: editRow.id, // Slot ID// date: data.date,
slotData: {
date: data.date,
startTime: data.startTime, startTime: data.startTime,
endTime: data.endTime, endTime: data.endTime,
isAvailable: availabilityStatus, isAvailable: availabilityStatus,
},
}) })
).unwrap(); // Ensure that it throws an error if the update fails ).unwrap(); // Ensure that it throws an error if the update fails
@ -147,7 +144,7 @@ const EditSlotModal: React.FC<EditSlotModalProps> = ({
{/* Input Fields */} {/* Input Fields */}
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 2 }}> <Box sx={{ display: "flex", flexWrap: "wrap", gap: 2 }}>
{/* Date */} {/* Date */}
<Box sx={{ flex: "1 1 100%" }}> {/* <Box sx={{ flex: "1 1 100%" }}>
<Typography variant="body2" fontWeight={500} mb={0.5}> <Typography variant="body2" fontWeight={500} mb={0.5}>
Date Date
</Typography> </Typography>
@ -166,7 +163,7 @@ const EditSlotModal: React.FC<EditSlotModalProps> = ({
/> />
)} )}
/> />
</Box> </Box> */}
{/* Start Time */} {/* Start Time */}
<Box sx={{ flex: "1 1 48%" }}> <Box sx={{ flex: "1 1 48%" }}>

View file

@ -11,7 +11,6 @@ import {
} from "../../redux/slices/slotSlice"; } from "../../redux/slices/slotSlice";
import AddSlotModal from "../../components/AddSlotModal"; import AddSlotModal from "../../components/AddSlotModal";
import dayjs from "dayjs"; import dayjs from "dayjs";
import EditManagerModal from "../../components/EditManagerModal";
import EditSlotModal from "../../components/EditSlotModal"; import EditSlotModal from "../../components/EditSlotModal";
export default function EVSlotList() { export default function EVSlotList() {
const [addModalOpen, setAddModalOpen] = useState<boolean>(false); const [addModalOpen, setAddModalOpen] = useState<boolean>(false);
@ -59,22 +58,19 @@ export default function EVSlotList() {
const handleUpdate = async ( const handleUpdate = async (
id: string, id: string,
startTime: string, startTime: string,
endTime: string, endTime: string,
isAvailable: boolean isAvailable: boolean
) => { ) => {
try { try {
// Update manager with stationId
await dispatch( await dispatch(
updateSlot({ updateSlot({
id, id, // Pass id separately, not inside slotData
startTime, startTime,
endTime, endTime,
isAvailable, isAvailable,
}) })
); ).unwrap(); // Ensure you unwrap the result so you can handle the error properly
await dispatch(fetchAvailableSlots()); // Refresh the list after update await dispatch(fetchAvailableSlots()); // Refresh the list after update
handleCloseModal(); // Close modal after update handleCloseModal(); // Close modal after update
} catch (error) { } catch (error) {
@ -82,6 +78,7 @@ export default function EVSlotList() {
} }
}; };
const slotColumns: Column[] = [ const slotColumns: Column[] = [
{ id: "srno", label: "Sr No" }, { id: "srno", label: "Sr No" },
{ id: "name", label: "Station Name" }, { id: "name", label: "Station Name" },
@ -100,7 +97,7 @@ export default function EVSlotList() {
const formattedDate = dayjs(slot?.date).format("YYYY-MM-DD"); const formattedDate = dayjs(slot?.date).format("YYYY-MM-DD");
const startTime = dayjs(slot?.startTime).format("HH:mm"); const startTime = dayjs(slot?.startTime).format("HH:mm");
const endTime = dayjs(slot?.endTime).format("HH:mm"); const endTime = dayjs(slot?.endTime).format("HH:mm");
console.log("availability", availableSlots.isAvailable);
console.log("first", startTime); console.log("first", startTime);
return { return {
srno: index + 1, srno: index + 1,

View file

@ -88,16 +88,16 @@ export const createSlot = createAsyncThunk<
// Update Slot details // Update Slot details
export const updateSlot = createAsyncThunk< export const updateSlot = createAsyncThunk<
Slot, 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 } { rejectValue: string }
>("slots/updateSlot", async ({ id, ...slotData }, { rejectWithValue }) => { >("slots/updateSlot", async ({ id, ...slotData }, { rejectWithValue }) => {
try { try {
const response = await http.patch( const response = await http.patch(
`/update-availability/${id}`, `/update-availability/${id}`,
slotData slotData // slotData is being sent here, but we should ensure its structure is correct
); );
toast.success("Slot updated successfully"); 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 return response.data.data; // Return updated slot data
} catch (error: any) { } catch (error: any) {
toast.error("Error updating the slot: " + error?.message); toast.error("Error updating the slot: " + error?.message);
@ -176,6 +176,7 @@ const slotSlice = createSlice({
} }
} }
) )
.addCase(updateSlot.rejected, (state, action) => { .addCase(updateSlot.rejected, (state, action) => {
state.loading = false; state.loading = false;
state.error = action.payload || "Failed to update slot"; state.error = action.payload || "Failed to update slot";