Skip to content

Commit

Permalink
Other manager pages: redirect to list if no gateway selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Elson9 committed Jun 28, 2024
1 parent 915326b commit 5c3e1d6
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/nextapp/components/no-gateway-redirect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './no-gateway-redirect';
17 changes: 17 additions & 0 deletions src/nextapp/components/no-gateway-redirect/no-gateway-redirect.tsx
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion src/nextapp/pages/manager/activity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
Expand Down Expand Up @@ -248,4 +252,4 @@ const query = gql`
blob
}
}
`;
`;
4 changes: 4 additions & 0 deletions src/nextapp/pages/manager/authorization-profiles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -69,6 +70,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const AuthorizationProfiles: React.FC<
InferGetServerSidePropsType<typeof getServerSideProps>
> = ({ queryKey }) => {
// Redirect to My Gateways page if no gateway selected
NoGatewayRedirect();

const breadcrumbs = useNamespaceBreadcrumbs([
{
href: '/manager/authorization-profiles',
Expand Down
4 changes: 4 additions & 0 deletions src/nextapp/pages/manager/consumers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down Expand Up @@ -76,6 +77,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const ConsumersPage: React.FC<
InferGetServerSidePropsType<typeof getServerSideProps>
> = ({ queryKey }) => {
// Redirect to My Gateways page if no gateway selected
NoGatewayRedirect();

const toast = useToast();
const breadcrumbs = useNamespaceBreadcrumbs([{ text: 'Consumers' }]);
const client = useQueryClient();
Expand Down
12 changes: 4 additions & 8 deletions src/nextapp/pages/manager/gateways/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/nextapp/pages/manager/namespace-access/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
4 changes: 4 additions & 0 deletions src/nextapp/pages/manager/products/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/nextapp/pages/manager/service-accounts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -63,6 +64,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const ServiceAccountsPage: React.FC<
InferGetServerSidePropsType<typeof getServerSideProps>
> = ({ 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<Record<string, string>>(
Expand Down
4 changes: 4 additions & 0 deletions src/nextapp/pages/manager/services/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -26,6 +27,9 @@ export const getServerSideProps: GetServerSideProps = async () => {
const ServicesPage: React.FC<
InferGetServerSidePropsType<typeof getServerSideProps>
> = ({ metricsUrl }) => {
// Redirect to My Gateways page if no gateway selected
NoGatewayRedirect();

const title = 'Gateway Services';
const breadcrumb = useNamespaceBreadcrumbs([{ text: title }]);
const { user } = useAuth();
Expand Down

0 comments on commit 5c3e1d6

Please sign in to comment.