feat: clean repository without any huge files
Build and Deploy / build-and-push (push) Failing after 1m20s
Build and Deploy / build-and-push (push) Failing after 1m20s
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ArrowLeft, ShieldAlert, Loader2, Save } from 'lucide-react';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
interface UserProfile {
|
||||
id: string;
|
||||
email: string;
|
||||
role: string;
|
||||
api_credits: number;
|
||||
storage_limit_mb: number;
|
||||
is_active: number;
|
||||
}
|
||||
|
||||
export default function Admin() {
|
||||
const navigate = useNavigate();
|
||||
const { profile } = useAuthStore();
|
||||
const [users, setUsers] = useState<UserProfile[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUsers = async () => {
|
||||
if (profile?.role !== 'admin') return;
|
||||
try {
|
||||
const data = await api.getUsers();
|
||||
setUsers(data.users || []);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
fetchUsers();
|
||||
}, [profile]);
|
||||
|
||||
const updateLimits = async (userObj: UserProfile) => {
|
||||
try {
|
||||
await api.updateUser(userObj.id, {
|
||||
role: userObj.role,
|
||||
api_credits: userObj.api_credits,
|
||||
storage_limit_mb: userObj.storage_limit_mb,
|
||||
is_active: userObj.is_active
|
||||
});
|
||||
alert("Updated successfully!");
|
||||
} catch (error: any) {
|
||||
alert("Failed to update user: " + error.message);
|
||||
}
|
||||
};
|
||||
|
||||
if (profile?.role !== 'admin') {
|
||||
return (
|
||||
<div className="min-h-screen bg-zinc-950 flex flex-col items-center justify-center text-white">
|
||||
<ShieldAlert size={48} className="text-red-500 mb-4" />
|
||||
<h1 className="text-2xl font-bold mb-2">Access Denied</h1>
|
||||
<p className="text-zinc-400 mb-6">You do not have administrative privileges.</p>
|
||||
<button onClick={() => navigate('/dashboard')} className="px-6 py-2 bg-zinc-800 rounded-lg hover:bg-zinc-700">
|
||||
Return to Dashboard
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-zinc-950 text-white p-8">
|
||||
<div className="max-w-6xl mx-auto">
|
||||
<button
|
||||
onClick={() => navigate('/dashboard')}
|
||||
className="flex items-center gap-2 text-zinc-400 hover:text-white mb-8 transition-colors"
|
||||
>
|
||||
<ArrowLeft size={16} /> Back to Dashboard
|
||||
</button>
|
||||
|
||||
<h1 className="text-3xl font-bold mb-8">Admin Control Panel</h1>
|
||||
|
||||
<div className="bg-zinc-900 border border-zinc-800 rounded-2xl overflow-hidden">
|
||||
<div className="p-6 border-b border-zinc-800 flex justify-between items-center">
|
||||
<h2 className="text-xl font-semibold">User Limit Management</h2>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="p-12 flex justify-center"><Loader2 className="animate-spin" /></div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="bg-zinc-950 text-zinc-400">
|
||||
<tr>
|
||||
<th className="p-4 font-medium">User ID</th>
|
||||
<th className="p-4 font-medium">Email</th>
|
||||
<th className="p-4 font-medium">Role</th>
|
||||
<th className="p-4 font-medium">Status</th>
|
||||
<th className="p-4 font-medium">API Credits</th>
|
||||
<th className="p-4 font-medium">Storage Limit (MB)</th>
|
||||
<th className="p-4 font-medium text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-zinc-800">
|
||||
{users.map(u => (
|
||||
<UserRow key={u.id} user={u} onUpdate={updateLimits} />
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const UserRow = ({ user, onUpdate }: { user: UserProfile, onUpdate: (u: UserProfile) => void }) => {
|
||||
const [role, setRole] = useState(user.role);
|
||||
const [isActive, setIsActive] = useState(user.is_active);
|
||||
const [credits, setCredits] = useState(user.api_credits);
|
||||
const [storage, setStorage] = useState(user.storage_limit_mb);
|
||||
|
||||
const handleUpdate = () => {
|
||||
onUpdate({
|
||||
...user,
|
||||
role,
|
||||
is_active: isActive,
|
||||
api_credits: credits,
|
||||
storage_limit_mb: storage
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<tr className="hover:bg-zinc-800/50">
|
||||
<td className="p-4 font-mono text-xs opacity-50" title={user.id}>{user.id.substring(0, 8)}...</td>
|
||||
<td className="p-4 font-mono text-xs">{user.email}</td>
|
||||
<td className="p-4">
|
||||
<select
|
||||
value={role}
|
||||
onChange={(e) => setRole(e.target.value)}
|
||||
className={`px-2 py-1 rounded text-xs focus:outline-none focus:border-primary border border-transparent ${role === 'admin' ? 'bg-red-500/20 text-red-400' : 'bg-blue-500/20 text-blue-400'}`}
|
||||
>
|
||||
<option value="user" className="bg-zinc-900 text-white">User</option>
|
||||
<option value="admin" className="bg-zinc-900 text-white">Admin</option>
|
||||
</select>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<select
|
||||
value={isActive}
|
||||
onChange={(e) => setIsActive(Number(e.target.value))}
|
||||
className={`px-2 py-1 rounded text-xs focus:outline-none focus:border-primary border border-transparent ${isActive === 1 ? 'bg-green-500/20 text-green-400' : 'bg-yellow-500/20 text-yellow-400'}`}
|
||||
>
|
||||
<option value={1} className="bg-zinc-900 text-white">Active</option>
|
||||
<option value={0} className="bg-zinc-900 text-white">Pending</option>
|
||||
</select>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<input
|
||||
type="number"
|
||||
value={credits}
|
||||
onChange={e => setCredits(Number(e.target.value))}
|
||||
className="w-24 bg-zinc-950 border border-zinc-700 rounded px-2 py-1 text-white focus:outline-none focus:border-primary"
|
||||
/>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<input
|
||||
type="number"
|
||||
value={storage}
|
||||
onChange={e => setStorage(Number(e.target.value))}
|
||||
className="w-24 bg-zinc-950 border border-zinc-700 rounded px-2 py-1 text-white focus:outline-none focus:border-primary"
|
||||
/>
|
||||
</td>
|
||||
<td className="p-4 text-right">
|
||||
<button
|
||||
onClick={handleUpdate}
|
||||
className="bg-zinc-800 hover:bg-zinc-700 text-white px-3 py-1.5 rounded flex items-center justify-center gap-2 ml-auto transition-colors"
|
||||
>
|
||||
<Save size={14} /> Save
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import { LogOut, Plus, Folder, Loader2, Trash2 } from 'lucide-react';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export default function Dashboard() {
|
||||
const { user, profile, signOut } = useAuthStore();
|
||||
const navigate = useNavigate();
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProjects = async () => {
|
||||
if (!user) return;
|
||||
try {
|
||||
const data = await api.getProjects();
|
||||
setProjects(data.projects || []);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
fetchProjects();
|
||||
}, [user]);
|
||||
|
||||
const handleDeleteProject = async (e: React.MouseEvent, id: string) => {
|
||||
e.stopPropagation(); // prevent navigating to editor
|
||||
if (!confirm('Are you sure you want to delete this project?')) return;
|
||||
try {
|
||||
await api.deleteProject(id);
|
||||
setProjects(projects.filter(p => p.id !== id));
|
||||
} catch (err) {
|
||||
console.error('Error deleting project:', err);
|
||||
alert('Failed to delete project');
|
||||
}
|
||||
};
|
||||
|
||||
const handleNewProject = async () => {
|
||||
const name = prompt('Enter a name for the new project:');
|
||||
if (!name || name.trim() === '') return;
|
||||
|
||||
try {
|
||||
const res = await api.saveProject({
|
||||
name: name.trim(),
|
||||
scene_data: {}
|
||||
});
|
||||
if (res.id) {
|
||||
navigate(`/editor/${res.id}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to create project', err);
|
||||
alert('Failed to create project');
|
||||
}
|
||||
};
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await signOut();
|
||||
navigate('/');
|
||||
};
|
||||
|
||||
const createNewProject = () => {
|
||||
navigate('/editor/new');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-zinc-950 text-white flex flex-col">
|
||||
<header className="h-16 border-b border-zinc-800 bg-zinc-900 flex items-center justify-between px-8">
|
||||
<div className="font-bold text-lg tracking-tight">Titan<span className="text-primary">3d</span> / Dashboard</div>
|
||||
<div className="flex items-center gap-4">
|
||||
{profile?.role === 'admin' && (
|
||||
<Link to="/admin" className="text-sm text-primary hover:underline font-medium">Admin Panel</Link>
|
||||
)}
|
||||
<div className="text-sm text-zinc-400">{user?.email}</div>
|
||||
<button
|
||||
onClick={handleSignOut}
|
||||
className="p-2 text-zinc-400 hover:text-white hover:bg-zinc-800 rounded-lg transition-colors"
|
||||
title="Sign Out"
|
||||
>
|
||||
<LogOut size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="flex-1 p-8 max-w-6xl mx-auto w-full">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
|
||||
<div className="bg-zinc-900 border border-zinc-800 rounded-2xl p-6">
|
||||
<h3 className="text-zinc-400 text-sm font-medium mb-2">AI Credits</h3>
|
||||
<div className="text-3xl font-bold text-white">{profile?.api_credits ?? 0}</div>
|
||||
</div>
|
||||
<div className="bg-zinc-900 border border-zinc-800 rounded-2xl p-6">
|
||||
<h3 className="text-zinc-400 text-sm font-medium mb-2">Storage Usage</h3>
|
||||
<div className="text-3xl font-bold text-white">0 / {profile?.storage_limit_mb ?? 100} MB</div>
|
||||
</div>
|
||||
<div className="bg-zinc-900 border border-zinc-800 rounded-2xl p-6">
|
||||
<h3 className="text-zinc-400 text-sm font-medium mb-2">Total Projects</h3>
|
||||
<div className="text-3xl font-bold text-white">{projects.length}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-2xl font-bold">Your Projects</h2>
|
||||
<button
|
||||
onClick={handleNewProject}
|
||||
className="flex items-center gap-2 bg-primary hover:bg-primary/90 text-white px-4 py-2 rounded-xl transition-colors font-medium text-sm"
|
||||
>
|
||||
<Plus size={16} /> New Project
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center p-12">
|
||||
<Loader2 size={32} className="animate-spin text-zinc-500" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||
<div className="aspect-video bg-zinc-900 border border-zinc-800 border-dashed rounded-2xl flex flex-col items-center justify-center text-zinc-500 hover:text-white hover:border-zinc-700 transition-colors cursor-pointer group" onClick={createNewProject}>
|
||||
<div className="w-10 h-10 rounded-full bg-zinc-800 group-hover:bg-zinc-700 flex items-center justify-center mb-2 transition-colors">
|
||||
<Plus size={20} />
|
||||
</div>
|
||||
<span className="text-sm font-medium">Create Blank Scene</span>
|
||||
</div>
|
||||
|
||||
{projects.map(project => (
|
||||
<div key={project.id} onClick={() => navigate(`/editor/${project.id}`)} className="aspect-video bg-zinc-900 border border-zinc-800 rounded-2xl p-4 flex flex-col cursor-pointer hover:border-zinc-700 transition-colors group relative overflow-hidden">
|
||||
<div className="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-transparent via-primary/50 to-transparent opacity-0 group-hover:opacity-100 transition-opacity" />
|
||||
<div className="flex-1 flex items-center justify-center">
|
||||
<Folder size={48} className="text-zinc-800 group-hover:text-zinc-700 transition-colors" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold text-white truncate">{project.name}</h3>
|
||||
<p className="text-xs text-zinc-500 mt-1">{new Date(project.created_at).toLocaleDateString()}</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={(e) => handleDeleteProject(e, project.id)}
|
||||
className="absolute top-4 right-4 p-2 text-zinc-500 hover:text-red-500 bg-zinc-900/80 rounded-lg opacity-0 group-hover:opacity-100 transition-all hover:bg-zinc-800"
|
||||
title="Delete Project"
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
import { Canvas } from '@react-three/fiber';
|
||||
import { ScrollControls } from '@react-three/drei';
|
||||
import { Scene } from '../components/home/Scene';
|
||||
import { Overlay } from '../components/home/Overlay';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="w-screen h-screen bg-zinc-950 overflow-hidden">
|
||||
<Canvas shadows camera={{ position: [0, 0, 10], fov: 45 }}>
|
||||
<Suspense fallback={null}>
|
||||
<ScrollControls pages={3} damping={0.2}>
|
||||
<Scene />
|
||||
<Overlay />
|
||||
</ScrollControls>
|
||||
</Suspense>
|
||||
</Canvas>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user