diff --git a/src/components/DailySummary.jsx b/src/components/DailySummary.jsx index 11229f1..6916afa 100644 --- a/src/components/DailySummary.jsx +++ b/src/components/DailySummary.jsx @@ -1,6 +1,5 @@ //react import { useState, useEffect } from 'react'; -import { Link } from 'react-router-dom'; // component import Button from './Button'; @@ -14,20 +13,31 @@ const DailySummary = ({ onSave, }) => { const max_chars = 500; - const [comment, setComment] = useState(initialComment || ''); + + const initialCommentObject = initialComment || {}; + const [comment, setComment] = useState(initialCommentObject.comment || ''); + + const [isOptedOut, setIsOptedOut] = useState( + initialCommentObject.optOut || false + ); + const remainingChars = max_chars - comment.length; useEffect(() => { - setComment(initialComment || ''); + const updatedCommentObject = initialComment || {}; + setComment(updatedCommentObject.comment || ''); + setIsOptedOut(updatedCommentObject.optOut || false); }, [initialComment, day]); const handleSave = () => { - onSave(day, comment); + onSave(day, comment, isOptedOut); onClose(); }; const handleCancel = () => { - setComment(initialComment || ''); + const updatedCommentObject = initialComment || {}; + setComment(updatedCommentObject.comment || ''); + setIsOptedOut(updatedCommentObject.optOut || false); onClose(); }; @@ -46,8 +56,9 @@ const DailySummary = ({ Day {day} Summary -

{question}

- + +

{question}

+