From 5e54da8271c7fac5062f0aca9b10e7370fd4bae2 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Mon, 1 Jul 2024 22:12:19 -0400 Subject: Update button re-enable timeout to 3 seconds, update thing history --- src/views/ChoreEdit/ChoreEdit.jsx | 2 +- src/views/ChoreEdit/ThingTriggerSection.jsx | 3 +- src/views/Chores/ChoreCard.jsx | 2 +- src/views/Modals/Inputs/CreateThingModal.jsx | 151 +++++++++++++++--------- src/views/Things/ThingsHistory.jsx | 164 ++++++++++++++++++++++++++- src/views/Things/ThingsView.jsx | 87 +++++++++++--- 6 files changed, 333 insertions(+), 76 deletions(-) (limited to 'src/views') diff --git a/src/views/ChoreEdit/ChoreEdit.jsx b/src/views/ChoreEdit/ChoreEdit.jsx index e8eb17d..568b20a 100644 --- a/src/views/ChoreEdit/ChoreEdit.jsx +++ b/src/views/ChoreEdit/ChoreEdit.jsx @@ -506,7 +506,7 @@ const ChoreEdit = () => { )} - {!['once', 'no_repeat'].includes(frequencyType) && ( + {!['once', 'no_repeat', 'trigger'].includes(frequencyType) && ( Scheduling Preferences: diff --git a/src/views/ChoreEdit/ThingTriggerSection.jsx b/src/views/ChoreEdit/ThingTriggerSection.jsx index 7a040ad..981f84b 100644 --- a/src/views/ChoreEdit/ThingTriggerSection.jsx +++ b/src/views/ChoreEdit/ThingTriggerSection.jsx @@ -6,7 +6,6 @@ import { Card, Chip, FormControl, - FormLabel, Input, ListItem, ListItemContent, @@ -91,7 +90,7 @@ const ThingTriggerSection = ({ Trigger a task when a thing state changes to a desired state - {things.length !== 0 && ( + {things?.length === 0 && ( it's look like you don't have any things yet, create a thing to trigger a task when the state changes. diff --git a/src/views/Chores/ChoreCard.jsx b/src/views/Chores/ChoreCard.jsx index 0b2a408..8efaf04 100644 --- a/src/views/Chores/ChoreCard.jsx +++ b/src/views/Chores/ChoreCard.jsx @@ -125,7 +125,7 @@ const ChoreCard = ({ chore, performers, onChoreUpdate, onChoreRemove, sx }) => { } }) setIsDisabled(true) - setTimeout(() => setIsDisabled(false), 5000) // Re-enable the button after 5 seconds + setTimeout(() => setIsDisabled(false), 3000) // Re-enable the button after 5 seconds } const handleChangeDueDate = newDate => { if (activeUserId === null) { diff --git a/src/views/Modals/Inputs/CreateThingModal.jsx b/src/views/Modals/Inputs/CreateThingModal.jsx index 59263ff..ffce51c 100644 --- a/src/views/Modals/Inputs/CreateThingModal.jsx +++ b/src/views/Modals/Inputs/CreateThingModal.jsx @@ -1,6 +1,8 @@ import { Box, Button, + FormControl, + FormHelperText, FormLabel, Input, Modal, @@ -14,8 +16,9 @@ import { useEffect, useState } from 'react' function CreateThingModal({ isOpen, onClose, onSave, currentThing }) { const [name, setName] = useState(currentThing?.name || '') - const [type, setType] = useState(currentThing?.type || 'numeric') + const [type, setType] = useState(currentThing?.type || 'number') const [state, setState] = useState(currentThing?.state || '') + const [errors, setErrors] = useState({}) useEffect(() => { if (type === 'boolean') { if (state !== 'true' && state !== 'false') { @@ -27,7 +30,31 @@ function CreateThingModal({ isOpen, onClose, onSave, currentThing }) { } } }, [type]) + + const isValid = () => { + const newErrors = {} + if (!name || name.trim() === '') { + newErrors.name = 'Name is required' + } + + if (type === 'number' && isNaN(state)) { + newErrors.state = 'State must be a number' + } + if (type === 'boolean' && !['true', 'false'].includes(state)) { + newErrors.state = 'State must be true or false' + } + if ((type === 'text' && !state) || state.trim() === '') { + newErrors.state = 'State is required' + } + + setErrors(newErrors) + return Object.keys(newErrors).length === 0 + } + const handleSave = () => { + if (!isValid()) { + return + } onSave({ name, type, id: currentThing?.id, state: state || null }) onClose() } @@ -36,64 +63,81 @@ function CreateThingModal({ isOpen, onClose, onSave, currentThing }) { {/* */} - P;lease add info - Name - -