diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx
index 38149a80..749825e2 100644
--- a/src/components/dashboard/DashboardLayout.tsx
+++ b/src/components/dashboard/DashboardLayout.tsx
@@ -17,6 +17,7 @@ import {
useNotifications,
} from "@crossbell/notification"
import { useUserRole } from "~/hooks/useUserRole"
+import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
export function DashboardLayout({
children,
@@ -31,12 +32,30 @@ export function DashboardLayout({
const userSite = useAccountSites()
const userRole = useUserRole(subdomain)
+ const [ssrReady, isConnected] = useAccountState(({ ssrReady, computed }) => [
+ ssrReady,
+ !!computed.account,
+ ])
+ const connectModal = useConnectModal()
+ const [ready, setReady] = React.useState(false)
+ const [hasPermission, setHasPermission] = React.useState(false)
useEffect(() => {
- if (userRole.isSuccess && !userRole.data) {
- router.push("/dashboard")
+ if (ssrReady) {
+ if (!isConnected) {
+ setReady(false)
+ setHasPermission(false)
+ connectModal.show()
+ } else if (userRole.isSuccess) {
+ setReady(true)
+ if (userRole.data) {
+ setHasPermission(true)
+ } else {
+ setHasPermission(false)
+ }
+ }
}
- }, [router, userRole])
+ }, [ssrReady, userRole.isSuccess, userRole.data, isConnected, connectModal])
const showNotificationModal = useShowNotificationModal()
const { isAllRead } = useNotifications()
@@ -81,94 +100,110 @@ export function DashboardLayout({
},
]
- return (
- <>
-
- {site?.data?.css && (
-
- )}
-
-
- {(isOpen) => (
- <>
- {userSite.data?.[0]?.username &&
- subdomain &&
- userSite.data[0].username !== subdomain && (
-
-
You are operating
-
-
- {site.data?.name}
-
- @{site.data?.username}
+ return ready ? (
+ hasPermission ? (
+ <>
+
+ {site?.data?.css && (
+
+ )}
+
+
+ {(isOpen) => (
+ <>
+ {userSite.data?.[0]?.username &&
+ subdomain &&
+ userSite.data[0].username !== subdomain && (
+
+
You are operating
+
+
+ {site.data?.name}
+
+ @{site.data?.username}
+
-
-
- )}
-
-
-
+
+ )}
+
+
+
-
- {links.map((link) => {
- const active =
- link.href &&
- link.isActive({
- pathname: router.asPath,
- href: link.href,
- })
- return (
-
-
- {isOpen && {link.text}}
-
- )
- })}
-
-
-
-
+ {links.map((link) => {
+ const active =
+ link.href &&
+ link.isActive({
+ pathname: router.asPath,
+ href: link.href,
+ })
+ return (
+
+
+ {isOpen && {link.text}}
+
+ )
})}
- className="space-x-2 border rounded-lg bg-slate-100 border-slate-200 text-slate-500 hover:text-accent flex w-full h-12 items-center justify-center transition-colors"
- >
-
- {isOpen && View Site}
-
-
- >
- )}
-
- {children}
+
+
+
+
+
+ {isOpen && View Site}
+
+
+ >
+ )}
+
+ {children}
+
+ >
+ ) : (
+
+
+
+ Sorry, you do not have permission to access the current page.
+
+
+ Please switch account or request the owner to set you as the operator.
+
- >
+ )
+ ) : (
+
+ Loading...
+
)
}
diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx
index ca7b703e..89d577e9 100644
--- a/src/pages/dashboard/index.tsx
+++ b/src/pages/dashboard/index.tsx
@@ -1,20 +1,42 @@
import { useAccountSites } from "~/queries/site"
import { useEffect } from "react"
import { useRouter } from "next/router"
+import {
+ useAccountState,
+ useWalletMintNewCharacterModal,
+ useConnectModal,
+} from "@crossbell/connect-kit"
export default function Dashboard() {
const router = useRouter()
const userSites = useAccountSites()
+ const walletMintNewCharacterModal = useWalletMintNewCharacterModal()
+ const [ssrReady, isConnected] = useAccountState(({ ssrReady, computed }) => [
+ ssrReady,
+ !!computed.account,
+ ])
+ const connectModal = useConnectModal()
useEffect(() => {
- if (userSites.isSuccess) {
- if (!userSites.data?.length) {
- router.push(`/`)
- } else {
- router.push(`/dashboard/${userSites.data[0].username}`)
+ if (ssrReady) {
+ if (!isConnected) {
+ connectModal.show()
+ } else if (userSites.isSuccess) {
+ if (!userSites.data?.length) {
+ walletMintNewCharacterModal.show()
+ } else {
+ router.push(`/dashboard/${userSites.data[0].username}`)
+ }
}
}
- }, [userSites, router])
+ }, [
+ ssrReady,
+ userSites,
+ router,
+ walletMintNewCharacterModal,
+ isConnected,
+ connectModal,
+ ])
return (