1
0
mirror of https://github.com/0rangebananaspy/authelia.git synced 2024-09-14 22:47:21 +07:00
authelia/web/src/components/NotificationBar.tsx
Amir Zarrinkafsh 689fd7cb95
[CI] Add linting option for frontend and enforce styling ()
We now extend the default Eslint configuration and enforce styling with prettier for all of our frontend code.
2021-01-02 21:58:24 +11:00

43 lines
1.4 KiB
TypeScript

import React, { useState, useEffect } from "react";
import { Snackbar } from "@material-ui/core";
import { useNotifications } from "../hooks/NotificationsContext";
import { Notification } from "../models/Notifications";
import ColoredSnackbarContent from "./ColoredSnackbarContent";
export interface Props {
onClose: () => void;
}
const NotificationBar = function (props: Props) {
const [tmpNotification, setTmpNotification] = useState(null as Notification | null);
const { notification } = useNotifications();
useEffect(() => {
if (notification && notification !== null) {
setTmpNotification(notification);
}
}, [notification]);
const shouldSnackbarBeOpen = notification !== undefined && notification !== null;
return (
<Snackbar
open={shouldSnackbarBeOpen}
anchorOrigin={{ vertical: "top", horizontal: "right" }}
autoHideDuration={tmpNotification ? tmpNotification.timeout * 1000 : 10000}
onClose={props.onClose}
onExited={() => setTmpNotification(null)}
>
<ColoredSnackbarContent
className="notification"
level={tmpNotification ? tmpNotification.level : "info"}
message={tmpNotification ? tmpNotification.message : ""}
/>
</Snackbar>
);
};
export default NotificationBar;