{
onClick={() => {
dispatch(changeModalId(item._id));
dispatch(changeModalDeleteForm(true));
+ dispatch(changeModalId(item._id));
}}
>
@@ -85,11 +83,7 @@ const TodayElement = () => {
Add water
- {isModalOpen && (
- item._id === id)}
- />
- )}
+ {isModalOpen && }
>
);
diff --git a/src/store/water/operations.js b/src/store/water/operations.js
index 8871138..9e131dd 100644
--- a/src/store/water/operations.js
+++ b/src/store/water/operations.js
@@ -27,9 +27,9 @@ export const fetchAllWaterThunk = createAsyncThunk(
export const editWaterThunk = createAsyncThunk(
'water/editWater',
- async ({ id, water }, thunkApi) => {
+ async ({ id, milliliters, time }, thunkApi) => {
try {
- const { data } = await api.put(`water/${id}`, water);
+ const { data } = await api.put(`water/${id}`, { milliliters, time });
return data;
} catch (error) {
return thunkApi.rejectWithValue(error.message);
diff --git a/src/store/water/waterSlice.js b/src/store/water/waterSlice.js
index ec591d5..b0affac 100644
--- a/src/store/water/waterSlice.js
+++ b/src/store/water/waterSlice.js
@@ -1,6 +1,5 @@
import { createSlice } from '@reduxjs/toolkit';
-import { deleteWaterThunk, fetchAllWaterThunk } from './operations';
-import { toast } from 'react-toastify';
+import { fetchAllWaterThunk } from './operations';
const waterSlice = createSlice({
name: 'waterSlice',
@@ -56,6 +55,14 @@ const waterSlice = createSlice({
(waterItem) => waterItem._id !== action.payload
);
},
+ editWater: (state, action) => {
+ const index = state.waterTodayList.findIndex(
+ (el) => el._id === action.payload.id
+ );
+ if (index !== -1) {
+ state.waterTodayList[index] = action.payload;
+ }
+ },
},
extraReducers: (builder) => {
builder
@@ -64,12 +71,6 @@ const waterSlice = createSlice({
})
.addCase(fetchAllWaterThunk.rejected, (state, { payload }) => {
state.error = payload;
- })
- .addCase(deleteWaterThunk.fulfilled, (state, { payload }) => {
- state.waterTodayList = state.waterTodayList.filter(
- (waterItem) => waterItem._id !== payload.id
- );
- toast.success('Water note was successfully deleted');
});
},
});
@@ -84,4 +85,5 @@ export const {
changeTodayList,
changeModalId,
deleteWater,
+ editWater,
} = waterSlice.actions;