[WIP] style changes, work on error handling and user feedback

This commit is contained in:
Sina Blattmann 2023-02-23 16:37:14 +01:00
parent cba19ee1ed
commit 633c3de5bc
11 changed files with 331 additions and 270 deletions

View File

@ -1,10 +1,10 @@
import useToken from "./hooks/useToken";
import Login from "./Login";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { Box, Grid, Divider } from "@mui/material";
import NestedList from "./components/NestedList";
import { Box, Grid, Divider, createTheme, ThemeProvider } from "@mui/material";
import InstallationList from "./components/InstallationList";
import BasicTable from "./components/Table";
import BasicTabs from "./components/Tabs";
import InstallationTabs from "./components/InstallationTabs";
import Alarms from "./routes/Alarms";
import InstallationDetail from "./routes/Installation";
import Log from "./routes/Log";
@ -13,11 +13,23 @@ import { IntlProvider } from "react-intl";
import { useState } from "react";
import en from "./lang/en.json";
import de from "./lang/de.json";
import LanguageSelect from "./components/LanguageSelect";
import LogoutButton from "./components/LogoutButton";
import NavigationButtons from "./components/NavigationButtons";
import UserList from "./components/UserTree";
const App = () => {
const { token, setToken, removeToken } = useToken();
const [language, setLanguage] = useState("en");
const [currentView, setCurrentView] = useState("installations");
const theme = createTheme({
palette: {
primary: {
main: "#F59100",
},
},
});
const getTranslations = () => {
if (language === "de") {
@ -32,46 +44,62 @@ const App = () => {
return (
<BrowserRouter>
<IntlProvider
messages={getTranslations()}
locale={language}
defaultLocale="en"
>
<Box sx={{ padding: 2 }}>
<Grid container spacing={2}>
<Grid item xs={3}>
<NavigationButtons />
<NestedList />
</Grid>
<Grid
item
xs={1}
container
direction="row"
justifyContent="center"
alignItems="center"
>
<Divider orientation="vertical" variant="middle" />
</Grid>
<Grid item xs={8}>
<BasicTabs
removeToken={removeToken}
language={language}
setLanguage={setLanguage}
/>
<Routes>
<Route
path={routes.installationWithId}
element={<InstallationDetail />}
/>
<Route path={routes.alarmsWithId} element={<Alarms />} />
<Route path={routes.usersWithId} element={<BasicTable />} />
<Route path={routes.logWithId} element={<Log />} />
</Routes>
</Grid>
<ThemeProvider theme={theme}>
<IntlProvider
messages={getTranslations()}
locale={language}
defaultLocale="en"
>
<Grid container justifyContent="flex-end" sx={{ px: 1, pt: 1 }}>
<LanguageSelect language={language} setLanguage={setLanguage} />
<LogoutButton removeToken={removeToken} />
</Grid>
</Box>
</IntlProvider>
<Box sx={{ p: 1 }}>
<Grid container spacing={2}>
<Grid item xs={3}>
<NavigationButtons
currentView={currentView}
setCurrentView={setCurrentView}
/>
{currentView === "installations" ? (
<InstallationList />
) : (
<UserList />
)}
</Grid>
<Grid
item
xs={1}
container
direction="row"
justifyContent="center"
alignItems="center"
>
<Divider orientation="vertical" variant="middle" />
</Grid>
<Grid item xs={8}>
{currentView === "installations" && (
<>
<InstallationTabs />
<Routes>
<Route
path={routes.installationWithId}
element={<InstallationDetail />}
/>
<Route path={routes.alarmsWithId} element={<Alarms />} />
<Route
path={routes.usersWithId}
element={<BasicTable />}
/>
<Route path={routes.logWithId} element={<Log />} />
</Routes>
</>
)}
</Grid>
</Grid>
</Box>
</IntlProvider>
</ThemeProvider>
</BrowserRouter>
);
};

View File

@ -1,4 +1,4 @@
import { Alert, Button, Snackbar } from "@mui/material";
import { Alert, Button, Grid, InputLabel, Snackbar } from "@mui/material";
import { useFormik } from "formik";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
@ -92,20 +92,25 @@ const CustomerForm = (props: I_CustomerFormProps) => {
value={formik.values.orderNumbers}
handleChange={formik.handleChange}
/>
<Button variant="outlined" type="submit">
<FormattedMessage id="applyChanges" defaultMessage="Apply changes" />
</Button>
<Grid container justifyContent="flex-end" sx={{ pt: 1 }}>
<Button variant="outlined" type="submit">
<FormattedMessage id="applyChanges" defaultMessage="Apply changes" />
</Button>
</Grid>
<Snackbar
open={open}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
vertical: "top",
horizontal: "center",
}}
autoHideDuration={6000}
onClose={handleClose}
>
<Alert onClose={handleClose} severity="success" sx={{ width: "100%" }}>
<FormattedMessage id="updatedSuccessfully" defaultMessage="Updated successfully" />
<FormattedMessage
id="updatedSuccessfully"
defaultMessage="Updated successfully"
/>
</Alert>
</Snackbar>
</form>

View File

@ -1,4 +1,4 @@
import { TextField } from "@mui/material";
import { Grid, InputLabel, TextField } from "@mui/material";
interface I_InnovenergyTextfieldProps {
id: string;
@ -7,21 +7,31 @@ interface I_InnovenergyTextfieldProps {
name: string;
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
type?: string;
readOnly?: boolean;
}
const InnovenergyTextfield = (props: I_InnovenergyTextfieldProps) => {
return (
<TextField
id={props.id}
label={props.label}
variant="outlined"
name={props.name}
type={props.type}
fullWidth
sx={{ my: 0.5 }}
value={props.value || ""}
onChange={props.handleChange}
/>
<Grid container direction="row" alignItems="center" spacing={2}>
<Grid item xs={3}>
<InputLabel>{props.label}</InputLabel>
</Grid>
<Grid item xs={9}>
<TextField
id={props.id}
variant="outlined"
name={props.name}
type={props.type}
fullWidth
sx={{ my: 0.5 }}
value={props.value || ""}
onChange={props.handleChange}
InputProps={{
readOnly: props.readOnly,
}}
/>
</Grid>
</Grid>
);
};

View File

@ -32,7 +32,7 @@ const filterData = (
return data;
};
const NestedList = () => {
const InstallationList = () => {
const [data, setData] = useState<I_Installation[]>();
const [searchQuery, setSearchQuery] = useState("");
const intl = useIntl();
@ -46,7 +46,6 @@ const NestedList = () => {
]);
useEffect(() => {
console.log("useeffect");
axiosConfig.get("/GetAllInstallations", {}).then((res) => {
setData(res.data);
});
@ -66,7 +65,15 @@ const NestedList = () => {
onChange={(e) => setSearchQuery(e.target.value)}
/>
<List
sx={{ width: "100%", bgcolor: "background.paper" }}
sx={{
width: "100%",
bgcolor: "background.paper",
position: "relative",
overflow: "auto",
maxHeight: 400,
py: 0,
mt: 1,
}}
component="nav"
aria-labelledby="nested-list-subheader"
>
@ -92,4 +99,4 @@ const NestedList = () => {
);
};
export default NestedList;
export default InstallationList;

View File

@ -0,0 +1,73 @@
import * as React from "react";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Box from "@mui/material/Box";
import { Link } from "react-router-dom";
import routes from "../routes.json";
import useRouteMatch from "../hooks/useRouteMatch";
import { useIntl } from "react-intl";
const InstallationTabs = () => {
const routeMatch = useRouteMatch([
routes.installationWithId,
routes.alarmsWithId,
routes.usersWithId,
routes.logWithId,
]);
const id = routeMatch?.params?.id;
const intl = useIntl();
if (id) {
return (
<Box sx={{ width: "100%" }}>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<Tabs
value={routeMatch?.pattern?.path ?? routes.installationWithId}
aria-label="basic tabs example"
>
<Tab
label={intl.formatMessage({
id: "installation",
defaultMessage: "Installation",
})}
value={routes.installationWithId}
component={Link}
to={routes.installation + id}
/>
<Tab
label={intl.formatMessage({
id: "alarms",
defaultMessage: "Alarms",
})}
value={routes.alarmsWithId}
component={Link}
to={routes.alarms + id}
/>
<Tab
label={intl.formatMessage({
id: "users",
defaultMessage: "Users",
})}
value={routes.usersWithId}
component={Link}
to={routes.users + id}
/>
<Tab
label={intl.formatMessage({
id: "log",
defaultMessage: "Log",
})}
value={routes.logWithId}
component={Link}
to={routes.log + id}
/>
</Tabs>
</Box>
</Box>
);
}
return null;
};
export default InstallationTabs;

View File

@ -13,7 +13,6 @@ const LanguageSelect = (props: LanguageSelectProps) => {
value={props.language}
label="Age"
onChange={(e) => props.setLanguage(e.target.value)}
sx={{ ml: "auto" }}
>
<MenuItem value="en">
<FormattedMessage id="english" defaultMessage="English" />

View File

@ -1,23 +1,36 @@
import { Button, ButtonGroup } from "@mui/material";
import { ToggleButton, ToggleButtonGroup } from "@mui/material";
import { FormattedMessage } from "react-intl";
const NavigationButtons = () => {
interface NavigationButtonsProps {
currentView: string;
setCurrentView: (value: string) => void;
}
const NavigationButtons = (props: NavigationButtonsProps) => {
const handleChange = (
event: React.MouseEvent<HTMLElement>,
newAlignment: string
) => {
props.setCurrentView(newAlignment);
};
return (
<ButtonGroup
variant="outlined"
aria-label="outlined primary button group"
sx={{ paddingBottom: 3 }}
<ToggleButtonGroup
color="primary"
value={props.currentView}
exclusive
onChange={handleChange}
sx={{ mb: 1 }}
>
<Button>
<ToggleButton value="installations">
<FormattedMessage
id="allInstallations"
defaultMessage="All installations"
/>
</Button>
<Button>
</ToggleButton>
<ToggleButton value="users">
<FormattedMessage id="users" defaultMessage="Users" />
</Button>
</ButtonGroup>
</ToggleButton>
</ToggleButtonGroup>
);
};

View File

@ -1,82 +0,0 @@
import * as React from "react";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Box from "@mui/material/Box";
import { Link } from "react-router-dom";
import routes from "../routes.json";
import useRouteMatch from "../hooks/useRouteMatch";
import { useIntl } from "react-intl";
import LogoutButton from "./LogoutButton";
import LanguageSelect from "./LanguageSelect";
interface BasicTabsProps {
removeToken: () => void;
language: string;
setLanguage: (language: string) => void;
}
const BasicTabs = (props: BasicTabsProps) => {
const routeMatch = useRouteMatch([
routes.installationWithId,
routes.alarmsWithId,
routes.usersWithId,
routes.logWithId,
]);
const id = routeMatch?.params?.id;
const intl = useIntl();
return (
<Box sx={{ width: "100%" }}>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<Tabs
value={routeMatch?.pattern?.path ?? routes.installationWithId}
aria-label="basic tabs example"
>
<Tab
label={intl.formatMessage({
id: "installation",
defaultMessage: "Installation",
})}
value={routes.installationWithId}
component={Link}
to={routes.installation + id}
/>
<Tab
label={intl.formatMessage({
id: "alarms",
defaultMessage: "Alarms",
})}
value={routes.alarmsWithId}
component={Link}
to={routes.alarms + id}
/>
<Tab
label={intl.formatMessage({
id: "users",
defaultMessage: "Users",
})}
value={routes.usersWithId}
component={Link}
to={routes.users + id}
/>
<Tab
label={intl.formatMessage({
id: "log",
defaultMessage: "Log",
})}
value={routes.logWithId}
component={Link}
to={routes.log + id}
/>
<LanguageSelect
language={props.language}
setLanguage={props.setLanguage}
/>
<LogoutButton removeToken={props.removeToken} />
</Tabs>
</Box>
</Box>
);
};
export default BasicTabs;

View File

@ -0,0 +1,5 @@
const UserList = () => {
return <div>Userlist</div>;
};
export default UserList;

View File

@ -2,7 +2,7 @@
"alarms": "Alarms",
"allInstallations": "All installations",
"applyChanges": "Apply changes",
"country": "country",
"country": "Country",
"customerName": "Customer name",
"english": "English",
"german": "German",

View File

@ -13,26 +13,23 @@ const InstallationDetail = () => {
const [error, setError] = useState<AxiosError>();
useEffect(() => {
setLoading(true);
axiosConfig
.get("/GetInstallationById?id=" + id)
.then((res) => {
setValues(res.data);
setLoading(false);
})
.catch((err: AxiosError) => {
setError(err);
setLoading(false);
});
if (id !== "undefined") {
console.log(id);
setLoading(true);
axiosConfig
.get("/GetInstallationById?id=" + id)
.then((res) => {
setValues(res.data);
setLoading(false);
})
.catch((err: AxiosError) => {
setError(err);
setLoading(false);
});
}
}, [id]);
if (error) {
return (
<Alert severity="error" sx={{ mt: 1 }}>
{error.message}
</Alert>
);
} else if (values && values.id.toString() === id) {
if (values && values.id && values.id.toString() === id) {
return (
<Box sx={{ py: 3, width: 1 / 2 }}>
<CustomerForm values={values} id={id} />
@ -40,6 +37,12 @@ const InstallationDetail = () => {
);
} else if (loading) {
return <CircularProgress sx={{ m: 2 }} />;
} else if (error) {
return (
<Alert severity="error" sx={{ mt: 1 }}>
{error.message}
</Alert>
);
}
return null;
};