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

@@ -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>
);
};