Consistency fixes: - Extract getThisWeekRange/getThisMonthRange to shared lib/utils/dateRanges.ts (removed 4 identical copy-pasted definitions) - Add error boundaries for behavior, cdn, search, pagespeed pages (4 new error.tsx files — previously fell through to generic parent error) - Add "View setup guide" CTA to empty states on journeys and behavior pages (previously showed text with no actionable button) - Fix non-lazy useState initializer in funnel detail page - Fix Bot & Spam settings header from text-xl to text-2xl (matches all other sections) - Add useMinimumLoading to PageSpeed skeleton (consistent with all other pages) Cleanup: - Remove 438 redundant dark: class prefixes (app is dark-mode only) text-neutral-500 dark:text-neutral-400 → text-neutral-400 (206 occurrences) text-neutral-900 dark:text-white → text-white (232 occurrences) - Remove dead @stripe/react-stripe-js and @stripe/stripe-js packages (billing migrated to Polar, no code imports Stripe) - Remove duplicate motion package (framer-motion is the one actually used)
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { getAdminMe } from '@/lib/api/admin'
|
|
import { LoadingOverlay } from '@ciphera-net/ui'
|
|
|
|
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
|
const [isAdmin, setIsAdmin] = useState<boolean | null>(null)
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
getAdminMe()
|
|
.then((res) => {
|
|
if (res.is_admin) {
|
|
setIsAdmin(true)
|
|
} else {
|
|
setIsAdmin(false)
|
|
// Redirect to home if not admin
|
|
router.push('/')
|
|
}
|
|
})
|
|
.catch(() => {
|
|
setIsAdmin(false)
|
|
router.push('/')
|
|
})
|
|
}, [router])
|
|
|
|
if (isAdmin === null) {
|
|
return <LoadingOverlay logoSrc="/pulse_icon_no_margins.png" title="Checking access..." />
|
|
}
|
|
|
|
if (!isAdmin) {
|
|
return null // Will redirect
|
|
}
|
|
|
|
return (
|
|
<div className="w-full max-w-6xl mx-auto px-4 sm:px-6 py-8">
|
|
<div className="mb-8 flex items-center justify-between">
|
|
<h1 className="text-2xl font-bold text-white">Pulse Admin</h1>
|
|
</div>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|