Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 16336a0c10 | |||
| e871e1329a | |||
| 07abb2531d | |||
| 72b8e33f8c | |||
| 4b29fcd35f | |||
| 86fa7e0c9b | |||
| fb33ee51f0 |
343
src/app/admin/page.tsx
Normal file
343
src/app/admin/page.tsx
Normal file
@@ -0,0 +1,343 @@
|
||||
"use client";
|
||||
|
||||
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
|
||||
import NavbarStyleCentered from "@/components/navbar/NavbarStyleCentered/NavbarStyleCentered";
|
||||
import FooterBase from "@/components/sections/footer/FooterBase";
|
||||
import Input from "@/components/form/Input";
|
||||
import ButtonHoverMagnetic from "@/components/button/ButtonHoverMagnetic/ButtonHoverMagnetic";
|
||||
import { useState, useEffect } from "react";
|
||||
import { Edit2, Trash2, Plus, LogOut } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
interface Product {
|
||||
id: string;
|
||||
name: string;
|
||||
price: string;
|
||||
category: string;
|
||||
}
|
||||
|
||||
export default function AdminPage() {
|
||||
const [products, setProducts] = useState<Product[]>([
|
||||
{ id: "1", name: "Samsung Galaxy M54", price: "₹25,999", category: "Smartphones" },
|
||||
{ id: "2", name: "Redmi Note 13", price: "₹18,999", category: "Smartphones" },
|
||||
{ id: "3", name: "OPPO A78", price: "₹16,999", category: "Smartphones" },
|
||||
{ id: "4", name: "Vivo T2", price: "₹19,999", category: "Smartphones" },
|
||||
{ id: "5", name: "iPhone 14", price: "₹78,999", category: "Smartphones" },
|
||||
{ id: "6", name: "Universal Phone Case", price: "₹499", category: "Accessories" },
|
||||
]);
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [editValues, setEditValues] = useState<Partial<Product>>({});
|
||||
const [newProduct, setNewProduct] = useState<Partial<Product>>({
|
||||
name: "", price: "", category: "Smartphones"});
|
||||
const [isAuthorized, setIsAuthorized] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
// Check if user is authenticated
|
||||
const token = localStorage.getItem("adminToken");
|
||||
if (!token) {
|
||||
router.push("/login");
|
||||
} else {
|
||||
setIsAuthorized(true);
|
||||
setLoading(false);
|
||||
}
|
||||
}, [router]);
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem("adminToken");
|
||||
router.push("/login");
|
||||
};
|
||||
|
||||
const handleEdit = (product: Product) => {
|
||||
setEditingId(product.id);
|
||||
setEditValues({ ...product });
|
||||
};
|
||||
|
||||
const handleSave = (id: string) => {
|
||||
setProducts(
|
||||
products.map((p) => (p.id === id ? { ...p, ...editValues } : p))
|
||||
);
|
||||
setEditingId(null);
|
||||
setEditValues({});
|
||||
};
|
||||
|
||||
const handleDelete = (id: string) => {
|
||||
if (confirm("Are you sure you want to delete this product?")) {
|
||||
setProducts(products.filter((p) => p.id !== id));
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddProduct = () => {
|
||||
if (newProduct.name && newProduct.price && newProduct.category) {
|
||||
const product: Product = {
|
||||
id: Date.now().toString(),
|
||||
name: newProduct.name as string,
|
||||
price: newProduct.price as string,
|
||||
category: newProduct.category as string,
|
||||
};
|
||||
setProducts([...products, product]);
|
||||
setNewProduct({ name: "", price: "", category: "Smartphones" });
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!isAuthorized) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<p>Redirecting to login...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeProvider
|
||||
defaultButtonVariant="shift-hover"
|
||||
defaultTextAnimation="background-highlight"
|
||||
borderRadius="rounded"
|
||||
contentWidth="medium"
|
||||
sizing="largeSmallSizeMediumTitles"
|
||||
background="circleGradient"
|
||||
cardStyle="soft-shadow"
|
||||
primaryButtonStyle="primary-glow"
|
||||
secondaryButtonStyle="glass"
|
||||
headingFontWeight="semibold"
|
||||
>
|
||||
<div id="nav" data-section="nav">
|
||||
<NavbarStyleCentered
|
||||
brandName="City Cellworld"
|
||||
navItems={[
|
||||
{ name: "Home", id: "/" },
|
||||
{ name: "Services", id: "services" },
|
||||
{ name: "Products", id: "products" },
|
||||
{ name: "About", id: "why-choose" },
|
||||
{ name: "Contact", id: "contact-faq" },
|
||||
]}
|
||||
button={{
|
||||
text: "Call Now", href: "tel:+919876543210"}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div id="admin" data-section="admin" className="min-h-screen py-12 px-4">
|
||||
<div className="max-w-6xl mx-auto">
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
<div>
|
||||
<h1 className="text-4xl font-bold text-foreground mb-2">Admin Dashboard</h1>
|
||||
<p className="text-foreground/70">Manage prices and product inventory</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="flex items-center gap-2 bg-red-500 text-white px-6 py-2 rounded-lg hover:bg-red-600 transition"
|
||||
>
|
||||
<LogOut className="w-5 h-5" />
|
||||
Logout
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Add New Product Section */}
|
||||
<div className="bg-card rounded-lg p-6 mb-8 shadow-lg">
|
||||
<h2 className="text-2xl font-bold text-foreground mb-6 flex items-center gap-2">
|
||||
<Plus className="w-6 h-6" />
|
||||
Add New Product
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 mb-4">
|
||||
<Input
|
||||
value={newProduct.name || ""}
|
||||
onChange={(value) =>
|
||||
setNewProduct({ ...newProduct, name: value })
|
||||
}
|
||||
type="text"
|
||||
placeholder="Product name"
|
||||
/>
|
||||
<Input
|
||||
value={newProduct.price || ""}
|
||||
onChange={(value) =>
|
||||
setNewProduct({ ...newProduct, price: value })
|
||||
}
|
||||
type="text"
|
||||
placeholder="Price (e.g., ₹25,999)"
|
||||
/>
|
||||
<select
|
||||
value={newProduct.category || "Smartphones"}
|
||||
onChange={(e) =>
|
||||
setNewProduct({ ...newProduct, category: e.target.value })
|
||||
}
|
||||
className="px-4 py-2 rounded-lg bg-background border border-foreground/20 text-foreground"
|
||||
>
|
||||
<option>Smartphones</option>
|
||||
<option>Accessories</option>
|
||||
<option>Services</option>
|
||||
</select>
|
||||
<button
|
||||
onClick={handleAddProduct}
|
||||
className="bg-primary-cta text-primary-cta-text font-semibold px-6 py-2 rounded-lg hover:opacity-90 transition"
|
||||
>
|
||||
Add Product
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Products Table */}
|
||||
<div className="bg-card rounded-lg overflow-hidden shadow-lg">
|
||||
<table className="w-full">
|
||||
<thead className="bg-primary-cta text-primary-cta-text">
|
||||
<tr>
|
||||
<th className="px-6 py-4 text-left font-semibold">Product Name</th>
|
||||
<th className="px-6 py-4 text-left font-semibold">Price</th>
|
||||
<th className="px-6 py-4 text-left font-semibold">Category</th>
|
||||
<th className="px-6 py-4 text-left font-semibold">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{products.map((product) => (
|
||||
<tr
|
||||
key={product.id}
|
||||
className="border-t border-foreground/10 hover:bg-background/50 transition"
|
||||
>
|
||||
<td className="px-6 py-4">
|
||||
{editingId === product.id ? (
|
||||
<Input
|
||||
value={editValues.name || ""}
|
||||
onChange={(value) =>
|
||||
setEditValues({ ...editValues, name: value })
|
||||
}
|
||||
type="text"
|
||||
placeholder="Product name"
|
||||
/>
|
||||
) : (
|
||||
<span className="text-foreground">{product.name}</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
{editingId === product.id ? (
|
||||
<Input
|
||||
value={editValues.price || ""}
|
||||
onChange={(value) =>
|
||||
setEditValues({ ...editValues, price: value })
|
||||
}
|
||||
type="text"
|
||||
placeholder="Price"
|
||||
/>
|
||||
) : (
|
||||
<span className="text-foreground font-semibold">
|
||||
{product.price}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
{editingId === product.id ? (
|
||||
<select
|
||||
value={editValues.category || "Smartphones"}
|
||||
onChange={(e) =>
|
||||
setEditValues({
|
||||
...editValues,
|
||||
category: e.target.value,
|
||||
})
|
||||
}
|
||||
className="px-3 py-2 rounded-lg bg-background border border-foreground/20 text-foreground"
|
||||
>
|
||||
<option>Smartphones</option>
|
||||
<option>Accessories</option>
|
||||
<option>Services</option>
|
||||
</select>
|
||||
) : (
|
||||
<span className="text-foreground/70">{product.category}</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex gap-3">
|
||||
{editingId === product.id ? (
|
||||
<>
|
||||
<button
|
||||
onClick={() => handleSave(product.id)}
|
||||
className="bg-green-500 text-white px-4 py-2 rounded-lg hover:bg-green-600 transition font-semibold"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setEditingId(null)}
|
||||
className="bg-gray-500 text-white px-4 py-2 rounded-lg hover:bg-gray-600 transition font-semibold"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<button
|
||||
onClick={() => handleEdit(product)}
|
||||
className="flex items-center gap-2 bg-accent text-foreground px-4 py-2 rounded-lg hover:opacity-80 transition font-semibold"
|
||||
>
|
||||
<Edit2 className="w-4 h-4" />
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(product.id)}
|
||||
className="flex items-center gap-2 bg-red-500 text-white px-4 py-2 rounded-lg hover:bg-red-600 transition font-semibold"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
Delete
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{products.length === 0 && (
|
||||
<div className="bg-card rounded-lg p-12 text-center">
|
||||
<p className="text-foreground/70 text-lg">No products found. Add your first product above.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="footer" data-section="footer">
|
||||
<FooterBase
|
||||
logoText="City Cellworld"
|
||||
copyrightText="© 2025 City Cellworld. All rights reserved. Your trusted mobile store in Ongole."
|
||||
columns={[
|
||||
{
|
||||
title: "Quick Links", items: [
|
||||
{ label: "Home", href: "/" },
|
||||
{ label: "Products", href: "/products" },
|
||||
{ label: "Services", href: "services" },
|
||||
{ label: "About", href: "why-choose" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Services", items: [
|
||||
{ label: "Phone Sales", href: "/products" },
|
||||
{ label: "Screen Repair", href: "services" },
|
||||
{ label: "Battery Service", href: "services" },
|
||||
{ label: "Accessories", href: "/products" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Contact", items: [
|
||||
{
|
||||
label: "Call: +91-9876-543-210", href: "tel:+919876543210"},
|
||||
{
|
||||
label: "WhatsApp: Chat Now", href: "https://wa.me/919876543210"},
|
||||
{
|
||||
label: "Email: info@citycellworld.com", href: "mailto:info@citycellworld.com"},
|
||||
{
|
||||
label: "Visit Store", href: "https://maps.google.com/?q=Vijaya+Complex+Kurnool+Road+Ongole"},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
188
src/app/login/page.tsx
Normal file
188
src/app/login/page.tsx
Normal file
@@ -0,0 +1,188 @@
|
||||
"use client";
|
||||
|
||||
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
|
||||
import NavbarStyleCentered from "@/components/navbar/NavbarStyleCentered/NavbarStyleCentered";
|
||||
import FooterBase from "@/components/sections/footer/FooterBase";
|
||||
import Input from "@/components/form/Input";
|
||||
import ButtonHoverMagnetic from "@/components/button/ButtonHoverMagnetic/ButtonHoverMagnetic";
|
||||
import { useState } from "react";
|
||||
import { Lock, Mail } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function LoginPage() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
// Basic validation
|
||||
if (!email || !password) {
|
||||
setError("Please enter email and password");
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Replace with actual authentication logic
|
||||
// For now, accept demo credentials
|
||||
if (email === "admin@citycellworld.com" && password === "admin123") {
|
||||
// Store authentication token or session
|
||||
localStorage.setItem("adminToken", "authenticated");
|
||||
router.push("/admin");
|
||||
} else {
|
||||
setError("Invalid email or password");
|
||||
}
|
||||
} catch (err) {
|
||||
setError("Login failed. Please try again.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ThemeProvider
|
||||
defaultButtonVariant="shift-hover"
|
||||
defaultTextAnimation="background-highlight"
|
||||
borderRadius="rounded"
|
||||
contentWidth="medium"
|
||||
sizing="largeSmallSizeMediumTitles"
|
||||
background="circleGradient"
|
||||
cardStyle="soft-shadow"
|
||||
primaryButtonStyle="primary-glow"
|
||||
secondaryButtonStyle="glass"
|
||||
headingFontWeight="semibold"
|
||||
>
|
||||
<div id="nav" data-section="nav">
|
||||
<NavbarStyleCentered
|
||||
brandName="City Cellworld"
|
||||
navItems={[
|
||||
{ name: "Home", id: "/" },
|
||||
{ name: "Services", id: "services" },
|
||||
{ name: "Products", id: "products" },
|
||||
{ name: "About", id: "why-choose" },
|
||||
{ name: "Contact", id: "contact-faq" },
|
||||
]}
|
||||
button={{
|
||||
text: "Call Now", href: "tel:+919876543210"}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div id="login" data-section="login" className="min-h-screen flex items-center justify-center py-12 px-4">
|
||||
<div className="w-full max-w-md">
|
||||
<div className="bg-card rounded-lg shadow-lg p-8">
|
||||
<div className="text-center mb-8">
|
||||
<Lock className="w-12 h-12 mx-auto mb-4 text-primary-cta" />
|
||||
<h1 className="text-3xl font-bold text-foreground mb-2">Admin Login</h1>
|
||||
<p className="text-foreground/70">Access the admin dashboard to manage prices and inventory</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleLogin} className="space-y-6">
|
||||
{error && (
|
||||
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label htmlFor="email" className="block text-sm font-medium text-foreground mb-2">
|
||||
Email Address
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Mail className="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-foreground/50" />
|
||||
<Input
|
||||
value={email}
|
||||
onChange={setEmail}
|
||||
type="email"
|
||||
placeholder="admin@citycellworld.com"
|
||||
required
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="password" className="block text-sm font-medium text-foreground mb-2">
|
||||
Password
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Lock className="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-foreground/50" />
|
||||
<Input
|
||||
value={password}
|
||||
onChange={setPassword}
|
||||
type="password"
|
||||
placeholder="Enter your password"
|
||||
required
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full bg-primary-cta text-primary-cta-text font-semibold py-3 rounded-lg hover:opacity-90 transition-opacity disabled:opacity-50"
|
||||
>
|
||||
{loading ? "Logging in..." : "Login to Admin"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="mt-6 pt-6 border-t border-foreground/20">
|
||||
<p className="text-sm text-foreground/70 text-center">
|
||||
Demo credentials:
|
||||
</p>
|
||||
<p className="text-sm text-foreground/70 text-center">
|
||||
Email: admin@citycellworld.com
|
||||
</p>
|
||||
<p className="text-sm text-foreground/70 text-center">
|
||||
Password: admin123
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="footer" data-section="footer">
|
||||
<FooterBase
|
||||
logoText="City Cellworld"
|
||||
copyrightText="© 2025 City Cellworld. All rights reserved. Your trusted mobile store in Ongole."
|
||||
columns={[
|
||||
{
|
||||
title: "Quick Links", items: [
|
||||
{ label: "Home", href: "/" },
|
||||
{ label: "Products", href: "/products" },
|
||||
{ label: "Services", href: "services" },
|
||||
{ label: "About", href: "why-choose" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Services", items: [
|
||||
{ label: "Phone Sales", href: "/products" },
|
||||
{ label: "Screen Repair", href: "services" },
|
||||
{ label: "Battery Service", href: "services" },
|
||||
{ label: "Accessories", href: "/products" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Contact", items: [
|
||||
{
|
||||
label: "Call: +91-9876-543-210", href: "tel:+919876543210"},
|
||||
{
|
||||
label: "WhatsApp: Chat Now", href: "https://wa.me/919876543210"},
|
||||
{
|
||||
label: "Email: info@citycellworld.com", href: "mailto:info@citycellworld.com"},
|
||||
{
|
||||
label: "Visit Store", href: "https://maps.google.com/?q=Vijaya+Complex+Kurnool+Road+Ongole"},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
@@ -50,6 +50,7 @@ export default function HomePage() {
|
||||
{ name: "Products", id: "products" },
|
||||
{ name: "About", id: "why-choose" },
|
||||
{ name: "Contact", id: "contact-faq" },
|
||||
{ name: "Admin", id: "/admin" },
|
||||
]}
|
||||
button={{
|
||||
text: "Call Now", href: "tel:+919876543210"}}
|
||||
@@ -298,4 +299,4 @@ export default function HomePage() {
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user