Skip to content
Snippets Groups Projects
Settings.js 3.05 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";
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(value, index) {
Larbi Gharib's avatar
Larbi Gharib committed
  return {
    id: `simple-tab-${index}`,
    "aria-controls": `simple-tabpanel-${index}`,
    style: { color: index === value ? "inherit" : "#ffffff80" },
Larbi Gharib's avatar
Larbi Gharib committed
  };
}

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" color="primary">
Larbi Gharib's avatar
Larbi Gharib committed
          <Tabs
            value={value}
            onChange={handleChange}
            aria-label="settings tabs"
            textColor="secondary"
            indicatorColor="secondary"
Larbi Gharib's avatar
Larbi Gharib committed
          >
            <Tab
              label={i18next.t("general", "General")}
              {...a11yProps(value, 0)}
            />
            <Tab
              label={i18next.t("subscription", "Subscription")}
              {...a11yProps(value, 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
  }