diff --git a/src/nextapp/components/no-gateway-redirect/index.ts b/src/nextapp/components/no-gateway-redirect/index.ts new file mode 100644 index 000000000..001eb41b5 --- /dev/null +++ b/src/nextapp/components/no-gateway-redirect/index.ts @@ -0,0 +1 @@ +export { default } from './no-gateway-redirect'; 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..414fdb3db --- /dev/null +++ b/src/nextapp/components/no-gateway-redirect/no-gateway-redirect.tsx @@ -0,0 +1,17 @@ +import * as React from 'react'; +import { useRouter } from 'next/router'; +import { useAuth } from '@/shared/services/auth'; + +const NoGatewayRedirect = () => { + const router = useRouter(); + const { user } = useAuth(); + const hasNamespace = !!user?.namespace; + + React.useEffect(() => { + if (!hasNamespace) { + router.push('/manager/gateways/list'); + } + }, [hasNamespace]); +}; + +export default NoGatewayRedirect; diff --git a/src/nextapp/pages/manager/activity/index.tsx b/src/nextapp/pages/manager/activity/index.tsx index 7ac1a1ca2..67f579711 100644 --- a/src/nextapp/pages/manager/activity/index.tsx +++ b/src/nextapp/pages/manager/activity/index.tsx @@ -26,6 +26,7 @@ import ActivityFilters from '@/components/activity-filters'; import { FaTimesCircle } from 'react-icons/fa'; import EmptyPane from '@/components/empty-pane'; import ActivityItem from '@/components/activity-item'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; const timeZone = 'America/Vancouver'; @@ -50,6 +51,9 @@ interface FilterState { } const ActivityPage: React.FC = () => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const breadcrumbs = useNamespaceBreadcrumbs([ { text: 'Activity', @@ -248,4 +252,4 @@ const query = gql` blob } } -`; \ No newline at end of file +`; diff --git a/src/nextapp/pages/manager/authorization-profiles/index.tsx b/src/nextapp/pages/manager/authorization-profiles/index.tsx index f401af796..d53ce1adb 100644 --- a/src/nextapp/pages/manager/authorization-profiles/index.tsx +++ b/src/nextapp/pages/manager/authorization-profiles/index.tsx @@ -41,6 +41,7 @@ import type { Mutation, Query, } from '@/shared/types/query.types'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; export const getServerSideProps: GetServerSideProps = async (context) => { const queryKey = 'authorizationProfiles'; @@ -69,6 +70,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => { const AuthorizationProfiles: React.FC< InferGetServerSidePropsType > = ({ queryKey }) => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const breadcrumbs = useNamespaceBreadcrumbs([ { href: '/manager/authorization-profiles', diff --git a/src/nextapp/pages/manager/consumers/index.tsx b/src/nextapp/pages/manager/consumers/index.tsx index 187168192..466f4d7ac 100644 --- a/src/nextapp/pages/manager/consumers/index.tsx +++ b/src/nextapp/pages/manager/consumers/index.tsx @@ -36,6 +36,7 @@ import GrantAccessDialog from '@/components/access-request/grant-access-dialog'; import ConsumerFilters from '@/components/consumer-filters'; import AccessRequestsList from '@/components/access-request/access-requests-list'; import { useNamespaceBreadcrumbs } from '@/shared/hooks'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; const sortDate = new Intl.DateTimeFormat('en-ca', { dateStyle: 'short' }); @@ -76,6 +77,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => { const ConsumersPage: React.FC< InferGetServerSidePropsType > = ({ queryKey }) => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const toast = useToast(); const breadcrumbs = useNamespaceBreadcrumbs([{ text: 'Consumers' }]); const client = useQueryClient(); diff --git a/src/nextapp/pages/manager/gateways/detail.tsx b/src/nextapp/pages/manager/gateways/detail.tsx index 7a4e0207e..e06d99d16 100644 --- a/src/nextapp/pages/manager/gateways/detail.tsx +++ b/src/nextapp/pages/manager/gateways/detail.tsx @@ -61,6 +61,7 @@ import useCurrentNamespace from '@/shared/hooks/use-current-namespace'; import { useGlobal } from '@/shared/services/global'; import EditNamespaceDisplayName from '@/components/edit-display-name'; import { useNamespaceBreadcrumbs } from '@/shared/hooks'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; const actions = [ { @@ -120,6 +121,9 @@ const secondaryActions = [ ]; const NamespacesPage: React.FC = () => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const { user } = useAuth(); const breadcrumbs = useNamespaceBreadcrumbs(); const hasNamespace = !!user?.namespace; @@ -155,14 +159,6 @@ const NamespacesPage: React.FC = () => { text: 'Your Organization and Business Unit will appear here', }; }, [namespace]); - - // Redirect to My Gateways page if no gateway selected - React.useEffect(() => { - if (!hasNamespace) { - router.push('/manager/gateways/list'); - } - }, [hasNamespace]); - const handleDelete = React.useCallback(async () => { if (user?.namespace) { try { diff --git a/src/nextapp/pages/manager/namespace-access/index.tsx b/src/nextapp/pages/manager/namespace-access/index.tsx index da2e4eb43..f71208c6d 100644 --- a/src/nextapp/pages/manager/namespace-access/index.tsx +++ b/src/nextapp/pages/manager/namespace-access/index.tsx @@ -21,8 +21,12 @@ import { } from '@/components/namespace-access'; import { useAuth } from '@/shared/services/auth'; import { useNamespaceBreadcrumbs } from '@/shared/hooks'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; const AccessRedirectPage: React.FC = () => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const { user } = useAuth(); const breadcrumbs = useNamespaceBreadcrumbs([ { href: '/manager/namespace-access', text: 'Namespace Access' }, diff --git a/src/nextapp/pages/manager/products/index.tsx b/src/nextapp/pages/manager/products/index.tsx index 762042ba2..42aa9b0a1 100644 --- a/src/nextapp/pages/manager/products/index.tsx +++ b/src/nextapp/pages/manager/products/index.tsx @@ -23,8 +23,12 @@ import useCurrentNamespace, { import { useRestMutationApi } from '@/shared/services/api'; import { gql } from 'graphql-request'; import { useAuth } from '@/shared/services/auth'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; const ProductsPage: React.FC = () => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const { user } = useAuth(); const breadcrumbs = useNamespaceBreadcrumbs([{ text: 'Products' }]); const client = useQueryClient(); diff --git a/src/nextapp/pages/manager/service-accounts/index.tsx b/src/nextapp/pages/manager/service-accounts/index.tsx index 8801c4447..fcd65ed39 100644 --- a/src/nextapp/pages/manager/service-accounts/index.tsx +++ b/src/nextapp/pages/manager/service-accounts/index.tsx @@ -35,6 +35,7 @@ import { FaCheckCircle } from 'react-icons/fa'; import ServiceAccountCreate from '@/components/service-account-create'; import { useNamespaceBreadcrumbs } from '@/shared/hooks'; import EmptyPane from '@/components/empty-pane'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; export const getServerSideProps: GetServerSideProps = async (context) => { const queryKey = 'getServiceAccounts'; @@ -63,6 +64,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => { const ServiceAccountsPage: React.FC< InferGetServerSidePropsType > = ({ queryKey }) => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const breadcrumbs = useNamespaceBreadcrumbs([{ text: 'Service Accounts' }]); const client = useQueryClient(); const [credentials, setCredentials] = React.useState>( diff --git a/src/nextapp/pages/manager/services/index.tsx b/src/nextapp/pages/manager/services/index.tsx index a64dec765..bc3199cdd 100644 --- a/src/nextapp/pages/manager/services/index.tsx +++ b/src/nextapp/pages/manager/services/index.tsx @@ -12,6 +12,7 @@ import ServicesFilters from '@/components/services-list/services-filters'; import { useAuth } from '@/shared/services/auth'; import { useNamespaceBreadcrumbs } from '@/shared/hooks'; import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; +import NoGatewayRedirect from '@/components/no-gateway-redirect'; import { FilterState } from '@/components/services-list/types'; @@ -26,6 +27,9 @@ export const getServerSideProps: GetServerSideProps = async () => { const ServicesPage: React.FC< InferGetServerSidePropsType > = ({ metricsUrl }) => { + // Redirect to My Gateways page if no gateway selected + NoGatewayRedirect(); + const title = 'Gateway Services'; const breadcrumb = useNamespaceBreadcrumbs([{ text: title }]); const { user } = useAuth();