From d3b0a6866f053f46d35f63f7e37a629c4a292f6d Mon Sep 17 00:00:00 2001
From: DiegoT4l <128425675+DiegoT4l@users.noreply.github.com>
Date: Thu, 11 Jan 2024 23:50:48 -0600
Subject: [PATCH] =?UTF-8?q?[fix]:=20Se=20corrigi=C3=B3=20la=20funcion=20de?=
=?UTF-8?q?=20Crear=20meta.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/list/Goal.js | 1 +
src/components/list/List.js | 1 -
src/components/new/Details.js | 9 +++++----
src/services/Memory.js | 8 ++++++--
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/components/list/Goal.js b/src/components/list/Goal.js
index bd5b4fb..19d114b 100644
--- a/src/components/list/Goal.js
+++ b/src/components/list/Goal.js
@@ -1,6 +1,7 @@
import styles from './Goal.module.css';
import {Link} from "react-router-dom";
+
function Goal({ id, details, period, icon, frequency, finish, completed }) {
return (
diff --git a/src/components/list/List.js b/src/components/list/List.js
index 489a1d6..b80401e 100644
--- a/src/components/list/List.js
+++ b/src/components/list/List.js
@@ -14,5 +14,4 @@ function List() {
>
);
}
-
export default List;
\ No newline at end of file
diff --git a/src/components/new/Details.js b/src/components/new/Details.js
index b50c34b..cb35a3c 100644
--- a/src/components/new/Details.js
+++ b/src/components/new/Details.js
@@ -3,6 +3,7 @@ import {useContext, useEffect, useState} from 'react';
import {Context} from "../../services/Memory";
import {useNavigate, useParams} from "react-router-dom";
+
function Details() {
const {id} = useParams();
@@ -30,8 +31,8 @@ function Details() {
const [state, dispatch] = useContext(Context);
const onChange = (e, prop) => {
- setForm(estate => ({
- ...estate,
+ setForm(prevEstate => ({
+ ...prevEstate,
[prop]: e.target.value
}))
}
@@ -43,7 +44,7 @@ function Details() {
if (!id) return;
if (!goalMemory) {
- return navigate('/notFound');
+ return navigate('/list');
}
setForm(goalMemory);
}, [id, state.objects, navigate]);
@@ -139,7 +140,7 @@ function Details() {
onChange={(e) => {onChange(e, 'icon')}}
>
{icons.map((icon) => {
- return
+ return {icon}
})}
diff --git a/src/services/Memory.js b/src/services/Memory.js
index f74ccfc..644b818 100644
--- a/src/services/Memory.js
+++ b/src/services/Memory.js
@@ -76,7 +76,10 @@ const reducer = (state, action) => {
orderList: [...state.orderList, id],
objects: {
...state.objects,
- [id]: action.goal
+ [id]: {
+ ...action.goal,
+ id
+ }
}
}
}
@@ -90,9 +93,10 @@ const reducer = (state, action) => {
}
case 'DELETE_GOAL': {
const id = action.goal.id;
+ const newOrder = state.orderList.filter((goalId) => goalId !== id);
delete state.objects[id];
return {
- orderList: state.orderList.filter((goalId) => goalId !== id),
+ orderList: newOrder,
objects: { ...state.objects }
}
}