Skip to content

Commit 89b385e

Browse files
feat: new locaition/pattern for StatusAlert update
1 parent b764038 commit 89b385e

23 files changed

+712
-60
lines changed

src/components/StatefulStatus/index.jsx

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/components/StatusAlert/index.jsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { Alert } from '@edx/paragon';
5+
import { CheckCircle, Info, WarningFilled } from '@edx/paragon/icons';
6+
import { useActiveView } from 'hooks';
7+
import { routeSteps, stepStates } from 'data/services/lms/constants';
8+
import { useStepState } from 'data/services/lms/hooks/selectors';
9+
10+
export const alertMap = {
11+
[stepStates.completed]: {
12+
variant: 'success',
13+
icon: CheckCircle,
14+
},
15+
[stepStates.closed]: {
16+
variant: 'danger',
17+
icon: Info,
18+
},
19+
[stepStates.teamAlreadySubmitted]: {
20+
variant: 'warning',
21+
icon: WarningFilled,
22+
},
23+
[stepStates.cancelled]: {
24+
variant: 'warning',
25+
icon: WarningFilled,
26+
},
27+
[stepStates.inProgress]: {
28+
variant: 'dark',
29+
icon: null,
30+
},
31+
};
32+
33+
const StatusAlert = ({
34+
headerText,
35+
message,
36+
action,
37+
alertState,
38+
}) => {
39+
// let stepState = useStepState({ step: routeSteps[useActiveView()] });
40+
const { variant, icon } = alertMap[alertState];
41+
const actions = action ? [action] : [];
42+
43+
console.log({ alertState, variant, icon });
44+
45+
return (
46+
<Alert
47+
variant={variant}
48+
icon={icon}
49+
actions={actions}
50+
>
51+
<Alert.Heading>{headerText}</Alert.Heading>
52+
<p>{message}</p>
53+
</Alert>
54+
);
55+
};
56+
StatusAlert.defaultProps = {
57+
action: null,
58+
alertState: null,
59+
};
60+
StatusAlert.propTypes = {
61+
headerText: PropTypes.node.isRequired,
62+
message: PropTypes.node.isRequired,
63+
action: PropTypes.node,
64+
alertState: PropTypes.string,
65+
};
66+
67+
export default StatusAlert;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineMessages } from '@edx/frontend-platform/i18n';
2+
3+
const messages = defineMessages({
4+
inProgressBadge: {
5+
id: 'ora-grading.StatusAlert.inProgressBadge',
6+
defaultMessage: 'In Progress',
7+
description: 'Label for the in progress badge',
8+
},
9+
completedBadge: {
10+
id: 'ora-grading.StatusAlert.completedBadge',
11+
defaultMessage: 'Completed',
12+
description: 'Label for the completed badge',
13+
},
14+
closedBadge: {
15+
id: 'ora-grading.StatusAlert.closedBadge',
16+
defaultMessage: 'Incomplete',
17+
description: 'Label for the incomplete badge',
18+
},
19+
cancelledBadge: {
20+
id: 'ora-grading.StatusAlert.cancelledBadge',
21+
defaultMessage: 'Cancelled',
22+
description: 'Label for the cancelled badge',
23+
},
24+
});
25+
26+
export default messages;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { Alert } from '@edx/paragon';
5+
6+
import StatusAlert from 'components/StatusAlert';
7+
8+
const CancelledState = ({
9+
headerText,
10+
message,
11+
title,
12+
}) => (
13+
<StatusAlert status="cancelled" title={title}>
14+
<Alert.Heading>{headerText}</Alert.Heading>
15+
<p>{message}</p>
16+
</StatusAlert>
17+
);
18+
19+
CancelledState.propTypes = {
20+
headerText: PropTypes.node.isRequired,
21+
message: PropTypes.node.isRequired,
22+
title: PropTypes.node.isRequired,
23+
};
24+
25+
export default CancelledState;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { Alert } from '@edx/paragon';
5+
import { useIntl } from '@edx/frontend-platform/i18n';
6+
7+
import StatusAlert from 'components/StatusAlert';
8+
9+
const ErrorState = ({
10+
headerText,
11+
message,
12+
title,
13+
}) => (
14+
<StatusAlert title={title} status="error">
15+
<Alert.Heading>{headerText}</Alert.Heading>
16+
<p>{message}</p>
17+
</StatusAlert>
18+
);
19+
ErrorState.propTypes = {
20+
headerText: PropTypes.node.isRequired,
21+
message: PropTypes.node.isRequired,
22+
title: PropTypes.node.isRequired,
23+
};
24+
25+
export default ErrorState;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { useIntl } from '@edx/frontend-platform/i18n';
5+
6+
import StatusAlert from 'components/StatusAlert';
7+
import messages from './messages';
8+
9+
const InProgressState = ({
10+
inProgressText,
11+
actions,
12+
title,
13+
}) => {
14+
const { formatMessage } = useIntl();
15+
return (
16+
<StatusAlert status="default" title={title}>
17+
<div>
18+
<p><strong>{formatMessage(messages.instructions)}: </strong>{inProgressText}</p>
19+
{actions}
20+
</div>
21+
</StatusAlert>
22+
);
23+
};
24+
InProgressState.defaultProps = {
25+
inProgressText: null,
26+
actions: null,
27+
};
28+
InProgressState.propTypes = {
29+
inProgressText: PropTypes.node,
30+
actions: PropTypes.arrayOf(PropTypes.node),
31+
title: PropTypes.node.isRequired,
32+
};
33+
34+
export default InProgressState;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { Alert } from '@edx/paragon';
5+
6+
import StatusAlert from 'components/StatusAlert';
7+
8+
const SuccessState = ({
9+
headerText,
10+
message,
11+
actions,
12+
title,
13+
}) => (
14+
<StatusAlert
15+
title={title}
16+
status="success"
17+
>
18+
<div className="d-flex align-items-center">
19+
<div className="d-flex flex-column">
20+
<Alert.Heading>{headerText}</Alert.Heading>
21+
<p>{message}</p>
22+
</div>
23+
{actions}
24+
</div>
25+
</StatusAlert>
26+
);
27+
28+
SuccessState.propTypes = {
29+
headerText: PropTypes.node.isRequired,
30+
message: PropTypes.node.isRequired,
31+
actions: PropTypes.arrayOf(PropTypes.node),
32+
title: PropTypes.node.isRequired,
33+
};
34+
export default SuccessState;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { default as InProgressState } from './InProgressState';
2+
export { default as CancelledState } from './CancelledState';
3+
export { default as SuccessState } from './SuccessState';
4+
export { default as ErrorState } from './ErrorState';
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { defineMessages } from '@edx/frontend-platform/i18n';
2+
3+
const messages = defineMessages({
4+
yourResponse: {
5+
id: 'ora-grading.AssessmentView.yourResponse',
6+
defaultMessage: 'Your response',
7+
description: 'Label for the response textarea',
8+
},
9+
instructions: {
10+
id: 'ora-grading.AssessmentView.instructions',
11+
defaultMessage: 'Instructions',
12+
description: 'Label for the instructions textarea',
13+
},
14+
instructionsText: {
15+
id: 'ora-grading.AssessmentView.instructionsText',
16+
defaultMessage: `Create a response to the prompt below.
17+
Progress will be saved automatically and you can return to complete your
18+
progress at any time. After you submit your response, you cannot edit
19+
it.`,
20+
description: 'Description for the instructions textarea',
21+
},
22+
inProgressBadge: {
23+
id: 'ora-grading.AssessmentView.inProgressBadge',
24+
defaultMessage: 'In Progress',
25+
description: 'Label for the in progress badge',
26+
},
27+
inProgressHeader: {
28+
id: 'ora-grading.AssessmentView.inProgressHeader',
29+
defaultMessage: 'Self-grading due by {dueDate}',
30+
description: 'Header for the in progress badge',
31+
},
32+
inProgressText: {
33+
id: 'ora-grading.AssessmentView.inProgressBadgeText',
34+
defaultMessage: `Assess your own response and give
35+
yourself a grade. Progress will be saved automatically and you
36+
can return to complete your self assessment at any time. After
37+
you submit your grade, you cannot edit it.`,
38+
description: 'Description for the in progress badge',
39+
},
40+
inProgressButton: {
41+
id: 'ora-grading.AssessmentView.inProgressButton',
42+
defaultMessage: 'Begin self assessment',
43+
description: 'Label for button to begin self assessment',
44+
},
45+
completedBadge: {
46+
id: 'ora-grading.AssessmentView.completedBadge',
47+
defaultMessage: 'Completed',
48+
description: 'Label for the completed badge',
49+
},
50+
completedHeader: {
51+
id: 'ora-grading.AssessmentView.completedHeader',
52+
defaultMessage: 'Practice grading is complete!',
53+
description: 'Header for the completed badge',
54+
},
55+
completedBodyHeader: {
56+
id: 'ora-grading.AssessmentView.completedBodyHeader',
57+
defaultMessage: 'Practice grading complete',
58+
description: 'Alert header for the completed badge',
59+
},
60+
completedBodyButton: {
61+
id: 'ora-grading.AssessmentView.completedBodyButton',
62+
defaultMessage: 'Begin peer grading',
63+
description: 'Label for button to view your grade',
64+
},
65+
errorBadge: {
66+
id: 'ora-grading.AssessmentView.errorBadge',
67+
defaultMessage: 'Incomplete',
68+
description: 'Label for the incomplete badge',
69+
},
70+
errorHeader: {
71+
id: 'ora-grading.AssessmentView.errorBadgeHeader',
72+
defaultMessage: 'This step is past due!',
73+
description: 'Header for the incomplete badge',
74+
},
75+
errorBodyHeader: {
76+
id: 'ora-grading.AssessmentView.errorBodyHeader',
77+
defaultMessage: 'The due date for this step has passed',
78+
description: 'Alert header for the incomplete badge',
79+
},
80+
cancelledBadge: {
81+
id: 'ora-grading.AssessmentView.cancelledBadge',
82+
defaultMessage: 'Cancelled',
83+
description: 'Label for the cancelled badge',
84+
},
85+
cancelledHeader: {
86+
id: 'ora-grading.AssessmentView.cancelledBadgeHeader',
87+
defaultMessage: 'Self-grading Due by {dueDate}',
88+
description: 'Header for the cancelled badge',
89+
},
90+
cancelledBodyHeader: {
91+
id: 'ora-grading.AssessmentView.cancelledBodyHeader',
92+
defaultMessage: 'This step has been cancelled',
93+
description: 'Alert header for the cancelled badge',
94+
},
95+
});
96+
97+
export default messages;

0 commit comments

Comments
 (0)