firebase-os 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FirebaseOS.d.ts +15 -0
- package/dist/firebase-os.cjs.js +2 -17
- package/dist/firebase-os.es.js +63 -72
- package/dist/index.d.ts +3 -0
- package/dist/lib/ConfigContext.d.ts +12 -0
- package/package.json +3 -2
- package/scripts/postinstall.js +89 -10
- package/src/App.css +184 -0
- package/src/App.tsx +214 -0
- package/src/FirebaseOS.tsx +80 -0
- package/src/assets/hero.png +0 -0
- package/src/assets/react.svg +1 -0
- package/src/assets/vite.svg +1 -0
- package/src/components/AdminNotifications.test.tsx +98 -0
- package/src/components/AdminNotifications.tsx +194 -0
- package/src/components/Button.test.tsx +22 -0
- package/src/components/Button.tsx +53 -0
- package/src/components/ConfirmModal.test.tsx +98 -0
- package/src/components/ConfirmModal.tsx +73 -0
- package/src/components/ContactPopup.test.tsx +98 -0
- package/src/components/ContactPopup.tsx +437 -0
- package/src/components/CustomSelect.test.tsx +47 -0
- package/src/components/CustomSelect.tsx +89 -0
- package/src/components/DashboardNav.test.tsx +98 -0
- package/src/components/DashboardNav.tsx +281 -0
- package/src/components/Input.test.tsx +33 -0
- package/src/components/Input.tsx +61 -0
- package/src/components/JsonEditor.tsx +579 -0
- package/src/components/Navbar.test.tsx +98 -0
- package/src/components/Navbar.tsx +563 -0
- package/src/configs/forms/contactForm.config.ts +15 -0
- package/src/configs/forms/index.ts +29 -0
- package/src/configs/forms/pubForm.config.ts +11 -0
- package/src/configs/forms/supportForm.config.ts +14 -0
- package/src/configs/forms/userForm.config.ts +11 -0
- package/src/configs/pages/admin.config.ts +29 -0
- package/src/configs/pages/contact.config.ts +6 -0
- package/src/configs/pages/home.config.ts +18 -0
- package/src/configs/pages/mem.config.ts +2 -0
- package/src/configs/pages/menuOrders.config.ts +11 -0
- package/src/configs/pages/pub.config.ts +11 -0
- package/src/configs/pages/shared.config.ts +29 -0
- package/src/configs/pages/support.config.ts +7 -0
- package/src/configs/pages/tabOrders.config.ts +33 -0
- package/src/configs/pages/user.config.ts +29 -0
- package/src/configs/theme.config.ts +93 -0
- package/src/index.css +403 -0
- package/src/index.ts +22 -0
- package/src/lib/AuthContext.test.tsx +88 -0
- package/src/lib/AuthContext.tsx +191 -0
- package/src/lib/ConfigContext.tsx +45 -0
- package/src/lib/ThemeContext.tsx +227 -0
- package/src/lib/firebase.ts +91 -0
- package/src/main.tsx +22 -0
- package/src/microcomponents/AdminExampleContent.tsx +44 -0
- package/src/microcomponents/PrivateExampleContent.tsx +39 -0
- package/src/microcomponents/Public.tsx +126 -0
- package/src/microcomponents/SharedExampleContent.tsx +53 -0
- package/src/pages/Dashboard.test.tsx +98 -0
- package/src/pages/Dashboard.tsx +60 -0
- package/src/pages/DynamicPage.tsx +237 -0
- package/src/pages/FormsAdmin.test.tsx +98 -0
- package/src/pages/FormsAdmin.tsx +459 -0
- package/src/pages/Home.test.tsx +98 -0
- package/src/pages/Home.tsx +144 -0
- package/src/pages/Login.test.tsx +98 -0
- package/src/pages/Login.tsx +108 -0
- package/src/pages/PagesAdmin.test.tsx +98 -0
- package/src/pages/PagesAdmin.tsx +1022 -0
- package/src/pages/Profile.test.tsx +98 -0
- package/src/pages/Profile.tsx +319 -0
- package/src/pages/Register.test.tsx +98 -0
- package/src/pages/Register.tsx +116 -0
- package/src/pages/Requests.test.tsx +95 -0
- package/src/pages/Requests.tsx +422 -0
- package/src/pages/ResetPassword.test.tsx +98 -0
- package/src/pages/ResetPassword.tsx +92 -0
- package/src/pages/Settings.test.tsx +98 -0
- package/src/pages/Settings.tsx +393 -0
- package/src/pages/Setup.tsx +401 -0
- package/src/pages/StorageAdmin.test.tsx +150 -0
- package/src/pages/StorageAdmin.tsx +769 -0
- package/src/pages/Submissions.test.tsx +95 -0
- package/src/pages/Submissions.tsx +372 -0
- package/src/pages/Templates.test.tsx +98 -0
- package/src/pages/Templates.tsx +103 -0
- package/src/pages/ThemeAdmin.test.tsx +144 -0
- package/src/pages/ThemeAdmin.tsx +1000 -0
- package/src/pages/Users.test.tsx +95 -0
- package/src/pages/Users.tsx +334 -0
- package/src/pages/Verify.test.tsx +98 -0
- package/src/pages/Verify.tsx +95 -0
- package/src/prompts/index.ts +13 -0
- package/src/prompts/pages/publicPage.ts +44 -0
- package/src/prompts/sharedConstants.ts +12 -0
- package/src/prompts/tabs/board/adminboard.ts +32 -0
- package/src/prompts/tabs/board/privateboard.ts +36 -0
- package/src/prompts/tabs/board/publicboard.ts +36 -0
- package/src/prompts/tabs/calendar/admincalendar.ts +32 -0
- package/src/prompts/tabs/calendar/privatecalendar.ts +36 -0
- package/src/prompts/tabs/calendar/publiccalendar.ts +36 -0
- package/src/prompts/tabs/crud/admin.ts +54 -0
- package/src/prompts/tabs/crud/private.ts +55 -0
- package/src/prompts/tabs/crud/shared.ts +53 -0
- package/src/prompts/tabs/table/admintable.ts +32 -0
- package/src/prompts/tabs/table/privatetable.ts +36 -0
- package/src/prompts/tabs/table/publictable.ts +36 -0
- package/src/setupTests.ts +1 -0
- package/src/templates/AdminPageTemplate.tsx +678 -0
- package/src/templates/PrivatePageTemplate.tsx +594 -0
- package/src/templates/PublicPageTemplate.tsx +92 -0
- package/src/templates/SharedPageTemplate.tsx +551 -0
- package/src/templates/TemplateBoard.test.tsx +106 -0
- package/src/templates/TemplateBoard.tsx +642 -0
- package/src/templates/TemplateCalendar.test.tsx +106 -0
- package/src/templates/TemplateCalendar.tsx +848 -0
- package/src/templates/TemplateConfirmation.test.tsx +106 -0
- package/src/templates/TemplateConfirmation.tsx +145 -0
- package/src/templates/TemplateInlineForm.test.tsx +106 -0
- package/src/templates/TemplateInlineForm.tsx +129 -0
- package/src/templates/TemplatePopupForm.test.tsx +106 -0
- package/src/templates/TemplatePopupForm.tsx +174 -0
- package/src/templates/TemplateTable.test.tsx +106 -0
- package/src/templates/TemplateTable.tsx +675 -0
package/src/App.tsx
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { BrowserRouter, Routes, Route, Navigate, useLocation, useSearchParams } from 'react-router-dom';
|
|
2
|
+
import { AuthProvider, useAuth } from './lib/AuthContext';
|
|
3
|
+
import { Navbar } from './components/Navbar';
|
|
4
|
+
import { Home } from './pages/Home';
|
|
5
|
+
import { Register } from './pages/Register';
|
|
6
|
+
import { Login } from './pages/Login';
|
|
7
|
+
import { Verify } from './pages/Verify';
|
|
8
|
+
import { Profile } from './pages/Profile';
|
|
9
|
+
import { ResetPassword } from './pages/ResetPassword';
|
|
10
|
+
import { UsersTab as Users } from './pages/Users';
|
|
11
|
+
import { SettingsTab as Settings } from './pages/Settings';
|
|
12
|
+
import { Submissions } from './pages/Submissions';
|
|
13
|
+
import { Requests } from './pages/Requests';
|
|
14
|
+
import { StorageAdmin } from './pages/StorageAdmin';
|
|
15
|
+
import { Templates } from './pages/Templates';
|
|
16
|
+
import { TemplateInlineForm } from './templates/TemplateInlineForm';
|
|
17
|
+
import { TemplatePopupForm } from './templates/TemplatePopupForm';
|
|
18
|
+
import { TemplateConfirmation } from './templates/TemplateConfirmation';
|
|
19
|
+
import { TemplateBoard } from './templates/TemplateBoard';
|
|
20
|
+
import { TemplateTable } from './templates/TemplateTable';
|
|
21
|
+
import { TemplateCalendar } from './templates/TemplateCalendar';
|
|
22
|
+
import { ThemeAdmin } from './pages/ThemeAdmin';
|
|
23
|
+
import { PagesAdmin } from './pages/PagesAdmin';
|
|
24
|
+
import { FormsAdmin } from './pages/FormsAdmin';
|
|
25
|
+
import { DynamicPage } from './pages/DynamicPage';
|
|
26
|
+
import { Setup, isSetupComplete } from './pages/Setup';
|
|
27
|
+
import { motion } from 'framer-motion';
|
|
28
|
+
import { Database } from 'lucide-react';
|
|
29
|
+
import { Dashboard } from './pages/Dashboard';
|
|
30
|
+
import { useConfig } from './lib/ConfigContext';
|
|
31
|
+
|
|
32
|
+
const PageLoader = () => (
|
|
33
|
+
<div className="flex-1 flex flex-col items-center justify-center min-h-[60vh] z-10 animate-in fade-in duration-500">
|
|
34
|
+
<div className="w-12 h-12 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mb-6 shadow-xl">
|
|
35
|
+
<Database className="w-6 h-6 text-accent animate-pulse" />
|
|
36
|
+
</div>
|
|
37
|
+
<div className="flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]">
|
|
38
|
+
<div className="w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin" />
|
|
39
|
+
<span className="text-[13px] font-bold tracking-widest uppercase text-foreground/70">Connecting</span>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
function PrivateRoute({ children }: { children: React.ReactNode }) {
|
|
45
|
+
const { user, loading, userInactive, signOut, roleResolved } = useAuth();
|
|
46
|
+
const location = useLocation();
|
|
47
|
+
if (loading || !roleResolved) return <PageLoader />;
|
|
48
|
+
if (!user) return <Navigate to={`/login?from=${encodeURIComponent(location.pathname)}`} />;
|
|
49
|
+
if (userInactive) {
|
|
50
|
+
return (
|
|
51
|
+
<div className="flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500">
|
|
52
|
+
<div className="glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden">
|
|
53
|
+
<div className="absolute inset-0 bg-red-500/5" />
|
|
54
|
+
<h2 className="text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight">Access Denied</h2>
|
|
55
|
+
<p className="text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6">You don't have access to this app. Please contact the administrator.</p>
|
|
56
|
+
<button onClick={() => signOut()} className="w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors">Sign Out</button>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (!user.emailVerified) return <Navigate to="/verify" />;
|
|
62
|
+
return <>{children}</>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function PublicRoute({ children }: { children: React.ReactNode }) {
|
|
66
|
+
const { user, loading, roleResolved } = useAuth();
|
|
67
|
+
const [searchParams] = useSearchParams();
|
|
68
|
+
if (loading || !roleResolved) return <PageLoader />;
|
|
69
|
+
if (user && user.emailVerified) {
|
|
70
|
+
const from = searchParams.get('from') || '/dashboard';
|
|
71
|
+
return <Navigate to={from} replace />;
|
|
72
|
+
}
|
|
73
|
+
return <>{children}</>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function VerifyRoute({ children }: { children: React.ReactNode }) {
|
|
77
|
+
const { user, loading, roleResolved } = useAuth();
|
|
78
|
+
if (loading || !roleResolved) return <PageLoader />;
|
|
79
|
+
if (!user) return <Navigate to="/" />;
|
|
80
|
+
if (user.emailVerified) return <Navigate to="/dashboard" />;
|
|
81
|
+
return <>{children}</>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function AdminRoute({ children }: { children: React.ReactNode }) {
|
|
85
|
+
const { user, userRole, loading, userInactive, signOut, roleResolved } = useAuth();
|
|
86
|
+
const location = useLocation();
|
|
87
|
+
if (loading || !roleResolved) return <PageLoader />;
|
|
88
|
+
if (!user) return <Navigate to={`/login?from=${encodeURIComponent(location.pathname)}`} />;
|
|
89
|
+
if (userInactive) {
|
|
90
|
+
return (
|
|
91
|
+
<div className="flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500">
|
|
92
|
+
<div className="glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden">
|
|
93
|
+
<div className="absolute inset-0 bg-red-500/5" />
|
|
94
|
+
<h2 className="text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight">Access Denied</h2>
|
|
95
|
+
<p className="text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6">You don't have access to this app. Please contact the administrator.</p>
|
|
96
|
+
<button onClick={() => signOut()} className="w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors">Sign Out</button>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (!user.emailVerified) return <Navigate to="/verify" />;
|
|
102
|
+
if (userRole !== 'admin') return <Navigate to="/dashboard" />;
|
|
103
|
+
return <>{children}</>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── Background decoration (shared between setup and main app) ──
|
|
107
|
+
function BgDecor() {
|
|
108
|
+
return (
|
|
109
|
+
<div className="fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden">
|
|
110
|
+
<motion.div
|
|
111
|
+
animate={{ scale: [1, 1.1, 1], opacity: [0.6, 1, 0.6] }}
|
|
112
|
+
transition={{ duration: 12, repeat: Infinity, ease: "easeInOut" }}
|
|
113
|
+
className="absolute -top-[30%] md:-top-[400px] -right-[10%] md:-right-[200px] w-[500px] md:w-[800px] h-[500px] md:h-[800px] rounded-full bg-decorator-1 blur-[80px] md:blur-[120px]"
|
|
114
|
+
/>
|
|
115
|
+
<motion.div
|
|
116
|
+
animate={{ scale: [1, 1.2, 1], opacity: [0.5, 0.9, 0.5] }}
|
|
117
|
+
transition={{ duration: 18, repeat: Infinity, ease: "easeInOut", delay: 2 }}
|
|
118
|
+
className="absolute -bottom-[20%] md:-bottom-[300px] -left-[10%] md:-left-[100px] w-[400px] md:w-[600px] h-[400px] md:h-[600px] rounded-full bg-decorator-2 blur-[60px] md:blur-[100px]"
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ── The authenticated app with Navbar + routes ──
|
|
125
|
+
function AuthenticatedApp() {
|
|
126
|
+
const config = useConfig();
|
|
127
|
+
const HomeComponent = config.components?.Home || Home;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<AuthProvider>
|
|
131
|
+
<div className="min-h-screen relative flex flex-col overflow-x-hidden">
|
|
132
|
+
<Navbar />
|
|
133
|
+
|
|
134
|
+
<Routes>
|
|
135
|
+
<Route path="/" element={<PublicRoute><HomeComponent /></PublicRoute>} />
|
|
136
|
+
<Route path="/register" element={<PublicRoute><Register /></PublicRoute>} />
|
|
137
|
+
<Route path="/login" element={<PublicRoute><Login /></PublicRoute>} />
|
|
138
|
+
<Route path="/reset-password" element={<PublicRoute><ResetPassword /></PublicRoute>} />
|
|
139
|
+
|
|
140
|
+
<Route path="/verify" element={<VerifyRoute><Verify /></VerifyRoute>} />
|
|
141
|
+
|
|
142
|
+
{/* Templates */}
|
|
143
|
+
<Route path="/templates" element={<Templates />} />
|
|
144
|
+
<Route path="/templates/inline_form" element={<TemplateInlineForm />} />
|
|
145
|
+
<Route path="/templates/popup_form" element={<TemplatePopupForm />} />
|
|
146
|
+
<Route path="/templates/confirmation" element={<TemplateConfirmation />} />
|
|
147
|
+
<Route path="/templates/board" element={<TemplateBoard />} />
|
|
148
|
+
<Route path="/templates/table" element={<TemplateTable />} />
|
|
149
|
+
<Route path="/templates/calendar" element={<TemplateCalendar />} />
|
|
150
|
+
|
|
151
|
+
<Route path="/users" element={<AdminRoute><Users /></AdminRoute>} />
|
|
152
|
+
<Route path="/users/:id" element={<AdminRoute><Users /></AdminRoute>} />
|
|
153
|
+
<Route path="/submissions" element={<AdminRoute><Submissions /></AdminRoute>} />
|
|
154
|
+
<Route path="/requests" element={<AdminRoute><Requests /></AdminRoute>} />
|
|
155
|
+
<Route path="/drive/*" element={<PrivateRoute><StorageAdmin /></PrivateRoute>} />
|
|
156
|
+
<Route path="/theme" element={<AdminRoute><ThemeAdmin /></AdminRoute>} />
|
|
157
|
+
<Route path="/pages/*" element={<AdminRoute><PagesAdmin /></AdminRoute>} />
|
|
158
|
+
<Route path="/forms/*" element={<AdminRoute><FormsAdmin /></AdminRoute>} />
|
|
159
|
+
<Route path="/settings" element={<AdminRoute><Settings /></AdminRoute>} />
|
|
160
|
+
<Route path="/profile" element={<PrivateRoute><Profile /></PrivateRoute>} />
|
|
161
|
+
<Route path="/dashboard" element={<PrivateRoute><Dashboard /></PrivateRoute>} />
|
|
162
|
+
|
|
163
|
+
{/* Setup (accessible even after completion for reference) */}
|
|
164
|
+
<Route path="/setup" element={<Setup />} />
|
|
165
|
+
|
|
166
|
+
{/* Dynamic Content Routing */}
|
|
167
|
+
<Route path="*" element={<DynamicPage />} />
|
|
168
|
+
</Routes>
|
|
169
|
+
|
|
170
|
+
<BgDecor />
|
|
171
|
+
</div>
|
|
172
|
+
</AuthProvider>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function App() {
|
|
177
|
+
// If setup is not complete AND user is NOT on /setup, redirect to /setup.
|
|
178
|
+
// The Setup page itself is rendered outside AuthProvider to avoid Firebase init errors.
|
|
179
|
+
return (
|
|
180
|
+
<BrowserRouter>
|
|
181
|
+
<SetupGate />
|
|
182
|
+
</BrowserRouter>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function SetupGate() {
|
|
187
|
+
const config = useConfig();
|
|
188
|
+
|
|
189
|
+
// If firebaseConfig was passed as props (library mode), check if it has real values
|
|
190
|
+
const hasPropsConfig = config.firebaseConfig &&
|
|
191
|
+
config.firebaseConfig.apiKey &&
|
|
192
|
+
config.firebaseConfig.apiKey.trim() !== '' &&
|
|
193
|
+
config.firebaseConfig.projectId &&
|
|
194
|
+
config.firebaseConfig.projectId.trim() !== '';
|
|
195
|
+
|
|
196
|
+
// Props config takes priority; otherwise fall back to env var check
|
|
197
|
+
const setupDone = hasPropsConfig || isSetupComplete();
|
|
198
|
+
|
|
199
|
+
// If setup not complete, always show Setup regardless of current URL
|
|
200
|
+
if (!setupDone) {
|
|
201
|
+
return (
|
|
202
|
+
<div className="min-h-screen relative flex flex-col overflow-x-hidden">
|
|
203
|
+
<Navbar standalone={true} />
|
|
204
|
+
<Setup standalone />
|
|
205
|
+
<BgDecor />
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Setup is complete — render the full app (which includes /setup route for reference)
|
|
211
|
+
return <AuthenticatedApp />;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export default App;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ThemeProvider } from './lib/ThemeContext';
|
|
3
|
+
import { ConfigProvider, type FirebaseOSConfig } from './lib/ConfigContext';
|
|
4
|
+
import { initializeFirebase } from './lib/firebase';
|
|
5
|
+
import App from './App';
|
|
6
|
+
|
|
7
|
+
// ── Import CSS so Tailwind utilities are bundled into the library ──
|
|
8
|
+
import './index.css';
|
|
9
|
+
|
|
10
|
+
// ── Public Props API ─────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
export interface FirebaseOSProps {
|
|
13
|
+
/** Skip the setup wizard — pass Firebase config directly */
|
|
14
|
+
firebaseConfig?: {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
authDomain: string;
|
|
17
|
+
projectId: string;
|
|
18
|
+
storageBucket: string;
|
|
19
|
+
messagingSenderId: string;
|
|
20
|
+
appId: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Admin email addresses (replaces VITE_ADMIN_EMAILS env var) */
|
|
24
|
+
adminEmails?: string[];
|
|
25
|
+
|
|
26
|
+
/** Custom basename for the router (e.g., "/app") */
|
|
27
|
+
basename?: string;
|
|
28
|
+
|
|
29
|
+
/** Called when auth state changes */
|
|
30
|
+
onAuthChange?: (user: any) => void;
|
|
31
|
+
|
|
32
|
+
/** Override the theme configuration */
|
|
33
|
+
themeConfig?: any;
|
|
34
|
+
|
|
35
|
+
/** Component overrides for the hybrid template architecture */
|
|
36
|
+
components?: {
|
|
37
|
+
Home?: React.ComponentType<any>;
|
|
38
|
+
TemplateBoard?: React.ComponentType<any>;
|
|
39
|
+
TemplateTable?: React.ComponentType<any>;
|
|
40
|
+
TemplateCalendar?: React.ComponentType<any>;
|
|
41
|
+
TemplatePopupForm?: React.ComponentType<any>;
|
|
42
|
+
TemplateInlineForm?: React.ComponentType<any>;
|
|
43
|
+
TemplatePages?: React.ComponentType<any>;
|
|
44
|
+
TemplateStorage?: React.ComponentType<any>;
|
|
45
|
+
TemplateNone?: React.ComponentType<any>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ── The Library Component ────────────────────────────────────────────────
|
|
50
|
+
// This is the single public export. It wraps the entire OS in providers
|
|
51
|
+
// and handles Firebase initialization from props when available.
|
|
52
|
+
|
|
53
|
+
export function FirebaseOS(props: FirebaseOSProps) {
|
|
54
|
+
// If the consumer passed firebaseConfig as props, initialize Firebase
|
|
55
|
+
// before any child component tries to use auth/db/storage.
|
|
56
|
+
if (props.firebaseConfig) {
|
|
57
|
+
initializeFirebase(props.firebaseConfig);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const config: FirebaseOSConfig = {
|
|
61
|
+
firebaseConfig: props.firebaseConfig,
|
|
62
|
+
adminEmails: props.adminEmails,
|
|
63
|
+
basename: props.basename,
|
|
64
|
+
onAuthChange: props.onAuthChange,
|
|
65
|
+
themeConfig: props.themeConfig,
|
|
66
|
+
components: props.components,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<ConfigProvider config={config}>
|
|
71
|
+
<ThemeProvider scopeSelector=".firebase-os">
|
|
72
|
+
<div
|
|
73
|
+
className="firebase-os flex-1 flex flex-col min-h-screen"
|
|
74
|
+
>
|
|
75
|
+
<App />
|
|
76
|
+
</div>
|
|
77
|
+
</ThemeProvider>
|
|
78
|
+
</ConfigProvider>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="77" height="47" fill="none" aria-labelledby="vite-logo-title" viewBox="0 0 77 47"><title id="vite-logo-title">Vite</title><style>.parenthesis{fill:#000}@media (prefers-color-scheme:dark){.parenthesis{fill:#fff}}</style><path fill="#9135ff" d="M40.151 45.71c-.663.844-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.493c-.92 0-1.457-1.04-.92-1.788l7.479-10.471c1.07-1.498 0-3.578-1.842-3.578H15.443c-.92 0-1.456-1.04-.92-1.788l9.696-13.576c.213-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.472c-1.07 1.497 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.087.89 1.83L40.153 45.712z"/><mask id="a" width="48" height="47" x="14" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M40.047 45.71c-.663.843-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.389c-.92 0-1.457-1.04-.92-1.788l7.479-10.472c1.07-1.497 0-3.578-1.842-3.578H15.34c-.92 0-1.456-1.04-.92-1.788l9.696-13.575c.213-.297.556-.474.92-.474H53.93c.92 0 1.456 1.04.92 1.788L47.37 13.03c-1.07 1.498 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.088.89 1.831L40.049 45.712z"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#eee6ff" rx="5.508" ry="14.704" transform="rotate(269.814 20.96 11.29)scale(-1 1)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#eee6ff" rx="10.399" ry="29.851" transform="rotate(89.814 -16.902 -8.275)scale(1 -1)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#8900ff" rx="5.508" ry="30.487" transform="rotate(89.814 -19.197 -7.127)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.928 4.177)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.738 5.52)scale(1 -1)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#eee6ff" rx="14.072" ry="22.078" transform="rotate(93.35 31.245 55.578)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx="14.592" cy="9.743" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(39.51 14.592 9.743)"/></g><g filter="url(#k)"><ellipse cx="61.728" cy="-5.321" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 61.728 -5.32)"/></g><g filter="url(#l)"><ellipse cx="55.618" cy="7.104" fill="#00c2ff" rx="5.971" ry="9.665" transform="rotate(37.892 55.618 7.104)"/></g><g filter="url(#m)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#n)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#o)"><ellipse cx="49.857" cy="30.678" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 49.857 30.678)"/></g><g filter="url(#p)"><ellipse cx="52.623" cy="33.171" fill="#00c2ff" rx="5.971" ry="15.297" transform="rotate(37.892 52.623 33.17)"/></g></g><path d="M6.919 0c-9.198 13.166-9.252 33.575 0 46.789h6.215c-9.25-13.214-9.196-33.623 0-46.789zm62.424 0h-6.215c9.198 13.166 9.252 33.575 0 46.789h6.215c9.25-13.214 9.196-33.623 0-46.789" class="parenthesis"/><defs><filter id="b" width="60.045" height="41.654" x="-5.564" y="16.92" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-40.407" y="-6.762" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="d" width="79.355" height="29.4" x="-35.435" y="2.801" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="e" width="79.579" height="29.4" x="-30.84" y="20.8" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="f" width="79.579" height="29.4" x="-29.307" y="21.949" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="g" width="74.749" height="58.852" x="29.961" y="-17.13" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="h" width="61.377" height="25.362" x="37.754" y="3.055" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="i" width="61.377" height="25.362" x="37.754" y="3.055" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="j" width="56.045" height="63.649" x="-13.43" y="-22.082" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="k" width="54.814" height="64.646" x="34.321" y="-37.644" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="l" width="33.541" height="35.313" x="38.847" y="-10.552" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="m" width="54.814" height="64.646" x="-15.081" y="6.78" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="n" width="54.814" height="64.646" x="-15.081" y="6.78" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="o" width="54.814" height="64.646" x="22.45" y="-1.645" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="p" width="39.409" height="43.623" x="32.919" y="11.36" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter></defs></svg>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// @generated-test
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
|
+
import { render, screen, act } from '@testing-library/react';
|
|
4
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
5
|
+
import { AuthProvider } from '../lib/AuthContext';
|
|
6
|
+
import { ThemeProvider } from '../lib/ThemeContext';
|
|
7
|
+
import { AdminNotifications } from './AdminNotifications';
|
|
8
|
+
|
|
9
|
+
// Global mocks
|
|
10
|
+
Object.defineProperty(window, 'matchMedia', {
|
|
11
|
+
writable: true,
|
|
12
|
+
value: vi.fn().mockImplementation(query => ({
|
|
13
|
+
matches: false,
|
|
14
|
+
media: query,
|
|
15
|
+
onchange: null,
|
|
16
|
+
addListener: vi.fn(),
|
|
17
|
+
removeListener: vi.fn(),
|
|
18
|
+
addEventListener: vi.fn(),
|
|
19
|
+
removeEventListener: vi.fn(),
|
|
20
|
+
dispatchEvent: vi.fn(),
|
|
21
|
+
})),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
vi.mock('../lib/AuthContext', () => ({
|
|
25
|
+
AuthProvider: ({ children }: any) => <>{children}</>,
|
|
26
|
+
useAuth: () => ({
|
|
27
|
+
user: { uid: 'mock-user-123', email: 'test@example.com' },
|
|
28
|
+
userWorkspaces: [],
|
|
29
|
+
activeWorkspace: null,
|
|
30
|
+
activeOrg: null,
|
|
31
|
+
loading: false
|
|
32
|
+
})
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
vi.mock('../lib/ThemeContext', () => ({
|
|
36
|
+
ThemeProvider: ({ children }: any) => <>{children}</>,
|
|
37
|
+
useTheme: () => ({ themeMode: 'light', setThemeMode: vi.fn(), activeConfig: {} })
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
vi.mock('firebase/auth', () => ({
|
|
41
|
+
getAuth: vi.fn(() => ({})),
|
|
42
|
+
onAuthStateChanged: vi.fn((auth, cb) => { cb({ uid: 'mock-user-123', email: 'test@example.com', getIdToken: vi.fn(() => Promise.resolve('mock-token')) }); return () => {}; })
|
|
43
|
+
}));
|
|
44
|
+
vi.mock('firebase/firestore', () => ({
|
|
45
|
+
getFirestore: vi.fn(() => ({})),
|
|
46
|
+
collection: vi.fn(),
|
|
47
|
+
doc: vi.fn(),
|
|
48
|
+
setDoc: vi.fn(() => Promise.resolve()),
|
|
49
|
+
addDoc: vi.fn(() => Promise.resolve()),
|
|
50
|
+
updateDoc: vi.fn(() => Promise.resolve()),
|
|
51
|
+
deleteDoc: vi.fn(() => Promise.resolve()),
|
|
52
|
+
query: vi.fn(),
|
|
53
|
+
where: vi.fn(),
|
|
54
|
+
orderBy: vi.fn(),
|
|
55
|
+
limit: vi.fn(),
|
|
56
|
+
getDoc: vi.fn(() => Promise.resolve({ exists: () => true, data: () => ({ role: 'super_admin' }) })),
|
|
57
|
+
getDocs: vi.fn(() => Promise.resolve({ docs: [], forEach: vi.fn() })),
|
|
58
|
+
onSnapshot: vi.fn((...args: any[]) => {
|
|
59
|
+
let cb = args[1];
|
|
60
|
+
if (typeof args[2] === 'function') {
|
|
61
|
+
cb = args[2];
|
|
62
|
+
}
|
|
63
|
+
if (typeof cb === 'function') {
|
|
64
|
+
cb({docs: [], forEach: vi.fn(), data: () => ({}), exists: () => true});
|
|
65
|
+
}
|
|
66
|
+
return () => {};
|
|
67
|
+
})
|
|
68
|
+
}));
|
|
69
|
+
vi.mock('firebase/storage', () => ({
|
|
70
|
+
getStorage: vi.fn(() => ({})),
|
|
71
|
+
ref: vi.fn(),
|
|
72
|
+
listAll: vi.fn(() => Promise.resolve({ items: [], prefixes: [] })),
|
|
73
|
+
getDownloadURL: vi.fn(() => Promise.resolve('mock-url')),
|
|
74
|
+
getMetadata: vi.fn(() => Promise.resolve({ size: 1024, timeCreated: new Date().toISOString() }))
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
describe('AdminNotifications Component', () => {
|
|
78
|
+
it('renders without crashing', async () => {
|
|
79
|
+
// Wrap in standard application providers inside act to process async side effects and prevent warnings
|
|
80
|
+
await act(async () => {
|
|
81
|
+
render(
|
|
82
|
+
<BrowserRouter>
|
|
83
|
+
<AuthProvider>
|
|
84
|
+
<ThemeProvider>
|
|
85
|
+
{/* @ts-ignore */}
|
|
86
|
+
<AdminNotifications />
|
|
87
|
+
</ThemeProvider>
|
|
88
|
+
</AuthProvider>
|
|
89
|
+
</BrowserRouter>
|
|
90
|
+
);
|
|
91
|
+
// Wait a tick to flush background state updates
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Check if the document has anything rendered without throwing
|
|
96
|
+
expect(document.body).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { Bell, User, Mail, HelpCircle } from 'lucide-react';
|
|
3
|
+
import { motion, AnimatePresence } from 'framer-motion';
|
|
4
|
+
import { db } from '../lib/firebase';
|
|
5
|
+
import { collection, query, orderBy, limit, onSnapshot } from 'firebase/firestore';
|
|
6
|
+
import { useNavigate } from 'react-router-dom';
|
|
7
|
+
|
|
8
|
+
interface NotificationItem {
|
|
9
|
+
id: string;
|
|
10
|
+
type: 'user' | 'submission' | 'request';
|
|
11
|
+
title: string;
|
|
12
|
+
subtitle: string;
|
|
13
|
+
time: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function AdminNotifications() {
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const [notifications, setNotifications] = useState<NotificationItem[]>([]);
|
|
19
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
20
|
+
const navigate = useNavigate();
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
function handleClickOutside(event: MouseEvent) {
|
|
24
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
|
25
|
+
setOpen(false);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
29
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
// Use a ref to combine data reliably on client side
|
|
33
|
+
const dataRef = useRef({ users: [] as NotificationItem[], submissions: [] as NotificationItem[], requests: [] as NotificationItem[] });
|
|
34
|
+
|
|
35
|
+
const updateNotifications = (type: 'users' | 'submissions' | 'requests', data: NotificationItem[]) => {
|
|
36
|
+
dataRef.current[type] = data;
|
|
37
|
+
const combined = [...dataRef.current.users, ...dataRef.current.submissions, ...dataRef.current.requests];
|
|
38
|
+
combined.sort((a, b) => {
|
|
39
|
+
const tA = a.time?.toDate ? a.time.toDate().getTime() : new Date(a.time).getTime();
|
|
40
|
+
const tB = b.time?.toDate ? b.time.toDate().getTime() : new Date(b.time).getTime();
|
|
41
|
+
return (tB || 0) - (tA || 0);
|
|
42
|
+
});
|
|
43
|
+
setNotifications(combined.slice(0, 8)); // keep top 8
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
// Listen to recent users
|
|
48
|
+
const usersQ = query(collection(db, 'user_profiles'), orderBy('createdAt', 'desc'), limit(5));
|
|
49
|
+
const unsubUsers = onSnapshot(usersQ, (snap) => {
|
|
50
|
+
const usersData = snap.docs.map(doc => {
|
|
51
|
+
const data = doc.data();
|
|
52
|
+
return {
|
|
53
|
+
id: `u_${doc.id}`,
|
|
54
|
+
type: 'user' as const,
|
|
55
|
+
title: 'New user registered',
|
|
56
|
+
subtitle: data.email || 'Unknown',
|
|
57
|
+
time: data.createdAt
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
updateNotifications('users', usersData);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Listen to recent submissions
|
|
64
|
+
const subsQ = query(collection(db, 'user_submissions'), orderBy('submittedAt', 'desc'), limit(5));
|
|
65
|
+
const unsubSubs = onSnapshot(subsQ, (snap) => {
|
|
66
|
+
const subsData = snap.docs.map(doc => {
|
|
67
|
+
const data = doc.data();
|
|
68
|
+
return {
|
|
69
|
+
id: `s_${doc.id}`,
|
|
70
|
+
type: 'submission' as const,
|
|
71
|
+
title: 'New form submission',
|
|
72
|
+
subtitle: data.name || data.email || 'Anonymous',
|
|
73
|
+
time: data.submittedAt
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
updateNotifications('submissions', subsData);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Listen to recent user requests
|
|
80
|
+
const reqQ = query(collection(db, 'user_requests'), orderBy('submittedAt', 'desc'), limit(5));
|
|
81
|
+
const unsubReq = onSnapshot(reqQ, (snap) => {
|
|
82
|
+
const reqData = snap.docs.map(doc => {
|
|
83
|
+
const data = doc.data();
|
|
84
|
+
return {
|
|
85
|
+
id: `r_${doc.id}`,
|
|
86
|
+
type: 'request' as const,
|
|
87
|
+
title: 'New support request',
|
|
88
|
+
subtitle: data.name || data.submitterName || data.contactEmail || data.email || 'Anonymous',
|
|
89
|
+
time: data.submittedAt
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
updateNotifications('requests', reqData);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return () => {
|
|
96
|
+
unsubUsers();
|
|
97
|
+
unsubSubs();
|
|
98
|
+
unsubReq();
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
const [lastReadTime, setLastReadTime] = useState(() => {
|
|
105
|
+
if (typeof window !== 'undefined') {
|
|
106
|
+
return parseInt(localStorage.getItem('admin_notifications_last_read') || '0', 10);
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const handleToggleOpen = () => {
|
|
112
|
+
const nextState = !open;
|
|
113
|
+
setOpen(nextState);
|
|
114
|
+
if (nextState) {
|
|
115
|
+
const now = Date.now();
|
|
116
|
+
setLastReadTime(now);
|
|
117
|
+
if (typeof window !== 'undefined') {
|
|
118
|
+
localStorage.setItem('admin_notifications_last_read', now.toString());
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const hasUnread = notifications.some(n => {
|
|
124
|
+
if (!n.time) return true;
|
|
125
|
+
const t = n.time?.toDate ? n.time.toDate().getTime() : new Date(n.time).getTime();
|
|
126
|
+
return t > lastReadTime || isNaN(t);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const handleNavigate = (type: 'user' | 'submission' | 'request') => {
|
|
130
|
+
setOpen(false);
|
|
131
|
+
if (type === 'user') navigate('/users');
|
|
132
|
+
else if (type === 'submission') navigate('/submissions');
|
|
133
|
+
else navigate('/requests');
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const formatTime = (ts: any) => {
|
|
137
|
+
if (!ts) return '';
|
|
138
|
+
const date = ts.toDate ? ts.toDate() : new Date(ts);
|
|
139
|
+
return new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }).format(date);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<div className="relative z-50 flex-shrink-0 mr-1 md:mr-2" ref={dropdownRef}>
|
|
144
|
+
<button
|
|
145
|
+
onClick={handleToggleOpen}
|
|
146
|
+
className="p-2 rounded-xl glass-panel transition-all border border-transparent relative text-notification-icon hover:bg-foreground/5 hover:border-[var(--panel-border)]"
|
|
147
|
+
aria-label="Admin Notifications"
|
|
148
|
+
>
|
|
149
|
+
<Bell className="w-4 h-4 md:w-5 md:h-5" />
|
|
150
|
+
{hasUnread && (
|
|
151
|
+
<span className="absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full animate-pulse" />
|
|
152
|
+
)}
|
|
153
|
+
</button>
|
|
154
|
+
|
|
155
|
+
<AnimatePresence>
|
|
156
|
+
{open && (
|
|
157
|
+
<motion.div
|
|
158
|
+
initial={{ opacity: 0, y: -5, scale: 0.98 }}
|
|
159
|
+
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
160
|
+
exit={{ opacity: 0, scale: 0.98, y: -5 }}
|
|
161
|
+
className="absolute top-full mt-2 right-[-60px] md:right-0 w-[320px] md:w-[400px] glass-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col origin-top-right overflow-hidden bg-[var(--panel-bg)]"
|
|
162
|
+
>
|
|
163
|
+
<div className="px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between">
|
|
164
|
+
<span className="font-bold text-[14px] text-foreground tracking-wide">Notifications</span>
|
|
165
|
+
<span className="text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md">Admin</span>
|
|
166
|
+
</div>
|
|
167
|
+
<div className="max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1">
|
|
168
|
+
{notifications.length === 0 ? (
|
|
169
|
+
<div className="p-6 text-center text-foreground/40 text-[13px] font-medium">No recent activity.</div>
|
|
170
|
+
) : (
|
|
171
|
+
notifications.map((n) => (
|
|
172
|
+
<button
|
|
173
|
+
key={n.id}
|
|
174
|
+
onClick={() => handleNavigate(n.type)}
|
|
175
|
+
className="w-full flex items-start gap-3 p-3 rounded-xl hover:bg-foreground/5 transition-all text-left group border border-transparent hover:border-[var(--panel-border)]"
|
|
176
|
+
>
|
|
177
|
+
<div className="mt-0.5 w-8 h-8 rounded-full flex items-center justify-center shrink-0 bg-foreground/5 text-notification-icon">
|
|
178
|
+
{n.type === 'user' ? <User className="w-4 h-4" /> : n.type === 'submission' ? <Mail className="w-4 h-4" /> : <HelpCircle className="w-4 h-4" />}
|
|
179
|
+
</div>
|
|
180
|
+
<div className="flex flex-col flex-1 min-w-0 pr-2">
|
|
181
|
+
<span className="text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate">{n.title}</span>
|
|
182
|
+
<span className="text-[12px] text-foreground/60 truncate">{n.subtitle}</span>
|
|
183
|
+
<span className="text-[10px] font-mono tracking-wide text-foreground/40 mt-1">{formatTime(n.time)}</span>
|
|
184
|
+
</div>
|
|
185
|
+
</button>
|
|
186
|
+
))
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
</motion.div>
|
|
190
|
+
)}
|
|
191
|
+
</AnimatePresence>
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { Button } from '../components/Button';
|
|
4
|
+
|
|
5
|
+
describe('Button component', () => {
|
|
6
|
+
it('renders correctly with given text', () => {
|
|
7
|
+
render(<Button>Click me</Button>);
|
|
8
|
+
expect(screen.getByText('Click me')).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('triggers onClick when properly clicked', () => {
|
|
12
|
+
const handleClick = vi.fn();
|
|
13
|
+
render(<Button onClick={handleClick}>Submit</Button>);
|
|
14
|
+
fireEvent.click(screen.getByText('Submit'));
|
|
15
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('shows loading state properly', () => {
|
|
19
|
+
render(<Button isLoading={true}>Submit</Button>);
|
|
20
|
+
expect(screen.queryByText('Submit')?.closest('span')).toHaveClass('opacity-0');
|
|
21
|
+
});
|
|
22
|
+
});
|