Skip to content
Snippets Groups Projects
Settings.js 2.95 KiB
Newer Older
import React, { useState } from "react";
// core components
Larbi Gharib's avatar
Larbi Gharib committed
import Subscription from "./Subscription";
Larbi Gharib's avatar
Larbi Gharib committed
import PropTypes from "prop-types";
import AppBar from "@mui/material/AppBar";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
Larbi Gharib's avatar
Larbi Gharib committed
import { infoColor } from "assets/jss/material-dashboard-react.js";
import MuiAlert from "@mui/material/Alert";
Larbi Gharib's avatar
Larbi Gharib committed
import auth from "auth.js";
Larbi Gharib's avatar
Larbi Gharib committed
import i18next from "i18next";

function TabPanel(props) {
Larbi Gharib's avatar
Larbi Gharib committed
  const { children, value, index, ...other } = props;
Larbi Gharib's avatar
Larbi Gharib committed
  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      aria-labelledby={`simple-tab-${index}`}
      {...other}
    >
      {value === index && (
        <Box p={3}>
          <Typography component="div">{children}</Typography>
Larbi Gharib's avatar
Larbi Gharib committed
        </Box>
      )}
    </div>
  );
}

TabPanel.propTypes = {
Larbi Gharib's avatar
Larbi Gharib committed
  children: PropTypes.node,
  index: PropTypes.any.isRequired,
  value: PropTypes.any.isRequired,
};

function a11yProps(index) {
Larbi Gharib's avatar
Larbi Gharib committed
  return {
    id: `simple-tab-${index}`,
    "aria-controls": `simple-tabpanel-${index}`,
  };
}

function Alert(props) {
Larbi Gharib's avatar
Larbi Gharib committed
  return <MuiAlert elevation={6} variant="filled" {...props} />;
export default function Settings() {
  const [value, setValue] = useState(0);
  const [error, setError] = useState(false);
  const [severity, setSeverity] = useState("error");
  const [errorMessage, setErrorMessage] = useState("Test");
Larbi Gharib's avatar
Larbi Gharib committed
  const handleChange = (event, newValue) => {
    setValue(newValue);
  };
  if (!auth.hasAdminScope()) {
    return (
      <div>
        <h4>
          {i18next.t(
            "you_are_not_allowed_to_access_this_section",
            "You are not allowed to access this section. Please contact your administrator to get administrator privileges."
          )}
Larbi Gharib's avatar
Larbi Gharib committed
        </h4>
      </div>
    );
  } else {
    return (
Larbi Gharib's avatar
Larbi Gharib committed
      <div>
        <AppBar position="static" style={{ background: infoColor[0] }}>
          <Tabs
            value={value}
            onChange={handleChange}
            aria-label="simple tabs example"
          >
            <Tab label={i18next.t("general", "General")} {...a11yProps(0)} />
            <Tab
              label={i18next.t("subscription", "Subscription")}
              {...a11yProps(1)}
            />
Larbi Gharib's avatar
Larbi Gharib committed
          </Tabs>
        </AppBar>
        <TabPanel value={value} index={0}>
Larbi Gharib's avatar
Larbi Gharib committed
            username="admin"
            setError={setError}
            setErrorMessage={setErrorMessage}
            setSeverity={setSeverity}
          />
        </TabPanel>
        <TabPanel value={value} index={1}>
          <Subscription
            setError={setError}
            setErrorMessage={setErrorMessage}
            setSeverity={setSeverity}
          />
        </TabPanel>
        {error && errorMessage && (
          <Alert severity={severity}>{errorMessage}</Alert>
        )}
      </div>
Larbi Gharib's avatar
Larbi Gharib committed
  }