From e93cc24dbf087ac0792ef63aafcf47a527066d3a Mon Sep 17 00:00:00 2001 From: Gabriel Cavalcante Date: Sat, 9 Nov 2024 23:03:39 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20edi=C3=A7=C3=A3o=20de=20movimenta=C3=A7?= =?UTF-8?q?=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- context/MovimentationCtx.tsx | 32 ++++++++++++++++++++++++++ src/App.tsx | 2 ++ src/components/ReceivedTable/index.tsx | 26 ++++++++++++++++++++- src/components/SpentTable/index.tsx | 21 +++++++++++++++++ src/main.tsx | 17 ++++++++------ 5 files changed, 90 insertions(+), 8 deletions(-) diff --git a/context/MovimentationCtx.tsx b/context/MovimentationCtx.tsx index f72e545..4853778 100644 --- a/context/MovimentationCtx.tsx +++ b/context/MovimentationCtx.tsx @@ -12,6 +12,7 @@ interface IMovimentationCtx { spentValues: IMovimentation[]; addMovimentation: (movimentation: IMovimentation) => void; removeMovimentation: (id: string) => void; + editMovimentation: (id: string, mov: IMovimentation) => void; } const Movimentation = createContext(undefined); @@ -100,6 +101,36 @@ const MovimentationProvider = ({ children }: { children: ReactNode }) => { } }; + const editMovimentation = (id: string, mov: IMovimentation) => { + const { date, reason, value } = mov; + + const formatDate = (dateStr: string) => { + const [day, month, year] = dateStr.split("-"); + return `${year}/${month}/${day}`; + }; + + const treatedDate = formatDate(date as string); + + const updatedReceivedValues = receivedValues.map((receivedValue) => + receivedValue.id === id + ? { ...receivedValue, date: treatedDate, reason, value } + : receivedValue + ); + + const updatedSpentValues = spentValues.map((spentValue) => + spentValue.id === id + ? { ...spentValue, date: treatedDate, reason, value } + : spentValue + ); + + // Atualiza o estado e salva no storage + setReceivedValues(updatedReceivedValues); + setSpentValues(updatedSpentValues); + + saveToStorage("receivedValues", updatedReceivedValues); + saveToStorage("spentValues", updatedSpentValues); + }; + return ( { spentValues, addMovimentation, removeMovimentation, + editMovimentation, }} > {children} diff --git a/src/App.tsx b/src/App.tsx index f041473..8275b13 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import Header from "./components/Header"; import Informations from "./components/Informations"; import ReceivedTable from "./components/ReceivedTable"; import RemoveModal from "./components/RemoveModal"; +import EditModal from "./components/EditModal"; import SpentTable from "./components/SpentTable"; const App = () => { @@ -31,6 +32,7 @@ const App = () => { +