diff --git a/src/nextapp/components/no-gateway-redirect/gateway-toast-handler.tsx b/src/nextapp/components/no-gateway-redirect/gateway-toast-handler.tsx new file mode 100644 index 000000000..b67ca18e5 --- /dev/null +++ b/src/nextapp/components/no-gateway-redirect/gateway-toast-handler.tsx @@ -0,0 +1,34 @@ +import * as React from 'react'; +import { useToast } from '@chakra-ui/react'; +import { useRouter } from 'next/router'; + +const GatewayToastHandler = () => { + const toast = useToast(); + const router = useRouter(); + + React.useEffect(() => { + const handleRouteChange = () => { + const showToast = localStorage.getItem('showNoGatewayToast'); + if (showToast === 'true') { + toast.closeAll(); + toast({ + title: `First select a Gateway to view that page`, + status: 'error', + isClosable: true, + duration: 5000, + }); + localStorage.removeItem('showNoGatewayToast'); + } + }; + + router.events.on('routeChangeComplete', handleRouteChange); + + return () => { + router.events.off('routeChangeComplete', handleRouteChange); + }; + }, [toast, router]); + + return null; +}; + +export default GatewayToastHandler; \ No newline at end of file diff --git a/src/nextapp/components/no-gateway-redirect/no-gateway-redirect.tsx b/src/nextapp/components/no-gateway-redirect/no-gateway-redirect.tsx new file mode 100644 index 000000000..e69de29bb diff --git a/src/nextapp/pages/_app.tsx b/src/nextapp/pages/_app.tsx index f3bb362ba..2aeeeca2b 100644 --- a/src/nextapp/pages/_app.tsx +++ b/src/nextapp/pages/_app.tsx @@ -31,6 +31,7 @@ import '@/shared/styles/global.css'; import { AppWrapper } from './context'; import '../../mocks'; import CompleteProfile from '@/components/complete-profile'; +import GatewayToastHandler from '@/components/no-gateway-redirect/gateway-toast-handler'; const footerItems = [ { href: 'http://www2.gov.bc.ca/gov/content/home', text: 'Home' }, @@ -114,6 +115,7 @@ const App: React.FC = ({ Component, pageProps }) => { }} > +