-
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
feat(dashboard,web): opt-in app switching and redirects #7002
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useNewDashboardOptIn } from '@/hooks/use-new-dashboard-opt-in'; | ||
import { NewDashboardOptInStatusEnum } from '@novu/shared'; | ||
import { PropsWithChildren, useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export const OptInProvider = (props: PropsWithChildren) => { | ||
const navigate = useNavigate(); | ||
const { children } = props; | ||
const { status, isLoaded } = useNewDashboardOptIn(); | ||
|
||
useEffect(() => { | ||
if (isLoaded && status !== NewDashboardOptInStatusEnum.OPTED_IN) { | ||
window.location.href = '/legacy/workflows'; | ||
} | ||
}, [status, navigate, isLoaded]); | ||
|
||
return <>{children}</>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { FeatureFlagsKeysEnum, NewDashboardOptInStatusEnum } from '@novu/shared'; | ||
import { PropsWithChildren, useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useNewDashboardOptIn } from '../../hooks/useNewDashboardOptIn'; | ||
|
||
import { ROUTES } from '../../constants/routes'; | ||
import { IS_EE_AUTH_ENABLED } from '../../config'; | ||
import { useFeatureFlag } from '../../hooks'; | ||
|
||
const NEW_DASHBOARD_ROUTES = [ROUTES.WORKFLOWS]; | ||
|
||
export const OptInProvider = ({ children }: { children: React.ReactNode }) => { | ||
const isNewDashboardEnabled = useFeatureFlag(FeatureFlagsKeysEnum.IS_NEW_DASHBOARD_ENABLED); | ||
|
||
if (IS_EE_AUTH_ENABLED && isNewDashboardEnabled) { | ||
return <_OptInProvider>{children}</_OptInProvider>; | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export const _OptInProvider = (props: PropsWithChildren) => { | ||
const navigate = useNavigate(); | ||
const { children } = props; | ||
const { status, isLoaded } = useNewDashboardOptIn(); | ||
|
||
useEffect(() => { | ||
if (isLoaded && status === NewDashboardOptInStatusEnum.OPTED_IN) { | ||
const currentRoute = window.location.pathname.replace('/legacy', ''); | ||
|
||
/** | ||
* if equivalent of current route (incl. subroutes) exits in new dashboard, redirect to it | ||
* - /legacy/workflows -> /workflows | ||
* - /legacy/workflows/edit/123 -> /workflows | ||
*/ | ||
if (NEW_DASHBOARD_ROUTES.some((route) => currentRoute.includes(route))) { | ||
/** | ||
* TODO: in order to redirect to the same route, we need to translate the | ||
* "dev_env_<id>" or wf/step slugs to legacy environment id and vice-versa | ||
* | ||
* note: /legacy is part of public URL, so we can't navigate() outside of that | ||
*/ | ||
window.location.href = window.location.origin; | ||
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. for now we redirect to the default page which is the workflows page - otherwise we would need to parse old env id to new env slugs to redirect to |
||
} | ||
} | ||
}, [status, navigate, isLoaded]); | ||
|
||
return <>{children}</>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,17 @@ import { NEW_DASHBOARD_URL } from '../config'; | |
import { useSegment } from '../components/providers/SegmentProvider'; | ||
|
||
export function useNewDashboardOptIn() { | ||
const { user } = useUser(); | ||
const { user, isLoaded } = useUser(); | ||
const segment = useSegment(); | ||
|
||
const updateUserOptInStatus = (status: NewDashboardOptInStatusEnum) => { | ||
const updateUserOptInStatus = async (status: NewDashboardOptInStatusEnum) => { | ||
if (!user) return; | ||
|
||
user.update({ | ||
await user.update({ | ||
unsafeMetadata: { | ||
...user.unsafeMetadata, | ||
newDashboardOptInStatus: status, | ||
newDashboardFirstVisit: true, | ||
}, | ||
}); | ||
}; | ||
|
@@ -28,9 +29,11 @@ export function useNewDashboardOptIn() { | |
window.location.href = NEW_DASHBOARD_URL || window.location.origin; | ||
}; | ||
|
||
const optIn = () => { | ||
const optIn = async () => { | ||
segment.track('New dashboard opt-in'); | ||
updateUserOptInStatus(NewDashboardOptInStatusEnum.OPTED_IN); | ||
await updateUserOptInStatus(NewDashboardOptInStatusEnum.OPTED_IN); | ||
localStorage.setItem('mantine-theme', 'light'); | ||
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. this needs to be set directly in local storage otherwise when using hook the operation seems to be async and can't be awaited |
||
redirectToNewDashboard(); | ||
}; | ||
|
||
const dismiss = () => { | ||
|
@@ -39,9 +42,9 @@ export function useNewDashboardOptIn() { | |
}; | ||
|
||
return { | ||
isLoaded, | ||
optIn, | ||
dismiss, | ||
status: getCurrentOptInStatus(), | ||
redirectToNewDashboard, | ||
}; | ||
} |
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.
using
navigate()
here won't work since its external url