From 93512eb6665e7d35660db133319be54ed1c09232 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Mon, 15 Jul 2024 21:58:23 -0400 Subject: Update Chore view --- src/views/ChoreEdit/ChoreView.jsx | 298 ++++++++++++++++++++------------------ 1 file changed, 157 insertions(+), 141 deletions(-) (limited to 'src/views/ChoreEdit') diff --git a/src/views/ChoreEdit/ChoreView.jsx b/src/views/ChoreEdit/ChoreView.jsx index 0e88016..afdc379 100644 --- a/src/views/ChoreEdit/ChoreView.jsx +++ b/src/views/ChoreEdit/ChoreView.jsx @@ -3,11 +3,10 @@ import { CancelScheduleSend, Check, Checklist, - Edit, History, - Note, PeopleAlt, Person, + SwitchAccessShortcut, Timelapse, } from '@mui/icons-material' import { @@ -22,7 +21,6 @@ import { Input, ListItem, ListItemContent, - ListItemDecorator, Sheet, Snackbar, styled, @@ -35,15 +33,17 @@ import { GetAllUsers, GetChoreDetailById, MarkChoreComplete, + SkipChore, } from '../../utils/Fetcher' +import ConfirmationModal from '../Modals/Inputs/ConfirmationModal' const IconCard = styled('div')({ display: 'flex', alignItems: 'center', justifyContent: 'center', backgroundColor: '#f0f0f0', // Adjust the background color as needed borderRadius: '50%', - minWidth: '50px', - height: '50px', + minWidth: '40px', + height: '40px', marginRight: '16px', }) const ChoreView = () => { @@ -60,6 +60,8 @@ const ChoreView = () => { const [timeoutId, setTimeoutId] = useState(null) const [secondsLeftToCancel, setSecondsLeftToCancel] = useState(null) const [completedDate, setCompletedDate] = useState(null) + const [confirmModelConfig, setConfirmModelConfig] = useState({}) + useEffect(() => { Promise.all([ GetChoreDetailById(choreId).then(resp => { @@ -88,24 +90,21 @@ const ChoreView = () => { const generateInfoCards = chore => { const cards = [ - // { - // size: 6, - // icon: , - // text: 'Due Date', - // subtext: moment(chore.nextDueDate).format('MM/DD/YYYY hh:mm A'), - // }, { size: 6, icon: , text: 'Assigned To', subtext: performers.find(p => p.id === chore.assignedTo)?.displayName, }, - // { - // size: 6, - // icon: , - // text: 'Created By', - // subtext: performers.find(p => p.id === chore.createdBy)?.displayName, - // }, + { + size: 6, + icon: , + text: 'Due Date', + subtext: chore.nextDueDate + ? moment(chore.nextDueDate).fromNow() + : 'N/A', + }, + // { // icon: , // text: 'Frequency', @@ -116,37 +115,40 @@ const ChoreView = () => { { size: 6, icon: , - text: 'Completed', + text: 'Total Completed', subtext: `${chore.totalCompletedCount} times`, }, { size: 6, icon: , - text: 'Last time', + text: 'Last Completed', subtext: - chore.lastCompletedDate && - moment(chore.lastCompletedDate).format('MM/DD/YYYY hh:mm A'), + // chore.lastCompletedDate && + // moment(chore.lastCompletedDate).format('MM/DD/YYYY hh:mm A'), + chore.lastCompletedDate && moment(chore.lastCompletedDate).fromNow(), }, { size: 6, icon: , - text: 'Last', + text: 'Last Performer', subtext: chore.lastCompletedDate ? `${ - chore.lastCompletedDate && - moment(chore.lastCompletedDate).fromNow() - // moment(chore.lastCompletedDate).format('MM/DD/YYYY hh:mm A')) - }(${ performers.find(p => p.id === chore.lastCompletedBy)?.displayName - })` + }` : 'Never', }, { - size: 12, - icon: , - text: 'Recent Note', - subtext: chore.notes || '--', + size: 6, + icon: , + text: 'Created By', + subtext: performers.find(p => p.id === chore.createdBy)?.displayName, }, + // { + // size: 12, + // icon: , + // text: 'Recent Note', + // subtext: chore.notes || '--', + // }, ] setInfoCards(cards) } @@ -195,7 +197,16 @@ const ChoreView = () => { setTimeoutId(id) } - + const handleSkippingTask = () => { + SkipChore(choreId).then(response => { + if (response.ok) { + response.json().then(data => { + const newChore = data.res + setChore(newChore) + }) + } + }) + } return ( { - - {infoCards.map((info, index) => ( - - - - - {info.icon} - + + Details + + + + + {infoCards.map((detail, index) => ( + + {/* divider between the list items: */} + + - - {info.text} + + {detail.text} - - {info.subtext ? info.subtext : '--'} + + {detail.subtext ? detail.subtext : '--'} - - - ))} - - + + ))} - - - - + + {chore.notes && ( + <> + + Previous note: + + + + {chore.notes || '--'} + + + + )} + + + + {/* */} - + + Actions + { }} size='md' sx={{ - my: 1, + mb: 1, }} /> - + { /> )} - {/* {completedDate === null && ( - // placeholder for the completion date with margin: - - - )} */} - - {/* */} - + - } - > - - Task will be marked as completed in {secondsLeftToCancel} seconds - - + message: 'Are you sure you want to skip this task?', + + confirmText: 'Skip', + cancelText: 'Cancel', + onClose: confirmed => { + if (confirmed) { + handleSkippingTask() + } + setConfirmModelConfig({}) + }, + }) + }} + startDecorator={} + > + Skip + + { + if (timeoutId) { + clearTimeout(timeoutId) + setIsPendingCompletion(false) + setTimeoutId(null) + setSecondsLeftToCancel(null) // Reset or adjust as needed + } + }} + size='lg' + variant='outlined' + color='danger' + startDecorator={} + > + Cancel + + } + > + + Task will be marked as completed in {secondsLeftToCancel} seconds + + + + ) } -- cgit