From 67aad233fa06e84a97f18195806770a4fed61fdd Mon Sep 17 00:00:00 2001
From: "Rasamoelina, Haja Onjatiana" <26148770+rhahao@users.noreply.github.com>
Date: Fri, 16 Feb 2024 23:47:31 +0300
Subject: [PATCH] fix(schedules): support custom middle song for midweek
 meeting

---
 src/current/pages/SourceWeekDetails.jsx | 16 ++++++++++++++--
 src/current/views/S140.jsx              | 14 ++++++++++----
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/current/pages/SourceWeekDetails.jsx b/src/current/pages/SourceWeekDetails.jsx
index 652f0c7ad3..0e15f9844d 100644
--- a/src/current/pages/SourceWeekDetails.jsx
+++ b/src/current/pages/SourceWeekDetails.jsx
@@ -191,7 +191,7 @@ const SourceWeekDetails = () => {
     obj.mwb_ayf_part4_type = Ass4Type === '' ? undefined : +Ass4Type;
     obj.mwb_ayf_part4_time = Ass4Time === '' ? undefined : +Ass4Time;
     obj.mwb_ayf_part4 = Ass4Src;
-    obj.mwb_song_middle = +SongMiddle;
+    obj.mwb_song_middle = isNaN(SongMiddle) ? SongMiddle : +SongMiddle;
     obj.mwb_lc_cbs = CBSSrc;
     obj.mwb_song_conclude = isNaN(SongConclude) ? SongConclude : +SongConclude;
     obj.mwb_song_conclude_override = isNaN(SongConcludeOverride) ? SongConcludeOverride : +SongConcludeOverride;
@@ -508,7 +508,19 @@ const SourceWeekDetails = () => {
             <Typography variant="h6">{t('livingPart')}</Typography>
           </Box>
           <Box sx={{ marginTop: '20px' }}>
-            <SongsList song={SongMiddle} setSong={setSongMiddle} readOnly={!lmmoRole} />
+            {!isNaN(SongMiddle) && <SongsList song={SongMiddle} setSong={setSongMiddle} readOnly={!lmmoRole} />}
+            {isNaN(SongMiddle) && (
+              <TextField
+                id="outlined-song-middle"
+                label={t('song')}
+                variant="outlined"
+                size="small"
+                InputProps={{ readOnly: !lmmoRole }}
+                value={SongMiddle}
+                sx={{ width: '100%' }}
+                onChange={(value) => setSongMiddle(value)}
+              />
+            )}
           </Box>
           <Box sx={{ margin: '20px 0' }}>
             <Box sx={sharedStyles.ayfStuPart}>
diff --git a/src/current/views/S140.jsx b/src/current/views/S140.jsx
index 42dd060e55..4cdd0f176d 100644
--- a/src/current/views/S140.jsx
+++ b/src/current/views/S140.jsx
@@ -332,6 +332,15 @@ const S140 = ({ data, currentSchedule }) => {
     return src;
   };
 
+  const getMiddleSong = (weekItem) => {
+    let src = t('song', { lng: source_lang });
+
+    if (isNaN(weekItem.sourceData.mwb_song_middle)) return weekItem.sourceData.mwb_song_middle;
+
+    src += ` ${weekItem.sourceData.mwb_song_middle}`;
+    return src;
+  };
+
   const getConcludingSong = (weekItem) => {
     let src = t('song', { lng: source_lang });
 
@@ -585,10 +594,7 @@ const S140 = ({ data, currentSchedule }) => {
                             {/* Middle Song */}
                             <View style={styles.rowBase}>
                               <S140Time time={weekItem.sourceData.middleSong} />
-                              <S140SourceSimple
-                                source={`${t('song', { lng: source_lang })} ${weekItem.sourceData.mwb_song_middle}`}
-                                bulletColor="#942926"
-                              />
+                              <S140SourceSimple source={getMiddleSong(weekItem)} bulletColor="#942926" />
                               <S140PartMiniLabel part="" />
                               <S140Person person="" />
                             </View>