Different alerts for statuses

This commit is contained in:
powermaker450 2024-08-29 03:58:32 +00:00
parent d9ef325044
commit bd1530f0af

View file

@ -1,4 +1,4 @@
import { Alert, Grow, Rating, Typography } from "@mui/material"; import { Alert, Grow, Rating, Slide, Typography } from "@mui/material";
import "./App.css"; import "./App.css";
import ButtonRow, { ActionProps } from "./components/ButtonRow"; import ButtonRow, { ActionProps } from "./components/ButtonRow";
import ReviewField, { ReviewFieldProps } from "./components/ReviewField"; import ReviewField, { ReviewFieldProps } from "./components/ReviewField";
@ -9,6 +9,9 @@ function App() {
const [showAlert, changeAlert] = useState(false); const [showAlert, changeAlert] = useState(false);
const [alertText, changeAlertText] = useState(""); const [alertText, changeAlertText] = useState("");
const [showInfo, changeInfo] = useState(false);
const [infoText, changeInfoText] = useState("");
const fields: ReviewFieldProps[] = [ const fields: ReviewFieldProps[] = [
{ {
name: "Name", name: "Name",
@ -42,22 +45,26 @@ function App() {
content: fields[2].dynamicState[0] content: fields[2].dynamicState[0]
}) })
}) })
.then(async ({ json }) => { .then(async (response) => {
const result = await json(); const result = await response.json();
changeAlertText(result.error ? `${result.error.type}: ${result.error.message}` : `Success: ${result.message}`); changeInfoText(result.error ? `${result.error.type}: ${result.error.message}` : `Success: ${result.message}`);
changeInfo(true);
setTimeout(() => {
changeInfo(false);
}, 2000);
}) })
.catch((err) => changeAlertText(err.toString())); .catch((err) => {
changeAlertText(err.toString());
if (showAlert) {
return;
}
changeAlert(true); changeAlert(true);
setTimeout(() => { setTimeout(() => {
changeAlert(false); changeAlert(false);
}, 2500); }, 2500);
});
} }
const buttons: ActionProps[] = [ const buttons: ActionProps[] = [
@ -73,8 +80,14 @@ function App() {
}, },
]; ];
const alert = ( const info = (
<Alert severity="info"> <Alert severity="info">
{infoText}
</Alert>
);
const alert = (
<Alert severity="error">
{alertText} {alertText}
</Alert> </Alert>
); );
@ -108,9 +121,13 @@ function App() {
<br /> <br />
<Grow in={showAlert}> <Grow in={showAlert} mountOnEnter unmountOnExit>
{alert} {alert}
</Grow> </Grow>
<Grow in={showInfo} mountOnEnter unmountOnExit>
{info}
</Grow>
</> </>
); );
} }