Merge branch 'master' into 14078-obtain-configuration-data-from-discovery-endpoint
[arvados.git] / src / views-components / snackbar / snackbar.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { connect } from "react-redux";
7 import { RootState } from "~/store/store";
8 import MaterialSnackbar, { SnackbarProps } from "@material-ui/core/Snackbar";
9 import { Dispatch } from "redux";
10 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
11
12 const mapStateToProps = (state: RootState): SnackbarProps => ({
13     anchorOrigin: { vertical: "bottom", horizontal: "center" },
14     open: state.snackbar.open,
15     message: <span>{state.snackbar.message}</span>,
16     autoHideDuration: state.snackbar.hideDuration
17 });
18
19 const mapDispatchToProps = (dispatch: Dispatch): Pick<SnackbarProps, "onClose"> => ({
20     onClose: (event: any, reason: string) => {
21         if (reason !== "clickaway") {
22             dispatch(snackbarActions.CLOSE_SNACKBAR());
23         }
24     }
25 });
26
27 export const Snackbar = connect(mapStateToProps, mapDispatchToProps)(MaterialSnackbar);