chore: temp solution for fetching clerk on every navigated

This commit is contained in:
Aslam H
2024-10-07 17:01:26 +07:00
parent 950ebc3dad
commit b43c9762a1
5 changed files with 41 additions and 91 deletions

View File

@@ -1,4 +1,4 @@
import { useEffect, useState } from "react"
import { useEffect } from "react"
import { atom, useAtom } from "jotai"
import { atomWithStorage } from "jotai/utils"
import {
@@ -11,7 +11,6 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { isExistingUserFn } from "~/actions"
import { useLocation } from "@tanstack/react-router"
const hasVisitedAtom = atomWithStorage("hasVisitedLearnAnything", false)
@@ -21,24 +20,10 @@ export function Onboarding() {
const { pathname } = useLocation()
const [hasVisited, setHasVisited] = useAtom(hasVisitedAtom)
const [isOpen, setIsOpen] = useAtom(isDialogOpenAtom)
const [isFetching, setIsFetching] = useState(true)
const [isExisting, setIsExisting] = useState(false)
useEffect(() => {
const loadUser = async () => {
try {
const existingUser = await isExistingUserFn()
setIsExisting(existingUser)
setIsOpen(true)
} catch (error) {
console.error("Error loading user:", error)
} finally {
setIsFetching(false)
}
}
if (!hasVisited && pathname !== "/") {
loadUser()
setIsOpen(true)
}
}, [hasVisited, pathname, setIsOpen])
@@ -47,50 +32,36 @@ export function Onboarding() {
setHasVisited(true)
}
if (hasVisited || isFetching) return null
if (hasVisited) return null
return (
<AlertDialog open={isOpen} onOpenChange={setIsOpen}>
<AlertDialogContent className="max-w-xl">
<AlertDialogHeader>
<AlertDialogTitle>
<h1 className="text-2xl font-bold">Welcome to Learn Anything!</h1>
</AlertDialogTitle>
<AlertDialogTitle>Welcome to Learn Anything!</AlertDialogTitle>
</AlertDialogHeader>
<AlertDialogDescription className="text-foreground/70 space-y-4 text-base leading-5">
{isExisting && (
<>
<p className="font-medium">Existing Customer Notice</p>
<p>
We noticed you are an existing Learn Anything customer. We
sincerely apologize for any broken experience you may have
encountered on the old website. We&apos;ve been working hard on
this new version, which addresses previous issues and offers
more features. As an early customer, you&apos;re locked in at
the <strong>$3</strong> price for our upcoming pro version.
Thank you for your support!
</p>
</>
)}
<p>
Learn Anything is a learning platform that organizes knowledge in a
social way. You can create pages, add links, track learning status
of any topic, and more things in the future.
</p>
<p>
Try do these quick onboarding steps to get a feel for the product:
</p>
<ul className="list-inside list-disc">
<li>Create your first page</li>
<li>Add a link to a resource</li>
<li>Update your learning status on a topic</li>
</ul>
<p>
If you have any questions, don&apos;t hesitate to reach out. Click
on question mark button in the bottom right corner and enter your
message.
</p>
<AlertDialogDescription asChild>
<div className="text-foreground/70 space-y-4 text-base leading-5">
<p>
Learn Anything is a learning platform that organizes knowledge in
a social way. You can create pages, add links, track learning
status of any topic, and more things in the future.
</p>
<p>
Try do these quick onboarding steps to get a feel for the product:
</p>
<ul className="list-inside list-disc">
<li>Create your first page</li>
<li>Add a link to a resource</li>
<li>Update your learning status on a topic</li>
</ul>
<p>
If you have any questions, don't hesitate to reach out. Click on
question mark button in the bottom right corner and enter your
message.
</p>
</div>
</AlertDialogDescription>
<AlertDialogFooter className="mt-4">