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(dashboard): Opt-in new orgs created from org switcher in v2 #7277

Merged
merged 3 commits into from
Dec 12, 2024
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
@@ -1,5 +1,6 @@
import { OrganizationSwitcher as ClerkOrganizationSwitcher } from '@clerk/clerk-react';
import type { OrganizationSwitcherTheme } from '@clerk/types';
import { ROUTES } from '../../utils/routes';

const OrganizationSwitcherAppearance: OrganizationSwitcherTheme = {
elements: {
Expand All @@ -11,19 +12,28 @@ const OrganizationSwitcherAppearance: OrganizationSwitcherTheme = {
organizationSwitcherPopoverActionButton__manageOrganization: {
display: 'none',
},
organizationSwitcherPopoverInvitationActionsBox: 'p-0 pr-2',
organizationSwitcherInvitationAcceptButton: '!text-[10px] !min-w-[90px] !w-[90px] px-0',
organizationPreviewMainIdentifier: 'text-foreground-950 text-base',
organizationPreviewAvatarContainer: 'size-6 rounded-full',
organizationPreviewAvatarBox: 'rounded-full size-6',
organizationPreview: 'py-1.5 px-4 gap-2',
organizationSwitcherPopoverActionButton: 'py-1.5 px-4 -ml-1.5 text-sm gap-0',
organizationPreview: 'py-1.5 px-2 gap-2',
organizationSwitcherPopoverActionButton: 'py-1 px-2 -ml-1.5 text-sm gap-0',
organizationSwitcherPopoverCard: 'w-64',
organizationSwitcherPreviewButton: 'p-0 [&>svg]:mr-2 !border-0',
organizationPreviewSecondaryIdentifier: 'hidden',
organizationSwitcherPopoverActions:
'py-2 [&_.cl-organizationPreviewMainIdentifier]:text-sm [&>div:nth-child(2)]:!border-0',
'py-0.5 [&_.cl-organizationPreviewMainIdentifier]:text-sm [&>div:nth-child(2)]:!border-0',
Comment on lines +15 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something was cmpletly off when a new invitation is available to a user to join an org. Fixed the excess paddings

},
};

export const OrganizationDropdown = () => {
return <ClerkOrganizationSwitcher hidePersonal appearance={OrganizationSwitcherAppearance} />;
return (
<ClerkOrganizationSwitcher
hidePersonal
skipInvitationScreen
afterCreateOrganizationUrl={ROUTES.USECASE_SELECT + '?v2_opt_in=true'}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to redirect the user and skip the questionnaire straight to the usecase select page

appearance={OrganizationSwitcherAppearance}
/>
);
};
15 changes: 11 additions & 4 deletions apps/dashboard/src/context/opt-in-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { PropsWithChildren, useLayoutEffect } from 'react';
import { NewDashboardOptInStatusEnum } from '@novu/shared';
import { useNewDashboardOptIn } from '@/hooks/use-new-dashboard-opt-in';
import { useSearchParams } from 'react-router-dom';

export const OptInProvider = (props: PropsWithChildren) => {
const { children } = props;
const { status, isLoaded, redirectToLegacyDashboard } = useNewDashboardOptIn();
const { status, isLoaded, redirectToLegacyDashboard, optIn } = useNewDashboardOptIn();
const [searchParams] = useSearchParams();
const hasV2OptIn = searchParams.has('v2_opt_in');

useLayoutEffect(() => {
if (isLoaded && status !== NewDashboardOptInStatusEnum.OPTED_IN) {
redirectToLegacyDashboard();
if (isLoaded && status !== NewDashboardOptInStatusEnum.OPTED_IN && !hasV2OptIn) {
(async () => {
await optIn();
redirectToLegacyDashboard();
})();
}

// set light theme on the new domain for both legacy and new dashboard
localStorage.setItem('mantine-theme', 'light');
}, [status, redirectToLegacyDashboard, isLoaded]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [status, redirectToLegacyDashboard, isLoaded, hasV2OptIn]);

return <>{children}</>;
};
5 changes: 5 additions & 0 deletions apps/dashboard/src/hooks/use-new-dashboard-opt-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ export function useNewDashboardOptIn() {
redirectToLegacyDashboard();
};

const optIn = async () => {
await updateUserOptInStatus(NewDashboardOptInStatusEnum.OPTED_IN);
};

return {
isLoaded,
optOut,
optIn,
status: getCurrentOptInStatus(),
isFirstVisit: getNewDashboardFirstVisit(),
updateNewDashboardFirstVisit,
Expand Down
Loading