Skip to content

Commit 675a566

Browse files
committed
fix: error message
1 parent 1c07594 commit 675a566

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useEffect } from 'react';
2+
import {
3+
Alert,
4+
} from '@openedx/paragon';
5+
6+
import { Info } from '@openedx/paragon/icons';
7+
import { useIntl } from '@edx/frontend-platform/i18n';
8+
import './TableView.scss';
9+
import messages from './messages';
10+
11+
interface SaveErrorAlertProps {
12+
draftError: string | undefined;
13+
isError: boolean | undefined;
14+
isUpdateError: boolean | undefined;
15+
}
16+
const SaveErrorAlert = ({ draftError, isError, isUpdateError }: SaveErrorAlertProps) => {
17+
const intl = useIntl();
18+
const hasError = (isError || isUpdateError) && !!draftError;
19+
const [alertOpen, setAlertOpen] = React.useState(hasError);
20+
21+
useEffect(() => {
22+
if (hasError) {
23+
setAlertOpen(true);
24+
}
25+
if (!hasError) {
26+
setAlertOpen(false);
27+
}
28+
}, [hasError, isError, isUpdateError, draftError]);
29+
30+
if (!alertOpen) { return null; }
31+
32+
return (
33+
<Alert variant="danger" icon={Info} dismissible onClose={() => { setAlertOpen(false) }}>
34+
<Alert.Heading>
35+
{intl.formatMessage(messages.errorSavingTitle)}
36+
</Alert.Heading>
37+
{intl.formatMessage(messages.errorSavingMessage, { errorMessage: draftError }) }
38+
</Alert>
39+
);
40+
};
41+
42+
export default SaveErrorAlert;

src/taxonomy/tree-table/TableView.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
Card,
66
ActionRow,
77
Pagination,
8-
Alert,
98
Icon,
109
} from '@openedx/paragon';
1110

@@ -18,7 +17,7 @@ import {
1817
type PaginationState,
1918
} from '@tanstack/react-table';
2019

21-
import { ArrowDropUpDown, Info } from '@openedx/paragon/icons';
20+
import { ArrowDropUpDown } from '@openedx/paragon/icons';
2221
import { useIntl } from '@edx/frontend-platform/i18n';
2322
import TableBody from './TableBody';
2423
import './TableView.scss';
@@ -30,6 +29,7 @@ import type {
3029
TreeRowData,
3130
} from './types';
3231
import messages from './messages';
32+
import SaveErrorAlert from './SaveErrorAlert';
3333

3434
interface TableViewProps {
3535
treeData: TreeRowData[];
@@ -102,18 +102,10 @@ const TableView = ({
102102

103103
const { isError } = createRowMutation;
104104
const { isError: isUpdateError } = updateRowMutation;
105-
const [showError, setShowError] = React.useState(true);
106105

107106
return (
108107
<>
109-
{(isError || isUpdateError) && showError && (
110-
<Alert variant="danger" icon={Info} dismissible onClose={() => setShowError(false)}>
111-
<Alert.Heading>
112-
{intl.formatMessage(messages.errorSavingTitle)}
113-
</Alert.Heading>
114-
{intl.formatMessage(messages.errorSavingMessage, { errorMessage: draftError || intl.formatMessage(messages.errorSavingMessage, { errorMessage: '' }) })}
115-
</Alert>
116-
)}
108+
<SaveErrorAlert draftError={draftError} isError={isError} isUpdateError={isUpdateError} />
117109
<Card className="tag-list-card">
118110
<Card.Section className="p-0">
119111
<div className="d-flex justify-content-end align-items-center p-4">

0 commit comments

Comments
 (0)