Certainly! Below is a page.tsx file for a Next.js application using Shadcn UI components to create a modern dashboard for a PufferPanel client. This dashboard includes:
- Header: Displays the user's profile picture and the amount of coins they have.
- Server List: A responsive, modern list of servers managed by the user.
Prerequisites
-
Next.js Setup: Ensure you have a Next.js project set up. If not, you can create one using:
npx create-next-app@latest your-app-name --typescript
-
Shadcn UI Installation: Install Shadcn UI and its dependencies. Follow the official installation guide for detailed steps. Generally, you can install it using:
npm install shadcn-ui
-
Tailwind CSS Configuration: Shadcn UI relies on Tailwind CSS. Ensure Tailwind is properly configured in your project.
page.tsx Implementation
// app/dashboard/page.tsx
import React from 'react';
import Image from 'next/image';
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
import { Card } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { useSession } from 'next-auth/react'; // If using next-auth for authentication
import { serverData } from '@/data/servers'; // Assume you have server data here
interface Server {
id: string;
name: string;
status: 'online' | 'offline';
playerCount: number;
maxPlayers: number;
}
const Dashboard: React.FC = () => {
// Replace this with your actual data fetching logic
const servers: Server[] = serverData;
// Example user data; replace with your actual user data
const user = {
name: 'John Doe',
coins: 1200,
image: '/images/user-avatar.png', // Path to user avatar
};
return (
<div className="min-h-screen bg-gray-100 p-6">
{/* Header */}
<header className="flex justify-between items-center mb-8">
<h1 className="text-3xl font-bold">Dashboard</h1>
<div className="flex items-center space-x-4">
<div className="text-right">
<p className="text-sm text-gray-600">Coins</p>
<p className="text-lg font-semibold">{user.coins}</p>
</div>
<Avatar>
<AvatarImage src={user.image} alt={user.name} />
<AvatarFallback>{user.name.charAt(0)}</AvatarFallback>
</Avatar>
</div>
</header>
{/* Server List */}
<section>
<h2 className="text-2xl font-semibold mb-4">Your Servers</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{servers.map((server) => (
<Card key={server.id} className="p-6 shadow-md hover:shadow-xl transition-shadow">
<div className="flex justify-between items-center mb-4">
<h3 className="text-xl font-medium">{server.name}</h3>
<span
className={`px-2 py-1 text-sm font-semibold rounded ${
server.status === 'online'
? 'bg-green-100 text-green-800'
: 'bg-red-100 text-red-800'
}`}
>
{server.status}
</span>
</div>
<div className="mb-4">
<p className="text-gray-700">
Players: {server.playerCount} / {server.maxPlayers}
</p>
<div className="w-full bg-gray-200 rounded-full h-2.5 mt-2">
<div
className={`h-2.5 rounded-full ${
server.status === 'online' ? 'bg-green-500' : 'bg-red-500'
}`}
style={{
width: `${(server.playerCount / server.maxPlayers) * 100}%`,
}}
></div>
</div>
</div>
<Button variant="default" className="w-full">
Manage Server
</Button>
</Card>
))}
</div>
</section>
</div>
);
};
export default Dashboard;
Explanation
-
Imports:
Avatar, Card, and Button are imported from Shadcn UI components.
useSession from next-auth/react is included in case you're using authentication to fetch user data. You can remove it if not needed.
serverData is assumed to be a static data file. Replace this with your actual data fetching logic (e.g., from PufferPanel's API).
-
User Data:
- Replace the
user object with your actual user data source. This example uses static data.
- The user's coins and avatar are displayed in the header.
-
Server List:
- The servers are displayed in a responsive grid. Adjust the
grid-cols classes based on your design preferences.
- Each server card shows:
- Name and Status: The server's name and its current status (online/offline) with color-coded badges.
- Player Count: Displays the current number of players vs. the maximum allowed.
- Progress Bar: Visually represents the player occupancy.
- Manage Button: A button to perform actions on the server (e.g., start, stop, manage settings).
-
Styling:
- Tailwind CSS classes are used for styling. Adjust the classes to match your design requirements.
- Hover effects and transitions are added for interactivity.
-
Responsive Design:
- The grid adjusts based on screen size (
grid-cols-1 for small screens, md:grid-cols-2 for medium, and lg:grid-cols-3 for large screens).
Data Fetching
In a real-world application, you'd fetch the server and user data from an API. Here's a basic example using getServerSideProps:
// app/dashboard/page.tsx
import { GetServerSideProps } from 'next';
// ... (rest of the imports and Dashboard component)
export const getServerSideProps: GetServerSideProps = async (context) => {
// Fetch user data
const user = await fetchUserData(context);
// Fetch server data from PufferPanel API
const servers = await fetchServers(user.id);
return {
props: {
user,
servers,
},
};
};
export default Dashboard;
However, with Next.js 13's App Router, data fetching would be handled differently, possibly using React's useEffect and client-side fetching or Server Actions.
Final Notes
- Authentication: Ensure that only authenticated users can access the dashboard. Implement authentication checks as needed.
- Dynamic Data: Replace static data with dynamic data fetched from your backend or PufferPanel's API.
- Error Handling: Add appropriate error handling for data fetching operations.
- Enhancements: Consider adding features like server creation, deletion, real-time server status updates, etc., based on your requirements.
Feel free to customize the components and styles to better fit your application's needs!