refactoring error page
This commit is contained in:
committed by
Daniel Hutzel
parent
938abb6387
commit
3d176237c1
9
media-store/.vscode/launch.json
vendored
9
media-store/.vscode/launch.json
vendored
@@ -4,13 +4,8 @@
|
|||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
|
||||||
"name": "Launch import",
|
|
||||||
"command": "npm run import",
|
|
||||||
"request": "launch",
|
|
||||||
"skipFiles": ["<node_internals>/**"],
|
|
||||||
"type": "node-terminal"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"command": "cds run --with-mocks --in-memory?",
|
"command": "cds run --with-mocks --in-memory?",
|
||||||
"name": "cds run",
|
"name": "cds run",
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {
|
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
|
||||||
BrowserRouter as Router,
|
|
||||||
Switch,
|
|
||||||
Route,
|
|
||||||
Redirect,
|
|
||||||
} from "react-router-dom";
|
|
||||||
import { isEmpty } from "lodash";
|
import { isEmpty } from "lodash";
|
||||||
import { TracksContainer } from "../pages/tracks/TracksPage";
|
import { TracksContainer } from "../pages/tracks/TracksPage";
|
||||||
import { CurrentPageHeader } from "./CurrentPageHeader";
|
import { CurrentPageHeader } from "./CurrentPageHeader";
|
||||||
@@ -40,39 +35,32 @@ const RestrictedManageStore = withRestrictions(
|
|||||||
const MyRouter = () => {
|
const MyRouter = () => {
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
<Switch>
|
<Header />
|
||||||
<Route path="/error">
|
<div style={{ padding: "2em 20vh" }}>
|
||||||
<ErrorPage />
|
<CurrentPageHeader />
|
||||||
</Route>
|
<Switch>
|
||||||
<Route>
|
<Route exact path={["/", "/tracks"]}>
|
||||||
<Header />
|
<TracksContainer />
|
||||||
<div style={{ padding: "2em 20vh" }}>
|
</Route>
|
||||||
<CurrentPageHeader />
|
<Route exact path="/person">
|
||||||
<Switch>
|
<RestrictedPersonPage
|
||||||
<Route exact path={["/"]}>
|
myInvoicesSection={<RestrictedMyInvoicesSection />}
|
||||||
<TracksContainer />
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/person">
|
<Route exact path="/login">
|
||||||
<RestrictedPersonPage
|
<RestrictedLogin />
|
||||||
myInvoicesSection={<RestrictedMyInvoicesSection />}
|
</Route>
|
||||||
/>
|
<Route exact path="/invoice">
|
||||||
</Route>
|
<RestrictedInvoicePage />
|
||||||
<Route exact path="/login">
|
</Route>
|
||||||
<RestrictedLogin />
|
<Route exact path="/manage">
|
||||||
</Route>
|
<RestrictedManageStore />
|
||||||
<Route exact path="/invoice">
|
</Route>
|
||||||
<RestrictedInvoicePage />
|
<Route path="/">
|
||||||
</Route>
|
<ErrorPage />
|
||||||
<Route exact path="/manage">
|
</Route>
|
||||||
<RestrictedManageStore />
|
</Switch>
|
||||||
</Route>
|
</div>
|
||||||
<Route>
|
|
||||||
<Redirect to="/error" />
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
|
||||||
</div>
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { isEmpty } from "lodash";
|
import { isEmpty } from "lodash";
|
||||||
import { Result, Button } from "antd";
|
import { Result, Button } from "antd";
|
||||||
import { useAppState } from "../hooks/useAppState";
|
import { useAppState } from "../hooks/useAppState";
|
||||||
|
|
||||||
const ErrorPage = () => {
|
const ErrorPage = () => {
|
||||||
const { error, setError } = useAppState();
|
const { user, error, setError } = useAppState();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setError({});
|
|
||||||
history.replace("/");
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const onGoHome = () => {
|
const onGoHome = () => {
|
||||||
|
setError({});
|
||||||
history.push("/");
|
history.push("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const goLoginPage = () => {
|
||||||
|
setError({});
|
||||||
|
history.push("/login");
|
||||||
|
};
|
||||||
|
|
||||||
const errorResultProps = isEmpty(error)
|
const errorResultProps = isEmpty(error)
|
||||||
? {
|
? {
|
||||||
status: 404,
|
status: 404,
|
||||||
@@ -35,9 +36,16 @@ const ErrorPage = () => {
|
|||||||
<Result
|
<Result
|
||||||
{...errorResultProps}
|
{...errorResultProps}
|
||||||
extra={
|
extra={
|
||||||
<Button onClick={onGoHome} type="primary">
|
<>
|
||||||
Back Home
|
<Button onClick={onGoHome} type="primary">
|
||||||
</Button>
|
Back Home
|
||||||
|
</Button>
|
||||||
|
{!user && (
|
||||||
|
<Button onClick={goLoginPage} type="primary">
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ const cds = require("@sap/cds");
|
|||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
const db = await cds.connect.to("db"); // connect to database service
|
const db = await cds.connect.to("db"); // connect to database service
|
||||||
|
|
||||||
this.before("CREATE", "*", async (req) => {
|
this.on("CREATE", "*", async (req) => {
|
||||||
let { ID: lastEntityID } = await db.run(
|
const transaction = await db.tx(req);
|
||||||
|
let { ID: lastEntityID } = await transaction.run(
|
||||||
SELECT.one(req.entity).columns("ID").orderBy({ ID: "desc" })
|
SELECT.one(req.entity).columns("ID").orderBy({ ID: "desc" })
|
||||||
);
|
);
|
||||||
req.data = { ...req.data, ID: ++lastEntityID };
|
const columns = ["ID", ...Object.keys(req.data)];
|
||||||
|
const values = [++lastEntityID, ...Object.values(req.data)];
|
||||||
|
|
||||||
|
await transaction.run(req.query.columns(columns).values(values));
|
||||||
|
await transaction.commit();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user