fix skip onboarding if no orgs/projects

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-11 23:32:15 +02:00
parent 2e037ca16d
commit 601c2264a2
5 changed files with 69 additions and 10 deletions

View File

@@ -2,7 +2,6 @@ import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
import ServerLiveCounter from '@/components/overview/live-counter';
import { OverviewLiveHistogram } from '@/components/overview/overview-live-histogram';
import OverviewShareServer from '@/components/overview/overview-share';
import OverviewTopDevices from '@/components/overview/overview-top-devices';
import OverviewTopEvents from '@/components/overview/overview-top-events';

View File

@@ -7,9 +7,9 @@ type Props = {
const Page = ({ children }: Props) => {
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="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 />
</div>
<div className="min-h-screen">{children}</div>

View File

@@ -3,7 +3,7 @@ import { SignUp } from '@clerk/nextjs';
export default function Page() {
return (
<div className="flex min-h-screen items-center justify-center p-4">
<SignUp signInUrl="/register" />
<SignUp signInUrl="/login" />
</div>
);
}

View File

@@ -1,20 +1,44 @@
'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 Link from 'next/link';
import { usePathname } from 'next/navigation';
import { usePathname, useRouter } from 'next/navigation';
const SkipOnboarding = () => {
const router = useRouter();
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;
return (
<Link
href="/"
<button
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"
>
Skip onboarding
<ChevronLastIcon size={16} />
</Link>
</button>
);
};

View File

@@ -2,7 +2,14 @@ import crypto from 'crypto';
import type { z } from 'zod';
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 { zOnboardingProject } from '@openpanel/validation';
@@ -30,6 +37,35 @@ async function createOrGetOrganization(
}
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
.input(zOnboardingProject)
.mutation(async ({ input, ctx }) => {