Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add proper error page

dominik-zeglenf20a9a031c1b
diff --git a/saleor/static/dashboard-next/components/ErrorPage/ErrorPage.tsx b/saleor/static/dashboard-next/components/ErrorPage/ErrorPage.tsx
new file mode 100644
index 0000000000..17fdc7ef7d
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ErrorPage/ErrorPage.tsx
@@ -0,0 +1,100 @@
+import Button from "@material-ui/core/Button";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import * as React from "react";
+import SVG from "react-inlinesvg";
+
+import * as notFoundImage from "../../../images/what.svg";
+import i18n from "../../i18n";
+
+export interface ErrorPageProps extends WithStyles<typeof styles> {
+ onBack: () => void;
+}
+
+const styles = (theme: Theme) =>
+ createStyles({
+ bottomHeader: {
+ fontWeight: 600 as 600,
+ textTransform: "uppercase"
+ },
+ button: {
+ marginTop: theme.spacing.unit * 2,
+ padding: 20
+ },
+ container: {
+ [theme.breakpoints.down("sm")]: {
+ gridTemplateColumns: "1fr",
+ padding: theme.spacing.unit * 3,
+ width: "100%"
+ },
+ display: "grid",
+ gridTemplateColumns: "1fr 487px",
+ margin: "0 auto",
+ width: 830
+ },
+ innerContainer: {
+ [theme.breakpoints.down("sm")]: {
+ order: 1,
+ textAlign: "center"
+ },
+ display: "flex",
+ flexDirection: "column",
+ justifyContent: "center"
+ },
+ notFoundImage: {
+ "& svg": {
+ width: "100%"
+ }
+ },
+ root: {
+ alignItems: "center",
+ display: "flex",
+ height: "calc(100vh - 88px)"
+ },
+ upperHeader: {
+ fontWeight: 600 as 600
+ }
+ });
+
+const ErrorPage = withStyles(styles, { name: "NotFoundPage" })(
+ ({ classes, onBack }: ErrorPageProps) => (
+ <div className={classes.root}>
+ <div className={classes.container}>
+ <div className={classes.innerContainer}>
+ <div>
+ <Typography className={classes.upperHeader} variant="display1">
+ {i18n.t("Ooops!...")}
+ </Typography>
+ <Typography className={classes.bottomHeader} variant="display2">
+ {i18n.t("Error")}
+ </Typography>
+ <Typography>{i18n.t("We've encountered a problem...")}</Typography>
+ <Typography>
+ {i18n.t("Don't worry, everything is gonna be fine")}
+ </Typography>
+ </div>
+ <div>
+ <Button
+ className={classes.button}
+ color="secondary"
+ variant="contained"
+ onClick={onBack}
+ >
+ {i18n.t("Back to home", { context: "button" })}
+ </Button>
+ </div>
+ </div>
+ <div>
+ <SVG className={classes.notFoundImage} src={notFoundImage} />
+ </div>
+ </div>
+ </div>
+ )
+);
+ErrorPage.displayName = "ErrorPage";
+export default ErrorPage;
diff --git a/saleor/static/dashboard-next/components/ErrorPage/index.ts b/saleor/static/dashboard-next/components/ErrorPage/index.ts
new file mode 100644
index 0000000000..3d294a58f8
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ErrorPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ErrorPage";
+export * from "./ErrorPage";
diff --git a/saleor/static/dashboard-next/queries.tsx b/saleor/static/dashboard-next/queries.tsx
index 01eacaccc7..14d57d3b2d 100644
--- a/saleor/static/dashboard-next/queries.tsx
+++ b/saleor/static/dashboard-next/queries.tsx
@@ -3,7 +3,9 @@ import * as React from "react";
import { Query, QueryResult } from "react-apollo";
import AppProgress from "./components/AppProgress";
+import ErrorPage from "./components/ErrorPage/ErrorPage";
import Messages from "./components/messages";
+import Navigator from "./components/Navigator";
import i18n from "./i18n";
interface TypedQueryInnerProps<TData, TVariables> {
@@ -55,53 +57,62 @@ export function TypedQuery<TData, TVariables>(query: DocumentNode) {
}: TypedQueryInnerProps<TData, TVariables>) => (
<AppProgress>
{({ funcs: changeProgressState }) => (
- <Messages>
- {pushMessage => (
- <StrictTypedQuery
- context={{ useBatching: true }}
- fetchPolicy="cache-and-network"
- query={query}
- variables={variables}
- skip={skip}
- >
- {queryData => {
- if (queryData.error) {
- const msg = i18n.t("Something went wrong: {{ message }}", {
- message: queryData.error.message
- });
- pushMessage({ text: msg });
- }
+ <Navigator>
+ {navigate => (
+ <Messages>
+ {pushMessage => (
+ <StrictTypedQuery
+ fetchPolicy="cache-and-network"
+ query={query}
+ variables={variables}
+ skip={skip}
+ context={{ useBatching: true }}
+ >
+ {queryData => {
+ if (queryData.error) {
+ const msg = i18n.t(
+ "Something went wrong: {{ message }}",
+ {
+ message: queryData.error.message
+ }
+ );
+ pushMessage({ text: msg });
+ }
- let childrenOrNotFound = children(queryData);
- if (
- !queryData.loading &&
- require &&
- queryData.data &&
- !require.reduce(
- (acc, key) => acc && queryData.data[key] !== null,
- true
- )
- ) {
- childrenOrNotFound = <>Not found</>;
- }
+ let childrenOrNotFound = children(queryData);
+ if (
+ !queryData.loading &&
+ require &&
+ queryData.data &&
+ !require.reduce(
+ (acc, key) => acc && queryData.data[key] !== null,
+ true
+ )
+ ) {
+ childrenOrNotFound = (
+ <ErrorPage onBack={() => navigate("/")} />
+ );
+ }
- if (displayLoader) {
- return (
- <QueryProgress
- loading={queryData.loading}
- onCompleted={changeProgressState.disable}
- onLoading={changeProgressState.enable}
- >
- {childrenOrNotFound}
- </QueryProgress>
- );
- }
+ if (displayLoader) {
+ return (
+ <QueryProgress
+ loading={queryData.loading}
+ onCompleted={changeProgressState.disable}
+ onLoading={changeProgressState.enable}
+ >
+ {childrenOrNotFound}
+ </QueryProgress>
+ );
+ }
- return childrenOrNotFound;
- }}
- </StrictTypedQuery>
+ return childrenOrNotFound;
+ }}
+ </StrictTypedQuery>
+ )}
+ </Messages>
)}
- </Messages>
+ </Navigator>
)}
</AppProgress>
);
diff --git a/saleor/static/dashboard-next/storybook/stories/components/ErrorPage.tsx b/saleor/static/dashboard-next/storybook/stories/components/ErrorPage.tsx
new file mode 100644
index 0000000000..8268959e50
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/components/ErrorPage.tsx
@@ -0,0 +1,14 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import ErrorPage, { ErrorPageProps } from "../../../components/ErrorPage";
+import Decorator from "../../Decorator";
+
+const props:ErrorPageProps = {
+
+}
+
+storiesOf("Components / ErrorPage", module)
+ .addDecorator(Decorator)
+ .add("default", () => <ErrorPage {...ErrorPageProps} />)
+ .add("other", () => <ErrorPage {...ErrorPageProps} />);
diff --git a/saleor/static/images/what.svg b/saleor/static/images/what.svg
new file mode 100644
index 0000000000..52ca6ab45f
--- /dev/null
+++ b/saleor/static/images/what.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="488" height="359" viewBox="0 0 488 359" fill="none">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M186.62 211.896H227.139L272.972 0L306.039 33.7306L253.045 238.466H216.123L186.62 211.896ZM170.678 298.931H211.197L219.832 259.74L246.235 285.944L237.103 325.501H200.181L170.678 298.931ZM318.141 328.822H358.66L367.296 289.632L393.698 315.835L384.566 355.392H347.645L318.141 328.822ZM468.031 64.7883C479.185 98.6093 467.483 129.579 432.905 157.677C392.561 177.947 377.642 200.848 371.77 245.169L340.471 245.773L370.612 259.748L400.253 261.165L405.769 230.574C419.118 196.387 459.156 192.667 476.599 159.502C487.498 141.701 490.586 124.17 485.848 106.886L468.031 64.7883ZM429.669 97.3605C431.638 75.985 422.397 64.6821 401.927 63.4306C367.716 62.7717 346.204 79.928 337.378 114.881L303.894 116.754L335.699 144.15L365.933 144.023C374.549 110.04 396.119 93.8932 429.669 97.3605ZM14.2468 331.554H54.7661L63.4013 292.363L89.804 318.566L80.6718 358.124H43.7502L14.2468 331.554ZM164.136 67.5171C175.29 101.338 163.589 132.308 129.011 160.406C88.6667 180.676 73.7478 203.577 67.8758 247.898L36.5762 248.501L66.7172 262.48L96.3587 263.893L101.875 233.303C115.223 199.116 155.262 195.396 172.705 162.231C183.604 144.429 186.692 126.898 181.954 109.617L164.136 67.5171ZM125.774 100.092C127.743 78.7163 118.502 67.4134 98.0327 66.162C63.8211 65.5004 42.31 82.6566 33.4835 117.609L0 119.485L31.8044 146.879L62.0383 146.751C70.6549 112.771 92.2244 96.6218 125.774 100.092Z" fill="#C4C4C4"/>
+</svg>
\ No newline at end of file