Skip to content

Commit 4f1710c

Browse files
Merge pull request #144 from mercedes-benz/VULCAN-941/GrayedOutButton
notification handler for rups package creation
2 parents e41142f + 5fe843a commit 4f1710c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/chart/table/TableChart.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { renderCellExpand } from '../../component/misc/DataGridExpandRenderer';
2525
import { getCheckboxes, hasCheckboxes, updateCheckBoxes } from './TableActionsHelper';
2626
import ApiService from '../../utils/apiService';
2727
import { AxiosResponse } from 'axios';
28+
import Notification from '../../component/custom/Notification';
2829

2930
const TABLE_HEADER_HEIGHT = 32;
3031
const TABLE_FOOTER_HEIGHT = 62;
@@ -143,6 +144,13 @@ export const NeoTableChart = (props: ChartProps) => {
143144
setAnchorEl(null);
144145
};
145146

147+
const [alertOpen, setAlertOpen] = React.useState(false);
148+
const [notificationMessage, setNotificationMessage] = React.useState('');
149+
const [notificationSeverity, setNotificationSeverity] = React.useState<'success' | 'warning' | 'error'>('success');
150+
151+
const handleNotificationClose = () => {
152+
setAlertOpen(false);
153+
};
146154
const lineBreakColumns: string[] = props.settings?.lineBreaksAfterListEntry;
147155

148156
const actionableFields = actionsRules.filter((r) => r.condition !== 'rowCheck').map((r) => r.field);
@@ -335,9 +343,15 @@ export const NeoTableChart = (props: ChartProps) => {
335343
}
336344

337345
props.updateReportSetting('apiSpec', { ...props.settings?.apiSpec, response });
346+
setNotificationMessage('RUPS package created. Please find the link above');
347+
setNotificationSeverity('success');
348+
setAlertOpen(true);
338349
} catch (error) {
339350
// Handle errors here
340351
console.error('API call error:', error);
352+
setNotificationMessage('RUPS package creation is currently not working. Please try again later.');
353+
setNotificationSeverity('error');
354+
setAlertOpen(true);
341355
} finally {
342356
setApiLoading(false);
343357
}
@@ -401,6 +415,12 @@ export const NeoTableChart = (props: ChartProps) => {
401415

402416
return (
403417
<ThemeProvider theme={theme}>
418+
<Notification
419+
open={alertOpen}
420+
message={notificationMessage}
421+
severity={notificationSeverity}
422+
onClose={handleNotificationClose}
423+
/>
404424
{isApiSpecEnabled ? apiCallButton() : <></>}
405425
<div className={classes.root} style={tableStyle}>
406426
<Snackbar

src/component/custom/Notification.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import Snackbar from '@mui/material/Snackbar';
3+
import MuiAlert, { AlertProps } from '@mui/material/Alert';
4+
5+
interface NotificationProps {
6+
open: boolean;
7+
message: string;
8+
severity: 'success' | 'warning' | 'error';
9+
onClose: () => void;
10+
}
11+
12+
const Alert = React.forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
13+
return <MuiAlert elevation={6} ref={ref} variant='filled' {...props} />;
14+
});
15+
16+
const Notification: React.FC<NotificationProps> = ({ open, message, severity, onClose }) => {
17+
return (
18+
<Snackbar open={open} autoHideDuration={6000} onClose={onClose}>
19+
<Alert onClose={onClose} severity={severity}>
20+
{message}
21+
</Alert>
22+
</Snackbar>
23+
);
24+
};
25+
26+
export default Notification;

0 commit comments

Comments
 (0)