From e9745683748ac5ecfdf704607441a3204d8c5516 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Sat, 10 Aug 2024 02:08:49 -0400 Subject: Update Fetcher.jsx to include UpdateChoreAssignee function and ChoreCard.jsx to handle assignee change --- src/utils/Fetcher.jsx | 10 ++++++++++ src/views/Chores/ChoreCard.jsx | 23 ++++++++++++++++------- src/views/Modals/Inputs/SelectModal.jsx | 4 ++-- src/views/components/NavBar.jsx | 10 +++++----- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/utils/Fetcher.jsx b/src/utils/Fetcher.jsx index 17b6cd9..5b3bbd9 100644 --- a/src/utils/Fetcher.jsx +++ b/src/utils/Fetcher.jsx @@ -83,6 +83,15 @@ const SkipChore = id => { 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 => { return Fetch(`${API_URL}/chores/`, { method: 'POST', @@ -306,4 +315,5 @@ export { UpdateChoreHistory, UpdateThingState, UpdateUserDetails, + UpdateChoreAssignee, } diff --git a/src/views/Chores/ChoreCard.jsx b/src/views/Chores/ChoreCard.jsx index 97e407a..fdf025e 100644 --- a/src/views/Chores/ChoreCard.jsx +++ b/src/views/Chores/ChoreCard.jsx @@ -39,7 +39,7 @@ import moment from 'moment' import React, { useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { API_URL } from '../../Config' -import { MarkChoreComplete, SkipChore } from '../../utils/Fetcher' +import { MarkChoreComplete, SkipChore, UpdateChoreAssignee } from '../../utils/Fetcher' import { Fetch } from '../../utils/TokenManager' import ConfirmationModal from '../Modals/Inputs/ConfirmationModal' import DateModal from '../Modals/Inputs/DateModal' @@ -219,7 +219,16 @@ const ChoreCard = ({ }) } 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 => { Fetch(`${API_URL}/chores/${chore.id}/do`, { @@ -547,10 +556,6 @@ const ChoreCard = ({ Delegate to someone else - - - Complete as someone else - { @@ -620,10 +625,14 @@ const ChoreCard = ({ options={performers} displayKey='displayName' title={`Delegate to someone else`} + placeholder={'Select a performer'} onClose={() => { setIsChangeAssigneeModalOpen(false) }} - onSave={handleAssigneChange} + onSave={(selected)=>{ + handleAssigneChange(selected.id) + } + } /> { onSave(options.find(item => item.id === selected)) @@ -20,7 +20,7 @@ function SelectModal({ isOpen, onClose, onSave, options, title, displayKey }) { {title} - {options.map((item, index) => (