Skip to content

Commit 6711e0f

Browse files
refactor: Commented disable condition, and added separate condition to skip modal if only warnings are being logged through both button
1 parent 4b68b32 commit 6711e0f

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

src/components/UserProfile/UserProfileModal/UserProfileModal.jsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,43 @@ const UserProfileModal = props => {
189189
});
190190
};
191191

192-
const handleSubmitWarning = () => {
192+
const handleSubmitWarning = (warningData = warningSelections) => {
193193
setShowWarningSpinner(true);
194-
handleLogWarning(warningSelections);
194+
handleLogWarning(warningData);
195195
modifyBlueSquares(id, dateStamp, summary, 'delete');
196196
// setShowWarningSpinner(false);
197197
};
198+
199+
const handleLoggingBothWarnings = () => {
200+
// Handling both case when both Blue Square warning trackers have 1 or 0 warning occurrences logged for a user
201+
const updatedSelections = specialWarnings.reduce((acc, specialWarning) => {
202+
acc[specialWarning.title] = { warn: 'Log Warning', color: 'blue' };
203+
return acc;
204+
}, {});
205+
206+
updatedSelections.bothTriggered = true;
207+
208+
const issueBlueSquare = Object.entries(updatedSelections)
209+
.filter(([key]) => key !== 'bothTriggered' && key !== 'issueBlueSquare')
210+
.reduce((acc, [warningTitle, selection]) => {
211+
acc[warningTitle] = selection?.warn === 'Issue Blue Square';
212+
return acc;
213+
}, {});
214+
215+
const finalSelections = {
216+
...updatedSelections,
217+
issueBlueSquare,
218+
};
219+
220+
handleSubmitWarning(finalSelections);
221+
};
222+
198223
const handleToggleLogWarning = warningData => {
199224
if (warningData === 'both') {
225+
if(specialWarnings[0].warnings.length <= 1 && specialWarnings[1].warnings.length <= 1) {
226+
handleLoggingBothWarnings()
227+
return
228+
}
200229
setDisplayBothModal(true);
201230
setWarningType({
202231
specialWarnings,
@@ -679,7 +708,7 @@ const handleCcListUpdate = () => {
679708
<Button
680709
color="warning"
681710
name="both"
682-
disabled={!specialWarnings?.some(warn => warn.warnings.length >= 2)}
711+
// disabled={!specialWarnings?.some(warn => warn.warnings.length >= 2)}
683712
onClick={e => {
684713
handleToggleLogWarning('both');
685714
}}

0 commit comments

Comments
 (0)