From cefa4504a097647d7d54f2b4202923df5a47a974 Mon Sep 17 00:00:00 2001 From: Yiyun Tan Date: Mon, 19 Dec 2022 16:40:44 -0700 Subject: [PATCH 1/2] try to fix the blue squares cannot be edit --- src/components/UserProfile/UserProfile.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/UserProfile/UserProfile.jsx b/src/components/UserProfile/UserProfile.jsx index 1cdc9412a7..58f4b9845b 100644 --- a/src/components/UserProfile/UserProfile.jsx +++ b/src/components/UserProfile/UserProfile.jsx @@ -250,15 +250,15 @@ const UserProfile = props => { setShowModal(false); setUserProfile({ ...userProfile, - infringements: userProfile.infringements.concat(newBlueSquare), + infringements: userProfile.infringements?.concat(newBlueSquare), }); setModalTitle('Blue Square'); } else if (operation === 'update') { - const currentBlueSquares = [...userProfile.infringements]; - if (dateStamp != null) { + const currentBlueSquares = [...userProfile?.infringements] || []; + if (dateStamp != null && currentBlueSquares !== []) { currentBlueSquares.find(blueSquare => blueSquare._id === id).date = dateStamp; } - if (summary != null) { + if (summary != null && currentBlueSquares !== []) { currentBlueSquares.find(blueSquare => blueSquare._id === id).description = summary; } @@ -266,7 +266,7 @@ const UserProfile = props => { setUserProfile({ ...userProfile, infringements: currentBlueSquares }); } else if (operation === 'delete') { const newInfringements = []; - userProfile.infringements.forEach(infringement => { + userProfile.infringements?.forEach(infringement => { if (infringement._id !== id) newInfringements.push(infringement); }); From b08cfafdeaadefafdc3112ecba26c23ed6a5fb15 Mon Sep 17 00:00:00 2001 From: Yiyun Tan Date: Mon, 19 Dec 2022 16:49:50 -0700 Subject: [PATCH 2/2] update const to let --- src/components/UserProfile/UserProfile.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/UserProfile/UserProfile.jsx b/src/components/UserProfile/UserProfile.jsx index 58f4b9845b..3fa5cc35ee 100644 --- a/src/components/UserProfile/UserProfile.jsx +++ b/src/components/UserProfile/UserProfile.jsx @@ -254,7 +254,7 @@ const UserProfile = props => { }); setModalTitle('Blue Square'); } else if (operation === 'update') { - const currentBlueSquares = [...userProfile?.infringements] || []; + let currentBlueSquares = [...userProfile?.infringements] || []; if (dateStamp != null && currentBlueSquares !== []) { currentBlueSquares.find(blueSquare => blueSquare._id === id).date = dateStamp; }