-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(() => { | ||
|
There was a problem hiding this comment.
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
andorigin
fields that were introduced later. In that case the origin of the workflow isv1
.