Skip to content

Commit

Permalink
fix(web,api-service): redirect edit action of v1 workflows to old web…
Browse files Browse the repository at this point in the history
… app when opt-in (#7460)
  • Loading branch information
LetItRock authored Jan 9, 2025
1 parent 2af9e78 commit c1f020e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function buildStepTypeOverview(step: NotificationStepEntity): StepTypeEnum | und

function computeOrigin(template: NotificationTemplateEntity): WorkflowOriginEnum {
// Required to differentiate between old V1 and new workflows in an attempt to eliminate the need for type field
if (typeof template.type === 'undefined' && typeof template.origin === 'undefined') {
return WorkflowOriginEnum.NOVU_CLOUD_V1;
}

return template?.type === WorkflowTypeEnum.REGULAR
? WorkflowOriginEnum.NOVU_CLOUD_V1
: template.origin || WorkflowOriginEnum.EXTERNAL;
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/hooks/useNewDashboardOptIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function useNewDashboardOptIn() {
isLoaded,
optIn,
dismiss,
redirectToNewDashboard,
status: user?.unsafeMetadata?.newDashboardOptInStatus as NewDashboardOptInStatusEnum | null | undefined,
};
}
47 changes: 34 additions & 13 deletions apps/web/src/hooks/useOptInRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
import { useCallback, useLayoutEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { FeatureFlagsKeysEnum, NewDashboardOptInStatusEnum } from '@novu/shared';
import { NewDashboardOptInStatusEnum } from '@novu/shared';

import { useNewDashboardOptIn } from './useNewDashboardOptIn';
import { ROUTES } from '../constants/routes';
import { useFeatureFlag } from './useFeatureFlag';
import { IS_EE_AUTH_ENABLED } from '../config';

const ROUTES_THAT_REDIRECT_TO_DASHBOARD = [ROUTES.WORKFLOWS];
import { IS_EE_AUTH_ENABLED, NEW_DASHBOARD_URL } from '../config';
import { useEnvironment } from './useEnvironment';

export const useOptInRedirect = () => {
const { pathname } = useLocation();
const { status, isLoaded, redirectToNewDashboard } = useNewDashboardOptIn();
const { environment } = useEnvironment();
const { status, isLoaded } = useNewDashboardOptIn();

const getNewDashboardUrl = useCallback(
(currentRoute: string): string | undefined => {
const newDashboardUrl = NEW_DASHBOARD_URL || window.location.origin;

switch (currentRoute) {
case ROUTES.GET_STARTED:
return `${newDashboardUrl}/env/${environment?.slug}/welcome`;
case ROUTES.WORKFLOWS:
return `${newDashboardUrl}/env/${environment?.slug}/workflows`;
case ROUTES.ACTIVITIES:
return `${newDashboardUrl}/env/${environment?.slug}/activity-feed`;
case ROUTES.INTEGRATIONS:
return `${newDashboardUrl}/integrations`;
case ROUTES.API_KEYS:
return `${newDashboardUrl}/env/${environment?.slug}/api-keys`;
default:
return undefined;
}
},
[environment]
);

const checkAndRedirect = useCallback(() => {
if (!IS_EE_AUTH_ENABLED) return false;
if (!isLoaded || !status || status !== NewDashboardOptInStatusEnum.OPTED_IN) return false;

const currentRoute = pathname.replace('/legacy', '');
const isRedirectableRoute = ROUTES_THAT_REDIRECT_TO_DASHBOARD.some((route) => currentRoute.includes(route));

if (!isRedirectableRoute) return false;
const newDashboardUrl = getNewDashboardUrl(pathname.replace('/legacy', ''));
if (newDashboardUrl) {
window.location.href = newDashboardUrl;

redirectToNewDashboard();
return true;
}

return true;
}, [isLoaded, status, pathname, redirectToNewDashboard]);
return false;
}, [isLoaded, status, pathname, getNewDashboardUrl]);

// handling of updates to deps
useLayoutEffect(() => {
Expand Down

0 comments on commit c1f020e

Please sign in to comment.