Skip to content

Commit

Permalink
Fix subscription redirect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri committed Dec 17, 2024
1 parent 99503a6 commit 51e0565
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/App/redirects/SubscriptionDetailsRedirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
generatePath,
useNavigate,
useParams,
} from 'react-router-dom';

import routes from '#routes';

interface SubscriptionDetailsParams {
subscriptionId: string | undefined;
[key: string]: string | undefined;
}

// eslint-disable-next-line import/prefer-default-export
export function Component() {
const { subscriptionId } = useParams<SubscriptionDetailsParams>();
const navigate = useNavigate();

const subscriptionDetailsLink = (subscriptionId) ? ({
pathname: (generatePath(
routes.subscriptionDetail.absolutePath,
{ subscriptionId },
)),
})
: routes.pageNotFound.path;

if (subscriptionDetailsLink) {
navigate(subscriptionDetailsLink);
}

return null;
}

Component.displayName = 'AlertDetailsRedirect';
19 changes: 17 additions & 2 deletions src/App/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ const subscriptionDetail = customWrapRoute({
},
});

const subscriptionDetailRedirect = customWrapRoute({
parent: rootLayout,
path: 'permalink/subscription-detail/:subscriptionId',
component: {
render: () => import('../redirects/SubscriptionDetailsRedirect'),
props: {},
},
wrapperComponent: Auth,
context: {
title: 'Subscription Details',
visibility: 'is-authenticated',
},
});

const homeIndex = customWrapRoute({
parent: homeLayout,
index: true,
Expand Down Expand Up @@ -192,7 +206,7 @@ const alertDetailRedirect = customWrapRoute({
parent: rootLayout,
path: 'permalink/alert-detail/:alertId',
component: {
render: () => import('../redirects/AlertDetailsRedirect.tsx'),
render: () => import('../redirects/AlertDetailsRedirect'),
props: {},
},
wrapperComponent: Auth,
Expand Down Expand Up @@ -316,7 +330,7 @@ const resetPasswordRedirect = customWrapRoute({
parent: rootLayout,
path: 'permalink/user-password-reset/:userId/:resetToken',
component: {
render: () => import('../redirects/RecoverAccountRedirect.tsx'),
render: () => import('../redirects/RecoverAccountRedirect'),
props: {},
},
wrapperComponent: Auth,
Expand Down Expand Up @@ -409,6 +423,7 @@ const wrappedRoutes = {
alertDetailRedirect,
unsubscribeRedirect,
unsubscribe,
subscriptionDetailRedirect,
};

export const unwrappedRoutes = unwrapRoute(Object.values(wrappedRoutes));
Expand Down

0 comments on commit 51e0565

Please sign in to comment.