Skip to content

Commit 6eded8d

Browse files
Merge pull request #4963 from OneCommunityGlobal/Anthony/Hotfix-Both-Modal-For-PR#3978
Anthony/Hotfix-Both-Modal-For-PR#3978
2 parents 93dceb3 + cf9b8d6 commit 6eded8d

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

src/components/UserProfile/UserProfileModal/UserProfileModal.jsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { OverlayTrigger, Popover } from 'react-bootstrap';
2222
import WarningModal from '../../Warnings/modals/WarningModal';
2323
import BlueSquareEmailCCPopup from '../BlueSquareEmailCCPopup';
2424
import CcUserList from './CCUserList';
25+
import PropTypes from 'prop-types';
2526

2627
const UserProfileModal = props => {
2728
const {
@@ -188,14 +189,43 @@ const UserProfileModal = props => {
188189
});
189190
};
190191

191-
const handleSubmitWarning = () => {
192+
const handleSubmitWarning = (warningData = warningSelections) => {
192193
setShowWarningSpinner(true);
193-
handleLogWarning(warningSelections);
194+
handleLogWarning(warningData);
194195
modifyBlueSquares(id, dateStamp, summary, 'delete');
195196
// setShowWarningSpinner(false);
196197
};
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+
197223
const handleToggleLogWarning = warningData => {
198224
if (warningData === 'both') {
225+
if(specialWarnings[0].warnings.length <= 1 && specialWarnings[1].warnings.length <= 1) {
226+
handleLoggingBothWarnings()
227+
return
228+
}
199229
setDisplayBothModal(true);
200230
setWarningType({
201231
specialWarnings,
@@ -747,4 +777,14 @@ const handleCcListUpdate = () => {
747777
);
748778
};
749779

780+
UserProfileModal.propTypes = {
781+
specialWarnings: PropTypes.arrayOf(
782+
PropTypes.shape({
783+
title: PropTypes.string,
784+
warnings: PropTypes.arrayOf(PropTypes.string),
785+
abbreviation: PropTypes.string
786+
})
787+
),
788+
};
789+
750790
export default connect(null, { hasPermission })(UserProfileModal);

0 commit comments

Comments
 (0)