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/utils/Fetcher.jsx | 11 ++ src/views/ChoreEdit/ChoreView.jsx | 298 ++++++++++++++++++++------------------ src/views/Chores/ChoreCard.jsx | 10 +- 3 files changed, 170 insertions(+), 149 deletions(-) diff --git a/src/utils/Fetcher.jsx b/src/utils/Fetcher.jsx index afa9235..1161543 100644 --- a/src/utils/Fetcher.jsx +++ b/src/utils/Fetcher.jsx @@ -73,6 +73,16 @@ const MarkChoreComplete = (id, note, completedDate) => { body: JSON.stringify(body), }) } + +const SkipChore = id => { + return Fetch(`${API_URL}/chores/${id}/skip`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({}), + }) +} const CreateChore = chore => { return Fetch(`${API_URL}/chores/`, { method: 'POST', @@ -277,6 +287,7 @@ export { SaveChore, SaveThing, signUp, + SkipChore, UpdateThingState, UpdateUserDetails, } 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 + + + + ) } diff --git a/src/views/Chores/ChoreCard.jsx b/src/views/Chores/ChoreCard.jsx index 08a5406..6edcbd3 100644 --- a/src/views/Chores/ChoreCard.jsx +++ b/src/views/Chores/ChoreCard.jsx @@ -38,7 +38,7 @@ import moment from 'moment' import React, { useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { API_URL } from '../../Config' -import { MarkChoreComplete } from '../../utils/Fetcher' +import { MarkChoreComplete, SkipChore } from '../../utils/Fetcher' import { Fetch } from '../../utils/TokenManager' import ConfirmationModal from '../Modals/Inputs/ConfirmationModal' import DateModal from '../Modals/Inputs/DateModal' @@ -521,13 +521,7 @@ const ChoreCard = ({ { - Fetch(`${API_URL}/chores/${chore.id}/skip`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({}), - }).then(response => { + SkipChore(chore.id).then(response => { if (response.ok) { response.json().then(data => { const newChore = data.res -- cgit