From e039b732a8f74ae2d2c9ebaf9330c74c09502099 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Sun, 7 Jul 2024 00:25:11 -0400 Subject: Improve MarkChoreComplete, allow complete in past ,etc --- src/views/ChoreEdit/ChoreView.jsx | 214 +++++++++++++++++++++++++------------- 1 file changed, 143 insertions(+), 71 deletions(-) (limited to 'src/views/ChoreEdit') diff --git a/src/views/ChoreEdit/ChoreView.jsx b/src/views/ChoreEdit/ChoreView.jsx index 8116270..29268bc 100644 --- a/src/views/ChoreEdit/ChoreView.jsx +++ b/src/views/ChoreEdit/ChoreView.jsx @@ -3,14 +3,19 @@ import { CancelScheduleSend, Check, Checklist, + Note, PeopleAlt, Person, } from '@mui/icons-material' import { Box, Button, + Checkbox, Container, + Divider, + FormControl, Grid, + Input, ListItem, ListItemContent, ListItemDecorator, @@ -21,7 +26,7 @@ import { } from '@mui/joy' import moment from 'moment' import { useEffect, useState } from 'react' -import { useParams, useSearchParams } from 'react-router-dom' +import { useNavigate, useParams, useSearchParams } from 'react-router-dom' import { GetAllUsers, GetChoreDetailById, @@ -43,14 +48,16 @@ const ChoreView = () => { const [performers, setPerformers] = useState([]) const [infoCards, setInfoCards] = useState([]) const { choreId } = useParams() + const [note, setNote] = useState(null) - // query param `complete=true` + const Navigate = useNavigate() const [searchParams] = useSearchParams() const [isPendingCompletion, setIsPendingCompletion] = useState(false) const [timeoutId, setTimeoutId] = useState(null) const [secondsLeftToCancel, setSecondsLeftToCancel] = useState(null) + const [completedDate, setCompletedDate] = useState(null) useEffect(() => { Promise.all([ GetChoreDetailById(choreId).then(resp => { @@ -82,7 +89,7 @@ const ChoreView = () => { { icon: , text: 'Due Date', - subtext: moment(chore.dueDate).format('MM/DD/YYYY hh:mm A'), + subtext: moment(chore.nextDueDate).format('MM/DD/YYYY hh:mm A'), }, { icon: , @@ -119,12 +126,21 @@ const ChoreView = () => { subtext: chore.lastCompletedDate ? `${ chore.lastCompletedDate && - moment(chore.lastCompletedDate).format('MM/DD/YYYY hh:mm A') - }(${ - performers.find(p => p.id === chore.lastCompletedBy)?.displayName - })` + moment(chore.lastCompletedDate).fromNow() + // moment(chore.lastCompletedDate).format('MM/DD/YYYY hh:mm A')) + }( + ${ + performers.find(p => p.id === chore.lastCompletedBy) + ?.displayName + } + )` : 'Never', }, + { + icon: , + text: 'Recent Note', + subtext: chore.notes || '--', + }, ] setInfoCards(cards) } @@ -143,10 +159,11 @@ const ChoreView = () => { }, 1000) const id = setTimeout(() => { - MarkChoreComplete(choreId) + MarkChoreComplete(choreId, note, completedDate) .then(resp => { if (resp.ok) { return resp.json().then(data => { + setNote(null) setChore(data.res) }) } @@ -174,75 +191,130 @@ const ChoreView = () => { } return ( - - + + + {chore.name} + + + + {infoCards.map((info, index) => ( + + + + + {info.icon} + + + + {info.text} + + + {info.subtext ? info.subtext : '--'} + + + + + + ))} + + + - - + + + Additional Notes + { + if (e.target.value.trim() === '') { + setNote(null) + return + } + setNote(e.target.value) + }} + size='md' + sx={{ + my: 1, + }} + /> + + { + if (e.target.checked) { + setCompletedDate( + moment(new Date()).format('YYYY-MM-DDTHH:00:00'), + ) + } else { + setCompletedDate(null) + } + }} + overlay sx={{ - mt: 2, - mb: 4, + my: 1, }} - > - {chore.name} - + label={Set completion date} + /> + + {completedDate !== null && ( + { + setCompletedDate(e.target.value) + }} + /> + )} + {completedDate === null && ( + // placeholder for the completion date with margin: + + )} - - {infoCards.map((info, index) => ( - - - - - {info.icon} - - - - {info.text} - - - {info.subtext ? info.subtext : '--'} - - - - - - ))} - - - } > - - {/* + {/* */} - - + +