mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-20 10:31:15 +01:00
format code + change env
This commit is contained in:
@@ -34,4 +34,3 @@ export async function revalidateAllSubmissions() {
|
||||
return { success: false, error: "Failed to revalidate" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,4 +53,3 @@ export default async function CommunityPage() {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,144 +1,130 @@
|
||||
"use client"
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { SubmissionsDataTable } from "@/components/submissions-data-table"
|
||||
import { useAuth, useSubmissions, useApproveSubmission, useRejectSubmission } from "@/hooks/use-submissions"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
||||
import { AlertCircle, RefreshCw } from "lucide-react"
|
||||
import { SubmissionsDataTable } from "@/components/submissions-data-table"
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { useApproveSubmission, useAuth, useRejectSubmission, useSubmissions } from "@/hooks/use-submissions"
|
||||
|
||||
export default function DashboardPage() {
|
||||
// Fetch auth status
|
||||
const { data: auth, isLoading: authLoading } = useAuth()
|
||||
|
||||
// Fetch submissions
|
||||
const {
|
||||
data: submissions = [],
|
||||
isLoading: submissionsLoading,
|
||||
error: submissionsError,
|
||||
refetch
|
||||
} = useSubmissions()
|
||||
|
||||
// Mutations
|
||||
const approveMutation = useApproveSubmission()
|
||||
const rejectMutation = useRejectSubmission()
|
||||
|
||||
const isLoading = authLoading || submissionsLoading
|
||||
const isAuthenticated = auth?.isAuthenticated ?? false
|
||||
const isAdmin = auth?.isAdmin ?? false
|
||||
const currentUserId = auth?.userId ?? ''
|
||||
// Fetch auth status
|
||||
const { data: auth, isLoading: authLoading } = useAuth()
|
||||
|
||||
const handleApprove = (submissionId: string) => {
|
||||
approveMutation.mutate(submissionId)
|
||||
}
|
||||
// Fetch submissions
|
||||
const { data: submissions = [], isLoading: submissionsLoading, error: submissionsError, refetch } = useSubmissions()
|
||||
|
||||
const handleReject = (submissionId: string) => {
|
||||
rejectMutation.mutate(submissionId)
|
||||
}
|
||||
// Mutations
|
||||
const approveMutation = useApproveSubmission()
|
||||
const rejectMutation = useRejectSubmission()
|
||||
|
||||
// Not authenticated
|
||||
if (!authLoading && !isAuthenticated) {
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>Access Denied</CardTitle>
|
||||
<CardDescription>You need to be logged in to access the dashboard.</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
const isLoading = authLoading || submissionsLoading
|
||||
const isAuthenticated = auth?.isAuthenticated ?? false
|
||||
const isAdmin = auth?.isAdmin ?? false
|
||||
const currentUserId = auth?.userId ?? ""
|
||||
|
||||
// Loading state
|
||||
if (isLoading) {
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<Skeleton className="h-4 w-96" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-16 w-full" />
|
||||
<Skeleton className="h-16 w-full" />
|
||||
<Skeleton className="h-16 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
const handleApprove = (submissionId: string) => {
|
||||
approveMutation.mutate(submissionId)
|
||||
}
|
||||
|
||||
// Error state
|
||||
if (submissionsError) {
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>Submissions Dashboard</CardTitle>
|
||||
<CardDescription>
|
||||
{isAdmin
|
||||
? "Review and manage all icon submissions."
|
||||
: "View your icon submissions and track their status."
|
||||
}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Alert variant="destructive">
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertTitle>Error loading submissions</AlertTitle>
|
||||
<AlertDescription>
|
||||
Failed to load submissions. Please try again.
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="ml-4"
|
||||
onClick={() => refetch()}
|
||||
>
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
Retry
|
||||
</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
const handleReject = (submissionId: string) => {
|
||||
rejectMutation.mutate(submissionId)
|
||||
}
|
||||
|
||||
// Success state
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>Submissions Dashboard</CardTitle>
|
||||
<CardDescription>
|
||||
{isAdmin
|
||||
? "Review and manage all icon submissions. Click on a row to see details."
|
||||
: "View your icon submissions and track their status."
|
||||
}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SubmissionsDataTable
|
||||
data={submissions}
|
||||
isAdmin={isAdmin}
|
||||
currentUserId={currentUserId}
|
||||
onApprove={handleApprove}
|
||||
onReject={handleReject}
|
||||
isApproving={approveMutation.isPending}
|
||||
isRejecting={rejectMutation.isPending}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
// Not authenticated
|
||||
if (!authLoading && !isAuthenticated) {
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>Access Denied</CardTitle>
|
||||
<CardDescription>You need to be logged in to access the dashboard.</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
// Loading state
|
||||
if (isLoading) {
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<Skeleton className="h-4 w-96" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-16 w-full" />
|
||||
<Skeleton className="h-16 w-full" />
|
||||
<Skeleton className="h-16 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
// Error state
|
||||
if (submissionsError) {
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>Submissions Dashboard</CardTitle>
|
||||
<CardDescription>
|
||||
{isAdmin ? "Review and manage all icon submissions." : "View your icon submissions and track their status."}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Alert variant="destructive">
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertTitle>Error loading submissions</AlertTitle>
|
||||
<AlertDescription>
|
||||
Failed to load submissions. Please try again.
|
||||
<Button variant="outline" size="sm" className="ml-4" onClick={() => refetch()}>
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
Retry
|
||||
</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
// Success state
|
||||
return (
|
||||
<main className="container mx-auto pt-12 pb-14 px-4 sm:px-6 lg:px-8">
|
||||
<Card className="bg-background/50 border shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>Submissions Dashboard</CardTitle>
|
||||
<CardDescription>
|
||||
{isAdmin
|
||||
? "Review and manage all icon submissions. Click on a row to see details."
|
||||
: "View your icon submissions and track their status."}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SubmissionsDataTable
|
||||
data={submissions}
|
||||
isAdmin={isAdmin}
|
||||
currentUserId={currentUserId}
|
||||
onApprove={handleApprove}
|
||||
onReject={handleReject}
|
||||
isApproving={approveMutation.isPending}
|
||||
isRejecting={rejectMutation.isPending}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { PostHogProvider } from "@/components/PostHogProvider"
|
||||
import { BASE_URL, getDescription, WEB_URL, websiteTitle } from "@/constants"
|
||||
import { getTotalIcons } from "@/lib/api"
|
||||
import "./globals.css"
|
||||
import { ThemeProvider } from "./theme-provider"
|
||||
import { Providers } from "@/components/providers"
|
||||
import { ThemeProvider } from "./theme-provider"
|
||||
|
||||
const inter = Inter({
|
||||
variable: "--font-inter",
|
||||
|
||||
Reference in New Issue
Block a user