From cc14e60ac0296c85bf086a9c236e6a278b86bc7e Mon Sep 17 00:00:00 2001 From: Joanna Dyczka Date: Fri, 9 Aug 2024 04:28:11 +0200 Subject: [PATCH] [#1183] Add checks for registration and retirement routes --- .../molecules/CenteredBoxPageWrapper.tsx | 14 ++- .../components/organisms/WrongRouteInfo.tsx | 98 +++++++++++++++++++ .../src/components/organisms/index.ts | 1 + govtool/frontend/src/i18n/locales/en.ts | 17 ++++ .../frontend/src/pages/EditDRepMetadata.tsx | 14 +-- .../src/pages/RegisterAsDirectVoter.tsx | 24 ++++- govtool/frontend/src/pages/RegisterAsdRep.tsx | 35 ++++--- .../src/pages/RetireAsDirectVoter.tsx | 27 ++++- govtool/frontend/src/pages/RetireAsDrep.tsx | 29 ++++-- 9 files changed, 218 insertions(+), 41 deletions(-) create mode 100644 govtool/frontend/src/components/organisms/WrongRouteInfo.tsx diff --git a/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx b/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx index 6740a5576..2d33bd15f 100644 --- a/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx +++ b/govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.tsx @@ -48,17 +48,27 @@ export const CenteredBoxPageWrapper: FC> = ({ } /> {hideBox ? ( - {children} + + {children} + ) : ( diff --git a/govtool/frontend/src/components/organisms/WrongRouteInfo.tsx b/govtool/frontend/src/components/organisms/WrongRouteInfo.tsx new file mode 100644 index 000000000..9c09909fa --- /dev/null +++ b/govtool/frontend/src/components/organisms/WrongRouteInfo.tsx @@ -0,0 +1,98 @@ +import { Box } from "@mui/material"; + +import { Button, Typography } from "@atoms"; +import { useScreenDimension, useTranslation } from "@hooks"; + +import { useNavigate } from "react-router-dom"; +import { PATHS } from "@/consts"; + +type Props = { + title?: string; + description?: string; + primaryButtonText?: string; + secondaryButtonText?: string; + onPrimaryButton?: () => void; + onSecondaryButton?: () => void; + hideSecondaryButton?: boolean; +}; + +export const WrongRouteInfo = ({ + title, + description, + primaryButtonText, + secondaryButtonText, + hideSecondaryButton, + onPrimaryButton, + onSecondaryButton, +}: Props) => { + const { t } = useTranslation(); + const { isMobile } = useScreenDimension(); + const navigate = useNavigate(); + + const primaryButtonProps = { + children: primaryButtonText ?? t("backToDashboard"), + onClick: onPrimaryButton ?? (() => navigate(PATHS.dashboard)), + }; + + const secondaryButtonProps = + primaryButtonText || onPrimaryButton + ? { + children: secondaryButtonText ?? t("backToDashboard"), + onClick: onSecondaryButton ?? (() => navigate(PATHS.dashboard)), + } + : undefined; + + return ( + <> + {title && ( + + {title} + + )} + {description && ( + + {description} + + )} + + + {!hideSecondaryButton && secondaryButtonProps && ( +