fix skip onboarding if no orgs/projects
This commit is contained in:
@@ -2,7 +2,6 @@ import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
|||||||
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
||||||
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
|
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
|
||||||
import ServerLiveCounter from '@/components/overview/live-counter';
|
import ServerLiveCounter from '@/components/overview/live-counter';
|
||||||
import { OverviewLiveHistogram } from '@/components/overview/overview-live-histogram';
|
|
||||||
import OverviewShareServer from '@/components/overview/overview-share';
|
import OverviewShareServer from '@/components/overview/overview-share';
|
||||||
import OverviewTopDevices from '@/components/overview/overview-top-devices';
|
import OverviewTopDevices from '@/components/overview/overview-top-devices';
|
||||||
import OverviewTopEvents from '@/components/overview/overview-top-events';
|
import OverviewTopEvents from '@/components/overview/overview-top-events';
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ type Props = {
|
|||||||
const Page = ({ children }: Props) => {
|
const Page = ({ children }: Props) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="bg-def-200">
|
<div className="bg-def-100">
|
||||||
<div className="grid h-full md:grid-cols-[min(400px,40vw)_1fr]">
|
<div className="grid h-full md:grid-cols-[min(400px,40vw)_1fr]">
|
||||||
<div className="to-def-200 min-h-screen border-r border-r-background bg-gradient-to-r from-background max-md:hidden">
|
<div className="min-h-screen border-r border-r-background bg-gradient-to-r from-background to-def-200 max-md:hidden">
|
||||||
<LiveEventsServer />
|
<LiveEventsServer />
|
||||||
</div>
|
</div>
|
||||||
<div className="min-h-screen">{children}</div>
|
<div className="min-h-screen">{children}</div>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { SignUp } from '@clerk/nextjs';
|
|||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen items-center justify-center p-4">
|
<div className="flex min-h-screen items-center justify-center p-4">
|
||||||
<SignUp signInUrl="/register" />
|
<SignUp signInUrl="/login" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,44 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { showConfirm } from '@/modals';
|
||||||
|
import { api } from '@/trpc/client';
|
||||||
|
import { useAuth } from '@clerk/nextjs';
|
||||||
import { ChevronLastIcon } from 'lucide-react';
|
import { ChevronLastIcon } from 'lucide-react';
|
||||||
import Link from 'next/link';
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
import { usePathname } from 'next/navigation';
|
|
||||||
|
|
||||||
const SkipOnboarding = () => {
|
const SkipOnboarding = () => {
|
||||||
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
const res = api.onboarding.skipOnboardingCheck.useQuery();
|
||||||
|
const auth = useAuth();
|
||||||
|
useEffect(() => {
|
||||||
|
res.refetch();
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
console.log(res.data);
|
||||||
|
|
||||||
if (!pathname.startsWith('/onboarding')) return null;
|
if (!pathname.startsWith('/onboarding')) return null;
|
||||||
return (
|
return (
|
||||||
<Link
|
<button
|
||||||
href="/"
|
onClick={() => {
|
||||||
|
if (res.data?.canSkip && res.data?.url) {
|
||||||
|
router.push(res.data.url);
|
||||||
|
} else {
|
||||||
|
showConfirm({
|
||||||
|
title: 'Skip onboarding?',
|
||||||
|
text: 'Are you sure you want to skip onboarding? Since you do not have any projects, you will be logged out.',
|
||||||
|
onConfirm() {
|
||||||
|
auth.signOut();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="flex items-center gap-2 text-sm text-muted-foreground"
|
className="flex items-center gap-2 text-sm text-muted-foreground"
|
||||||
>
|
>
|
||||||
Skip onboarding
|
Skip onboarding
|
||||||
<ChevronLastIcon size={16} />
|
<ChevronLastIcon size={16} />
|
||||||
</Link>
|
</button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,14 @@ import crypto from 'crypto';
|
|||||||
import type { z } from 'zod';
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
||||||
import { db, getId, getOrganizationBySlug, getUserById } from '@openpanel/db';
|
import {
|
||||||
|
db,
|
||||||
|
getCurrentOrganizations,
|
||||||
|
getCurrentProjects,
|
||||||
|
getId,
|
||||||
|
getOrganizationBySlug,
|
||||||
|
getUserById,
|
||||||
|
} from '@openpanel/db';
|
||||||
import type { ProjectType } from '@openpanel/db';
|
import type { ProjectType } from '@openpanel/db';
|
||||||
import { zOnboardingProject } from '@openpanel/validation';
|
import { zOnboardingProject } from '@openpanel/validation';
|
||||||
|
|
||||||
@@ -30,6 +37,35 @@ async function createOrGetOrganization(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const onboardingRouter = createTRPCRouter({
|
export const onboardingRouter = createTRPCRouter({
|
||||||
|
skipOnboardingCheck: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const members = await db.member.findMany({
|
||||||
|
where: {
|
||||||
|
userId: ctx.session.userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (members.length > 0) {
|
||||||
|
return {
|
||||||
|
canSkip: true,
|
||||||
|
url: `/${members[0]?.organizationId}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectAccess = await db.projectAccess.findMany({
|
||||||
|
where: {
|
||||||
|
userId: ctx.session.userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (projectAccess.length > 0) {
|
||||||
|
return {
|
||||||
|
canSkip: true,
|
||||||
|
url: `/${projectAccess[0]?.organizationId}/${projectAccess[0]?.projectId}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { canSkip: false, url: null };
|
||||||
|
}),
|
||||||
project: protectedProcedure
|
project: protectedProcedure
|
||||||
.input(zOnboardingProject)
|
.input(zOnboardingProject)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user