From ca044349cac7434560f2646bc4ea4c27f5783d47 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sat, 30 Sep 2023 18:29:36 +0700 Subject: cursed state management --- src/App.jsx | 24 ++++++++++++++++++++++-- src/Entry.jsx | 36 ++++++++++++++++++++++++++---------- src/Result.jsx | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/SalaryInput.jsx | 11 +++++++---- 4 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 src/Result.jsx diff --git a/src/App.jsx b/src/App.jsx index da2bbc7..8a487e0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -4,9 +4,11 @@ import Entry from "./Entry.jsx"; import {Button, Container, Typography} from "@mui/material"; import dayjs from "dayjs"; import SalaryInput from "./SalaryInput.jsx"; +import Result from "./Result.jsx"; function App() { + const [baseSalary, setBaseSalary] = useState(0); const [listEntry, setListEntry] = useState( [ {id: 0, date: dayjs(), start: dayjs(), finish: dayjs()}, @@ -24,6 +26,20 @@ function App() { return lastEntry.id; } + const handleEntryChange = (entry, updatedAttr) => { + const updatedEntryList = listEntry.map((entryOnList) => { + if (entryOnList.id === entry.id) { + return {...entryOnList, [updatedAttr]: entry[updatedAttr]} + } + return entryOnList; + }); + setListEntry(updatedEntryList); + } + + const handleBaseSalaryChange = (baseSalaryInput) => { + setBaseSalary(baseSalaryInput); + } + const addToList = () => { const newEntry = { id: getLastId() + 1, @@ -43,19 +59,22 @@ function App() { return ( Overtime Calculator - 🤑🤑 Sudahkah anda lembur hari ini? 🤑🤑 + 🤑🤑 Sudahkah anda lembur hari ini? + 🤑🤑