Update Fetcher.jsx to include UpdateChoreAssignee function and ChoreCard.jsx to handle assignee change

This commit is contained in:
Mo Tarbin 2024-08-10 02:08:49 -04:00
parent b5f17dc7a6
commit e974568374
4 changed files with 33 additions and 14 deletions

View file

@ -83,6 +83,15 @@ const SkipChore = id => {
body: JSON.stringify({}), body: JSON.stringify({}),
}) })
} }
const UpdateChoreAssignee = (id, assignee) => {
return Fetch(`${API_URL}/chores/${id}/assignee`, {
method: 'PUT',
headers: HEADERS(),
body: JSON.stringify({ assignee:Number(assignee) }),
})
}
const CreateChore = chore => { const CreateChore = chore => {
return Fetch(`${API_URL}/chores/`, { return Fetch(`${API_URL}/chores/`, {
method: 'POST', method: 'POST',
@ -306,4 +315,5 @@ export {
UpdateChoreHistory, UpdateChoreHistory,
UpdateThingState, UpdateThingState,
UpdateUserDetails, UpdateUserDetails,
UpdateChoreAssignee,
} }

View file

@ -39,7 +39,7 @@ import moment from 'moment'
import React, { useEffect } from 'react' import React, { useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { API_URL } from '../../Config' import { API_URL } from '../../Config'
import { MarkChoreComplete, SkipChore } from '../../utils/Fetcher' import { MarkChoreComplete, SkipChore, UpdateChoreAssignee } from '../../utils/Fetcher'
import { Fetch } from '../../utils/TokenManager' import { Fetch } from '../../utils/TokenManager'
import ConfirmationModal from '../Modals/Inputs/ConfirmationModal' import ConfirmationModal from '../Modals/Inputs/ConfirmationModal'
import DateModal from '../Modals/Inputs/DateModal' import DateModal from '../Modals/Inputs/DateModal'
@ -219,7 +219,16 @@ const ChoreCard = ({
}) })
} }
const handleAssigneChange = assigneeId => { const handleAssigneChange = assigneeId => {
// TODO: Implement assignee change UpdateChoreAssignee(chore.id, assigneeId).then(response => {
if (response.ok) {
response.json().then(data => {
const newChore = data.res
onChoreUpdate(newChore, 'assigned')
})
}
}
)
} }
const handleCompleteWithNote = note => { const handleCompleteWithNote = note => {
Fetch(`${API_URL}/chores/${chore.id}/do`, { Fetch(`${API_URL}/chores/${chore.id}/do`, {
@ -547,10 +556,6 @@ const ChoreCard = ({
<RecordVoiceOver /> <RecordVoiceOver />
Delegate to someone else Delegate to someone else
</MenuItem> </MenuItem>
<MenuItem>
<HowToReg />
Complete as someone else
</MenuItem>
<Divider /> <Divider />
<MenuItem <MenuItem
onClick={() => { onClick={() => {
@ -620,10 +625,14 @@ const ChoreCard = ({
options={performers} options={performers}
displayKey='displayName' displayKey='displayName'
title={`Delegate to someone else`} title={`Delegate to someone else`}
placeholder={'Select a performer'}
onClose={() => { onClose={() => {
setIsChangeAssigneeModalOpen(false) setIsChangeAssigneeModalOpen(false)
}} }}
onSave={handleAssigneChange} onSave={(selected)=>{
handleAssigneChange(selected.id)
}
}
/> />
<ConfirmationModal config={confirmModelConfig} /> <ConfirmationModal config={confirmModelConfig} />
<TextModal <TextModal

View file

@ -9,7 +9,7 @@ import {
} from '@mui/joy' } from '@mui/joy'
import React from 'react' import React from 'react'
function SelectModal({ isOpen, onClose, onSave, options, title, displayKey }) { function SelectModal({ isOpen, onClose, onSave, options, title, displayKey,placeholder }) {
const [selected, setSelected] = React.useState(null) const [selected, setSelected] = React.useState(null)
const handleSave = () => { const handleSave = () => {
onSave(options.find(item => item.id === selected)) onSave(options.find(item => item.id === selected))
@ -20,7 +20,7 @@ function SelectModal({ isOpen, onClose, onSave, options, title, displayKey }) {
<Modal open={isOpen} onClose={onClose}> <Modal open={isOpen} onClose={onClose}>
<ModalDialog> <ModalDialog>
<Typography variant='h4'>{title}</Typography> <Typography variant='h4'>{title}</Typography>
<Select> <Select placeholder={placeholder}>
{options.map((item, index) => ( {options.map((item, index) => (
<Option <Option
value={item.id} value={item.id}

View file

@ -30,11 +30,11 @@ const links = [
label: 'Home', label: 'Home',
icon: <HomeOutlined />, icon: <HomeOutlined />,
}, },
{ // {
to: '/chores', // to: '/chores',
label: 'Desktop View', // label: 'Desktop View',
icon: <ListAltRounded />, // icon: <ListAltRounded />,
}, // },
{ {
to: '/things', to: '/things',
label: 'Things', label: 'Things',