feat: Implement browser-compatible processing pipeline for student requests

- Added SimpleBrowserProcessor class to handle student requests in a queue.
- Introduced methods for adding requests, notifying subscribers, and processing the queue.
- Mock AI matching logic implemented to simulate resource matching based on request categories and urgency.
- Added generateInsights method to analyze request trends and urgencies.

feat: Create authentication context for user management

- Developed AuthContext to manage user authentication state.
- Implemented login and logout functionalities with mock user data.
- Added loading state management during authentication processes.

feat: Add notification context for managing user notifications

- Created NotificationContext to handle notifications throughout the application.
- Implemented methods for adding, marking as read, and removing notifications.

feat: Introduce common hooks for utility functions

- Developed useHashRoute for hash-based routing.
- Created useLocalStorage for managing local storage with TypeScript support.
- Implemented useMediaQuery for responsive design handling.
- Added useDebounce for debouncing values in state.

feat: Implement donation impact calculation hook

- Created useDonationImpact hook to calculate the impact of donations.
- Added useFormValidation hook for form state management and validation.

feat: Design main layout and page structure components

- Developed MainLayout and PageShell components for consistent layout structure.
- Created SectionHeader and Card components for reusable UI elements.

feat: Build HomePage with impact statistics and service offerings

- Implemented HomePage component with hero section, impact stats, and service cards.
- Integrated tracking for donation and volunteer actions.

feat: Add analytics utilities for tracking events

- Created analytics utility for tracking page views and custom events.
- Implemented donation and volunteer tracking functionalities.

feat: Enhance helper functions for various utilities

- Developed utility functions for impact calculation, formatting, validation, and debouncing.
This commit is contained in:
defiQUG
2025-10-05 08:59:50 -07:00
parent e6aec40163
commit ad8e763750
20 changed files with 3398 additions and 1689 deletions
+103
View File
@@ -0,0 +1,103 @@
import React, { createContext, useContext, useState, ReactNode } from 'react'
// Types
export interface AuthUser {
id: string
email: string
role: 'admin' | 'volunteer' | 'resource'
name: string
lastLogin: Date
permissions: string[]
}
export interface AuthContextType {
user: AuthUser | null
login: (email: string, password: string) => Promise<boolean>
logout: () => void
isLoading: boolean
}
// Create Context
const AuthContext = createContext<AuthContextType | null>(null)
// Auth Provider Component
export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [user, setUser] = useState<AuthUser | null>(null)
const [isLoading, setIsLoading] = useState(false)
const login = async (email: string, password: string): Promise<boolean> => {
setIsLoading(true)
try {
// Mock authentication - replace with real API call
console.log('🔐 Attempting login for:', email)
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1000))
// Mock user data based on email
const mockUsers: Record<string, AuthUser> = {
'[email protected]': {
id: '1',
email: '[email protected]',
role: 'admin',
name: 'Admin User',
lastLogin: new Date(),
permissions: ['all']
},
'[email protected]': {
id: '2',
email: '[email protected]',
role: 'volunteer',
name: 'Volunteer User',
lastLogin: new Date(),
permissions: ['view_requests', 'update_assignments']
}
}
const authenticatedUser = mockUsers[email]
if (authenticatedUser && password === 'demo123') {
setUser(authenticatedUser)
localStorage.setItem('authToken', `token-${authenticatedUser.id}`)
console.log('✅ Login successful')
return true
} else {
console.log('❌ Login failed')
return false
}
} catch (error) {
console.error('Login error:', error)
return false
} finally {
setIsLoading(false)
}
}
const logout = (): void => {
setUser(null)
localStorage.removeItem('authToken')
console.log('👋 User logged out')
}
const value: AuthContextType = {
user,
login,
logout,
isLoading
}
return (
<AuthContext.Provider value={value}>
{children}
</AuthContext.Provider>
)
}
// Custom hook for using auth context
export const useAuth = (): AuthContextType => {
const context = useContext(AuthContext)
if (!context) {
throw new Error('useAuth must be used within an AuthProvider')
}
return context
}
+85
View File
@@ -0,0 +1,85 @@
import React, { createContext, useContext, useState, ReactNode } from 'react'
// Types
export interface Notification {
id: string
type: 'success' | 'info' | 'warning' | 'error'
title: string
message: string
timestamp: Date
read: boolean
actions?: { label: string; action: () => void }[]
}
export interface NotificationContextType {
notifications: Notification[]
addNotification: (notif: Omit<Notification, 'id' | 'timestamp' | 'read'>) => void
markAsRead: (id: string) => void
removeNotification: (id: string) => void
clearAll: () => void
}
// Create Context
const NotificationContext = createContext<NotificationContextType | null>(null)
// Notification Provider Component
export const NotificationProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [notifications, setNotifications] = useState<Notification[]>([])
const addNotification = (notif: Omit<Notification, 'id' | 'timestamp' | 'read'>): void => {
const newNotification: Notification = {
...notif,
id: Math.random().toString(36),
timestamp: new Date(),
read: false
}
setNotifications(prev => [newNotification, ...prev])
// Auto-remove success notifications after 5 seconds
if (notif.type === 'success') {
setTimeout(() => {
setNotifications(prev => prev.filter(n => n.id !== newNotification.id))
}, 5000)
}
}
const markAsRead = (id: string): void => {
setNotifications(prev =>
prev.map(notif =>
notif.id === id ? { ...notif, read: true } : notif
)
)
}
const removeNotification = (id: string): void => {
setNotifications(prev => prev.filter(notif => notif.id !== id))
}
const clearAll = (): void => {
setNotifications([])
}
const value: NotificationContextType = {
notifications,
addNotification,
markAsRead,
removeNotification,
clearAll
}
return (
<NotificationContext.Provider value={value}>
{children}
</NotificationContext.Provider>
)
}
// Custom hook for using notification context
export const useNotifications = (): NotificationContextType => {
const context = useContext(NotificationContext)
if (!context) {
throw new Error('useNotifications must be used within a NotificationProvider')
}
return context
}