diff --git a/jams-react-client/src/components/Devices/Devices.js b/jams-react-client/src/components/Devices/Devices.js index fd18e1c3999c0fc9f208c4695569b5f02a499a78..7eb82d483a881356025478cbdfa1e7da010a838e 100755 --- a/jams-react-client/src/components/Devices/Devices.js +++ b/jams-react-client/src/components/Devices/Devices.js @@ -271,7 +271,7 @@ export default function Devices(props) { <DialogTitle id="form-revoke-dialog-title">Revoke Device</DialogTitle> <DialogContent> <DialogContentText> - Are you sure you want to revoke this device!? + Are you sure you want to revoke this device? </DialogContentText> </DialogContent> <DialogActions> diff --git a/jams-react-client/src/components/Sidebar/Sidebar.js b/jams-react-client/src/components/Sidebar/Sidebar.js index 5f86acaa912850f98a1822eff7af6d7152f9c162..4bfe467d75a57b8053259e4ee282c67a46d45eb6 100755 --- a/jams-react-client/src/components/Sidebar/Sidebar.js +++ b/jams-react-client/src/components/Sidebar/Sidebar.js @@ -12,7 +12,7 @@ import List from "@material-ui/core/List"; import ListItem from "@material-ui/core/ListItem"; import ListItemText from "@material-ui/core/ListItemText"; import Icon from "@material-ui/core/Icon"; -import Button from '@material-ui/core/Button'; + // core components import AdminNavbarLinks from "components/Navbars/AdminNavbarLinks.js"; import RTLNavbarLinks from "components/Navbars/RTLNavbarLinks.js"; @@ -21,20 +21,16 @@ import UpdateIcon from '@material-ui/icons/Update'; import styles from "assets/jss/material-dashboard-react/components/sidebarStyle.js"; -import configApiCall from "api.js"; import auth from "auth"; -import { api_path_get_start_update } from "globalUrls"; -import axios from "axios"; import Snackbar from "@material-ui/core/Snackbar/Snackbar"; + const useStyles = makeStyles(styles); export default function Sidebar(props) { const classes = useStyles(); const mainPanel = React.createRef(); const [open, setOpen] = React.useState(false); - const [updating, setUpdating] = React.useState(false); - const [message, setMessage] = React.useState(false) const history = useHistory(); const handleCloseProfile = () => { @@ -46,21 +42,12 @@ export default function Sidebar(props) { history.push(layout+path.substring(0, 2)) }; - const handleUpdate = () => { - setMessage("Updating JAMS, shutting down shortly...") - axios(configApiCall(api_path_get_start_update, 'POST', null, null)).then(()=>{ - setUpdating(true) - }).catch((error) => { - setMessage("Error while attempting to update JAMS: " + error) - }) - } + React.useEffect(() => { - React.useEffect(() => { + if(auth.isUpdateAvailable()) + setOpen(true) - if(auth.isUpdateAvailable()) - setOpen(true) - - }, [mainPanel]); + }, [mainPanel]); // verifies if routeName is the one active (in browser input) function activeRoute(routeName) { @@ -87,15 +74,14 @@ export default function Sidebar(props) { }); return ( <div className={classes.wrapper}> - {updating &&<Snackbar + {props.updating && <Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} open={open} - message={message} + message={props.snackbarMessage} key={'bottomright'} > </Snackbar>} - <NavLink to={prop.layout + prop.path} className={activePro + classes.item} @@ -132,7 +118,10 @@ export default function Sidebar(props) { })} {open && - <ListItem button className={classes.itemLink} onClick={handleUpdate}> + <ListItem button className={classes.itemLink} onClick={e => { + props.handleQuery() + props.setOpenUpdate(true) + }}> <Icon className={classNames(classes.itemIcon, { [classes.itemIconRTL]: false diff --git a/jams-react-client/src/layouts/Admin.js b/jams-react-client/src/layouts/Admin.js index 132e6c1ad1b50123fceb5bd0e7cd066b4892feac..04b177d0ec9b62ed14aab9a812d1a830da071307 100644 --- a/jams-react-client/src/layouts/Admin.js +++ b/jams-react-client/src/layouts/Admin.js @@ -19,10 +19,23 @@ import bgImage from "assets/img/sidebar-2.jpg"; import logo from "assets/img/logo-jams.svg"; import auth from 'auth' +import configApiCall from "api.js"; +import { api_path_get_start_update, api_path_get_subscription_status } from "globalUrls"; + +import axios from "axios"; + import ReactDOM from "react-dom"; import {ConfiguredRoute} from "../configured.route"; import SignIn from "./SignIn"; import {ProtectedRoute} from "../protected.route"; +import Dialog from "@material-ui/core/Dialog/Dialog"; +import DialogTitle from "@material-ui/core/DialogTitle/DialogTitle"; +import {Field, Formik} from "formik"; +import DialogContent from "@material-ui/core/DialogContent/DialogContent"; +import TextField from "@material-ui/core/TextField/TextField"; +import DialogActions from "@material-ui/core/DialogActions/DialogActions"; +import DialogContentText from "@material-ui/core/DialogContentText/DialogContentText"; +import Button from '@material-ui/core/Button'; let ps; @@ -63,13 +76,17 @@ export default function Admin({ ...rest }) { const [mobileOpen, setMobileOpen] = React.useState(false); const [open, setOpen] = React.useState(false); const [message, setMessage] = React.useState(false) - const [signedUp, setSignedUp] = React.useState(false); const [signedIn, setSignedIn] = React.useState(false); const [token, setToken] = React.useState(false); const [severity, setSeverity] = React.useState("success") - - + const [openUpdate, setOpenUpdate] = React.useState(false) + const [dialogMessage, setDialogMessage] = React.useState("") + const [messageYes, setMessageYes] = React.useState("") + const [messageNo, setMessageNo] = React.useState("") + const [updating, setUpdating] = React.useState(false); + const [query, setQuery] = React.useState(false); + const [snackbarMessage, setSnackbarMessage] = React.useState(""); const handleImageClick = image => { setImage(image); @@ -95,6 +112,20 @@ export default function Admin({ ...rest }) { setMobileOpen(false); } }; + + const handleQuery = () => { + setQuery(true); + if (auth.isActivated()) { + setDialogMessage("A new version of JAMS is available. Would you like to update now?") + setMessageYes("Update Now") + setMessageNo("Update Later") + } else { + setDialogMessage("You are currently running the community version of JAMS. Would you like to purchase a JAMS subscription?") + setMessageYes("Yes, go to Jami Store") + setMessageNo("No thanks") + } + } + // initialize and destroy the PerfectScrollbar plugin React.useEffect(() => { @@ -122,10 +153,50 @@ export default function Admin({ ...rest }) { } window.removeEventListener("resize", resizeFunction); }; - }, [mainPanel]); + }, [openUpdate, mainPanel]); + + + + const handleCancel = () => { + setOpenUpdate(false); + } + + const handleUpdate = () => { + setQuery(false) + if (auth.isActivated()) { + setSnackbarMessage("Updating JAMS, shutting down shortly...") + axios(configApiCall(api_path_get_start_update, 'POST', null, null)).then(() => { + handleCancel() + setUpdating(true) + }).catch((error) => { + setSnackbarMessage("Error while attempting to update JAMS: " + error) + }) + } + } return ( <div className={classes.wrapper}> + <Dialog open={openUpdate} onClose={handleCancel} aria-labelledby="form-dialog-title"> + <DialogTitle id="form-revoke-dialog-title">Jams Update</DialogTitle> + <DialogContent> + <DialogContentText id="alert-dialog-description"> + {dialogMessage} + </DialogContentText> + </DialogContent> + <DialogActions> + <Button onClick={e => { + if (auth.isActivated()) + handleUpdate() + else + window.location.href ='https://staging.jami.biz/' + }} color="primary"> + {messageYes} + </Button> + <Button onClick={handleCancel} color="primary"> + {messageNo} + </Button> + </DialogActions> + </Dialog> <Sidebar routes={routes} logoText={"Jams"} @@ -134,6 +205,10 @@ export default function Admin({ ...rest }) { handleDrawerToggle={handleDrawerToggle} open={mobileOpen} color={color} + handleQuery={handleQuery} + updating={updating} + snackbarMessage={snackbarMessage} + setOpenUpdate={setOpenUpdate} {...rest} />