forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.jsx
More file actions
117 lines (109 loc) · 3.86 KB
/
index.jsx
File metadata and controls
117 lines (109 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { useState } from 'react';
import PropTypes from 'prop-types';
import {
Error as ErrorIcon,
Info as InfoIcon,
Warning as WarningIcon,
} from '@openedx/paragon/icons';
import { useIntl } from '@edx/frontend-platform/i18n';
import AlertMessage from '../../../generic/alert-message';
import { ActionButton, AlertContent } from './components';
import { getAlertStatus } from './utils';
import { initialNotificationAlertsState } from './constants';
import messages from './messages';
const PastNotificationAlert = ({ staticFileNotices, courseId }) => {
const intl = useIntl();
const [notificationAlerts, toggleNotificationAlerts] = useState(initialNotificationAlertsState);
const { conflictingFiles, errorFiles, newFiles } = staticFileNotices;
const hasConflictingErrors = getAlertStatus(conflictingFiles, 'conflictingFilesAlert', notificationAlerts);
const hasErrorFiles = getAlertStatus(errorFiles, 'errorFilesAlert', notificationAlerts);
const hasNewFiles = getAlertStatus(newFiles, 'newFilesAlert', notificationAlerts);
const handleCloseNotificationAlert = (alertKey) => {
toggleNotificationAlerts((prevAlerts) => ({
...prevAlerts,
[alertKey]: false,
}));
};
return (
<>
{hasConflictingErrors && (
<AlertMessage
data-testid="has-conflicting-errors-alert"
className="course-unit__alert"
title={intl.formatMessage(messages.hasConflictingErrorsTitle)}
onClose={() => handleCloseNotificationAlert('conflictingFilesAlert')}
description={(
<AlertContent
fileList={conflictingFiles}
text={intl.formatMessage(messages.hasConflictingErrorsDescription)}
/>
)}
variant="warning"
icon={WarningIcon}
dismissible
actions={[
// oxlint-disable-next-line react/jsx-key (Paragon <Alert> adds its own key for action buttons)
<ActionButton
courseId={courseId}
title={intl.formatMessage(messages.hasConflictingErrorsButtonText)}
/>,
]}
/>
)}
{hasErrorFiles && (
<AlertMessage
data-testid="has-error-files-alert"
className="course-unit__alert"
title={intl.formatMessage(messages.hasErrorsTitle)}
onClose={() => handleCloseNotificationAlert('errorFilesAlert')}
description={(
<AlertContent
fileList={errorFiles}
text={intl.formatMessage(messages.hasErrorsDescription)}
/>
)}
variant="danger"
icon={ErrorIcon}
dismissible
/>
)}
{hasNewFiles && (
<AlertMessage
data-testid="has-new-files-alert"
className="course-unit__alert"
title={intl.formatMessage(messages.hasNewFilesTitle)}
onClose={() => handleCloseNotificationAlert('newFilesAlert')}
description={(
<AlertContent
fileList={newFiles}
text={intl.formatMessage(messages.hasNewFilesDescription)}
/>
)}
variant="info"
icon={InfoIcon}
dismissible
actions={[
// oxlint-disable-next-line react/jsx-key (Paragon <Alert> adds its own key for action buttons)
<ActionButton
courseId={courseId}
title={intl.formatMessage(messages.hasNewFilesButtonText)}
/>,
]}
/>
)}
</>
);
};
PastNotificationAlert.propTypes = {
courseId: PropTypes.string.isRequired,
staticFileNotices:
PropTypes.shape({
conflictingFiles: PropTypes.arrayOf(PropTypes.string),
errorFiles: PropTypes.arrayOf(PropTypes.string),
newFiles: PropTypes.arrayOf(PropTypes.string),
}),
};
PastNotificationAlert.defaultProps = {
staticFileNotices: {},
};
export default PastNotificationAlert;