Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web,api-service): redirect edit action of v1 workflows to old web app when opt-in #7460

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Comment on lines +73 to +75
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the workflow badge in the Dashboard workflows list page.
The old v1 workflows like I do have in prod don't have type and origin fields that were introduced later. In that case the origin of the workflow is 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;
Comment on lines +19 to +31
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the Web application's current route calculate the new Dashboard URL and redirect the user when he is opt-in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to refactor the previous code because we want to allow editing the v1 workflows in the old Web app if the user is opt-in. Also at the same time clicking in the side navigation in the Web app should redirect user to the new Dashboard corresponding page.

}
},
[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
Loading