2024-11-05 23:42:59 +05:30
|
|
|
// Dashboard.js
|
|
|
|
|
import React, { useState } from "react";
|
|
|
|
|
import { FaPlus } from "react-icons/fa";
|
|
|
|
|
import PollTableRow from "../components/PollTableRow/PollTableRow";
|
2024-11-08 22:12:16 +05:30
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-11-08 22:26:36 +05:30
|
|
|
import useUserStore from "../store/useStore";
|
|
|
|
|
import useLogout from "../hooks/useLogout";
|
2024-11-05 23:42:59 +05:30
|
|
|
|
|
|
|
|
function Dashboard() {
|
|
|
|
|
|
2024-11-08 22:12:16 +05:30
|
|
|
const navigator = useNavigate();
|
2024-11-08 22:26:36 +05:30
|
|
|
const {handleLogout} = useLogout();
|
2024-11-08 22:12:16 +05:30
|
|
|
|
2024-11-05 23:42:59 +05:30
|
|
|
const pollData = [
|
|
|
|
|
{ _id: "1", title: "Poll 1", description: "Description of Poll 1", totalVotes: 120, published: true },
|
|
|
|
|
{ _id: "2", title: "Poll 2", description: "Description of Poll 2", totalVotes: 45, published: false },
|
|
|
|
|
// Add more poll data as needed
|
|
|
|
|
];
|
|
|
|
|
|
2024-11-08 22:26:36 +05:30
|
|
|
const {user} = useUserStore();
|
|
|
|
|
|
2024-11-05 23:42:59 +05:30
|
|
|
return (
|
2024-11-05 23:50:55 +05:30
|
|
|
<div className="flex flex-col lg:flex-row min-h-screen bg-base-200">
|
2024-11-05 23:42:59 +05:30
|
|
|
{/* User Profile Sidebar */}
|
2024-11-07 12:29:11 +05:30
|
|
|
<aside className="w-min lg:w-1/4 bg-slate-800 rounded-md m-4 bg-opacity-50 shadow-lg p-4 flex flex-col items-center">
|
2024-11-05 23:42:59 +05:30
|
|
|
<img
|
2024-11-08 22:26:36 +05:30
|
|
|
src={`https://placehold.co/200x200?text=${user?.username[0] || "LivePoll"}`} // Replace with actual path
|
2024-11-05 23:42:59 +05:30
|
|
|
alt="User Profile"
|
|
|
|
|
className="rounded-full h-24 w-24 object-cover mb-4"
|
|
|
|
|
/>
|
2024-11-08 22:26:36 +05:30
|
|
|
<h2 className="text-2xl font-bold text-center text-white">{user?.username || "User"}</h2>
|
|
|
|
|
<p className="mt-2 text-center text-gray-400">{user?.email || "Email"}</p>
|
2024-11-05 23:42:59 +05:30
|
|
|
<button className="btn btn-primary mt-4 w-full">Edit Profile</button>
|
2024-11-08 22:26:36 +05:30
|
|
|
<button className="btn btn-error btn-outline mt-4 w-full" onClick={handleLogout}>Logout</button>
|
2024-11-05 23:42:59 +05:30
|
|
|
</aside>
|
|
|
|
|
|
|
|
|
|
{/* Dashboard Main Content */}
|
|
|
|
|
<main className="w-full lg:w-3/4 p-6">
|
|
|
|
|
{/* Dashboard Header */}
|
|
|
|
|
<div className="mb-6">
|
2024-11-07 12:29:11 +05:30
|
|
|
<h1 className="text-2xl md:text-4xl font-bold text-white">Poll Dashboard</h1>
|
|
|
|
|
<p className="md:text-lg text-gray-300">Manage your polls, view results, and edit as needed.</p>
|
2024-11-05 23:42:59 +05:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Add New Poll Button */}
|
|
|
|
|
<div className="flex justify-end mb-4">
|
2024-11-08 22:12:16 +05:30
|
|
|
<button className="btn btn-primary" onClick={() => navigator("/create")}>
|
2024-11-05 23:42:59 +05:30
|
|
|
Add New Poll <FaPlus />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Polls Table */}
|
|
|
|
|
<div className="overflow-x-auto">
|
|
|
|
|
<table className="table w-full bg-gray-800 text-white">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>#</th>
|
|
|
|
|
<th>Title</th>
|
|
|
|
|
<th>Description</th>
|
|
|
|
|
<th>Total Votes</th>
|
|
|
|
|
<th>Published</th>
|
|
|
|
|
<th>Actions</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{pollData.map((poll, index) => (
|
|
|
|
|
<PollTableRow key={poll._id} poll={poll} index={index} /> // Replace with actual path
|
|
|
|
|
))}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Dashboard;
|