diff --git a/components/layout/Page.tsx b/components/layout/Page.tsx index 421823e..cc42c77 100644 --- a/components/layout/Page.tsx +++ b/components/layout/Page.tsx @@ -1,30 +1,69 @@ -import React from "react"; - +import { useRouter } from "next/router"; +import { useState } from "react"; import Head from "../head"; import StackableContainer from "./StackableContainer"; -interface Props { - title?: string; - rootMultisig?: string; - children: React.ReactNode; +interface PageProps { + readonly title?: string; + readonly goBack?: { + readonly pathname: string; + readonly title: string; + readonly needsConfirm?: boolean; + }; + readonly children: React.ReactNode; } -const Page = (props: Props) => { +const Page = ({ title, goBack, children }: PageProps) => { + const router = useRouter(); + const [showConfirm, setShowConfirm] = useState(false); + + const linkProps = (() => { + if (!goBack) { + return {}; + } + + if (goBack.needsConfirm && !showConfirm) { + return { + href: "", + onClick: (e: React.MouseEvent) => { + e.preventDefault(); + setShowConfirm(true); + }, + }; + } + + return { + href: goBack.pathname, + }; + })(); + return (
- -
- {props.rootMultisig && ( -
- -

- ← Back to multisig account -

-
-
- )} - {props.children} -
+ + + {goBack ? ( + router.push(linkProps.href) : linkProps.onClick, + }} + > +

+ ← Back to {goBack.title} +

+ {showConfirm ? ( + <> +

Changes to any form will be lost if you go back

+

Click again to confirm

+ + ) : null} +
+ ) : null} + {children} +

@@ -38,15 +77,6 @@ const Page = (props: Props) => { justify-content: center; padding: 120px 0; } - .container { - position: relative; - } - .nav { - position: absolute; - top: -40px; - left: 0; - display: flex; - } a, a:visited { color: white; diff --git a/components/layout/StackableContainer.tsx b/components/layout/StackableContainer.tsx index 4262e43..d4b6667 100644 --- a/components/layout/StackableContainer.tsx +++ b/components/layout/StackableContainer.tsx @@ -1,5 +1,3 @@ -import React from "react"; - interface Props { base?: boolean; children: React.ReactNode; @@ -7,10 +5,11 @@ interface Props { lessMargin?: boolean; lessRadius?: boolean; fullHeight?: boolean; + divProps?: React.HTMLAttributes; } const StackableContainer = (props: Props) => ( -

+
{props.children}