From 7991399bef62a0c13178ccca3e7cbd0da768455f Mon Sep 17 00:00:00 2001
From: Mo Tarbin <mhed.t91@gmail.com>
Date: Thu, 18 Jul 2024 18:06:04 -0400
Subject: Improve frequency metadata update

---
 src/views/ChoreEdit/RepeatSection.jsx | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

(limited to 'src/views/ChoreEdit/RepeatSection.jsx')

diff --git a/src/views/ChoreEdit/RepeatSection.jsx b/src/views/ChoreEdit/RepeatSection.jsx
index bdf6738..94d16c8 100644
--- a/src/views/ChoreEdit/RepeatSection.jsx
+++ b/src/views/ChoreEdit/RepeatSection.jsx
@@ -116,6 +116,7 @@ const RepeatOnSections = ({
                   onClick={() => {
                     setIntervalUnit(item)
                     onFrequencyMetadataUpdate({
+                      ...frequencyMetadata,
                       unit: item,
                     })
                   }}
@@ -167,6 +168,7 @@ const RepeatOnSections = ({
                         }
 
                         onFrequencyMetadataUpdate({
+                          ...frequencyMetadata,
                           days: newDaysOfTheWeek.sort(),
                         })
                       }}
@@ -247,6 +249,7 @@ const RepeatOnSections = ({
                         }
 
                         onFrequencyMetadataUpdate({
+                          ...frequencyMetadata,
                           months: newMonthsOfTheYear.sort(),
                         })
                         console.log('newMonthsOfTheYear', newMonthsOfTheYear)
@@ -363,7 +366,15 @@ const RepeatSection = ({
                         onFrequencyUpdate(1)
                         onFrequencyMetadataUpdate({
                           unit: 'days',
+                          time: frequencyMetadata?.time
+                            ? frequencyMetadata?.time
+                            : moment(
+                                moment(new Date()).format('YYYY-MM-DD') +
+                                  'T' +
+                                  '18:00',
+                              ).format(),
                         })
+
                         return
                       }
                       onFrequencyTypeUpdate(item)
@@ -419,11 +430,20 @@ const RepeatSection = ({
                                 }
                                 onFrequencyTypeUpdate(item)
                                 if (item === 'days_of_the_week') {
-                                  onFrequencyMetadataUpdate({ days: [] })
+                                  onFrequencyMetadataUpdate({
+                                    ...frequencyMetadata,
+                                    days: [],
+                                  })
                                 } else if (item === 'day_of_the_month') {
-                                  onFrequencyMetadataUpdate({ months: [] })
+                                  onFrequencyMetadataUpdate({
+                                    ...frequencyMetadata,
+                                    months: [],
+                                  })
                                 } else if (item === 'interval') {
-                                  onFrequencyMetadataUpdate({ unit: 'days' })
+                                  onFrequencyMetadataUpdate({
+                                    ...frequencyMetadata,
+                                    unit: 'days',
+                                  })
                                 }
                                 // setRepeatOn(item)
                               }}
-- 
cgit 

