diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 6c17d2e..9cd921a 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -9,7 +9,8 @@ "mcp__appwrite-mcp-server__bucket_operations", "Bash(npm run build:*)", "mcp__appwrite-mcp-server__attribute_operations", - "mcp__appwrite-mcp-server__collection_operations" + "mcp__appwrite-mcp-server__collection_operations", + "mcp__appwrite-mcp-server__index_operations" ] } } diff --git a/src/App.jsx b/src/App.jsx index 91180ea..46bec92 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,12 +1,16 @@ -import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' +import { BrowserRouter, Routes, Route, Navigate, useParams } from 'react-router-dom' import { useState, useEffect } from 'react' -import { databases, DATABASE_ID, COLLECTIONS, getFilePreview } from './lib/appwrite' +import { databases, DATABASE_ID, COLLECTIONS, Query, getFilePreview } from './lib/appwrite' -// Pages +// Public Pages +import Landing from './pages/Landing' +import Signup from './pages/Signup' +import Login from './pages/Login' import Home from './pages/Home' import ComingSoon from './pages/ComingSoon' -import Setup from './pages/admin/Setup' -import Login from './pages/admin/Login' + +// Admin Pages +import AdminLogin from './pages/admin/Login' import Dashboard from './pages/admin/Dashboard' import Links from './pages/admin/Links' import Social from './pages/admin/Social' @@ -22,25 +26,22 @@ import AdminLayout from './components/AdminLayout' // Session timeout: 24 hours const SESSION_TIMEOUT = 24 * 60 * 60 * 1000 -function App() { - const [isSetupComplete, setIsSetupComplete] = useState(null) +// Component to handle slug-based profile pages +function ProfilePage() { + const { slug } = useParams() const [clientData, setClientData] = useState(null) const [loading, setLoading] = useState(true) - const [isAuthenticated, setIsAuthenticated] = useState(false) + const [notFound, setNotFound] = useState(false) useEffect(() => { - checkSetup() - checkAuth() - }, []) + loadClientBySlug() + }, [slug]) - // Update page title and favicon when client data changes useEffect(() => { if (clientData?.businessName) { document.title = clientData.businessName } - if (clientData?.logoFileId) { - // Update favicon const faviconUrl = getFilePreview(clientData.logoFileId, 64, 64) let link = document.querySelector("link[rel~='icon']") if (!link) { @@ -52,50 +53,26 @@ function App() { } }, [clientData]) - const checkAuth = () => { - const authState = sessionStorage.getItem('arklinks_auth') - const authTime = sessionStorage.getItem('arklinks_auth_time') - - if (authState === 'true' && authTime) { - const elapsed = Date.now() - parseInt(authTime) - if (elapsed < SESSION_TIMEOUT) { - setIsAuthenticated(true) - } else { - // Session expired - handleLogout() - } - } - } - - const checkSetup = async () => { + const loadClientBySlug = async () => { try { - // Check if client exists by looking for any client record - const response = await databases.listDocuments(DATABASE_ID, COLLECTIONS.CLIENTS) + const response = await databases.listDocuments( + DATABASE_ID, + COLLECTIONS.CLIENTS, + [Query.equal('slug', slug)] + ) if (response.documents.length > 0) { - const client = response.documents[0] - setClientData(client) - setIsSetupComplete(client.isSetupComplete) + setClientData(response.documents[0]) } else { - setIsSetupComplete(false) + setNotFound(true) } } catch (error) { - console.error('Setup check error:', error) - setIsSetupComplete(false) + console.error('Error loading client:', error) + setNotFound(true) } finally { setLoading(false) } } - const handleLogin = () => { - setIsAuthenticated(true) - } - - const handleLogout = () => { - sessionStorage.removeItem('arklinks_auth') - sessionStorage.removeItem('arklinks_auth_time') - setIsAuthenticated(false) - } - if (loading) { return (
Admin Panel
+/{slug}