Compare commits
30 Commits
4cdccc0323
...
dav-prod
| Author | SHA1 | Date | |
|---|---|---|---|
| 48c5a916d9 | |||
|
|
002ef5c897 | ||
| 7d0c207f1b | |||
|
|
8ea486a4f4 | ||
|
|
264ee860df | ||
|
|
65c3e3b92d | ||
|
|
819062d697 | ||
|
|
c73ebfb6c0 | ||
|
|
3822ba8ffb | ||
|
|
c79db66739 | ||
|
|
57cd18ad9d | ||
| 56dd9eeb77 | |||
|
|
e831835e6d | ||
|
|
9287adec01 | ||
|
|
0c1202d89a | ||
|
|
0ebfe71361 | ||
|
|
a935c0f4dd | ||
|
|
4ccaca192d | ||
| 1f9e6ea191 | |||
|
|
ee0ad176b0 | ||
| 66c2bedbed | |||
|
|
180eb1ce85 | ||
|
|
5377a0f465 | ||
|
|
c54eb23689 | ||
| 9f7367ceeb | |||
| d94ea7b6d5 | |||
| 24519a7080 | |||
| b1b9a05d4f | |||
| a2070b4e4e | |||
| 6a21d32319 |
5
public/health.json
Normal file
5
public/health.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"status": "healthy",
|
||||||
|
"mode": "production",
|
||||||
|
"build": "optimized"
|
||||||
|
}
|
||||||
10
src/App.js
10
src/App.js
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||||
import { Toaster } from './components/ui/sonner';
|
import { Toaster } from './components/ui/sonner';
|
||||||
|
import IdleSessionWarning from './components/IdleSessionWarning';
|
||||||
import Landing from './pages/Landing';
|
import Landing from './pages/Landing';
|
||||||
import Register from './pages/Register';
|
import Register from './pages/Register';
|
||||||
import Login from './pages/Login';
|
import Login from './pages/Login';
|
||||||
@@ -21,6 +22,7 @@ import AdminUserView from './pages/admin/AdminUserView';
|
|||||||
import AdminStaff from './pages/admin/AdminStaff';
|
import AdminStaff from './pages/admin/AdminStaff';
|
||||||
import AdminMembers from './pages/admin/AdminMembers';
|
import AdminMembers from './pages/admin/AdminMembers';
|
||||||
import AdminPermissions from './pages/admin/AdminPermissions';
|
import AdminPermissions from './pages/admin/AdminPermissions';
|
||||||
|
import AdminSettings from './pages/admin/AdminSettings';
|
||||||
import AdminRoles from './pages/admin/AdminRoles';
|
import AdminRoles from './pages/admin/AdminRoles';
|
||||||
import AdminEvents from './pages/admin/AdminEvents';
|
import AdminEvents from './pages/admin/AdminEvents';
|
||||||
import AdminEventAttendance from './pages/admin/AdminEventAttendance';
|
import AdminEventAttendance from './pages/admin/AdminEventAttendance';
|
||||||
@@ -289,11 +291,19 @@ function App() {
|
|||||||
</AdminLayout>
|
</AdminLayout>
|
||||||
</PrivateRoute>
|
</PrivateRoute>
|
||||||
} />
|
} />
|
||||||
|
<Route path="/admin/settings" element={
|
||||||
|
<PrivateRoute adminOnly>
|
||||||
|
<AdminLayout>
|
||||||
|
<AdminSettings />
|
||||||
|
</AdminLayout>
|
||||||
|
</PrivateRoute>
|
||||||
|
} />
|
||||||
|
|
||||||
{/* 404 - Catch all undefined routes */}
|
{/* 404 - Catch all undefined routes */}
|
||||||
<Route path="*" element={<NotFound />} />
|
<Route path="*" element={<NotFound />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
<Toaster position="top-right" />
|
<Toaster position="top-right" />
|
||||||
|
<IdleSessionWarning />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ export default function AddToCalendarButton({
|
|||||||
return (
|
return (
|
||||||
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant={variant} size={size} className="gap-2">
|
<Button variant={variant} size={size} className="bg-[var(--purple-lavender)] text-white hover:bg-[var(--purple-muted)] rounded-full gap-2 dark:hover:bg-brand-lavender dark:hover:text-brand-dark-lavender">
|
||||||
<Calendar className="h-4 w-4" />
|
<Calendar className="h-4 w-4" />
|
||||||
Add to Calendar
|
Add to Calendar
|
||||||
<ChevronDown className="h-4 w-4" />
|
<ChevronDown className="h-4 w-4" />
|
||||||
|
|||||||
@@ -175,17 +175,28 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
path: '/admin/permissions',
|
path: '/admin/permissions',
|
||||||
disabled: false,
|
disabled: false,
|
||||||
superadminOnly: true
|
superadminOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Settings',
|
||||||
|
icon: Settings,
|
||||||
|
path: '/admin/settings',
|
||||||
|
disabled: false,
|
||||||
|
superadminOnly: true
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Filter nav items based on user role
|
// Filter nav items based on user role
|
||||||
const filteredNavItems = navItems.filter(item => {
|
const filteredNavItems = navItems.filter(item => {
|
||||||
if (item.superadminOnly && user?.role !== 'superadmin') {
|
if (item.superadminOnly && user?.role !== 'superadmin') {
|
||||||
|
console.log('Filtering out superadmin-only item:', item.name, 'User role:', user?.role);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Debug: Log filtered items count
|
||||||
|
console.log('Total nav items:', navItems.length, 'Filtered items:', filteredNavItems.length, 'User role:', user?.role);
|
||||||
|
|
||||||
const isActive = (path) => {
|
const isActive = (path) => {
|
||||||
if (path === '/admin') {
|
if (path === '/admin') {
|
||||||
return location.pathname === '/admin';
|
return location.pathname === '/admin';
|
||||||
@@ -213,7 +224,7 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
${item.disabled
|
${item.disabled
|
||||||
? 'opacity-50 cursor-not-allowed text-brand-purple '
|
? 'opacity-50 cursor-not-allowed text-brand-purple '
|
||||||
: active
|
: active
|
||||||
? 'bg-[var(--orange-light)]/10 text-[var(--orange-light)]'
|
? 'bg-[var(--orange-light)]/10 text-[var(--purple-ink)]'
|
||||||
: 'text-[var(--purple-ink)] hover:bg-[var(--neutral-800)]/20'
|
: 'text-[var(--purple-ink)] hover:bg-[var(--neutral-800)]/20'
|
||||||
}
|
}
|
||||||
`}
|
`}
|
||||||
@@ -243,7 +254,7 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
|
|
||||||
{/* Badge when collapsed */}
|
{/* Badge when collapsed */}
|
||||||
{!isOpen && item.badge > 0 && !item.disabled && (
|
{!isOpen && item.badge > 0 && !item.disabled && (
|
||||||
<div className="absolute -top-1 -right-1 bg-accent foreground text-xs rounded-full h-5 w-5 flex items-center justify-center font-medium">
|
<div className="absolute -top-1 -right-1 bg-accent text-white foreground text-xs rounded-full h-5 w-5 flex items-center justify-center font-medium">
|
||||||
{item.badge}
|
{item.badge}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -286,9 +297,6 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
<h2 className="text-xl font-semibold text-primary dark:text-brand-light-lavender " style={{ fontFamily: "'Inter', sans-serif" }}>
|
<h2 className="text-xl font-semibold text-primary dark:text-brand-light-lavender " style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
Admin
|
Admin
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-xs text-muted-foreground group-hover:text-accent transition-colors" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
View Public Site
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Link>
|
</Link>
|
||||||
@@ -367,11 +375,21 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
{renderNavItem(filteredNavItems.find(item => item.name === 'Bylaws'))}
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Bylaws'))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Permissions - Superadmin only (no header) */}
|
{/* SYSTEM Section - Superadmin only */}
|
||||||
{user?.role === 'superadmin' && (
|
{user?.role === 'superadmin' && (
|
||||||
<div className="mt-6">
|
<>
|
||||||
{renderNavItem(filteredNavItems.find(item => item.name === 'Permissions'))}
|
{isOpen && (
|
||||||
</div>
|
<div className="px-4 py-2 mt-6">
|
||||||
|
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||||
|
System
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="space-y-1">
|
||||||
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Permissions'))}
|
||||||
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Settings'))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export const AttendanceDialog = ({ event, open, onOpenChange, onSuccess }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto bg-background">
|
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto bg-background scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<DialogTitle className="text-2xl text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
Mark Attendance: {event?.title}
|
Mark Attendance: {event?.title}
|
||||||
|
|||||||
149
src/components/ChangeRoleDialog.js
Normal file
149
src/components/ChangeRoleDialog.js
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { AlertCircle, Shield } from 'lucide-react';
|
||||||
|
import api from '../utils/api';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
export default function ChangeRoleDialog({ open, onClose, user, onSuccess }) {
|
||||||
|
const [roles, setRoles] = useState([]);
|
||||||
|
const [selectedRole, setSelectedRole] = useState('');
|
||||||
|
const [selectedRoleId, setSelectedRoleId] = useState(null);
|
||||||
|
const [loadingRoles, setLoadingRoles] = useState(false);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
fetchRoles();
|
||||||
|
// Pre-select current role
|
||||||
|
setSelectedRole(user.role);
|
||||||
|
setSelectedRoleId(user.role_id);
|
||||||
|
}
|
||||||
|
}, [open, user]);
|
||||||
|
|
||||||
|
const fetchRoles = async () => {
|
||||||
|
setLoadingRoles(true);
|
||||||
|
try {
|
||||||
|
// Reuse existing endpoint that returns assignable roles based on privilege
|
||||||
|
const response = await api.get('/admin/roles/assignable');
|
||||||
|
// Map API response to format expected by Select component
|
||||||
|
const mappedRoles = response.data.map(role => ({
|
||||||
|
value: role.code,
|
||||||
|
label: role.name,
|
||||||
|
id: role.id,
|
||||||
|
description: role.description
|
||||||
|
}));
|
||||||
|
setRoles(mappedRoles);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch assignable roles:', error);
|
||||||
|
toast.error('Failed to load roles. Please try again.');
|
||||||
|
} finally {
|
||||||
|
setLoadingRoles(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!selectedRole) {
|
||||||
|
toast.error('Please select a role');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't submit if role hasn't changed
|
||||||
|
if (selectedRole === user.role && selectedRoleId === user.role_id) {
|
||||||
|
toast.info('The selected role is the same as current role');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
await api.put(`/admin/users/${user.id}/role`, {
|
||||||
|
role: selectedRole,
|
||||||
|
role_id: selectedRoleId
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.success(`Role changed to ${selectedRole}`);
|
||||||
|
|
||||||
|
onSuccess();
|
||||||
|
onClose();
|
||||||
|
} catch (error) {
|
||||||
|
const message = error.response?.data?.detail || 'Failed to change role';
|
||||||
|
toast.error(message);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onClose}>
|
||||||
|
<DialogContent className="sm:max-w-[500px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="flex items-center gap-2">
|
||||||
|
<Shield className="h-5 w-5 text-[#664fa3]" />
|
||||||
|
Change User Role
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Change role for {user.first_name} {user.last_name} ({user.email})
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="space-y-4 py-4">
|
||||||
|
{/* Current Role Display */}
|
||||||
|
<div className="p-3 bg-[#f1eef9] rounded-lg border border-[#DDD8EB]">
|
||||||
|
<p className="text-sm text-gray-600">Current Role</p>
|
||||||
|
<p className="font-semibold text-[#664fa3] capitalize">{user.role}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Role Selection */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="role">New Role</Label>
|
||||||
|
<Select value={selectedRole} onValueChange={setSelectedRole} disabled={loadingRoles}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder={loadingRoles ? "Loading roles..." : "Select role"} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{roles.map((role) => (
|
||||||
|
<SelectItem key={role.value} value={role.value}>
|
||||||
|
<span className="capitalize">{role.label}</span>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Warning for privileged roles */}
|
||||||
|
{(selectedRole === 'admin' || selectedRole === 'superadmin') && (
|
||||||
|
<div className="flex items-start gap-2 p-3 bg-amber-50 border border-amber-200 rounded-lg">
|
||||||
|
<AlertCircle className="h-5 w-5 text-amber-600 flex-shrink-0 mt-0.5" />
|
||||||
|
<div className="text-sm">
|
||||||
|
<p className="font-semibold text-amber-900">Admin Access Warning</p>
|
||||||
|
<p className="text-amber-700">
|
||||||
|
This user will gain full administrative access to the system.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-3">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={onClose}
|
||||||
|
disabled={submitting}
|
||||||
|
className="border-2 border-gray-300 rounded-full"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={submitting || loadingRoles}
|
||||||
|
className="bg-[#664fa3] hover:bg-[#7d5ec2] text-white rounded-full"
|
||||||
|
>
|
||||||
|
{submitting ? 'Changing Role...' : 'Change Role'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@ const CreateMemberDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
});
|
});
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
|
const getTodayDate = () => new Date().toISOString().slice(0, 10);
|
||||||
|
|
||||||
const handleChange = (field, value) => {
|
const handleChange = (field, value) => {
|
||||||
setFormData(prev => ({ ...prev, [field]: value }));
|
setFormData(prev => ({ ...prev, [field]: value }));
|
||||||
@@ -84,8 +85,8 @@ const CreateMemberDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
if (payload.date_of_birth === '') {
|
if (payload.date_of_birth === '') {
|
||||||
delete payload.date_of_birth;
|
delete payload.date_of_birth;
|
||||||
}
|
}
|
||||||
if (payload.member_since === '') {
|
if (!payload.member_since) {
|
||||||
delete payload.member_since;
|
payload.member_since = getTodayDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
await api.post('/admin/users/create', payload);
|
await api.post('/admin/users/create', payload);
|
||||||
@@ -119,7 +120,7 @@ const CreateMemberDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="sm:max-w-[700px] rounded-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="sm:max-w-[700px] rounded-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
<UserPlus className="h-6 w-6" />
|
<UserPlus className="h-6 w-6" />
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ const CreateStaffDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: '',
|
last_name: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
|
member_since: '',
|
||||||
role: 'admin'
|
role: 'admin'
|
||||||
});
|
});
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
|
const getTodayDate = () => new Date().toISOString().slice(0, 10);
|
||||||
|
|
||||||
const handleChange = (field, value) => {
|
const handleChange = (field, value) => {
|
||||||
setFormData(prev => ({ ...prev, [field]: value }));
|
setFormData(prev => ({ ...prev, [field]: value }));
|
||||||
@@ -74,7 +76,11 @@ const CreateStaffDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.post('/admin/users/create', formData);
|
const payload = { ...formData };
|
||||||
|
if (!payload.member_since) {
|
||||||
|
payload.member_since = getTodayDate();
|
||||||
|
}
|
||||||
|
await api.post('/admin/users/create', payload);
|
||||||
toast.success('Staff member created successfully');
|
toast.success('Staff member created successfully');
|
||||||
|
|
||||||
// Reset form
|
// Reset form
|
||||||
@@ -84,6 +90,7 @@ const CreateStaffDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: '',
|
last_name: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
|
member_since: '',
|
||||||
role: 'admin'
|
role: 'admin'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -200,6 +207,20 @@ const CreateStaffDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Member Since */}
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="member_since" className="text-[var(--purple-ink)]">
|
||||||
|
Member Since
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="member_since"
|
||||||
|
type="date"
|
||||||
|
value={formData.member_since}
|
||||||
|
onChange={(e) => handleChange('member_since', e.target.value)}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple "
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Role */}
|
{/* Role */}
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="role" className="text-[var(--purple-ink)]">
|
<Label htmlFor="role" className="text-[var(--purple-ink)]">
|
||||||
|
|||||||
232
src/components/IdleSessionWarning.js
Normal file
232
src/components/IdleSessionWarning.js
Normal file
@@ -0,0 +1,232 @@
|
|||||||
|
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useAuth } from '../context/AuthContext';
|
||||||
|
import logger from '../utils/logger';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { AlertTriangle, RefreshCw } from 'lucide-react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IdleSessionWarning Component
|
||||||
|
*
|
||||||
|
* Monitors user activity and warns before session expiration
|
||||||
|
* - Warns 1 minute before JWT expiry (at 29 minutes if JWT is 30 min)
|
||||||
|
* - Auto-logout on expiration
|
||||||
|
* - "Stay Logged In" extends session
|
||||||
|
*/
|
||||||
|
const IdleSessionWarning = () => {
|
||||||
|
const { user, logout, refreshUser } = useAuth();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
const SESSION_DURATION = 30 * 60 * 1000; // 30 minutes in milliseconds
|
||||||
|
const WARNING_BEFORE_EXPIRY = 1 * 60 * 1000; // Warn 1 minute before expiry
|
||||||
|
const WARNING_TIME = SESSION_DURATION - WARNING_BEFORE_EXPIRY; // 29 minutes
|
||||||
|
|
||||||
|
const [showWarning, setShowWarning] = useState(false);
|
||||||
|
const [timeRemaining, setTimeRemaining] = useState(60); // seconds
|
||||||
|
const [isExtending, setIsExtending] = useState(false);
|
||||||
|
|
||||||
|
const activityTimeoutRef = useRef(null);
|
||||||
|
const warningTimeoutRef = useRef(null);
|
||||||
|
const countdownIntervalRef = useRef(null);
|
||||||
|
const lastActivityRef = useRef(Date.now());
|
||||||
|
|
||||||
|
// Reset activity timer
|
||||||
|
const resetActivityTimer = useCallback(() => {
|
||||||
|
lastActivityRef.current = Date.now();
|
||||||
|
|
||||||
|
// Clear existing timers
|
||||||
|
if (activityTimeoutRef.current) {
|
||||||
|
clearTimeout(activityTimeoutRef.current);
|
||||||
|
}
|
||||||
|
if (warningTimeoutRef.current) {
|
||||||
|
clearTimeout(warningTimeoutRef.current);
|
||||||
|
}
|
||||||
|
if (countdownIntervalRef.current) {
|
||||||
|
clearInterval(countdownIntervalRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide warning if showing
|
||||||
|
if (showWarning) {
|
||||||
|
setShowWarning(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set new warning timer
|
||||||
|
warningTimeoutRef.current = setTimeout(() => {
|
||||||
|
// Show warning
|
||||||
|
setShowWarning(true);
|
||||||
|
setTimeRemaining(60); // 60 seconds until logout
|
||||||
|
|
||||||
|
// Start countdown
|
||||||
|
countdownIntervalRef.current = setInterval(() => {
|
||||||
|
setTimeRemaining((prev) => {
|
||||||
|
if (prev <= 1) {
|
||||||
|
// Time's up - logout
|
||||||
|
handleSessionExpired();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return prev - 1;
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
// Set auto-logout timer
|
||||||
|
activityTimeoutRef.current = setTimeout(() => {
|
||||||
|
handleSessionExpired();
|
||||||
|
}, WARNING_BEFORE_EXPIRY);
|
||||||
|
|
||||||
|
}, WARNING_TIME);
|
||||||
|
}, [showWarning]);
|
||||||
|
|
||||||
|
// Handle session expiration
|
||||||
|
const handleSessionExpired = useCallback(() => {
|
||||||
|
// Clear all timers
|
||||||
|
if (activityTimeoutRef.current) clearTimeout(activityTimeoutRef.current);
|
||||||
|
if (warningTimeoutRef.current) clearTimeout(warningTimeoutRef.current);
|
||||||
|
if (countdownIntervalRef.current) clearInterval(countdownIntervalRef.current);
|
||||||
|
|
||||||
|
setShowWarning(false);
|
||||||
|
logout();
|
||||||
|
navigate('/login', {
|
||||||
|
state: { message: 'Your session has expired due to inactivity. Please log in again.' }
|
||||||
|
});
|
||||||
|
}, [logout, navigate]);
|
||||||
|
|
||||||
|
// Handle "Stay Logged In" button
|
||||||
|
const handleExtendSession = async () => {
|
||||||
|
setIsExtending(true);
|
||||||
|
try {
|
||||||
|
// Refresh user data to get new token
|
||||||
|
await refreshUser();
|
||||||
|
|
||||||
|
// Reset activity timer
|
||||||
|
resetActivityTimer();
|
||||||
|
|
||||||
|
logger.log('[IdleSessionWarning] Session extended successfully');
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('[IdleSessionWarning] Failed to extend session:', error);
|
||||||
|
|
||||||
|
// If refresh fails, logout
|
||||||
|
handleSessionExpired();
|
||||||
|
} finally {
|
||||||
|
setIsExtending(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Track user activity
|
||||||
|
useEffect(() => {
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
const activityEvents = [
|
||||||
|
'mousedown',
|
||||||
|
'mousemove',
|
||||||
|
'keypress',
|
||||||
|
'scroll',
|
||||||
|
'touchstart',
|
||||||
|
'click'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Throttle activity detection to avoid too many resets
|
||||||
|
let throttleTimeout = null;
|
||||||
|
const handleActivity = () => {
|
||||||
|
if (throttleTimeout) return;
|
||||||
|
|
||||||
|
throttleTimeout = setTimeout(() => {
|
||||||
|
resetActivityTimer();
|
||||||
|
throttleTimeout = null;
|
||||||
|
}, 1000); // Throttle to once per second
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add event listeners
|
||||||
|
activityEvents.forEach(event => {
|
||||||
|
document.addEventListener(event, handleActivity, { passive: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize timer
|
||||||
|
resetActivityTimer();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
return () => {
|
||||||
|
activityEvents.forEach(event => {
|
||||||
|
document.removeEventListener(event, handleActivity);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (activityTimeoutRef.current) clearTimeout(activityTimeoutRef.current);
|
||||||
|
if (warningTimeoutRef.current) clearTimeout(warningTimeoutRef.current);
|
||||||
|
if (countdownIntervalRef.current) clearInterval(countdownIntervalRef.current);
|
||||||
|
if (throttleTimeout) clearTimeout(throttleTimeout);
|
||||||
|
};
|
||||||
|
}, [user, resetActivityTimer]);
|
||||||
|
|
||||||
|
// Don't render if user is not logged in
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={showWarning} onOpenChange={(open) => {
|
||||||
|
if (!open) {
|
||||||
|
// Prevent closing dialog by clicking outside
|
||||||
|
// User must click a button
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<DialogContent
|
||||||
|
className="max-w-md"
|
||||||
|
onPointerDownOutside={(e) => e.preventDefault()}
|
||||||
|
onEscapeKeyDown={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<div className="flex items-center gap-3 mb-2">
|
||||||
|
<div className="bg-[#ff9e77]/10 p-3 rounded-full">
|
||||||
|
<AlertTriangle className="h-6 w-6 text-[#ff9e77]" />
|
||||||
|
</div>
|
||||||
|
<DialogTitle className="text-[#422268]">
|
||||||
|
Session About to Expire
|
||||||
|
</DialogTitle>
|
||||||
|
</div>
|
||||||
|
<DialogDescription className="text-[#664fa3]">
|
||||||
|
Your session will expire in <strong className="text-[#422268] text-lg">{timeRemaining}</strong> seconds due to inactivity.
|
||||||
|
|
||||||
|
<div className="mt-4 p-4 bg-[#f1eef9] rounded-lg border border-[#ddd8eb]">
|
||||||
|
<p className="text-sm text-[#422268]">
|
||||||
|
Click <strong>"Stay Logged In"</strong> to continue your session, or you will be automatically logged out.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogFooter className="flex-col sm:flex-row gap-3 mt-4">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleSessionExpired}
|
||||||
|
className="border-[#ddd8eb] text-[#664fa3] hover:bg-[#f1eef9]"
|
||||||
|
>
|
||||||
|
Log Out Now
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleExtendSession}
|
||||||
|
disabled={isExtending}
|
||||||
|
className="bg-[#664fa3] hover:bg-[#422268] text-white"
|
||||||
|
>
|
||||||
|
{isExtending ? (
|
||||||
|
<>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Extending...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'Stay Logged In'
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IdleSessionWarning;
|
||||||
@@ -138,7 +138,7 @@ const ImportMembersDialog = ({ open, onOpenChange, onSuccess }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={handleClose}>
|
<Dialog open={open} onOpenChange={handleClose}>
|
||||||
<DialogContent className="sm:max-w-[800px] rounded-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="sm:max-w-[800px] rounded-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
<Upload className="h-6 w-6" />
|
<Upload className="h-6 w-6" />
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const Navbar = () => {
|
|||||||
style={{ fontFamily: "'Poppins', sans-serif" }}
|
style={{ fontFamily: "'Poppins', sans-serif" }}
|
||||||
data-testid="admin-nav-button"
|
data-testid="admin-nav-button"
|
||||||
>
|
>
|
||||||
Admin Panel
|
Dashboard
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
@@ -110,7 +110,7 @@ const Navbar = () => {
|
|||||||
className="text-white text-[17.5px] font-medium hover:opacity-80 transition-opacity"
|
className="text-white text-[17.5px] font-medium hover:opacity-80 transition-opacity"
|
||||||
style={{ fontFamily: "'Poppins', sans-serif" }}
|
style={{ fontFamily: "'Poppins', sans-serif" }}
|
||||||
>
|
>
|
||||||
Dashboard
|
My Profile
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
<Link
|
||||||
to="/events"
|
to="/events"
|
||||||
@@ -170,14 +170,7 @@ const Navbar = () => {
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<Link
|
|
||||||
to="/profile"
|
|
||||||
className="text-white text-[17.5px] font-medium hover:opacity-80 transition-opacity"
|
|
||||||
style={{ fontFamily: "'Poppins', sans-serif" }}
|
|
||||||
data-testid="profile-nav-button"
|
|
||||||
>
|
|
||||||
Profile
|
|
||||||
</Link>
|
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
{/* Mobile Hamburger Button */}
|
{/* Mobile Hamburger Button */}
|
||||||
@@ -231,7 +224,7 @@ const Navbar = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Navigation Links */}
|
{/* Navigation Links */}
|
||||||
<nav className="flex-1 overflow-y-auto py-6 px-4">
|
<nav className="flex-1 overflow-y-auto scrollbar-dashboard py-6 px-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Link
|
<Link
|
||||||
to="/"
|
to="/"
|
||||||
@@ -373,7 +366,7 @@ const Navbar = () => {
|
|||||||
className="w-full bg-background/20 hover:bg-background/30 text-white rounded-lg"
|
className="w-full bg-background/20 hover:bg-background/30 text-white rounded-lg"
|
||||||
style={{ fontFamily: "'Poppins', sans-serif" }}
|
style={{ fontFamily: "'Poppins', sans-serif" }}
|
||||||
>
|
>
|
||||||
Admin Panel
|
Dashboard
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ const PlanDialog = ({ open, onOpenChange, plan, onSuccess }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="sm:max-w-[700px] max-h-[90vh] overflow-y-auto">
|
<DialogContent className="sm:max-w-[700px] max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<DialogTitle className="text-2xl text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{plan ? 'Edit Plan' : 'Create New Plan'}
|
{plan ? 'Edit Plan' : 'Create New Plan'}
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ const PublicNavbar = () => {
|
|||||||
className={getDesktopLinkClasses(user ? "/dashboard" : "/become-a-member")}
|
className={getDesktopLinkClasses(user ? "/dashboard" : "/become-a-member")}
|
||||||
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
>
|
>
|
||||||
{user ? 'Dashboard' : 'Become a Member'}
|
{user ? 'My Profile' : 'Become a Member'}
|
||||||
</Link>
|
</Link>
|
||||||
{!user && (
|
{!user && (
|
||||||
<Link
|
<Link
|
||||||
@@ -204,7 +204,7 @@ const PublicNavbar = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Drawer */}
|
{/* Drawer */}
|
||||||
<div className="fixed right-0 top-0 h-full w-[280px] bg-brand-purple shadow-xl overflow-y-auto">
|
<div className="fixed right-0 top-0 h-full w-[280px] bg-brand-purple shadow-xl overflow-y-auto scrollbar-dashboard">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex justify-between items-center p-6 border-b border-[var(--purple-deep)]">
|
<div className="flex justify-between items-center p-6 border-b border-[var(--purple-deep)]">
|
||||||
<span className="text-white text-lg font-semibold" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<span className="text-white text-lg font-semibold" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
@@ -270,7 +270,7 @@ const PublicNavbar = () => {
|
|||||||
className={getMobileLinkClasses(user ? "/dashboard" : "/become-a-member")}
|
className={getMobileLinkClasses(user ? "/dashboard" : "/become-a-member")}
|
||||||
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
>
|
>
|
||||||
{user ? 'Dashboard' : 'Become a Member'}
|
{user ? 'My Profile' : 'Become a Member'}
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
{!user && (
|
{!user && (
|
||||||
|
|||||||
36
src/components/StatCard.jsx
Normal file
36
src/components/StatCard.jsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Card } from "./ui/card";
|
||||||
|
|
||||||
|
export const StatCard = ({
|
||||||
|
title,
|
||||||
|
value,
|
||||||
|
icon: Icon,
|
||||||
|
iconBgClass,
|
||||||
|
dataTestId,
|
||||||
|
}) => (
|
||||||
|
<Card
|
||||||
|
className="p-6 flex flex-col justify-between bg-background rounded-2xl border border-[var(--neutral-800)]"
|
||||||
|
data-testid={dataTestId}
|
||||||
|
>
|
||||||
|
<div className="flex items-start gap-4 mb-4 ">
|
||||||
|
<div className={`${iconBgClass} p-3 rounded-lg `}>
|
||||||
|
<Icon className="size-8" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-8">
|
||||||
|
<p
|
||||||
|
className="text-6xl font-semibold text-[var(--purple-ink)] mb-1"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
className="text-sm text-brand-purple "
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</p>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
252
src/components/TransactionHistory.js
Normal file
252
src/components/TransactionHistory.js
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Card } from './ui/card';
|
||||||
|
import { Badge } from './ui/badge';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs';
|
||||||
|
import { Receipt, CreditCard, Heart, Calendar, ExternalLink, DollarSign } from 'lucide-react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TransactionHistory Component
|
||||||
|
* Displays user transaction history including subscriptions and donations
|
||||||
|
*
|
||||||
|
* @param {Object} props
|
||||||
|
* @param {Array} props.subscriptions - List of subscription transactions
|
||||||
|
* @param {Array} props.donations - List of donation transactions
|
||||||
|
* @param {number} props.totalSubscriptionCents - Total subscription amount in cents
|
||||||
|
* @param {number} props.totalDonationCents - Total donation amount in cents
|
||||||
|
* @param {boolean} props.loading - Loading state
|
||||||
|
* @param {boolean} props.isAdmin - Whether viewing as admin (shows extra fields)
|
||||||
|
*/
|
||||||
|
const TransactionHistory = ({
|
||||||
|
subscriptions = [],
|
||||||
|
donations = [],
|
||||||
|
totalSubscriptionCents = 0,
|
||||||
|
totalDonationCents = 0,
|
||||||
|
loading = false,
|
||||||
|
isAdmin = false
|
||||||
|
}) => {
|
||||||
|
const [activeTab, setActiveTab] = useState('all');
|
||||||
|
|
||||||
|
const formatAmount = (cents) => {
|
||||||
|
if (!cents) return '$0.00';
|
||||||
|
return `$${(cents / 100).toFixed(2)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDate = (dateString) => {
|
||||||
|
if (!dateString) return 'N/A';
|
||||||
|
return new Date(dateString).toLocaleDateString('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatusBadgeClass = (status) => {
|
||||||
|
switch (status?.toLowerCase()) {
|
||||||
|
case 'active':
|
||||||
|
case 'completed':
|
||||||
|
return 'bg-green-100 text-green-800 border-green-200';
|
||||||
|
case 'pending':
|
||||||
|
return 'bg-yellow-100 text-yellow-800 border-yellow-200';
|
||||||
|
case 'cancelled':
|
||||||
|
case 'failed':
|
||||||
|
case 'expired':
|
||||||
|
return 'bg-red-100 text-red-800 border-red-200';
|
||||||
|
default:
|
||||||
|
return 'bg-gray-100 text-gray-800 border-gray-200';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const allTransactions = [
|
||||||
|
...subscriptions.map(s => ({ ...s, sortDate: s.created_at })),
|
||||||
|
...donations.map(d => ({ ...d, sortDate: d.created_at }))
|
||||||
|
].sort((a, b) => new Date(b.sortDate) - new Date(a.sortDate));
|
||||||
|
|
||||||
|
const TransactionRow = ({ transaction }) => {
|
||||||
|
const isSubscription = transaction.type === 'subscription';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between p-4 border-b border-[var(--neutral-800)] last:border-b-0 hover:bg-[var(--lavender-500)] transition-colors">
|
||||||
|
<div className="flex items-start gap-3 mb-2 sm:mb-0">
|
||||||
|
<div className={`p-2 rounded-lg ${isSubscription ? 'bg-[var(--purple-lavender)] bg-opacity-20' : 'bg-[var(--orange-light)] bg-opacity-20'}`}>
|
||||||
|
{isSubscription ? (
|
||||||
|
<CreditCard className="h-5 w-5 text-[var(--purple-lavender)]" />
|
||||||
|
) : (
|
||||||
|
<Heart className="h-5 w-5 text-[var(--orange-light)]" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
|
<span className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{transaction.description}
|
||||||
|
</span>
|
||||||
|
<Badge className={`text-xs ${getStatusBadgeClass(transaction.status)}`}>
|
||||||
|
{transaction.status}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 text-sm text-brand-purple mt-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
<Calendar className="h-3 w-3" />
|
||||||
|
<span>{formatDate(transaction.payment_completed_at || transaction.created_at)}</span>
|
||||||
|
{transaction.card_brand && transaction.card_last4 && (
|
||||||
|
<>
|
||||||
|
<span className="text-[var(--neutral-800)]">•</span>
|
||||||
|
<span>{transaction.card_brand} ****{transaction.card_last4}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{isSubscription && transaction.billing_cycle && (
|
||||||
|
<>
|
||||||
|
<span className="text-[var(--neutral-800)]">•</span>
|
||||||
|
<span className="capitalize">{transaction.billing_cycle}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{isAdmin && transaction.manual_payment && (
|
||||||
|
<div className="text-xs text-[var(--orange-light)] mt-1">
|
||||||
|
Manual Payment {transaction.manual_payment_notes && `- ${transaction.manual_payment_notes}`}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-3 pl-10 sm:pl-0">
|
||||||
|
<div className="text-right">
|
||||||
|
<div className="font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{formatAmount(transaction.amount_cents)}
|
||||||
|
</div>
|
||||||
|
{isSubscription && transaction.donation_cents > 0 && (
|
||||||
|
<div className="text-xs text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
(incl. {formatAmount(transaction.donation_cents)} donation)
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{transaction.stripe_receipt_url && (
|
||||||
|
<a
|
||||||
|
href={transaction.stripe_receipt_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="p-2 text-brand-purple hover:text-[var(--purple-ink)] hover:bg-[var(--lavender-300)] rounded-lg transition-colors"
|
||||||
|
title="View Receipt"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-4 w-4" />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmptyState = ({ type }) => (
|
||||||
|
<div className="py-12 text-center">
|
||||||
|
<div className="mx-auto w-16 h-16 bg-[var(--lavender-300)] rounded-full flex items-center justify-center mb-4">
|
||||||
|
{type === 'subscription' ? (
|
||||||
|
<CreditCard className="h-8 w-8 text-brand-purple" />
|
||||||
|
) : type === 'donation' ? (
|
||||||
|
<Heart className="h-8 w-8 text-brand-purple" />
|
||||||
|
) : (
|
||||||
|
<Receipt className="h-8 w-8 text-brand-purple" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<p className="text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{type === 'subscription'
|
||||||
|
? 'No subscription payments yet'
|
||||||
|
: type === 'donation'
|
||||||
|
? 'No donations yet'
|
||||||
|
: 'No transactions yet'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<Card className="p-8 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
||||||
|
<div className="flex items-center justify-center py-12">
|
||||||
|
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[var(--purple-lavender)]"></div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<h2 className="text-2xl font-semibold text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<Receipt className="h-6 w-6 text-brand-purple" />
|
||||||
|
Transaction History
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Summary Cards */}
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mb-6">
|
||||||
|
<div className="p-4 bg-[var(--lavender-500)] rounded-xl border border-[var(--neutral-800)]">
|
||||||
|
<div className="flex items-center gap-2 text-brand-purple mb-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
<CreditCard className="h-4 w-4" />
|
||||||
|
<span className="text-sm">Total Subscriptions</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-2xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{formatAmount(totalSubscriptionCents)}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-brand-purple mt-1">{subscriptions.length} payment(s)</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-4 bg-[var(--lavender-500)] rounded-xl border border-[var(--neutral-800)]">
|
||||||
|
<div className="flex items-center gap-2 text-brand-purple mb-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
<Heart className="h-4 w-4" />
|
||||||
|
<span className="text-sm">Total Donations</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-2xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{formatAmount(totalDonationCents)}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-brand-purple mt-1">{donations.length} donation(s)</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Tabs */}
|
||||||
|
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
|
||||||
|
<TabsList className="grid w-full grid-cols-3 mb-4">
|
||||||
|
<TabsTrigger value="all" className="data-[state=active]:bg-[var(--purple-lavender)] data-[state=active]:text-white">
|
||||||
|
All ({allTransactions.length})
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="subscriptions" className="data-[state=active]:bg-[var(--purple-lavender)] data-[state=active]:text-white">
|
||||||
|
Subscriptions ({subscriptions.length})
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="donations" className="data-[state=active]:bg-[var(--purple-lavender)] data-[state=active]:text-white">
|
||||||
|
Donations ({donations.length})
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<div className="border border-[var(--neutral-800)] rounded-xl overflow-hidden">
|
||||||
|
<TabsContent value="all" className="m-0">
|
||||||
|
{allTransactions.length > 0 ? (
|
||||||
|
allTransactions.map((transaction) => (
|
||||||
|
<TransactionRow key={transaction.id} transaction={transaction} />
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<EmptyState type="all" />
|
||||||
|
)}
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="subscriptions" className="m-0">
|
||||||
|
{subscriptions.length > 0 ? (
|
||||||
|
subscriptions.map((transaction) => (
|
||||||
|
<TransactionRow key={transaction.id} transaction={transaction} />
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<EmptyState type="subscription" />
|
||||||
|
)}
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="donations" className="m-0">
|
||||||
|
{donations.length > 0 ? (
|
||||||
|
donations.map((transaction) => (
|
||||||
|
<TransactionRow key={transaction.id} transaction={transaction} />
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<EmptyState type="donation" />
|
||||||
|
)}
|
||||||
|
</TabsContent>
|
||||||
|
</div>
|
||||||
|
</Tabs>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransactionHistory;
|
||||||
@@ -896,7 +896,7 @@ export default function WordPressImportWizard({ open, onOpenChange, onSuccess })
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="max-w-6xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="max-w-6xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl font-semibold text-[var(--purple-ink)]">
|
<DialogTitle className="text-2xl font-semibold text-[var(--purple-ink)]">
|
||||||
WordPress Import Wizard
|
WordPress Import Wizard
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const badgeVariants = cva(
|
|||||||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
||||||
outline: "text-foreground",
|
outline: "text-foreground",
|
||||||
green:
|
green:
|
||||||
"border-transparent bg-[var(--green-light)] text-white hover:bg-[var(--green-forest)]",
|
"border-transparent bg-[var(--green-forest)] text-white hover:bg-[var(--green-fern)]",
|
||||||
orange:
|
orange:
|
||||||
"border-transparent bg-orange-500 text-white hover:bg-orange-500/80",
|
"border-transparent bg-orange-500 text-white hover:bg-orange-500/80",
|
||||||
orange2:
|
orange2:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot"
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva } from "class-variance-authority"
|
import { cva } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva("btn", {
|
const buttonVariants = cva("btn", {
|
||||||
variants: {
|
variants: {
|
||||||
@@ -11,10 +11,10 @@ const buttonVariants = cva("btn", {
|
|||||||
secondary: "btn-secondary",
|
secondary: "btn-secondary",
|
||||||
ghost: "btn-ghost",
|
ghost: "btn-ghost",
|
||||||
outline: "btn-outline",
|
outline: "btn-outline",
|
||||||
|
"outline-destructive": "btn-outline-destructive",
|
||||||
accent: "btn-accent",
|
accent: "btn-accent",
|
||||||
destructive: "btn-destructive",
|
destructive: "btn-destructive",
|
||||||
link: "btn-link",
|
link: "btn-link",
|
||||||
|
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: "btn-md",
|
default: "btn-md",
|
||||||
@@ -27,18 +27,20 @@ const buttonVariants = cva("btn", {
|
|||||||
variant: "default",
|
variant: "default",
|
||||||
size: "default",
|
size: "default",
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
const Button = React.forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => {
|
const Button = React.forwardRef(
|
||||||
const Comp = asChild ? Slot : "button"
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||||
return (
|
const Comp = asChild ? Slot : "button";
|
||||||
<Comp
|
return (
|
||||||
className={cn(buttonVariants({ variant, size }), className)}
|
<Comp
|
||||||
ref={ref}
|
className={cn(buttonVariants({ variant, size }), className)}
|
||||||
{...props}
|
ref={ref}
|
||||||
/>
|
{...props}
|
||||||
)
|
/>
|
||||||
})
|
);
|
||||||
Button.displayName = "Button"
|
}
|
||||||
|
);
|
||||||
|
Button.displayName = "Button";
|
||||||
|
|
||||||
export { Button, buttonVariants }
|
export { Button, buttonVariants };
|
||||||
|
|||||||
@@ -1,50 +1,65 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Card = React.forwardRef(({ className, ...props }, ref) => (
|
const Card = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("rounded-xl border bg-card text-card-foreground shadow", className)}
|
className={cn(
|
||||||
{...props} />
|
"rounded-xl border bg-card text-card-foreground shadow",
|
||||||
))
|
className,
|
||||||
Card.displayName = "Card"
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
Card.displayName = "Card";
|
||||||
|
|
||||||
const CardHeader = React.forwardRef(({ className, ...props }, ref) => (
|
const CardHeader = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
CardHeader.displayName = "CardHeader"
|
));
|
||||||
|
CardHeader.displayName = "CardHeader";
|
||||||
|
|
||||||
const CardTitle = React.forwardRef(({ className, ...props }, ref) => (
|
const CardTitle = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
className={cn("font-semibold leading-none tracking-tight", className)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
CardTitle.displayName = "CardTitle"
|
));
|
||||||
|
CardTitle.displayName = "CardTitle";
|
||||||
|
|
||||||
const CardDescription = React.forwardRef(({ className, ...props }, ref) => (
|
const CardDescription = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("text-sm text-muted-foreground", className)}
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
CardDescription.displayName = "CardDescription"
|
));
|
||||||
|
CardDescription.displayName = "CardDescription";
|
||||||
|
|
||||||
const CardContent = React.forwardRef(({ className, ...props }, ref) => (
|
const CardContent = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||||
))
|
));
|
||||||
CardContent.displayName = "CardContent"
|
CardContent.displayName = "CardContent";
|
||||||
|
|
||||||
const CardFooter = React.forwardRef(({ className, ...props }, ref) => (
|
const CardFooter = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("flex items-center p-6 pt-0", className)}
|
className={cn("flex items-center p-6 pt-0", className)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
CardFooter.displayName = "CardFooter"
|
));
|
||||||
|
CardFooter.displayName = "CardFooter";
|
||||||
|
|
||||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|
export {
|
||||||
|
Card,
|
||||||
|
CardHeader,
|
||||||
|
CardFooter,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription,
|
||||||
|
CardContent,
|
||||||
|
};
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ CommandInput.displayName = CommandPrimitive.Input.displayName
|
|||||||
const CommandList = React.forwardRef(({ className, ...props }, ref) => (
|
const CommandList = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<CommandPrimitive.List
|
<CommandPrimitive.List
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
|
className={cn("max-h-[300px] overflow-y-auto scrollbar-dashboard scrollbar-x-dashboard overflow-x-hidden", className)}
|
||||||
{...props} />
|
{...props} />
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const ContextMenuContent = React.forwardRef(({ className, ...props }, ref) => (
|
|||||||
<ContextMenuPrimitive.Content
|
<ContextMenuPrimitive.Content
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 max-h-[--radix-context-menu-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-context-menu-content-transform-origin]",
|
"z-50 max-h-[--radix-context-menu-content-available-height] min-w-[8rem] overflow-y-auto scrollbar-dashboard scrollbar-x-dashboard overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-context-menu-content-transform-origin]",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props} />
|
{...props} />
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const DropdownMenuSubTrigger = React.forwardRef(({ className, inset, children, .
|
|||||||
<DropdownMenuPrimitive.SubTrigger
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
"flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-brand-light-lavender data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
||||||
inset && "pl-8",
|
inset && "pl-8",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
@@ -50,7 +50,7 @@ const DropdownMenuContent = React.forwardRef(({ className, sideOffset = 4, ...pr
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
|
"z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto scrollbar-dashboard scrollbar-x-dashboard overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
|
||||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
@@ -63,7 +63,7 @@ const DropdownMenuItem = React.forwardRef(({ className, inset, ...props }, ref)
|
|||||||
<DropdownMenuPrimitive.Item
|
<DropdownMenuPrimitive.Item
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",
|
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-brand-light-lavender focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
inset && "pl-8",
|
inset && "pl-8",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const Input = React.forwardRef(({ className, type, ...props }, ref) => {
|
|||||||
<input
|
<input
|
||||||
type={type}
|
type={type}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
"flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const SelectContent = React.forwardRef(({ className, children, position = "poppe
|
|||||||
<SelectPrimitive.Content
|
<SelectPrimitive.Content
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",
|
"relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden scrollbar-dashboard scrollbar-x-dashboard rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",
|
||||||
position === "popper" &&
|
position === "popper" &&
|
||||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
className
|
className
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import React, { createContext, useState, useContext, useEffect } from 'react';
|
import React, { createContext, useState, useContext, useEffect } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import api from '../utils/api';
|
||||||
|
import logger from '../utils/logger';
|
||||||
|
|
||||||
const AuthContext = createContext();
|
const AuthContext = createContext();
|
||||||
|
|
||||||
const API_URL = process.env.REACT_APP_BACKEND_URL || window.location.origin;
|
const API_URL = process.env.REACT_APP_BACKEND_URL || window.location.origin;
|
||||||
|
|
||||||
// Log environment on module load for debugging
|
// Log environment on module load for debugging
|
||||||
console.log('[AuthContext] Module initialized with:', {
|
logger.log('[AuthContext] Module initialized with:', {
|
||||||
REACT_APP_BACKEND_URL: process.env.REACT_APP_BACKEND_URL,
|
REACT_APP_BACKEND_URL: process.env.REACT_APP_BACKEND_URL,
|
||||||
REACT_APP_BASENAME: process.env.REACT_APP_BASENAME,
|
REACT_APP_BASENAME: process.env.REACT_APP_BASENAME,
|
||||||
API_URL: API_URL
|
API_URL: API_URL
|
||||||
@@ -55,31 +57,31 @@ export const AuthProvider = ({ children }) => {
|
|||||||
});
|
});
|
||||||
setPermissions(response.data.permissions || []);
|
setPermissions(response.data.permissions || []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch permissions:', error);
|
logger.error('Failed to fetch permissions:', error);
|
||||||
setPermissions([]);
|
setPermissions([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const login = async (email, password) => {
|
const login = async (email, password) => {
|
||||||
try {
|
try {
|
||||||
console.log('[AuthContext] Starting login request...', {
|
logger.log('[AuthContext] Starting login request...', {
|
||||||
API_URL: API_URL,
|
API_URL: API_URL,
|
||||||
envBackendUrl: process.env.REACT_APP_BACKEND_URL,
|
envBackendUrl: process.env.REACT_APP_BACKEND_URL,
|
||||||
fullUrl: `${API_URL}/api/auth/login`
|
fullUrl: `${API_URL}/api/auth/login`
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await axios.post(
|
// Use api instance for retry logic
|
||||||
`${API_URL}/api/auth/login`,
|
const response = await api.post(
|
||||||
|
'/auth/login',
|
||||||
{ email, password },
|
{ email, password },
|
||||||
{
|
{
|
||||||
timeout: 30000, // 30 second timeout
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('[AuthContext] Login response received:', {
|
logger.log('[AuthContext] Login response received:', {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
hasToken: !!response.data?.access_token,
|
hasToken: !!response.data?.access_token,
|
||||||
hasUser: !!response.data?.user
|
hasUser: !!response.data?.user
|
||||||
@@ -87,39 +89,46 @@ export const AuthProvider = ({ children }) => {
|
|||||||
|
|
||||||
const { access_token, user: userData } = response.data;
|
const { access_token, user: userData } = response.data;
|
||||||
|
|
||||||
// Store token first
|
if (!access_token || !userData) {
|
||||||
localStorage.setItem('token', access_token);
|
throw new Error('Invalid response from server - missing token or user data');
|
||||||
console.log('[AuthContext] Token stored in localStorage');
|
}
|
||||||
|
|
||||||
// Update state
|
// Store token FIRST and verify it was stored
|
||||||
|
localStorage.setItem('token', access_token);
|
||||||
|
const storedToken = localStorage.getItem('token');
|
||||||
|
if (storedToken !== access_token) {
|
||||||
|
throw new Error('Failed to store token in localStorage');
|
||||||
|
}
|
||||||
|
logger.log('[AuthContext] Token stored and verified in localStorage');
|
||||||
|
|
||||||
|
// Update state in correct order
|
||||||
setToken(access_token);
|
setToken(access_token);
|
||||||
setUser(userData);
|
setUser(userData);
|
||||||
console.log('[AuthContext] User state updated:', {
|
logger.log('[AuthContext] User state updated:', {
|
||||||
email: userData.email,
|
email: userData.email,
|
||||||
role: userData.role
|
role: userData.role
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch user permissions (don't let this fail the login)
|
// Fetch permissions immediately and WAIT for it (but don't fail login if it fails)
|
||||||
// Use setTimeout to defer permission fetching slightly
|
try {
|
||||||
setTimeout(async () => {
|
logger.log('[AuthContext] Fetching permissions...');
|
||||||
try {
|
await fetchPermissions(access_token);
|
||||||
console.log('[AuthContext] Fetching permissions...');
|
logger.log('[AuthContext] Permissions fetched successfully');
|
||||||
await fetchPermissions(access_token);
|
} catch (permError) {
|
||||||
console.log('[AuthContext] Permissions fetched successfully');
|
logger.error('[AuthContext] Failed to fetch permissions (non-critical):', {
|
||||||
} catch (error) {
|
message: permError.message,
|
||||||
console.error('[AuthContext] Failed to fetch permissions (non-critical):', {
|
response: permError.response?.data,
|
||||||
message: error.message,
|
status: permError.response?.status
|
||||||
response: error.response?.data,
|
});
|
||||||
status: error.response?.status
|
// Set empty permissions array so hasPermission doesn't break
|
||||||
});
|
setPermissions([]);
|
||||||
// Don't throw - permissions can be fetched later if needed
|
// Don't throw - login succeeded even if permissions failed
|
||||||
}
|
}
|
||||||
}, 100); // Small delay to ensure state is settled
|
|
||||||
|
|
||||||
return userData;
|
return userData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Enhanced error logging
|
// Enhanced error logging
|
||||||
console.error('[AuthContext] Login failed:', {
|
logger.error('[AuthContext] Login failed:', {
|
||||||
message: error.message,
|
message: error.message,
|
||||||
response: error.response?.data,
|
response: error.response?.data,
|
||||||
status: error.response?.status,
|
status: error.response?.status,
|
||||||
@@ -131,6 +140,12 @@ export const AuthProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clear any partial state
|
||||||
|
localStorage.removeItem('token');
|
||||||
|
setToken(null);
|
||||||
|
setUser(null);
|
||||||
|
setPermissions([]);
|
||||||
|
|
||||||
// Re-throw to let Login component handle the error
|
// Re-throw to let Login component handle the error
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -160,7 +175,7 @@ export const AuthProvider = ({ children }) => {
|
|||||||
setUser(response.data);
|
setUser(response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to refresh user:', error);
|
logger.error('Failed to refresh user:', error);
|
||||||
// If token expired, logout
|
// If token expired, logout
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
logout();
|
logout();
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ const AdminLayout = ({ children }) => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Main Content Area */}
|
{/* Main Content Area */}
|
||||||
<main className="flex-1 overflow-y-auto">
|
<main className="flex-1 overflow-y-auto scrollbar-dashboard">
|
||||||
<div className="max-w-7xl mx-auto px-6 py-8">
|
<div className="max-w-7xl mx-auto px-6 py-8">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const Dashboard = () => {
|
|||||||
const [resendLoading, setResendLoading] = useState(false);
|
const [resendLoading, setResendLoading] = useState(false);
|
||||||
const [eventActivity, setEventActivity] = useState(null);
|
const [eventActivity, setEventActivity] = useState(null);
|
||||||
const [activityLoading, setActivityLoading] = useState(true);
|
const [activityLoading, setActivityLoading] = useState(true);
|
||||||
|
const joinedDate = user?.member_since || user?.created_at;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchUpcomingEvents();
|
fetchUpcomingEvents();
|
||||||
@@ -168,11 +169,11 @@ const Dashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
<Link to="/profile">
|
<Link to="/profile">
|
||||||
<Button
|
<Button
|
||||||
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background rounded-full px-6"
|
className="btn-lavender"
|
||||||
data-testid="view-profile-button"
|
data-testid="view-profile-button"
|
||||||
>
|
>
|
||||||
<User className="h-4 w-4 mr-2" />
|
<User className="h-4 w-4 mr-2" />
|
||||||
View Profile
|
Edit Profile
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -197,7 +198,7 @@ const Dashboard = () => {
|
|||||||
<div>
|
<div>
|
||||||
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Member Since</p>
|
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Member Since</p>
|
||||||
<p className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
{user?.created_at ? new Date(user.created_at).toLocaleDateString() : 'N/A'}
|
{joinedDate ? new Date(joinedDate).toLocaleDateString() : 'N/A'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{user?.subscription_start_date && user?.subscription_end_date && (
|
{user?.subscription_start_date && user?.subscription_end_date && (
|
||||||
@@ -227,8 +228,7 @@ const Dashboard = () => {
|
|||||||
</h3>
|
</h3>
|
||||||
<Link to="/events">
|
<Link to="/events">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
className="btn-lavender "
|
||||||
className="text-[var(--orange-light)] hover:text-brand-purple "
|
|
||||||
data-testid="view-all-events-button"
|
data-testid="view-all-events-button"
|
||||||
>
|
>
|
||||||
View All
|
View All
|
||||||
@@ -442,7 +442,7 @@ const Dashboard = () => {
|
|||||||
Browse upcoming events and RSVP to start building your event history!
|
Browse upcoming events and RSVP to start building your event history!
|
||||||
</p>
|
</p>
|
||||||
<Link to="/events">
|
<Link to="/events">
|
||||||
<Button className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background rounded-full px-6">
|
<Button className="bg-[var(--purple-lavender)] text-white hover:bg-[var(--purple-muted)] rounded-full dark:hover:bg-brand-lavender dark:hover:text-brand-dark-lavender px-6">
|
||||||
<Calendar className="h-4 w-4 mr-2" />
|
<Calendar className="h-4 w-4 mr-2" />
|
||||||
Browse Events
|
Browse Events
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ const EventDetails = () => {
|
|||||||
disabled={rsvpLoading}
|
disabled={rsvpLoading}
|
||||||
className={`rounded-full px-8 py-6 flex items-center gap-2 ${event.user_rsvp_status === 'yes'
|
className={`rounded-full px-8 py-6 flex items-center gap-2 ${event.user_rsvp_status === 'yes'
|
||||||
? 'bg-[var(--green-light)] text-white'
|
? 'bg-[var(--green-light)] text-white'
|
||||||
: 'bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background'
|
: 'bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-brand-lavender'
|
||||||
}`}
|
}`}
|
||||||
data-testid="rsvp-yes-button"
|
data-testid="rsvp-yes-button"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import MemberFooter from '../components/MemberFooter';
|
|||||||
import { User, Save, Lock, Heart, Users, Mail, BookUser, Camera, Upload, Trash2 } from 'lucide-react';
|
import { User, Save, Lock, Heart, Users, Mail, BookUser, Camera, Upload, Trash2 } from 'lucide-react';
|
||||||
import { Avatar, AvatarImage, AvatarFallback } from '../components/ui/avatar';
|
import { Avatar, AvatarImage, AvatarFallback } from '../components/ui/avatar';
|
||||||
import ChangePasswordDialog from '../components/ChangePasswordDialog';
|
import ChangePasswordDialog from '../components/ChangePasswordDialog';
|
||||||
|
import TransactionHistory from '../components/TransactionHistory';
|
||||||
|
|
||||||
const Profile = () => {
|
const Profile = () => {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
@@ -24,6 +25,8 @@ const Profile = () => {
|
|||||||
const fileInputRef = useRef(null);
|
const fileInputRef = useRef(null);
|
||||||
const [maxFileSizeMB, setMaxFileSizeMB] = useState(50); // Default 50MB
|
const [maxFileSizeMB, setMaxFileSizeMB] = useState(50); // Default 50MB
|
||||||
const [maxFileSizeBytes, setMaxFileSizeBytes] = useState(52428800); // Default 50MB in bytes
|
const [maxFileSizeBytes, setMaxFileSizeBytes] = useState(52428800); // Default 50MB in bytes
|
||||||
|
const [transactions, setTransactions] = useState({ subscriptions: [], donations: [] });
|
||||||
|
const [transactionsLoading, setTransactionsLoading] = useState(true);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
// Personal Information
|
// Personal Information
|
||||||
first_name: '',
|
first_name: '',
|
||||||
@@ -58,6 +61,7 @@ const Profile = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConfig();
|
fetchConfig();
|
||||||
fetchProfile();
|
fetchProfile();
|
||||||
|
fetchTransactions();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchConfig = async () => {
|
const fetchConfig = async () => {
|
||||||
@@ -112,6 +116,19 @@ const Profile = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchTransactions = async () => {
|
||||||
|
try {
|
||||||
|
setTransactionsLoading(true);
|
||||||
|
const response = await api.get('/members/transactions');
|
||||||
|
setTransactions(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load transactions:', error);
|
||||||
|
// Don't show error toast - transactions are optional
|
||||||
|
} finally {
|
||||||
|
setTransactionsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleInputChange = (e) => {
|
const handleInputChange = (e) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
setFormData(prev => ({ ...prev, [name]: value }));
|
setFormData(prev => ({ ...prev, [name]: value }));
|
||||||
@@ -703,6 +720,18 @@ const Profile = () => {
|
|||||||
open={passwordDialogOpen}
|
open={passwordDialogOpen}
|
||||||
onOpenChange={setPasswordDialogOpen}
|
onOpenChange={setPasswordDialogOpen}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Transaction History Section */}
|
||||||
|
<div className="mt-8">
|
||||||
|
<TransactionHistory
|
||||||
|
subscriptions={transactions.subscriptions}
|
||||||
|
donations={transactions.donations}
|
||||||
|
totalSubscriptionCents={transactions.total_subscription_amount_cents}
|
||||||
|
totalDonationCents={transactions.total_donation_amount_cents}
|
||||||
|
loading={transactionsLoading}
|
||||||
|
isAdmin={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<MemberFooter />
|
<MemberFooter />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ const Register = () => {
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleNext}
|
onClick={handleNext}
|
||||||
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background rounded-full px-6 py-6 text-lg font-medium shadow-lg hover:scale-105 transition-transform"
|
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-brand-purple hover:text-background rounded-full px-6 py-6 text-lg font-medium shadow-lg hover:scale-105 transition-transform"
|
||||||
>
|
>
|
||||||
Next
|
Next
|
||||||
<ArrowRight className="ml-2 h-5 w-5" />
|
<ArrowRight className="ml-2 h-5 w-5" />
|
||||||
@@ -267,7 +267,7 @@ const Register = () => {
|
|||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background rounded-full px-6 py-6 text-lg font-medium shadow-lg hover:scale-105 transition-transform disabled:opacity-50 disabled:cursor-not-allowed"
|
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-brand-purple hover:text-backgroundrounded-full px-6 py-6 text-lg font-medium shadow-lg hover:scale-105 transition-transform disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
data-testid="submit-register-button"
|
data-testid="submit-register-button"
|
||||||
>
|
>
|
||||||
{loading ? 'Creating Account...' : 'Create Account'}
|
{loading ? 'Creating Account...' : 'Create Account'}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ const AdminBylaws = () => {
|
|||||||
{currentBylaws.title}
|
{currentBylaws.title}
|
||||||
</h3>
|
</h3>
|
||||||
<div className="flex items-center gap-2 mt-1">
|
<div className="flex items-center gap-2 mt-1">
|
||||||
<Badge className="bg-[var(--green-light)] text-white">
|
<Badge variant={'green'} className="">
|
||||||
<Check className="h-3 w-3 mr-1" />
|
<Check className="h-3 w-3 mr-1" />
|
||||||
Current Version
|
Current Version
|
||||||
</Badge>
|
</Badge>
|
||||||
@@ -222,7 +222,7 @@ const AdminBylaws = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => window.open(currentBylaws.document_url, '_blank')}
|
onClick={() => window.open(currentBylaws.document_url, '_blank')}
|
||||||
className="border-brand-purple text-brand-purple "
|
className="border-brand-purple text-brand-purple "
|
||||||
@@ -242,10 +242,10 @@ const AdminBylaws = () => {
|
|||||||
)}
|
)}
|
||||||
{hasPermission('bylaws.delete') && (
|
{hasPermission('bylaws.delete') && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline-destructive"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleDelete(currentBylaws)}
|
onClick={() => handleDelete(currentBylaws)}
|
||||||
className="border-red-500 text-red-500 hover:bg-red-50"
|
className="border-red-500 text-red-500"
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4" />
|
<Trash2 className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -4,13 +4,16 @@ import api from '../../utils/api';
|
|||||||
import { Card } from '../../components/ui/card';
|
import { Card } from '../../components/ui/card';
|
||||||
import { Button } from '../../components/ui/button';
|
import { Button } from '../../components/ui/button';
|
||||||
import { Badge } from '../../components/ui/badge';
|
import { Badge } from '../../components/ui/badge';
|
||||||
import { Users, Calendar, Clock, CheckCircle, Mail, AlertCircle, Globe } from 'lucide-react';
|
import { Users, Calendar, Clock, CheckCircle, Mail, AlertCircle, Globe, CircleMinus } from 'lucide-react';
|
||||||
|
import { StatCard } from '../../components/StatCard';
|
||||||
|
|
||||||
|
|
||||||
const AdminDashboard = () => {
|
const AdminDashboard = () => {
|
||||||
const [stats, setStats] = useState({
|
const [stats, setStats] = useState({
|
||||||
totalMembers: 0,
|
totalMembers: 0,
|
||||||
pendingValidations: 0,
|
pendingValidations: 0,
|
||||||
activeMembers: 0
|
activeMembers: 0,
|
||||||
|
inactiveMembers: 0
|
||||||
});
|
});
|
||||||
const [usersNeedingAttention, setUsersNeedingAttention] = useState([]);
|
const [usersNeedingAttention, setUsersNeedingAttention] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -29,7 +32,8 @@ const AdminDashboard = () => {
|
|||||||
pendingValidations: users.filter(u =>
|
pendingValidations: users.filter(u =>
|
||||||
['pending_email', 'pending_validation', 'pre_validated', 'payment_pending'].includes(u.status)
|
['pending_email', 'pending_validation', 'pre_validated', 'payment_pending'].includes(u.status)
|
||||||
).length,
|
).length,
|
||||||
activeMembers: users.filter(u => u.status === 'active' && u.role === 'member').length
|
activeMembers: users.filter(u => u.status === 'active' && u.role === 'member').length,
|
||||||
|
inactiveMembers: users.filter(u => u.status === 'inactive' && u.role === 'member').length
|
||||||
});
|
});
|
||||||
|
|
||||||
// Find users who have received 3+ reminders (may need personal outreach)
|
// Find users who have received 3+ reminders (may need personal outreach)
|
||||||
@@ -76,42 +80,42 @@ const AdminDashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Stats Grid */}
|
{/* Stats Grid */}
|
||||||
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6 mb-12">
|
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]" data-testid="stat-total-users">
|
|
||||||
<div className="flex items-center justify-between mb-4">
|
|
||||||
<div className="bg-[var(--neutral-800)]/20 p-3 rounded-lg">
|
|
||||||
<Users className="h-6 w-6 text-brand-purple" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p className="text-3xl font-semibold text-[var(--purple-ink)] mb-1" style={{ fontFamily: "'Inter', sans-serif" }}>
|
|
||||||
{loading ? '-' : stats.totalMembers}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Total Members</p>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]" data-testid="stat-pending-validations">
|
<div className='rounded-3xl bg-brand-lavender/10 p-8 mb-8'>
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className=' text-2xl text-[var(--purple-ink)] pb-8 font-semibold'>
|
||||||
<div className=" p-3 rounded-lg">
|
Quick Overview
|
||||||
<Clock className="h-6 w-6 text-orange-600" />
|
</div>
|
||||||
</div>
|
<div className="grid md:grid-cols-2 lg:grid-cols-4 gap-8 ">
|
||||||
</div>
|
<StatCard
|
||||||
<p className="text-3xl font-semibold text-[var(--purple-ink)] mb-1" style={{ fontFamily: "'Inter', sans-serif" }}>
|
title="Total Members"
|
||||||
{loading ? '-' : stats.pendingValidations}
|
value={loading ? '-' : stats.totalMembers}
|
||||||
</p>
|
icon={Users}
|
||||||
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Pending Validations</p>
|
iconBgClass="text-brand-purple"
|
||||||
</Card>
|
dataTestId="stat-total-users"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="Pending Validations"
|
||||||
|
value={loading ? '-' : stats.pendingValidations}
|
||||||
|
icon={Clock}
|
||||||
|
iconBgClass="text-brand-light-orange"
|
||||||
|
dataTestId="stat-total-users"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="Active Members"
|
||||||
|
value={loading ? '-' : stats.activeMembers}
|
||||||
|
icon={CheckCircle}
|
||||||
|
iconBgClass="text-[var(--green-light)]"
|
||||||
|
dataTestId="stat-total-users"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="Inactive Members"
|
||||||
|
value={loading ? '-' : stats.inactiveMembers}
|
||||||
|
icon={CircleMinus}
|
||||||
|
iconBgClass="text-brand-pink"
|
||||||
|
dataTestId="stat-total-users"
|
||||||
|
/>
|
||||||
|
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]" data-testid="stat-active-members">
|
</div>
|
||||||
<div className="flex items-center justify-between mb-4">
|
|
||||||
<div className="bg-[var(--green-light)]/20 p-3 rounded-lg">
|
|
||||||
<CheckCircle className="h-6 w-6 text-[var(--green-light)]" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p className="text-3xl font-semibold text-[var(--purple-ink)] mb-1" style={{ fontFamily: "'Inter', sans-serif" }}>
|
|
||||||
{loading ? '-' : stats.activeMembers}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Active Members</p>
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Quick Actions */}
|
{/* Quick Actions */}
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ import {
|
|||||||
Loader2,
|
Loader2,
|
||||||
Download,
|
Download,
|
||||||
FileDown,
|
FileDown,
|
||||||
Calendar
|
Calendar,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
ExternalLink,
|
||||||
|
Copy,
|
||||||
|
CreditCard,
|
||||||
|
Info
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
|
||||||
const AdminDonations = () => {
|
const AdminDonations = () => {
|
||||||
@@ -43,6 +49,7 @@ const AdminDonations = () => {
|
|||||||
const [statusFilter, setStatusFilter] = useState('all');
|
const [statusFilter, setStatusFilter] = useState('all');
|
||||||
const [startDate, setStartDate] = useState('');
|
const [startDate, setStartDate] = useState('');
|
||||||
const [endDate, setEndDate] = useState('');
|
const [endDate, setEndDate] = useState('');
|
||||||
|
const [expandedRows, setExpandedRows] = useState(new Set());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData();
|
fetchData();
|
||||||
@@ -157,6 +164,27 @@ const AdminDonations = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleRowExpansion = (donationId) => {
|
||||||
|
setExpandedRows((prev) => {
|
||||||
|
const newExpanded = new Set(prev);
|
||||||
|
if (newExpanded.has(donationId)) {
|
||||||
|
newExpanded.delete(donationId);
|
||||||
|
} else {
|
||||||
|
newExpanded.add(donationId);
|
||||||
|
}
|
||||||
|
return newExpanded;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = async (text, label) => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
toast.success(`${label} copied to clipboard`);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Failed to copy to clipboard');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getStatusBadgeVariant = (status) => {
|
const getStatusBadgeVariant = (status) => {
|
||||||
const variants = {
|
const variants = {
|
||||||
completed: 'default',
|
completed: 'default',
|
||||||
@@ -385,12 +413,15 @@ const AdminDonations = () => {
|
|||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
Payment Method
|
Payment Method
|
||||||
</th>
|
</th>
|
||||||
|
<th className="px-6 py-4 text-center text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Details
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="divide-y divide-[var(--neutral-800)]">
|
<tbody className="divide-y divide-[var(--neutral-800)]">
|
||||||
{filteredDonations.length === 0 ? (
|
{filteredDonations.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan="6" className="px-6 py-12 text-center">
|
<td colSpan="7" className="px-6 py-12 text-center">
|
||||||
<div className="flex flex-col items-center gap-3">
|
<div className="flex flex-col items-center gap-3">
|
||||||
<Heart className="h-12 w-12 text-[var(--neutral-800)]" />
|
<Heart className="h-12 w-12 text-[var(--neutral-800)]" />
|
||||||
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
@@ -400,51 +431,182 @@ const AdminDonations = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : (
|
) : (
|
||||||
filteredDonations.map((donation) => (
|
filteredDonations.map((donation) => {
|
||||||
<tr key={donation.id} className="hover:bg-[var(--lavender-400)] transition-colors">
|
const isExpanded = expandedRows.has(donation.id);
|
||||||
<td className="px-6 py-4">
|
return (
|
||||||
<div>
|
<React.Fragment key={donation.id}>
|
||||||
<p className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<tr className="hover:bg-[var(--lavender-400)] transition-colors">
|
||||||
{donation.donor_name || 'Anonymous'}
|
<td className="px-6 py-4">
|
||||||
</p>
|
<div>
|
||||||
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{donation.donor_email || 'No email'}
|
{donation.donor_name || 'Anonymous'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
</td>
|
{donation.donor_email || 'No email'}
|
||||||
<td className="px-6 py-4">
|
</p>
|
||||||
<Badge
|
</div>
|
||||||
className={`${getTypeBadgeColor(donation.donation_type)} text-white border-none rounded-full px-3 py-1`}
|
</td>
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
<td className="px-6 py-4">
|
||||||
>
|
<Badge
|
||||||
{donation.donation_type === 'member' ? 'Member' : 'Public'}
|
className={`${getTypeBadgeColor(donation.donation_type)} text-white border-none rounded-full px-3 py-1`}
|
||||||
</Badge>
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
</td>
|
>
|
||||||
<td className="px-6 py-4">
|
{donation.donation_type === 'member' ? 'Member' : 'Public'}
|
||||||
<p className="font-semibold text-[var(--purple-ink)] text-lg" style={{ fontFamily: "'Inter', sans-serif" }}>
|
</Badge>
|
||||||
{donation.amount}
|
</td>
|
||||||
</p>
|
<td className="px-6 py-4">
|
||||||
</td>
|
<p className="font-semibold text-[var(--purple-ink)] text-lg" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
<td className="px-6 py-4">
|
{donation.amount}
|
||||||
<Badge variant={getStatusBadgeVariant(donation.status)} className="rounded-full">
|
</p>
|
||||||
{donation.status.charAt(0).toUpperCase() + donation.status.slice(1)}
|
</td>
|
||||||
</Badge>
|
<td className="px-6 py-4">
|
||||||
</td>
|
<Badge variant={getStatusBadgeVariant(donation.status)} className="rounded-full">
|
||||||
<td className="px-6 py-4">
|
{donation.status.charAt(0).toUpperCase() + donation.status.slice(1)}
|
||||||
<div className="flex items-center gap-2 text-brand-purple ">
|
</Badge>
|
||||||
<Calendar className="h-4 w-4" />
|
</td>
|
||||||
<span style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<td className="px-6 py-4">
|
||||||
{formatDate(donation.created_at)}
|
<div className="flex items-center gap-2 text-brand-purple ">
|
||||||
</span>
|
<Calendar className="h-4 w-4" />
|
||||||
</div>
|
<span style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
</td>
|
{formatDate(donation.created_at)}
|
||||||
<td className="px-6 py-4">
|
</span>
|
||||||
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
</div>
|
||||||
{donation.payment_method || 'N/A'}
|
</td>
|
||||||
</p>
|
<td className="px-6 py-4">
|
||||||
</td>
|
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
</tr>
|
{donation.payment_method || 'N/A'}
|
||||||
))
|
</p>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 text-center">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => toggleRowExpansion(donation.id)}
|
||||||
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
|
>
|
||||||
|
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||||||
|
</Button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/* Expandable Details Row */}
|
||||||
|
{isExpanded && (
|
||||||
|
<tr className="bg-[var(--lavender-400)]/30">
|
||||||
|
<td colSpan="7" className="px-6 py-6">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h4 className="font-semibold text-[var(--purple-ink)] text-lg mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Transaction Details
|
||||||
|
</h4>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
|
{/* Payment Information */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h5 className="font-medium text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<CreditCard className="h-4 w-4" />
|
||||||
|
Payment Information
|
||||||
|
</h5>
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
{donation.payment_completed_at && (
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-brand-purple ">Payment Date:</span>
|
||||||
|
<span className="text-[var(--purple-ink)] font-medium">{formatDate(donation.payment_completed_at)}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{donation.payment_method && (
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-brand-purple ">Payment Method:</span>
|
||||||
|
<span className="text-[var(--purple-ink)] font-medium capitalize">{donation.payment_method}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{donation.card_brand && donation.card_last4 && (
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-brand-purple ">Card:</span>
|
||||||
|
<span className="text-[var(--purple-ink)] font-medium">{donation.card_brand} ****{donation.card_last4}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Stripe Transaction IDs */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h5 className="font-medium text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<Info className="h-4 w-4" />
|
||||||
|
Stripe Transaction IDs
|
||||||
|
</h5>
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
{donation.stripe_payment_intent_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Payment Intent:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{donation.stripe_payment_intent_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(donation.stripe_payment_intent_id, 'Payment Intent ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{donation.stripe_charge_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Charge ID:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{donation.stripe_charge_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(donation.stripe_charge_id, 'Charge ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{donation.stripe_customer_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Customer ID:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{donation.stripe_customer_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(donation.stripe_customer_id, 'Customer ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{donation.stripe_receipt_url && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Receipt:</span>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => window.open(donation.stripe_receipt_url, '_blank')}
|
||||||
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-3 w-3 mr-1" />
|
||||||
|
View Receipt
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
})
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ const AdminEventAttendance = () => {
|
|||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={exportToCSV}
|
onClick={exportToCSV}
|
||||||
className="bg-[var(--green-light)] hover:bg-[var(--green-eucalyptus)] text-white rounded-xl"
|
className="bg-[var(--green-light)] hover:bg-[var(--green-eucalyptus)] dark:bg-[var(--green-forest)] text-white rounded-xl"
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
>
|
>
|
||||||
<Download className="h-4 w-4 mr-2" />
|
<Download className="h-4 w-4 mr-2" />
|
||||||
@@ -282,7 +282,7 @@ const AdminEventAttendance = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Badge className={`${event.published ? 'bg-[var(--green-light)]' : 'bg-[var(--neutral-800)]'} text-white px-3 py-1`}>
|
<Badge className={`${event.published ? 'bg-[var(--green-light)] dark:bg-[var(--green-forest)]' : 'bg-[var(--neutral-800)]'} text-white px-3 py-1`}>
|
||||||
{event.published ? 'Published' : 'Draft'}
|
{event.published ? 'Published' : 'Draft'}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
@@ -302,7 +302,7 @@ const AdminEventAttendance = () => {
|
|||||||
|
|
||||||
<Card className="p-4 bg-background border-[var(--neutral-800)] rounded-xl">
|
<Card className="p-4 bg-background border-[var(--neutral-800)] rounded-xl">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<UserCheck className="h-8 w-8 text-[var(--green-light)]" />
|
<UserCheck className="h-8 w-8 text-[var(--green-light)] dark:text-[var(--green-forest)]" />
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Yes</p>
|
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Yes</p>
|
||||||
<p className="text-2xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>{stats.yesCount}</p>
|
<p className="text-2xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>{stats.yesCount}</p>
|
||||||
@@ -320,7 +320,7 @@ const AdminEventAttendance = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card className="p-4 bg-background border-[var(--neutral-800)] rounded-xl">
|
<Card className="p-4 bg-background border-[var(--neutral-800)] rounded-xl">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<HelpCircle className="h-8 w-8 text-[var(--gold-warm)]" />
|
<HelpCircle className="h-8 w-8 text-[var(--gold-warm)]" />
|
||||||
<div>
|
<div>
|
||||||
@@ -350,7 +350,7 @@ const AdminEventAttendance = () => {
|
|||||||
onClick={() => setActiveTab('all')}
|
onClick={() => setActiveTab('all')}
|
||||||
variant={activeTab === 'all' ? 'default' : 'outline'}
|
variant={activeTab === 'all' ? 'default' : 'outline'}
|
||||||
className={`rounded-xl ${activeTab === 'all'
|
className={`rounded-xl ${activeTab === 'all'
|
||||||
? 'bg-brand-purple hover:bg-[var(--purple-ink)] text-white'
|
? 'bg-brand-purple hover:bg-[var(--purple-ink)] dark:bg-brand-dark-lavender text-white'
|
||||||
: 'border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-500)]'
|
: 'border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-500)]'
|
||||||
}`}
|
}`}
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
@@ -361,7 +361,7 @@ const AdminEventAttendance = () => {
|
|||||||
onClick={() => setActiveTab('yes')}
|
onClick={() => setActiveTab('yes')}
|
||||||
variant={activeTab === 'yes' ? 'default' : 'outline'}
|
variant={activeTab === 'yes' ? 'default' : 'outline'}
|
||||||
className={`rounded-xl ${activeTab === 'yes'
|
className={`rounded-xl ${activeTab === 'yes'
|
||||||
? 'bg-[var(--green-light)] hover:bg-[var(--green-eucalyptus)] text-white'
|
? 'bg-[var(--green-light)] hover:bg-[var(--green-eucalyptus)] dark:bg-[var(--green-forest)] text-white'
|
||||||
: 'border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-500)]'
|
: 'border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-500)]'
|
||||||
}`}
|
}`}
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
@@ -383,7 +383,7 @@ const AdminEventAttendance = () => {
|
|||||||
onClick={() => setActiveTab('maybe')}
|
onClick={() => setActiveTab('maybe')}
|
||||||
variant={activeTab === 'maybe' ? 'default' : 'outline'}
|
variant={activeTab === 'maybe' ? 'default' : 'outline'}
|
||||||
className={`rounded-xl ${activeTab === 'maybe'
|
className={`rounded-xl ${activeTab === 'maybe'
|
||||||
? 'bg-[var(--gold-warm)] hover:bg-[var(--gold-soft)] text-[var(--purple-ink)]'
|
? 'bg-[var(--gold-warm)] dark:bg-orange-400 hover:bg-[var(--gold-soft)] text-white'
|
||||||
: 'border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-500)]'
|
: 'border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-500)]'
|
||||||
}`}
|
}`}
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
@@ -483,7 +483,7 @@ const AdminEventAttendance = () => {
|
|||||||
<td className="px-4 py-3">
|
<td className="px-4 py-3">
|
||||||
<Badge
|
<Badge
|
||||||
className={`${rsvp.rsvp_status === 'yes'
|
className={`${rsvp.rsvp_status === 'yes'
|
||||||
? 'bg-[var(--green-light)]'
|
? 'bg-[var(--green-light)] dark:bg-[var(--green-forest)]'
|
||||||
: rsvp.rsvp_status === 'no'
|
: rsvp.rsvp_status === 'no'
|
||||||
? 'bg-[var(--orange-soft)]'
|
? 'bg-[var(--orange-soft)]'
|
||||||
: 'bg-[var(--gold-warm)] text-[var(--purple-ink)]'
|
: 'bg-[var(--gold-warm)] text-[var(--purple-ink)]'
|
||||||
@@ -498,7 +498,7 @@ const AdminEventAttendance = () => {
|
|||||||
onClick={() => handleIndividualAttendance(rsvp.user_id, false)}
|
onClick={() => handleIndividualAttendance(rsvp.user_id, false)}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="bg-[var(--green-light)] hover:bg-[var(--green-eucalyptus)] text-white rounded-lg min-w-[120px]"
|
className="bg-[var(--green-light)] dark:bg-[var(--green-forest)] hover:bg-[var(--green-eucalyptus)] text-white rounded-lg min-w-[120px]"
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
>
|
>
|
||||||
<Check className="h-3 w-3 mr-1" />
|
<Check className="h-3 w-3 mr-1" />
|
||||||
@@ -510,7 +510,7 @@ const AdminEventAttendance = () => {
|
|||||||
disabled={saving}
|
disabled={saving}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--green-light)] hover:text-white hover:border-[var(--green-light)] rounded-lg min-w-[120px]"
|
className="border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--green-light)] dark:bg-[var(--green-forest)] hover:text-white hover:border-[var(--green-light)] dark:bg-[var(--green-forest)] rounded-lg min-w-[120px]"
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
>
|
>
|
||||||
<X className="h-3 w-3 mr-1" />
|
<X className="h-3 w-3 mr-1" />
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ const AdminEvents = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
|
|
||||||
<DialogContent className="max-w-[calc(100vw-2rem)] sm:max-w-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="max-w-[calc(100vw-2rem)] sm:max-w-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="text-2xl text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<DialogTitle className="text-2xl text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{editingEvent ? 'Edit Event' : 'Create New Event'}
|
{editingEvent ? 'Edit Event' : 'Create New Event'}
|
||||||
@@ -186,7 +186,7 @@ const AdminEvents = () => {
|
|||||||
value={formData.description}
|
value={formData.description}
|
||||||
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
|
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
|
||||||
rows={4}
|
rows={4}
|
||||||
className="w-full border-2 border-[var(--neutral-800)] focus:border-brand-purple rounded-lg p-3"
|
className="w-full border-2 border-[var(--neutral-800)] bg-background focus:border-brand-purple rounded-lg p-3"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ const AdminEvents = () => {
|
|||||||
id="published"
|
id="published"
|
||||||
checked={formData.published}
|
checked={formData.published}
|
||||||
onChange={(e) => setFormData({ ...formData, published: e.target.checked })}
|
onChange={(e) => setFormData({ ...formData, published: e.target.checked })}
|
||||||
className="w-4 h-4 text-brand-purple border-[var(--neutral-800)] rounded focus:ring-brand-purple "
|
className="w-4 h-4 ui-checkbox text-brand-purple border-[var(--neutral-800)] rounded focus:ring-brand-purple "
|
||||||
/>
|
/>
|
||||||
<label htmlFor="published" className="text-sm font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<label htmlFor="published" className="text-sm font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
Publish event (make visible to members)
|
Publish event (make visible to members)
|
||||||
@@ -267,7 +267,7 @@ const AdminEvents = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="flex-1 bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background rounded-full"
|
className="btn-lavender flex-1"
|
||||||
>
|
>
|
||||||
{editingEvent ? 'Update Event' : 'Create Event'}
|
{editingEvent ? 'Update Event' : 'Create Event'}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -297,8 +297,9 @@ const AdminEvents = () => {
|
|||||||
<Calendar className="h-6 w-6 text-brand-purple " />
|
<Calendar className="h-6 w-6 text-brand-purple " />
|
||||||
</div>
|
</div>
|
||||||
<Badge
|
<Badge
|
||||||
|
|
||||||
className={`${event.published
|
className={`${event.published
|
||||||
? 'bg-[var(--green-light)] text-white'
|
? 'border-transparent bg-[var(--green-light)] text-white hover:bg-[var(--green-forest)]'
|
||||||
: 'bg-gray-400 text-white'
|
: 'bg-gray-400 text-white'
|
||||||
} px-3 py-1 rounded-full`}
|
} px-3 py-1 rounded-full`}
|
||||||
>
|
>
|
||||||
@@ -345,7 +346,7 @@ const AdminEvents = () => {
|
|||||||
onClick={() => navigate(`/admin/events/${event.id}/attendance`)}
|
onClick={() => navigate(`/admin/events/${event.id}/attendance`)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="w-full border-[var(--green-light)] text-[var(--green-light)] hover:bg-[var(--green-light)] hover:text-white"
|
className="w-full border-[var(--green-light)] text-[var(--green-light)] hover:bg-[var(--green-light)] hover:text-white dark:hover:text-background"
|
||||||
data-testid={`mark-attendance-${event.id}`}
|
data-testid={`mark-attendance-${event.id}`}
|
||||||
>
|
>
|
||||||
<Users className="h-4 w-4 mr-2" />
|
<Users className="h-4 w-4 mr-2" />
|
||||||
@@ -358,7 +359,7 @@ const AdminEvents = () => {
|
|||||||
onClick={() => togglePublish(event)}
|
onClick={() => togglePublish(event)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 border-brand-purple text-brand-purple hover:bg-brand-purple hover:text-white"
|
className="flex-1 border-brand-purple text-brand-purple hover:bg-brand-purple hover:text-white dark:hover:bg-brand-lavender dark:hover:text-background"
|
||||||
data-testid={`toggle-publish-${event.id}`}
|
data-testid={`toggle-publish-${event.id}`}
|
||||||
>
|
>
|
||||||
{event.published ? (
|
{event.published ? (
|
||||||
@@ -377,7 +378,7 @@ const AdminEvents = () => {
|
|||||||
onClick={() => handleEdit(event)}
|
onClick={() => handleEdit(event)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="border-gray-400 text-gray-600 hover:bg-gray-400 hover:text-white"
|
className="border-gray-400 text-gray-600 dark:text-gray-400 hover:bg-gray-400 dark:hover:text-background hover:text-white"
|
||||||
data-testid={`edit-event-${event.id}`}
|
data-testid={`edit-event-${event.id}`}
|
||||||
>
|
>
|
||||||
<Edit className="h-4 w-4" />
|
<Edit className="h-4 w-4" />
|
||||||
@@ -407,7 +408,7 @@ const AdminEvents = () => {
|
|||||||
</p>
|
</p>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setIsCreateDialogOpen(true)}
|
onClick={() => setIsCreateDialogOpen(true)}
|
||||||
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background rounded-full px-8"
|
className="btn-lavender px-8"
|
||||||
>
|
>
|
||||||
<Plus className="mr-2 h-5 w-5" />
|
<Plus className="mr-2 h-5 w-5" />
|
||||||
Create Event
|
Create Event
|
||||||
|
|||||||
@@ -229,10 +229,10 @@ const AdminFinancials = () => {
|
|||||||
)}
|
)}
|
||||||
{hasPermission('financials.delete') && (
|
{hasPermission('financials.delete') && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline-destructive"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleDelete(report)}
|
onClick={() => handleDelete(report)}
|
||||||
className="border-red-500 text-red-500 hover:bg-red-50"
|
className=""
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4" />
|
<Trash2 className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ const AdminGallery = () => {
|
|||||||
|
|
||||||
{/* Empty State Message */}
|
{/* Empty State Message */}
|
||||||
{events.length === 0 && (
|
{events.length === 0 && (
|
||||||
<div className="mt-4 p-4 bg-[var(--lavender-300)] border-2 border-[var(--neutral-800)] rounded-xl">
|
<div className="mt-4 p-4 bg-[var(--lavender-300)] dark:bg-brand-lavender/10 dark:border-transparent border-2 border-[var(--neutral-800)] rounded-xl">
|
||||||
<div className="flex items-start gap-3">
|
<div className="flex items-start gap-3">
|
||||||
<AlertCircle className="h-5 w-5 text-brand-purple flex-shrink-0 mt-0.5" />
|
<AlertCircle className="h-5 w-5 text-brand-purple flex-shrink-0 mt-0.5" />
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
@@ -196,7 +196,7 @@ const AdminGallery = () => {
|
|||||||
</p>
|
</p>
|
||||||
<Link to="/admin/events">
|
<Link to="/admin/events">
|
||||||
<Button
|
<Button
|
||||||
className="btn-lavender text-sm"
|
className="btn-lavender text-sm"
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
>
|
>
|
||||||
<Calendar className="h-4 w-4 mr-2" />
|
<Calendar className="h-4 w-4 mr-2" />
|
||||||
|
|||||||
@@ -14,12 +14,13 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '../../components/ui/dropdown-menu';
|
} from '../../components/ui/dropdown-menu';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { Users, Search, User, CreditCard, Eye, CheckCircle, Calendar, AlertCircle, Clock, Mail, UserPlus, Upload, Download, FileDown, ChevronDown } from 'lucide-react';
|
import { Users, Search, User, CreditCard, Eye, CheckCircle, Calendar, AlertCircle, Clock, Mail, UserPlus, Upload, Download, FileDown, ChevronDown, CircleMinus } from 'lucide-react';
|
||||||
import PaymentActivationDialog from '../../components/PaymentActivationDialog';
|
import PaymentActivationDialog from '../../components/PaymentActivationDialog';
|
||||||
import ConfirmationDialog from '../../components/ConfirmationDialog';
|
import ConfirmationDialog from '../../components/ConfirmationDialog';
|
||||||
import CreateMemberDialog from '../../components/CreateMemberDialog';
|
import CreateMemberDialog from '../../components/CreateMemberDialog';
|
||||||
import InviteStaffDialog from '../../components/InviteStaffDialog';
|
import InviteStaffDialog from '../../components/InviteStaffDialog';
|
||||||
import WordPressImportWizard from '../../components/WordPressImportWizard';
|
import WordPressImportWizard from '../../components/WordPressImportWizard';
|
||||||
|
import { StatCard } from '@/components/StatCard';
|
||||||
|
|
||||||
const AdminMembers = () => {
|
const AdminMembers = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -319,31 +320,45 @@ const AdminMembers = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Stats */}
|
{/* Stats */}
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4 mb-8">
|
<div className='rounded-3xl bg-brand-lavender/10 p-8 mb-8'>
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
<div className=' text-2xl text-[var(--purple-ink)] pb-8 font-semibold'>
|
||||||
<p className="text-sm text-brand-purple dark:text-brand-lavender mb-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Total Members</p>
|
Quick Overview
|
||||||
<p className="text-4xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
</div>
|
||||||
{users.length}
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
</p>
|
|
||||||
</Card>
|
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
<StatCard
|
||||||
<p className="text-sm text-brand-purple dark:text-brand-lavender mb-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Active</p>
|
title="Total Members"
|
||||||
<p className="text-4xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
value={users.length}
|
||||||
{users.filter(u => u.status === 'active').length}
|
icon={Users}
|
||||||
</p>
|
iconBgClass="bg-[var(--blue-light)] text-[var(--blue-dark)]"
|
||||||
</Card>
|
dataTestId="stat-total-members"
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
/>
|
||||||
<p className="text-sm text-brand-purple dark:text-brand-lavender mb-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Payment Pending</p>
|
<StatCard
|
||||||
<p className="text-4xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
title="Active"
|
||||||
{users.filter(u => u.status === 'payment_pending').length}
|
value={users.filter(u => u.status === 'active').length}
|
||||||
</p>
|
icon={CheckCircle}
|
||||||
</Card>
|
iconBgClass="text-[var(--green-light)]"
|
||||||
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
dataTestId="stat-active-members"
|
||||||
<p className="text-sm text-brand-purple dark:text-brand-lavender mb-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Inactive</p>
|
/>
|
||||||
<p className="text-4xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<StatCard
|
||||||
{users.filter(u => u.status === 'inactive').length}
|
title="Payment Pending"
|
||||||
</p>
|
value={users.filter(u => u.status === 'payment_pending').length}
|
||||||
</Card>
|
icon={CreditCard}
|
||||||
|
iconBgClass="text-brand-light-orange"
|
||||||
|
dataTestId="stat-payment-pending-members"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="Inactive"
|
||||||
|
value={users.filter(u => u.status === 'inactive').length}
|
||||||
|
icon={CircleMinus}
|
||||||
|
iconBgClass=" text-brand-pink"
|
||||||
|
dataTestId="stat-inactive-members"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Filters */}
|
{/* Filters */}
|
||||||
@@ -385,145 +400,148 @@ const AdminMembers = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : filteredUsers.length > 0 ? (
|
) : filteredUsers.length > 0 ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{filteredUsers.map((user) => (
|
{filteredUsers.map((user) => {
|
||||||
<Card
|
const joinedDate = user.member_since || user.created_at;
|
||||||
key={user.id}
|
return (
|
||||||
className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)] hover:shadow-md transition-shadow"
|
<Card
|
||||||
data-testid={`member-card-${user.id}`}
|
key={user.id}
|
||||||
>
|
className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)] hover:shadow-md transition-shadow"
|
||||||
<div className="flex justify-between items-start flex-wrap gap-4">
|
data-testid={`member-card-${user.id}`}
|
||||||
<div className="flex items-start gap-4 flex-1">
|
>
|
||||||
{/* Avatar */}
|
<div className="flex justify-between items-start flex-wrap gap-4">
|
||||||
<div className="h-14 w-14 rounded-full bg-[var(--neutral-800)] flex items-center justify-center text-[var(--purple-ink)] font-semibold text-lg flex-shrink-0">
|
<div className="flex items-start gap-4 flex-1">
|
||||||
{user.first_name?.[0]}{user.last_name?.[0]}
|
{/* Avatar */}
|
||||||
|
<div className="h-14 w-14 rounded-full bg-[var(--neutral-800)] flex items-center justify-center text-[var(--purple-ink)] font-semibold text-lg flex-shrink-0">
|
||||||
|
{user.first_name?.[0]}{user.last_name?.[0]}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Info */}
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex items-center gap-3 mb-2 flex-wrap">
|
||||||
|
<h3 className="text-xl font-semibold text-[var(--purple-ink)] " style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{user.first_name} {user.last_name}
|
||||||
|
</h3>
|
||||||
|
{getStatusBadge(user.status)}
|
||||||
|
</div>
|
||||||
|
<div className="grid md:grid-cols-2 gap-2 text-sm text-brand-purple dark:text-brand-lavender " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
<p>Email: {user.email}</p>
|
||||||
|
<p>Phone: {user.phone}</p>
|
||||||
|
<p>Joined: {joinedDate ? new Date(joinedDate).toLocaleDateString() : 'N/A'}</p>
|
||||||
|
{user.referred_by_member_name && (
|
||||||
|
<p>Referred by: {user.referred_by_member_name}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Reminder Info */}
|
||||||
|
{(() => {
|
||||||
|
const reminderInfo = getReminderInfo(user);
|
||||||
|
if (reminderInfo.totalReminders > 0) {
|
||||||
|
return (
|
||||||
|
<div className="mt-4 p-3 bg-[var(--lavender-500)] rounded-lg border border-[var(--neutral-800)]">
|
||||||
|
<div className="flex items-center gap-2 mb-2">
|
||||||
|
<AlertCircle className="h-4 w-4 text-[var(--orange-light)]" />
|
||||||
|
<span className="text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{reminderInfo.totalReminders} reminder{reminderInfo.totalReminders !== 1 ? 's' : ''} sent
|
||||||
|
{reminderInfo.totalReminders >= 3 && (
|
||||||
|
<Badge className="ml-2 bg-[var(--orange-light)] text-white px-2 py-0.5 rounded-full text-xs">
|
||||||
|
Needs attention
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-2 text-xs text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{reminderInfo.emailReminders > 0 && (
|
||||||
|
<p>
|
||||||
|
<Mail className="inline h-3 w-3 mr-1" />
|
||||||
|
{reminderInfo.emailReminders} email verification
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{reminderInfo.eventReminders > 0 && (
|
||||||
|
<p>
|
||||||
|
<Calendar className="inline h-3 w-3 mr-1" />
|
||||||
|
{reminderInfo.eventReminders} event attendance
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{reminderInfo.paymentReminders > 0 && (
|
||||||
|
<p>
|
||||||
|
<Clock className="inline h-3 w-3 mr-1" />
|
||||||
|
{reminderInfo.paymentReminders} payment
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{reminderInfo.renewalReminders > 0 && (
|
||||||
|
<p>
|
||||||
|
<CheckCircle className="inline h-3 w-3 mr-1" />
|
||||||
|
{reminderInfo.renewalReminders} renewal
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{reminderInfo.lastReminderAt && (
|
||||||
|
<p className="mt-2 text-xs text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
Last reminder: {new Date(reminderInfo.lastReminderAt).toLocaleDateString()} at {new Date(reminderInfo.lastReminderAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Info */}
|
{/* Actions */}
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex items-center gap-3 mb-2 flex-wrap">
|
<div className="flex gap-2 flex-wrap">
|
||||||
<h3 className="text-xl font-semibold text-[var(--purple-ink)] " style={{ fontFamily: "'Inter', sans-serif" }}>
|
<Link to={`/admin/users/${user.id}`}>
|
||||||
{user.first_name} {user.last_name}
|
<Button
|
||||||
</h3>
|
variant="outline"
|
||||||
{getStatusBadge(user.status)}
|
size="sm"
|
||||||
</div>
|
className=""
|
||||||
<div className="grid md:grid-cols-2 gap-2 text-sm text-brand-purple dark:text-brand-lavender " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
>
|
||||||
<p>Email: {user.email}</p>
|
<Eye className="h-4 w-4 mr-1" />
|
||||||
<p>Phone: {user.phone}</p>
|
View Profile
|
||||||
<p>Joined: {new Date(user.created_at).toLocaleDateString()}</p>
|
</Button>
|
||||||
{user.referred_by_member_name && (
|
</Link>
|
||||||
<p>Referred by: {user.referred_by_member_name}</p>
|
|
||||||
|
{/* Show Activate Payment button for payment_pending users */}
|
||||||
|
{user.status === 'payment_pending' && (
|
||||||
|
<Button
|
||||||
|
onClick={() => handleActivatePayment(user)}
|
||||||
|
size="sm"
|
||||||
|
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background"
|
||||||
|
>
|
||||||
|
<CheckCircle className="h-4 w-4 mr-1" />
|
||||||
|
Activate Payment
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Reminder Info */}
|
{/* Status Management */}
|
||||||
{(() => {
|
<div className="flex items-center gap-2">
|
||||||
const reminderInfo = getReminderInfo(user);
|
<span className="text-sm text-brand-purple dark:text-brand-lavender whitespace-nowrap" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
if (reminderInfo.totalReminders > 0) {
|
Change Status:
|
||||||
return (
|
</span>
|
||||||
<div className="mt-4 p-3 bg-[var(--lavender-500)] rounded-lg border border-[var(--neutral-800)]">
|
<Select
|
||||||
<div className="flex items-center gap-2 mb-2">
|
value={user.status}
|
||||||
<AlertCircle className="h-4 w-4 text-[var(--orange-light)]" />
|
onValueChange={(newStatus) => handleStatusChangeRequest(user.id, user.status, newStatus, user)}
|
||||||
<span className="text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
disabled={statusChanging === user.id}
|
||||||
{reminderInfo.totalReminders} reminder{reminderInfo.totalReminders !== 1 ? 's' : ''} sent
|
>
|
||||||
{reminderInfo.totalReminders >= 3 && (
|
<SelectTrigger className="w-[180px] h-9 border-[var(--neutral-800)]">
|
||||||
<Badge className="ml-2 bg-[var(--orange-light)] text-white px-2 py-0.5 rounded-full text-xs">
|
<SelectValue />
|
||||||
Needs attention
|
</SelectTrigger>
|
||||||
</Badge>
|
<SelectContent>
|
||||||
)}
|
<SelectItem value="payment_pending">Payment Pending</SelectItem>
|
||||||
</span>
|
<SelectItem value="active">Active</SelectItem>
|
||||||
</div>
|
<SelectItem value="inactive">Inactive</SelectItem>
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-2 text-xs text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<SelectItem value="canceled">Canceled</SelectItem>
|
||||||
{reminderInfo.emailReminders > 0 && (
|
<SelectItem value="expired">Expired</SelectItem>
|
||||||
<p>
|
</SelectContent>
|
||||||
<Mail className="inline h-3 w-3 mr-1" />
|
</Select>
|
||||||
{reminderInfo.emailReminders} email verification
|
</div>
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{reminderInfo.eventReminders > 0 && (
|
|
||||||
<p>
|
|
||||||
<Calendar className="inline h-3 w-3 mr-1" />
|
|
||||||
{reminderInfo.eventReminders} event attendance
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{reminderInfo.paymentReminders > 0 && (
|
|
||||||
<p>
|
|
||||||
<Clock className="inline h-3 w-3 mr-1" />
|
|
||||||
{reminderInfo.paymentReminders} payment
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{reminderInfo.renewalReminders > 0 && (
|
|
||||||
<p>
|
|
||||||
<CheckCircle className="inline h-3 w-3 mr-1" />
|
|
||||||
{reminderInfo.renewalReminders} renewal
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{reminderInfo.lastReminderAt && (
|
|
||||||
<p className="mt-2 text-xs text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
Last reminder: {new Date(reminderInfo.lastReminderAt).toLocaleDateString()} at {new Date(reminderInfo.lastReminderAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
})()}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</Card>
|
||||||
{/* Actions */}
|
);
|
||||||
<div className="flex flex-col gap-3">
|
})}
|
||||||
<div className="flex gap-2 flex-wrap">
|
|
||||||
<Link to={`/admin/users/${user.id}`}>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="border-brand-purple text-brand-purple dark:bg-background dark:border-brand-lavender dark:text-brand-light-lavender hover:bg-brand-light-lavender "
|
|
||||||
>
|
|
||||||
<Eye className="h-4 w-4 mr-1" />
|
|
||||||
View Profile
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
{/* Show Activate Payment button for payment_pending users */}
|
|
||||||
{user.status === 'payment_pending' && (
|
|
||||||
<Button
|
|
||||||
onClick={() => handleActivatePayment(user)}
|
|
||||||
size="sm"
|
|
||||||
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background"
|
|
||||||
>
|
|
||||||
<CheckCircle className="h-4 w-4 mr-1" />
|
|
||||||
Activate Payment
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Status Management */}
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="text-sm text-brand-purple dark:text-brand-lavender whitespace-nowrap" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
Change Status:
|
|
||||||
</span>
|
|
||||||
<Select
|
|
||||||
value={user.status}
|
|
||||||
onValueChange={(newStatus) => handleStatusChangeRequest(user.id, user.status, newStatus, user)}
|
|
||||||
disabled={statusChanging === user.id}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-[180px] h-9 border-[var(--neutral-800)]">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="payment_pending">Payment Pending</SelectItem>
|
|
||||||
<SelectItem value="active">Active</SelectItem>
|
|
||||||
<SelectItem value="inactive">Inactive</SelectItem>
|
|
||||||
<SelectItem value="canceled">Canceled</SelectItem>
|
|
||||||
<SelectItem value="expired">Expired</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-center py-20">
|
<div className="text-center py-20">
|
||||||
|
|||||||
@@ -266,10 +266,10 @@ const AdminNewsletters = () => {
|
|||||||
)}
|
)}
|
||||||
{hasPermission('newsletters.delete') && (
|
{hasPermission('newsletters.delete') && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline-destructive"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleDelete(newsletter)}
|
onClick={() => handleDelete(newsletter)}
|
||||||
className="border-red-500 text-red-500 hover:bg-red-50"
|
className=""
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4" />
|
<Trash2 className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ const AdminPlans = () => {
|
|||||||
onClick={() => handleEditPlan(plan)}
|
onClick={() => handleEditPlan(plan)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 border-brand-purple text-brand-purple hover:bg-brand-purple hover:text-white rounded-full"
|
className="flex-1 border-brand-purple text-brand-purple hover:bg-brand-purple hover:text-white rounded-full dark:hover:text-background"
|
||||||
>
|
>
|
||||||
<Edit className="h-4 w-4 mr-1" />
|
<Edit className="h-4 w-4 mr-1" />
|
||||||
Edit
|
Edit
|
||||||
@@ -303,7 +303,7 @@ const AdminPlans = () => {
|
|||||||
onClick={() => handleDeleteClick(plan)}
|
onClick={() => handleDeleteClick(plan)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 border-red-500 text-red-500 hover:bg-red-500 hover:text-white rounded-full"
|
className="flex-1 border-red-500 text-red-500 hover:bg-red-500 dark:hover:bg-red-500/10 hover:text-white rounded-full"
|
||||||
disabled={plan.subscriber_count > 0}
|
disabled={plan.subscriber_count > 0}
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4 mr-1" />
|
<Trash2 className="h-4 w-4 mr-1" />
|
||||||
|
|||||||
@@ -184,9 +184,9 @@ const AdminRoles = () => {
|
|||||||
const groupedPermissions = groupPermissionsByModule();
|
const groupedPermissions = groupPermissionsByModule();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6 ">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center ">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-3xl font-bold text-[var(--purple-ink)]">Role Management</h1>
|
<h1 className="text-3xl font-bold text-[var(--purple-ink)]">Role Management</h1>
|
||||||
<p className="text-gray-600 mt-1">
|
<p className="text-gray-600 mt-1">
|
||||||
@@ -273,7 +273,7 @@ const AdminRoles = () => {
|
|||||||
|
|
||||||
{/* Create Role Modal */}
|
{/* Create Role Modal */}
|
||||||
<Dialog open={showCreateModal} onOpenChange={setShowCreateModal}>
|
<Dialog open={showCreateModal} onOpenChange={setShowCreateModal}>
|
||||||
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
|
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto scrollbar-dashboard scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Create New Role</DialogTitle>
|
<DialogTitle>Create New Role</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
@@ -317,7 +317,7 @@ const AdminRoles = () => {
|
|||||||
<p className="text-sm text-gray-600 mb-3">
|
<p className="text-sm text-gray-600 mb-3">
|
||||||
Select permissions for this role. You can also add permissions later.
|
Select permissions for this role. You can also add permissions later.
|
||||||
</p>
|
</p>
|
||||||
<div className="border rounded-lg p-4 max-h-64 overflow-y-auto">
|
<div className="border rounded-lg p-4 max-h-64 overflow-y-auto scrollbar-dashboard">
|
||||||
{Object.entries(groupedPermissions).map(([module, perms]) => (
|
{Object.entries(groupedPermissions).map(([module, perms]) => (
|
||||||
<div key={module} className="mb-4">
|
<div key={module} className="mb-4">
|
||||||
<button
|
<button
|
||||||
@@ -373,7 +373,7 @@ const AdminRoles = () => {
|
|||||||
|
|
||||||
{/* Edit Role Modal */}
|
{/* Edit Role Modal */}
|
||||||
<Dialog open={showEditModal} onOpenChange={setShowEditModal}>
|
<Dialog open={showEditModal} onOpenChange={setShowEditModal}>
|
||||||
<DialogContent>
|
<DialogContent >
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Edit Role</DialogTitle>
|
<DialogTitle>Edit Role</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
@@ -417,7 +417,7 @@ const AdminRoles = () => {
|
|||||||
|
|
||||||
{/* Manage Permissions Modal */}
|
{/* Manage Permissions Modal */}
|
||||||
<Dialog open={showPermissionsModal} onOpenChange={setShowPermissionsModal}>
|
<Dialog open={showPermissionsModal} onOpenChange={setShowPermissionsModal}>
|
||||||
<DialogContent className="max-w-3xl max-h-[80vh] overflow-y-auto">
|
<DialogContent className="max-w-3xl max-h-[80vh] overflow-y-auto scrollbar-dashboard">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Manage Permissions: {selectedRole?.name}</DialogTitle>
|
<DialogTitle>Manage Permissions: {selectedRole?.name}</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
|
|||||||
506
src/pages/admin/AdminSettings.js
Normal file
506
src/pages/admin/AdminSettings.js
Normal file
@@ -0,0 +1,506 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../../components/ui/card';
|
||||||
|
import { Button } from '../../components/ui/button';
|
||||||
|
import { Input } from '../../components/ui/input';
|
||||||
|
import { Label } from '../../components/ui/label';
|
||||||
|
import { AlertCircle, CheckCircle, Settings as SettingsIcon, RefreshCw, Zap, Edit, Save, X, Copy, Eye, EyeOff, ExternalLink } from 'lucide-react';
|
||||||
|
import api from '../../utils/api';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
export default function AdminSettings() {
|
||||||
|
const [stripeStatus, setStripeStatus] = useState(null);
|
||||||
|
const [loadingStatus, setLoadingStatus] = useState(true);
|
||||||
|
const [testing, setTesting] = useState(false);
|
||||||
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
|
// Form state
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
secret_key: '',
|
||||||
|
webhook_secret: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show/hide sensitive values
|
||||||
|
const [showSecretKey, setShowSecretKey] = useState(false);
|
||||||
|
const [showWebhookSecret, setShowWebhookSecret] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchStripeStatus();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const fetchStripeStatus = async () => {
|
||||||
|
setLoadingStatus(true);
|
||||||
|
try {
|
||||||
|
const response = await api.get('/admin/settings/stripe/status');
|
||||||
|
setStripeStatus(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch Stripe status:', error);
|
||||||
|
toast.error('Failed to load Stripe status');
|
||||||
|
} finally {
|
||||||
|
setLoadingStatus(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTestConnection = async () => {
|
||||||
|
setTesting(true);
|
||||||
|
try {
|
||||||
|
const response = await api.post('/admin/settings/stripe/test-connection');
|
||||||
|
toast.success(response.data.message);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error.response?.data?.detail || 'Connection test failed';
|
||||||
|
toast.error(message);
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditClick = () => {
|
||||||
|
setIsEditing(true);
|
||||||
|
setFormData({
|
||||||
|
secret_key: '',
|
||||||
|
webhook_secret: ''
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancelEdit = () => {
|
||||||
|
setIsEditing(false);
|
||||||
|
setFormData({
|
||||||
|
secret_key: '',
|
||||||
|
webhook_secret: ''
|
||||||
|
});
|
||||||
|
setShowSecretKey(false);
|
||||||
|
setShowWebhookSecret(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
// Validate inputs
|
||||||
|
if (!formData.secret_key || !formData.webhook_secret) {
|
||||||
|
toast.error('Both Secret Key and Webhook Secret are required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formData.secret_key.startsWith('sk_test_') && !formData.secret_key.startsWith('sk_live_')) {
|
||||||
|
toast.error('Invalid Secret Key format. Must start with sk_test_ or sk_live_');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formData.webhook_secret.startsWith('whsec_')) {
|
||||||
|
toast.error('Invalid Webhook Secret format. Must start with whsec_');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
await api.put('/admin/settings/stripe', formData);
|
||||||
|
toast.success('Stripe settings updated successfully');
|
||||||
|
setIsEditing(false);
|
||||||
|
setFormData({
|
||||||
|
secret_key: '',
|
||||||
|
webhook_secret: ''
|
||||||
|
});
|
||||||
|
setShowSecretKey(false);
|
||||||
|
setShowWebhookSecret(false);
|
||||||
|
// Refresh status
|
||||||
|
await fetchStripeStatus();
|
||||||
|
} catch (error) {
|
||||||
|
const message = error.response?.data?.detail || 'Failed to update Stripe settings';
|
||||||
|
toast.error(message);
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = (text, label) => {
|
||||||
|
navigator.clipboard.writeText(text);
|
||||||
|
toast.success(`${label} copied to clipboard`);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loadingStatus) {
|
||||||
|
return (
|
||||||
|
<div className="container mx-auto p-6">
|
||||||
|
<div className="flex items-center justify-center py-12">
|
||||||
|
<RefreshCw className="h-8 w-8 animate-spin text-brand-purple" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="container mx-auto p-6 max-w-4xl">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="mb-8">
|
||||||
|
<h1 className="text-3xl font-bold text-gray-900 flex items-center gap-3">
|
||||||
|
<SettingsIcon className="h-8 w-8 text-brand-purple" />
|
||||||
|
Settings
|
||||||
|
</h1>
|
||||||
|
<p className="text-gray-600 mt-2">
|
||||||
|
Manage system configuration and integrations
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Stripe Integration Card */}
|
||||||
|
<Card className="border-2 border-[var(--lavender-200)] shadow-sm">
|
||||||
|
<CardHeader className="bg-gradient-to-r from-[var(--lavender-100)] to-white border-b-2 border-[var(--lavender-200)]">
|
||||||
|
<div className="flex justify-between items-start">
|
||||||
|
<div>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<Zap className="h-5 w-5 text-brand-purple" />
|
||||||
|
Stripe Integration
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Payment processing and subscription management
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
{!isEditing && (
|
||||||
|
<Button
|
||||||
|
onClick={handleEditClick}
|
||||||
|
variant="outline"
|
||||||
|
className="border-2 border-brand-purple text-brand-purple hover:bg-[#f1eef9] rounded-full"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4 mr-2" />
|
||||||
|
Edit Settings
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent className="pt-6 space-y-6">
|
||||||
|
{isEditing ? (
|
||||||
|
/* Edit Mode */
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Secret Key Input */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="secret_key">Stripe Secret Key</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Input
|
||||||
|
id="secret_key"
|
||||||
|
type={showSecretKey ? 'text' : 'password'}
|
||||||
|
value={formData.secret_key}
|
||||||
|
onChange={(e) => setFormData({ ...formData, secret_key: e.target.value })}
|
||||||
|
placeholder="sk_test_... or sk_live_..."
|
||||||
|
className="pr-10"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowSecretKey(!showSecretKey)}
|
||||||
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700"
|
||||||
|
>
|
||||||
|
{showSecretKey ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-gray-500">
|
||||||
|
Get this from your Stripe Dashboard → Developers → API keys
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Webhook Secret Input */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="webhook_secret">Stripe Webhook Secret</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Input
|
||||||
|
id="webhook_secret"
|
||||||
|
type={showWebhookSecret ? 'text' : 'password'}
|
||||||
|
value={formData.webhook_secret}
|
||||||
|
onChange={(e) => setFormData({ ...formData, webhook_secret: e.target.value })}
|
||||||
|
placeholder="whsec_..."
|
||||||
|
className="pr-10"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowWebhookSecret(!showWebhookSecret)}
|
||||||
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700"
|
||||||
|
>
|
||||||
|
{showWebhookSecret ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-gray-500">
|
||||||
|
Get this from your Stripe Dashboard → Developers → Webhooks → Add endpoint
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Action Buttons */}
|
||||||
|
<div className="flex justify-end gap-3 pt-4 border-t-2 border-gray-100">
|
||||||
|
<Button
|
||||||
|
onClick={handleCancelEdit}
|
||||||
|
variant="outline"
|
||||||
|
className="border-2 border-gray-300 rounded-full"
|
||||||
|
disabled={saving}
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4 mr-2" />
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={saving}
|
||||||
|
className="bg-brand-purple hover:bg-[var(--purple-dark)] text-white rounded-full"
|
||||||
|
>
|
||||||
|
{saving ? (
|
||||||
|
<>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Saving...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Save className="h-4 w-4 mr-2" />
|
||||||
|
Save Settings
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
/* View Mode */
|
||||||
|
<>
|
||||||
|
{/* Status Display */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold text-gray-900">Configuration Status</p>
|
||||||
|
<p className="text-sm text-gray-600">Credentials stored in database (encrypted)</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{stripeStatus?.configured ? (
|
||||||
|
<>
|
||||||
|
<CheckCircle className="h-5 w-5 text-green-600" />
|
||||||
|
<span className="text-green-600 font-semibold">Configured</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<AlertCircle className="h-5 w-5 text-amber-600" />
|
||||||
|
<span className="text-amber-600 font-semibold">Not Configured</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{stripeStatus?.configured && (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold text-gray-900">Environment</p>
|
||||||
|
<p className="text-sm text-gray-600">Detected from secret key prefix</p>
|
||||||
|
</div>
|
||||||
|
<span className={`px-3 py-1 rounded-full text-sm font-semibold ${
|
||||||
|
stripeStatus.environment === 'live'
|
||||||
|
? 'bg-green-100 text-green-800 border-2 border-green-300'
|
||||||
|
: 'bg-blue-100 text-blue-800 border-2 border-blue-300'
|
||||||
|
}`}>
|
||||||
|
{stripeStatus.environment === 'live' ? 'Live' : 'Test'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold text-gray-900">Secret Key</p>
|
||||||
|
<p className="text-sm text-gray-600 font-mono">
|
||||||
|
{stripeStatus.secret_key_prefix}...
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<CheckCircle className="h-5 w-5 text-green-600" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold text-gray-900">Webhook Secret</p>
|
||||||
|
<p className="text-sm text-gray-600">Webhook endpoint configuration</p>
|
||||||
|
</div>
|
||||||
|
{stripeStatus.webhook_secret_set ? (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<CheckCircle className="h-5 w-5 text-green-600" />
|
||||||
|
<span className="text-green-600 font-semibold text-sm">Set</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<AlertCircle className="h-5 w-5 text-amber-600" />
|
||||||
|
<span className="text-amber-600 font-semibold text-sm">Not Set</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Webhook URL */}
|
||||||
|
<div className="p-4 bg-blue-50 border-2 border-blue-200 rounded-lg">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="flex-1">
|
||||||
|
<p className="font-semibold text-blue-900 mb-2 flex items-center gap-2">
|
||||||
|
<ExternalLink className="h-4 w-4" />
|
||||||
|
Webhook URL
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-blue-700 mb-2">
|
||||||
|
Configure this webhook endpoint in your Stripe Dashboard:
|
||||||
|
</p>
|
||||||
|
<div className="bg-white p-2 rounded border border-blue-300 font-mono text-sm break-all">
|
||||||
|
{stripeStatus.webhook_url}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => copyToClipboard(stripeStatus.webhook_url, 'Webhook URL')}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="border-blue-300 text-blue-700 hover:bg-blue-100"
|
||||||
|
>
|
||||||
|
<Copy className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 text-xs text-blue-600">
|
||||||
|
<p className="font-semibold mb-1">Webhook Events to Configure:</p>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div>
|
||||||
|
<p className="font-medium text-blue-700">✅ Required (Configure in Stripe):</p>
|
||||||
|
<ul className="list-disc list-inside ml-2">
|
||||||
|
<li>checkout.session.completed - Handles subscriptions & donations</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div className="opacity-80">
|
||||||
|
<p className="font-medium text-blue-700">🔔 Automatically Triggered:</p>
|
||||||
|
<ul className="list-disc list-inside ml-2 text-xs">
|
||||||
|
<li>payment_intent.created</li>
|
||||||
|
<li>payment_intent.succeeded</li>
|
||||||
|
<li>charge.succeeded</li>
|
||||||
|
<li>charge.updated</li>
|
||||||
|
</ul>
|
||||||
|
<p className="text-xs italic mt-1">These fire automatically with checkout.session.completed</p>
|
||||||
|
</div>
|
||||||
|
<div className="opacity-70">
|
||||||
|
<p className="font-medium text-blue-700">🔄 Coming Soon (Recurring Subscriptions):</p>
|
||||||
|
<ul className="list-disc list-inside ml-2">
|
||||||
|
<li>invoice.payment_succeeded</li>
|
||||||
|
<li>invoice.payment_failed</li>
|
||||||
|
<li>customer.subscription.updated</li>
|
||||||
|
<li>customer.subscription.deleted</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Configuration Instructions (Not Configured) */}
|
||||||
|
{!stripeStatus?.configured && (
|
||||||
|
<>
|
||||||
|
<div className="p-4 bg-amber-50 border-2 border-amber-200 rounded-lg">
|
||||||
|
<div className="flex items-start gap-2">
|
||||||
|
<AlertCircle className="h-5 w-5 text-amber-600 flex-shrink-0 mt-0.5" />
|
||||||
|
<div className="text-sm">
|
||||||
|
<p className="font-semibold text-amber-900 mb-2">Configuration Required</p>
|
||||||
|
<p className="text-amber-700 mb-2">
|
||||||
|
Click "Edit Settings" above to configure your Stripe credentials.
|
||||||
|
</p>
|
||||||
|
<p className="text-amber-700">
|
||||||
|
Get your API keys from{' '}
|
||||||
|
<a
|
||||||
|
href="https://dashboard.stripe.com/apikeys"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="font-semibold underline"
|
||||||
|
>
|
||||||
|
Stripe Dashboard
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Webhook URL Info (Always visible) */}
|
||||||
|
<div className="p-4 bg-blue-50 border-2 border-blue-200 rounded-lg">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="flex-1">
|
||||||
|
<p className="font-semibold text-blue-900 mb-2 flex items-center gap-2">
|
||||||
|
<ExternalLink className="h-4 w-4" />
|
||||||
|
Webhook URL Configuration
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-blue-700 mb-2">
|
||||||
|
After configuring your API keys, set up this webhook endpoint in your Stripe Dashboard:
|
||||||
|
</p>
|
||||||
|
<div className="bg-white p-2 rounded border border-blue-300 font-mono text-sm break-all">
|
||||||
|
{stripeStatus?.webhook_url || 'http://localhost:8000/api/webhooks/stripe'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => copyToClipboard(stripeStatus?.webhook_url || 'http://localhost:8000/api/webhooks/stripe', 'Webhook URL')}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="border-blue-300 text-blue-700 hover:bg-blue-100"
|
||||||
|
>
|
||||||
|
<Copy className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 text-xs text-blue-600">
|
||||||
|
<p className="font-semibold mb-1">Webhook Events to Configure:</p>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div>
|
||||||
|
<p className="font-medium text-blue-700">✅ Required (Configure in Stripe):</p>
|
||||||
|
<ul className="list-disc list-inside ml-2">
|
||||||
|
<li>checkout.session.completed - Handles subscriptions & donations</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div className="opacity-80">
|
||||||
|
<p className="font-medium text-blue-700">🔔 Automatically Triggered:</p>
|
||||||
|
<ul className="list-disc list-inside ml-2 text-xs">
|
||||||
|
<li>payment_intent.created</li>
|
||||||
|
<li>payment_intent.succeeded</li>
|
||||||
|
<li>charge.succeeded</li>
|
||||||
|
<li>charge.updated</li>
|
||||||
|
</ul>
|
||||||
|
<p className="text-xs italic mt-1">These fire automatically with checkout.session.completed</p>
|
||||||
|
</div>
|
||||||
|
<div className="opacity-70">
|
||||||
|
<p className="font-medium text-blue-700">🔄 Coming Soon (Recurring Subscriptions):</p>
|
||||||
|
<ul className="list-disc list-inside ml-2">
|
||||||
|
<li>invoice.payment_succeeded</li>
|
||||||
|
<li>invoice.payment_failed</li>
|
||||||
|
<li>customer.subscription.updated</li>
|
||||||
|
<li>customer.subscription.deleted</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Test Connection Button */}
|
||||||
|
{stripeStatus?.configured && (
|
||||||
|
<div className="flex justify-end gap-3 pt-4 border-t-2 border-gray-100">
|
||||||
|
<Button
|
||||||
|
onClick={fetchStripeStatus}
|
||||||
|
variant="outline"
|
||||||
|
className="border-2 border-gray-300 rounded-full"
|
||||||
|
disabled={loadingStatus}
|
||||||
|
>
|
||||||
|
<RefreshCw className={`h-4 w-4 mr-2 ${loadingStatus ? 'animate-spin' : ''}`} />
|
||||||
|
Refresh Status
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleTestConnection}
|
||||||
|
disabled={testing}
|
||||||
|
className="bg-brand-purple hover:bg-[var(--purple-dark)] text-white rounded-full"
|
||||||
|
>
|
||||||
|
{testing ? (
|
||||||
|
<>
|
||||||
|
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Testing...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Zap className="h-4 w-4 mr-2" />
|
||||||
|
Test Connection
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Future Settings Sections Placeholder */}
|
||||||
|
<div className="mt-6 p-6 border-2 border-dashed border-gray-300 rounded-lg text-center text-gray-500">
|
||||||
|
<p className="text-sm">Additional settings sections will be added here</p>
|
||||||
|
<p className="text-xs mt-1">(Email, Storage, Notifications, etc.)</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -242,12 +242,14 @@ const AdminStaff = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : filteredUsers.length > 0 ? (
|
) : filteredUsers.length > 0 ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{filteredUsers.map((user) => (
|
{filteredUsers.map((user) => {
|
||||||
<Card
|
const joinedDate = user.member_since || user.created_at;
|
||||||
key={user.id}
|
return (
|
||||||
className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)] hover:shadow-md transition-shadow"
|
<Card
|
||||||
data-testid={`staff-card-${user.id}`}
|
key={user.id}
|
||||||
>
|
className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)] hover:shadow-md transition-shadow"
|
||||||
|
data-testid={`staff-card-${user.id}`}
|
||||||
|
>
|
||||||
<div className="flex justify-between items-start flex-wrap gap-4">
|
<div className="flex justify-between items-start flex-wrap gap-4">
|
||||||
<div className="flex items-start gap-4 flex-1">
|
<div className="flex items-start gap-4 flex-1">
|
||||||
{/* Avatar */}
|
{/* Avatar */}
|
||||||
@@ -267,7 +269,7 @@ const AdminStaff = () => {
|
|||||||
<div className="grid md:grid-cols-2 gap-2 text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<div className="grid md:grid-cols-2 gap-2 text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
<p>Email: {user.email}</p>
|
<p>Email: {user.email}</p>
|
||||||
<p>Phone: {user.phone}</p>
|
<p>Phone: {user.phone}</p>
|
||||||
<p>Joined: {new Date(user.created_at).toLocaleDateString()}</p>
|
<p>Joined: {joinedDate ? new Date(joinedDate).toLocaleDateString() : 'N/A'}</p>
|
||||||
{user.last_login && (
|
{user.last_login && (
|
||||||
<p>Last Login: {new Date(user.last_login).toLocaleDateString()}</p>
|
<p>Last Login: {new Date(user.last_login).toLocaleDateString()}</p>
|
||||||
)}
|
)}
|
||||||
@@ -291,8 +293,8 @@ const AdminStaff = () => {
|
|||||||
onClick={() => handleToggleStatus(user.id, user.status)}
|
onClick={() => handleToggleStatus(user.id, user.status)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={`border-2 rounded-full px-4 py-2 ${user.status === 'active'
|
className={`border-2 rounded-full px-4 py-2 ${user.status === 'active'
|
||||||
? 'border-orange-500 text-orange-600 hover:bg-orange-50'
|
? 'border-orange-500 text-orange-600 hover:bg-orange-50 dark:hover:bg-orange-600/10'
|
||||||
: 'border-green-500 text-green-600 hover:bg-green-50'
|
: 'border-green-500 text-green-600 hover:bg-green-50 hover:dark:bg-green-600/10'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{user.status === 'active' ? (
|
{user.status === 'active' ? (
|
||||||
@@ -313,7 +315,7 @@ const AdminStaff = () => {
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => handleDeleteUser(user.id, `${user.first_name} ${user.last_name}`)}
|
onClick={() => handleDeleteUser(user.id, `${user.first_name} ${user.last_name}`)}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="border-2 border-red-500 text-red-600 hover:bg-red-50 rounded-full px-4 py-2"
|
className="border-2 border-red-500 text-red-600 hover:bg-red-50 dark:hover:bg-red-600/10 rounded-full px-4 py-2"
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4 mr-2" />
|
<Trash2 className="h-4 w-4 mr-2" />
|
||||||
Delete
|
Delete
|
||||||
@@ -321,8 +323,9 @@ const AdminStaff = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-center py-20">
|
<div className="text-center py-20">
|
||||||
|
|||||||
@@ -35,7 +35,11 @@ import {
|
|||||||
Download,
|
Download,
|
||||||
FileDown,
|
FileDown,
|
||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
Info
|
Info,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
ExternalLink,
|
||||||
|
Copy
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@@ -55,6 +59,7 @@ const AdminSubscriptions = () => {
|
|||||||
const [statusFilter, setStatusFilter] = useState('all');
|
const [statusFilter, setStatusFilter] = useState('all');
|
||||||
const [planFilter, setPlanFilter] = useState('all');
|
const [planFilter, setPlanFilter] = useState('all');
|
||||||
const [exporting, setExporting] = useState(false);
|
const [exporting, setExporting] = useState(false);
|
||||||
|
const [expandedRows, setExpandedRows] = useState(new Set());
|
||||||
|
|
||||||
// Edit subscription dialog state
|
// Edit subscription dialog state
|
||||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||||
@@ -265,6 +270,38 @@ Proceed with activation?`;
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const formatDateTime = (dateString) => {
|
||||||
|
if (!dateString) return 'N/A';
|
||||||
|
return new Date(dateString).toLocaleString('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleRowExpansion = (subscriptionId) => {
|
||||||
|
setExpandedRows((prev) => {
|
||||||
|
const newExpanded = new Set(prev);
|
||||||
|
if (newExpanded.has(subscriptionId)) {
|
||||||
|
newExpanded.delete(subscriptionId);
|
||||||
|
} else {
|
||||||
|
newExpanded.add(subscriptionId);
|
||||||
|
}
|
||||||
|
return newExpanded;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = async (text, label) => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
toast.success(`${label} copied to clipboard`);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Failed to copy to clipboard');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getStatusBadgeVariant = (status) => {
|
const getStatusBadgeVariant = (status) => {
|
||||||
const variants = {
|
const variants = {
|
||||||
active: 'default',
|
active: 'default',
|
||||||
@@ -419,7 +456,7 @@ Proceed with activation?`;
|
|||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
disabled={exporting}
|
disabled={exporting}
|
||||||
className="bg-[var(--green-light)] text-white hover:bg-[var(--green-soft)] rounded-full px-6 py-2 flex items-center gap-2"
|
className="btn-green py-2 flex items-center gap-2"
|
||||||
>
|
>
|
||||||
<Download className="h-4 w-4" />
|
<Download className="h-4 w-4" />
|
||||||
{exporting ? 'Exporting...' : 'Export'}
|
{exporting ? 'Exporting...' : 'Export'}
|
||||||
@@ -521,9 +558,9 @@ Proceed with activation?`;
|
|||||||
{sub.status === 'active' && hasPermission('subscriptions.cancel') && (
|
{sub.status === 'active' && hasPermission('subscriptions.cancel') && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline-destructive"
|
||||||
onClick={() => handleCancelSubscription(sub.id)}
|
onClick={() => handleCancelSubscription(sub.id)}
|
||||||
className="flex-1 text-red-600 hover:bg-red-50"
|
className="flex-1 "
|
||||||
>
|
>
|
||||||
<XCircle className="h-4 w-4 mr-2" />
|
<XCircle className="h-4 w-4 mr-2" />
|
||||||
Cancel
|
Cancel
|
||||||
@@ -566,6 +603,9 @@ Proceed with activation?`;
|
|||||||
<th className="text-right p-4 text-[var(--purple-ink)] font-semibold" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<th className="text-right p-4 text-[var(--purple-ink)] font-semibold" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
Total
|
Total
|
||||||
</th>
|
</th>
|
||||||
|
<th className="text-center p-4 text-[var(--purple-ink)] font-semibold" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Details
|
||||||
|
</th>
|
||||||
<th className="text-center p-4 text-[var(--purple-ink)] font-semibold" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<th className="text-center p-4 text-[var(--purple-ink)] font-semibold" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
Actions
|
Actions
|
||||||
</th>
|
</th>
|
||||||
@@ -573,73 +613,238 @@ Proceed with activation?`;
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{filteredSubscriptions.length > 0 ? (
|
{filteredSubscriptions.length > 0 ? (
|
||||||
filteredSubscriptions.map((sub) => (
|
filteredSubscriptions.map((sub) => {
|
||||||
<tr key={sub.id} className="border-b border-[var(--neutral-800)] hover:bg-[var(--lavender-400)] transition-colors">
|
const isExpanded = expandedRows.has(sub.id);
|
||||||
<td className="p-4">
|
return (
|
||||||
<div className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<React.Fragment key={sub.id}>
|
||||||
{sub.user.first_name} {sub.user.last_name}
|
<tr className="border-b border-[var(--neutral-800)] hover:bg-[var(--lavender-400)] transition-colors">
|
||||||
</div>
|
<td className="p-4">
|
||||||
<div className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<div className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{sub.user.email}
|
{sub.user.first_name} {sub.user.last_name}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
<div className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
<td className="p-4">
|
{sub.user.email}
|
||||||
<div className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
</div>
|
||||||
{sub.plan.name}
|
</td>
|
||||||
</div>
|
<td className="p-4">
|
||||||
<div className="text-xs text-brand-purple ">
|
<div className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
{sub.plan.billing_cycle}
|
{sub.plan.name}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
<div className="text-xs text-brand-purple ">
|
||||||
<td className="p-4">
|
{sub.plan.billing_cycle}
|
||||||
<Badge variant={getStatusBadgeVariant(sub.status)}>
|
</div>
|
||||||
{sub.status}
|
</td>
|
||||||
</Badge>
|
<td className="p-4">
|
||||||
</td>
|
<Badge variant={getStatusBadgeVariant(sub.status)}>
|
||||||
<td className="p-4">
|
{sub.status}
|
||||||
<div className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
</Badge>
|
||||||
<div>{formatDate(sub.start_date)}</div>
|
</td>
|
||||||
<div className="text-xs text-brand-purple ">to {formatDate(sub.end_date)}</div>
|
<td className="p-4">
|
||||||
</div>
|
<div className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
</td>
|
<div>{formatDate(sub.start_date)}</div>
|
||||||
<td className="p-4 text-right text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<div className="text-xs text-brand-purple ">to {formatDate(sub.end_date)}</div>
|
||||||
{formatPrice(sub.base_subscription_cents || 0)}
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="p-4 text-right text-[var(--orange-light)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<td className="p-4 text-right text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{formatPrice(sub.donation_cents || 0)}
|
{formatPrice(sub.base_subscription_cents || 0)}
|
||||||
</td>
|
</td>
|
||||||
<td className="p-4 text-right font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<td className="p-4 text-right text-[var(--orange-light)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{formatPrice(sub.amount_paid_cents || 0)}
|
{formatPrice(sub.donation_cents || 0)}
|
||||||
</td>
|
</td>
|
||||||
<td className="p-4">
|
<td className="p-4 text-right font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
<div className="flex items-center justify-center gap-2">
|
{formatPrice(sub.amount_paid_cents || 0)}
|
||||||
{hasPermission('subscriptions.edit') && (
|
</td>
|
||||||
|
<td className="p-4">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="ghost"
|
||||||
onClick={() => handleEdit(sub)}
|
onClick={() => toggleRowExpansion(sub.id)}
|
||||||
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
>
|
>
|
||||||
<Edit className="h-4 w-4" />
|
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
</td>
|
||||||
{sub.status === 'active' && hasPermission('subscriptions.cancel') && (
|
<td className="p-4">
|
||||||
<Button
|
<div className="flex items-center justify-center gap-2">
|
||||||
size="sm"
|
{hasPermission('subscriptions.edit') && (
|
||||||
variant="outline"
|
<Button
|
||||||
onClick={() => handleCancelSubscription(sub.id)}
|
size="sm"
|
||||||
className="text-red-600 hover:bg-red-50"
|
variant="outline"
|
||||||
>
|
onClick={() => handleEdit(sub)}
|
||||||
<XCircle className="h-4 w-4" />
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
</Button>
|
>
|
||||||
)}
|
<Edit className="h-4 w-4" />
|
||||||
</div>
|
</Button>
|
||||||
</td>
|
)}
|
||||||
</tr>
|
{sub.status === 'active' && hasPermission('subscriptions.cancel') && (
|
||||||
))
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline-destructive"
|
||||||
|
onClick={() => handleCancelSubscription(sub.id)}
|
||||||
|
className=""
|
||||||
|
>
|
||||||
|
<XCircle className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/* Expandable Details Row */}
|
||||||
|
{isExpanded && (
|
||||||
|
<tr className="bg-[var(--lavender-400)]/30">
|
||||||
|
<td colSpan="9" className="p-6">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h4 className="font-semibold text-[var(--purple-ink)] text-lg mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Transaction Details
|
||||||
|
</h4>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
|
{/* Payment Information */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h5 className="font-medium text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<CreditCard className="h-4 w-4" />
|
||||||
|
Payment Information
|
||||||
|
</h5>
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
{sub.payment_completed_at && (
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-brand-purple ">Payment Date:</span>
|
||||||
|
<span className="text-[var(--purple-ink)] font-medium">{formatDateTime(sub.payment_completed_at)}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.payment_method && (
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-brand-purple ">Payment Method:</span>
|
||||||
|
<span className="text-[var(--purple-ink)] font-medium capitalize">{sub.payment_method}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.card_brand && sub.card_last4 && (
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-brand-purple ">Card:</span>
|
||||||
|
<span className="text-[var(--purple-ink)] font-medium">{sub.card_brand} ****{sub.card_last4}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Stripe Transaction IDs */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h5 className="font-medium text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<Info className="h-4 w-4" />
|
||||||
|
Stripe Transaction IDs
|
||||||
|
</h5>
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
{sub.stripe_payment_intent_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Payment Intent:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{sub.stripe_payment_intent_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(sub.stripe_payment_intent_id, 'Payment Intent ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.stripe_charge_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Charge ID:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{sub.stripe_charge_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(sub.stripe_charge_id, 'Charge ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.stripe_subscription_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Subscription ID:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{sub.stripe_subscription_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(sub.stripe_subscription_id, 'Subscription ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.stripe_invoice_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Invoice ID:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{sub.stripe_invoice_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(sub.stripe_invoice_id, 'Invoice ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.stripe_customer_id && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Customer ID:</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<code className="text-xs bg-[var(--neutral-800)]/30 px-2 py-1 rounded text-[var(--purple-ink)]">
|
||||||
|
{sub.stripe_customer_id.substring(0, 20)}...
|
||||||
|
</code>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => copyToClipboard(sub.stripe_customer_id, 'Customer ID')}
|
||||||
|
>
|
||||||
|
<Copy className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{sub.stripe_receipt_url && (
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="text-brand-purple ">Receipt:</span>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => window.open(sub.stripe_receipt_url, '_blank')}
|
||||||
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
|
>
|
||||||
|
<ExternalLink className="h-3 w-3 mr-1" />
|
||||||
|
View Receipt
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
})
|
||||||
) : (
|
) : (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan="8" className="p-12 text-center text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<td colSpan="9" className="p-12 text-center text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
No subscriptions found
|
No subscriptions found
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import { Card } from '../../components/ui/card';
|
|||||||
import { Button } from '../../components/ui/button';
|
import { Button } from '../../components/ui/button';
|
||||||
import { Badge } from '../../components/ui/badge';
|
import { Badge } from '../../components/ui/badge';
|
||||||
import { Avatar, AvatarImage, AvatarFallback } from '../../components/ui/avatar';
|
import { Avatar, AvatarImage, AvatarFallback } from '../../components/ui/avatar';
|
||||||
import { ArrowLeft, Mail, Phone, MapPin, Calendar, Lock, AlertTriangle, Camera, Upload, Trash2 } from 'lucide-react';
|
import { Input } from '../../components/ui/input';
|
||||||
|
import { ArrowLeft, Mail, Phone, MapPin, Calendar, Lock, AlertTriangle, Camera, Upload, Trash2, Shield } from 'lucide-react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import ConfirmationDialog from '../../components/ConfirmationDialog';
|
import ConfirmationDialog from '../../components/ConfirmationDialog';
|
||||||
|
import ChangeRoleDialog from '../../components/ChangeRoleDialog';
|
||||||
|
import TransactionHistory from '../../components/TransactionHistory';
|
||||||
|
|
||||||
const AdminUserView = () => {
|
const AdminUserView = () => {
|
||||||
const { userId } = useParams();
|
const { userId } = useParams();
|
||||||
@@ -16,21 +19,65 @@ const AdminUserView = () => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [resetPasswordLoading, setResetPasswordLoading] = useState(false);
|
const [resetPasswordLoading, setResetPasswordLoading] = useState(false);
|
||||||
const [resendVerificationLoading, setResendVerificationLoading] = useState(false);
|
const [resendVerificationLoading, setResendVerificationLoading] = useState(false);
|
||||||
const [subscriptions, setSubscriptions] = useState([]);
|
const [transactions, setTransactions] = useState({ subscriptions: [], donations: [] });
|
||||||
const [subscriptionsLoading, setSubscriptionsLoading] = useState(true);
|
const [transactionsLoading, setTransactionsLoading] = useState(true);
|
||||||
const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
|
const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
|
||||||
const [pendingAction, setPendingAction] = useState(null);
|
const [pendingAction, setPendingAction] = useState(null);
|
||||||
const [uploadingPhoto, setUploadingPhoto] = useState(false);
|
const [uploadingPhoto, setUploadingPhoto] = useState(false);
|
||||||
const [maxFileSizeMB, setMaxFileSizeMB] = useState(50);
|
const [maxFileSizeMB, setMaxFileSizeMB] = useState(50);
|
||||||
const [maxFileSizeBytes, setMaxFileSizeBytes] = useState(52428800);
|
const [maxFileSizeBytes, setMaxFileSizeBytes] = useState(52428800);
|
||||||
|
const [memberSince, setMemberSince] = useState('');
|
||||||
|
const [memberSinceSaving, setMemberSinceSaving] = useState(false);
|
||||||
const fileInputRef = useRef(null);
|
const fileInputRef = useRef(null);
|
||||||
|
const [changeRoleDialogOpen, setChangeRoleDialogOpen] = useState(false);
|
||||||
|
|
||||||
|
const formatLocalDateInputValue = (date) => {
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDateInputValue = (value) => {
|
||||||
|
if (!value) return '';
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
const parsed = new Date(value);
|
||||||
|
if (Number.isNaN(parsed.getTime())) {
|
||||||
|
return value.slice(0, 10);
|
||||||
|
}
|
||||||
|
return formatLocalDateInputValue(parsed);
|
||||||
|
}
|
||||||
|
const parsed = new Date(value);
|
||||||
|
if (Number.isNaN(parsed.getTime())) return '';
|
||||||
|
return formatLocalDateInputValue(parsed);
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDateDisplayValue = (value) => {
|
||||||
|
if (!value) return 'N/A';
|
||||||
|
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
||||||
|
const [year, month, day] = value.split('-').map(Number);
|
||||||
|
return new Date(year, month - 1, day).toLocaleDateString();
|
||||||
|
}
|
||||||
|
const parsed = new Date(value);
|
||||||
|
if (Number.isNaN(parsed.getTime())) return 'N/A';
|
||||||
|
return parsed.toLocaleDateString();
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConfig();
|
fetchConfig();
|
||||||
fetchUserProfile();
|
fetchUserProfile();
|
||||||
fetchSubscriptions();
|
fetchTransactions();
|
||||||
}, [userId]);
|
}, [userId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) {
|
||||||
|
setMemberSince(formatDateInputValue(user.member_since));
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
const fetchUserProfile = async () => {
|
const fetchUserProfile = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(`/admin/users/${userId}`);
|
const response = await api.get(`/admin/users/${userId}`);
|
||||||
@@ -43,14 +90,15 @@ const AdminUserView = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchSubscriptions = async () => {
|
const fetchTransactions = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(`/admin/subscriptions?user_id=${userId}`);
|
setTransactionsLoading(true);
|
||||||
setSubscriptions(response.data);
|
const response = await api.get(`/admin/users/${userId}/transactions`);
|
||||||
|
setTransactions(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch subscriptions:', error);
|
console.error('Failed to fetch transactions:', error);
|
||||||
} finally {
|
} finally {
|
||||||
setSubscriptionsLoading(false);
|
setTransactionsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -175,6 +223,27 @@ const AdminUserView = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMemberSinceSave = async () => {
|
||||||
|
if (!user) return;
|
||||||
|
setMemberSinceSaving(true);
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
member_since: memberSince ? memberSince : null
|
||||||
|
};
|
||||||
|
const response = await api.put(`/admin/users/${userId}`, payload);
|
||||||
|
setUser(prev => ({
|
||||||
|
...prev,
|
||||||
|
...(response?.data || {}),
|
||||||
|
member_since: payload.member_since
|
||||||
|
}));
|
||||||
|
toast.success('Member since updated successfully');
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(error.response?.data?.detail || 'Failed to update member since');
|
||||||
|
} finally {
|
||||||
|
setMemberSinceSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getActionMessage = () => {
|
const getActionMessage = () => {
|
||||||
if (!pendingAction || !user) return {};
|
if (!pendingAction || !user) return {};
|
||||||
|
|
||||||
@@ -202,9 +271,18 @@ const AdminUserView = () => {
|
|||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRoleChanged = () => {
|
||||||
|
// Refresh user data after role change
|
||||||
|
fetchUserProfile();
|
||||||
|
};
|
||||||
|
|
||||||
if (loading) return <div>Loading...</div>;
|
if (loading) return <div>Loading...</div>;
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
|
||||||
|
const joinedDate = user.member_since || user.created_at;
|
||||||
|
const memberSinceBaseline = formatDateInputValue(user.member_since);
|
||||||
|
const memberSinceHasChanges = memberSince !== memberSinceBaseline;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Back Button */}
|
{/* Back Button */}
|
||||||
@@ -255,7 +333,7 @@ const AdminUserView = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Calendar className="h-4 w-4" />
|
<Calendar className="h-4 w-4" />
|
||||||
<span>Joined {new Date(user.created_at).toLocaleDateString()}</span>
|
<span>Joined {formatDateDisplayValue(joinedDate)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -278,6 +356,15 @@ const AdminUserView = () => {
|
|||||||
{resetPasswordLoading ? 'Resetting...' : 'Reset Password'}
|
{resetPasswordLoading ? 'Resetting...' : 'Reset Password'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => setChangeRoleDialogOpen(true)}
|
||||||
|
variant="outline"
|
||||||
|
className="border-2 border-brand-purple text-brand-purple hover:bg-[var(--lavender-300)] rounded-full px-4 py-2"
|
||||||
|
>
|
||||||
|
<Shield className="h-4 w-4 mr-2" />
|
||||||
|
Change Role
|
||||||
|
</Button>
|
||||||
|
|
||||||
{!user.email_verified && (
|
{!user.email_verified && (
|
||||||
<Button
|
<Button
|
||||||
onClick={handleResendVerificationRequest}
|
onClick={handleResendVerificationRequest}
|
||||||
@@ -343,10 +430,31 @@ const AdminUserView = () => {
|
|||||||
<div>
|
<div>
|
||||||
<label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Date of Birth</label>
|
<label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Date of Birth</label>
|
||||||
<p className="text-[var(--purple-ink)] mt-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p className="text-[var(--purple-ink)] mt-1" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
{new Date(user.date_of_birth).toLocaleDateString()}
|
{formatDateDisplayValue(user.date_of_birth)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Member Since</label>
|
||||||
|
<div className="mt-1 flex flex-wrap items-center gap-2">
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
value={memberSince}
|
||||||
|
onChange={(e) => setMemberSince(e.target.value)}
|
||||||
|
className="max-w-[200px] border-[var(--neutral-800)]"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleMemberSinceSave}
|
||||||
|
disabled={memberSinceSaving || !memberSinceHasChanges}
|
||||||
|
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background"
|
||||||
|
>
|
||||||
|
{memberSinceSaving ? 'Saving...' : 'Save'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{user.partner_first_name && (
|
{user.partner_first_name && (
|
||||||
<div>
|
<div>
|
||||||
<label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Partner</label>
|
<label className="text-sm font-medium text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Partner</label>
|
||||||
@@ -376,97 +484,17 @@ const AdminUserView = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Subscription Info (if applicable) */}
|
{/* Transaction History */}
|
||||||
{user.role === 'member' && (
|
<div className="mt-8">
|
||||||
<Card className="p-8 bg-background rounded-2xl border border-[var(--neutral-800)] mt-8">
|
<TransactionHistory
|
||||||
<h2 className="text-2xl font-semibold text-[var(--purple-ink)] mb-6" style={{ fontFamily: "'Inter', sans-serif" }}>
|
subscriptions={transactions.subscriptions}
|
||||||
Subscription Information
|
donations={transactions.donations}
|
||||||
</h2>
|
totalSubscriptionCents={transactions.total_subscription_amount_cents}
|
||||||
|
totalDonationCents={transactions.total_donation_amount_cents}
|
||||||
{subscriptionsLoading ? (
|
loading={transactionsLoading}
|
||||||
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Loading subscriptions...</p>
|
isAdmin={true}
|
||||||
) : subscriptions.length === 0 ? (
|
/>
|
||||||
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>No subscriptions found for this member.</p>
|
</div>
|
||||||
) : (
|
|
||||||
<div className="space-y-6">
|
|
||||||
{subscriptions.map((sub) => (
|
|
||||||
<div key={sub.id} className="p-6 bg-[var(--lavender-500)] rounded-xl border border-[var(--neutral-800)]">
|
|
||||||
<div className="flex items-start justify-between mb-4">
|
|
||||||
<div>
|
|
||||||
<h3 className="text-lg font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
|
||||||
{sub.plan.name}
|
|
||||||
</h3>
|
|
||||||
<p className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
{sub.plan.billing_cycle}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Badge className={
|
|
||||||
sub.status === 'active' ? 'bg-[var(--green-light)] text-white' :
|
|
||||||
sub.status === 'expired' ? 'bg-red-500 text-white' :
|
|
||||||
'bg-gray-400 text-white'
|
|
||||||
}>
|
|
||||||
{sub.status}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid md:grid-cols-2 gap-4 text-sm">
|
|
||||||
<div>
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Start Date</label>
|
|
||||||
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
{new Date(sub.start_date).toLocaleDateString()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{sub.end_date && (
|
|
||||||
<div>
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>End Date</label>
|
|
||||||
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
{new Date(sub.end_date).toLocaleDateString()}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div>
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Base Amount</label>
|
|
||||||
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
${(sub.base_subscription_cents / 100).toFixed(2)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{sub.donation_cents > 0 && (
|
|
||||||
<div>
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Donation</label>
|
|
||||||
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
${(sub.donation_cents / 100).toFixed(2)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div>
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Total Paid</label>
|
|
||||||
<p className="text-[var(--purple-ink)] font-semibold" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
${(sub.amount_paid_cents / 100).toFixed(2)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{sub.payment_method && (
|
|
||||||
<div>
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Payment Method</label>
|
|
||||||
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
{sub.payment_method}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{sub.stripe_subscription_id && (
|
|
||||||
<div className="md:col-span-2">
|
|
||||||
<label className="text-brand-purple font-medium" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>Stripe Subscription ID</label>
|
|
||||||
<p className="text-[var(--purple-ink)] text-xs font-mono" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
|
||||||
{sub.stripe_subscription_id}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Admin Action Confirmation Dialog */}
|
{/* Admin Action Confirmation Dialog */}
|
||||||
<ConfirmationDialog
|
<ConfirmationDialog
|
||||||
@@ -476,6 +504,14 @@ const AdminUserView = () => {
|
|||||||
loading={resetPasswordLoading || resendVerificationLoading}
|
loading={resetPasswordLoading || resendVerificationLoading}
|
||||||
{...getActionMessage()}
|
{...getActionMessage()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Change Role Dialog */}
|
||||||
|
<ChangeRoleDialog
|
||||||
|
open={changeRoleDialogOpen}
|
||||||
|
onClose={() => setChangeRoleDialogOpen(false)}
|
||||||
|
user={user}
|
||||||
|
onSuccess={handleRoleChanged}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ const AdminValidations = () => {
|
|||||||
disabled={actionLoading === user.id}
|
disabled={actionLoading === user.id}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="border-2 border-red-500 text-red-500 hover:bg-red-50"
|
className="border-2 border-red-500 text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10"
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4 mr-1" />
|
<X className="h-4 w-4 mr-1" />
|
||||||
Reject
|
Reject
|
||||||
@@ -462,7 +462,7 @@ const AdminValidations = () => {
|
|||||||
disabled={actionLoading === user.id}
|
disabled={actionLoading === user.id}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="border-2 border-red-500 text-red-500 hover:bg-red-50"
|
className="border-2 border-red-500 text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10"
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4 mr-1" />
|
<X className="h-4 w-4 mr-1" />
|
||||||
Reject
|
Reject
|
||||||
@@ -487,7 +487,7 @@ const AdminValidations = () => {
|
|||||||
disabled={actionLoading === user.id}
|
disabled={actionLoading === user.id}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="border-2 border-red-500 text-red-500 hover:bg-red-50"
|
className="border-2 border-red-500 text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10"
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4 mr-1" />
|
<X className="h-4 w-4 mr-1" />
|
||||||
Reject
|
Reject
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ export default function MemberCalendar() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
|
||||||
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
{selectedEvent && (
|
{selectedEvent && (
|
||||||
<>
|
<>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
|
|||||||
@@ -118,8 +118,10 @@ const MembersDirectory = () => {
|
|||||||
: <div className=' border-2 w-full border-brand-purple mb-24' />
|
: <div className=' border-2 w-full border-brand-purple mb-24' />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const MemberCard = ({ member }) => (
|
const MemberCard = ({ member }) => {
|
||||||
<Card className="p-6 bg-background rounded-3xl border border-[var(--neutral-800)] hover:shadow-lg transition-all h-full">
|
const joinedDate = member.member_since || member.created_at;
|
||||||
|
return (
|
||||||
|
<Card className="p-6 bg-background rounded-3xl border border-[var(--neutral-800)] hover:shadow-lg transition-all h-full">
|
||||||
{/* Profile Photo */}
|
{/* Profile Photo */}
|
||||||
<div className="flex justify-center mb-4">
|
<div className="flex justify-center mb-4">
|
||||||
{member.profile_photo_url ? (
|
{member.profile_photo_url ? (
|
||||||
@@ -160,11 +162,11 @@ const MembersDirectory = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Member Since */}
|
{/* Member Since */}
|
||||||
{member.created_at && (
|
{joinedDate && (
|
||||||
<div className="flex items-center justify-center gap-2 mb-4">
|
<div className="flex items-center justify-center gap-2 mb-4">
|
||||||
<Calendar className="h-4 w-4 text-brand-purple " />
|
<Calendar className="h-4 w-4 text-brand-purple " />
|
||||||
<span className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<span className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
Member since {new Date(member.created_at).toLocaleDateString('en-US', {
|
Member since {new Date(joinedDate).toLocaleDateString('en-US', {
|
||||||
month: 'long',
|
month: 'long',
|
||||||
year: 'numeric'
|
year: 'numeric'
|
||||||
})}
|
})}
|
||||||
@@ -276,7 +278,8 @@ const MembersDirectory = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gradient-to-bl from-[var(--neutral-100:)] to-[var(--neutral-800)]">
|
<div className="min-h-screen bg-gradient-to-bl from-[var(--neutral-100:)] to-[var(--neutral-800)]">
|
||||||
@@ -377,7 +380,7 @@ const MembersDirectory = () => {
|
|||||||
|
|
||||||
{/* Profile Detail Dialog */}
|
{/* Profile Detail Dialog */}
|
||||||
<Dialog open={profileDialogOpen} onOpenChange={setProfileDialogOpen}>
|
<Dialog open={profileDialogOpen} onOpenChange={setProfileDialogOpen}>
|
||||||
<DialogContent className="sm:max-w-[600px] bg-background rounded-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="sm:max-w-[600px] bg-background rounded-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
{selectedMember && (
|
{selectedMember && (
|
||||||
<>
|
<>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export default function NewsletterArchive() {
|
|||||||
onClick={clearFilter}
|
onClick={clearFilter}
|
||||||
variant={selectedYear === null ? "default" : "outline"}
|
variant={selectedYear === null ? "default" : "outline"}
|
||||||
size="sm"
|
size="sm"
|
||||||
className={selectedYear === null ? "bg-brand-purple text-white" : "border-brand-purple text-brand-purple "}
|
className={selectedYear === null ? "bg-brand-purple hover:bg-[var(--purple-muted)] text-white" : "border-brand-lavender text-brand-lavender "}
|
||||||
>
|
>
|
||||||
All Years
|
All Years
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-ghost {
|
.btn-ghost {
|
||||||
@apply hover:bg-accent hover:text-accent-foreground rounded-full disabled:opacity-50 px-6 transition-transform;
|
@apply hover:bg-brand-purple bg-brand-purple/10 rounded-full disabled:opacity-50 px-6 transition-transform text-brand-purple hover:text-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-outline {
|
.btn-outline {
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-outline-destructive {
|
.btn-outline-destructive {
|
||||||
@apply border border-destructive border-2 text-destructive shadow-sm hover:bg-destructive/10 dark:hover:bg-destructive/10 rounded-full disabled:opacity-50 px-6 transition-transform;
|
@apply border border-destructive bg-none border-2 text-destructive shadow-sm hover:bg-destructive/10 dark:hover:bg-destructive/10 rounded-full disabled:opacity-50 px-6 transition-transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-link {
|
.btn-link {
|
||||||
@@ -55,12 +55,15 @@
|
|||||||
.btn-icon {
|
.btn-icon {
|
||||||
@apply h-9 w-9 rounded-full disabled:opacity-50 px-6;
|
@apply h-9 w-9 rounded-full disabled:opacity-50 px-6;
|
||||||
}
|
}
|
||||||
|
.btn-green {
|
||||||
|
@apply bg-[var(--green-light)] hover:bg-[var(--green-forest)] text-white transition-transform rounded-full px-6;
|
||||||
|
}
|
||||||
.btn-util-green {
|
.btn-util-green {
|
||||||
@apply bg-[var(--green-light)] hover:bg-[var(--green-forest)] text-white transition-transform rounded-xl h-12 px-6 transition-transform;
|
@apply bg-[var(--green-light)] hover:bg-[var(--green-forest)] text-white transition-transform rounded-xl h-12 px-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-util-purple {
|
.btn-util-purple {
|
||||||
@apply bg-[var(--purple-lavender)] transition-transform hover:bg-[var(--purple-ink-2)] text-background dark:text-white dark:hover:text-white rounded-xl h-12 px-6 transition-transform;
|
@apply bg-[var(--purple-lavender)] hover:bg-[var(--purple-ink-2)] text-background dark:text-white dark:hover:text-white rounded-xl h-12 px-6 transition-transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-light-orange {
|
.btn-light-orange {
|
||||||
@@ -70,24 +73,22 @@
|
|||||||
@apply bg-brand-pink hover:bg-brand-dark-rose dark:text-[var(--lavender-100)] text-background dark:hover:text-white rounded-xl h-12 px-6 transition-transform;
|
@apply bg-brand-pink hover:bg-brand-dark-rose dark:text-[var(--lavender-100)] text-background dark:hover:text-white rounded-xl h-12 px-6 transition-transform;
|
||||||
}
|
}
|
||||||
.btn-lavender {
|
.btn-lavender {
|
||||||
@apply bg-[var(--purple-lavender)] text-white hover:bg-[var(--purple-muted)] rounded-full flex items-center gap-2 dark:hover:bg-brand-lavender dark:hover:text-brand-dark-lavender;
|
@apply bg-[var(--purple-lavender)] text-white hover:bg-[var(--purple-muted)] rounded-full flex items-center gap-2 dark:hover:bg-foreground dark:hover:text-background;
|
||||||
}
|
}
|
||||||
.btn-light-lavender {
|
.btn-light-lavender {
|
||||||
@apply bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-brand-lavender rounded-full px-6 transition-transform dark:hover:bg-brand-lavender dark:hover:text-brand-dark-lavender ;
|
@apply bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-brand-lavender rounded-full px-6 transition-transform dark:hover:bg-brand-lavender dark:hover:text-brand-dark-lavender;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Badges */
|
/* Badges */
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
@apply px-3 py-1 rounded-full text-sm font-medium transition-transform;
|
@apply px-3 py-1 rounded-full text-sm font-medium transition-transform;
|
||||||
}
|
}
|
||||||
.badge-green {
|
.badge-green {
|
||||||
@apply bg-[var(--green-light)] text-white transition-transform;
|
@apply bg-[var(--green-light)] text-white transition-transform;
|
||||||
}
|
}
|
||||||
/* Backgrounds */
|
/* Backgrounds */
|
||||||
.bg-light-lavender {
|
.bg-light-lavender {
|
||||||
@apply bg-gradient-to-br from-brand-purple to-[var(--purple-ink)] text-white bg-[var(--neutral-800)] transition-transform dark:bg-brand-lavender dark:text-brand-dark-lavender;
|
@apply bg-gradient-to-br from-brand-purple to-[var(--purple-ink)] text-white bg-[var(--neutral-800)] transition-transform dark:bg-brand-lavender dark:text-brand-dark-lavender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
--blue-linkedin: #0a66c2;
|
--blue-linkedin: #0a66c2;
|
||||||
--blue-facebook: #1877f2;
|
--blue-facebook: #1877f2;
|
||||||
--blue-twitter: #1da1f2;
|
--blue-twitter: #1da1f2;
|
||||||
|
--red-instagram: #e4405f;
|
||||||
--purple-ink: #422268;
|
--purple-ink: #422268;
|
||||||
--purple-ink-2: #422268;
|
--purple-ink-2: #422268;
|
||||||
--purple-deep: #48286e;
|
--purple-deep: #48286e;
|
||||||
@@ -77,7 +78,7 @@
|
|||||||
--green-muted: #66927e;
|
--green-muted: #66927e;
|
||||||
--green-soft: #6a9680;
|
--green-soft: #6a9680;
|
||||||
--green-eucalyptus: #6a9a83;
|
--green-eucalyptus: #6a9a83;
|
||||||
--green-forest: #5e8374;
|
--green-forest: #5a7d68;
|
||||||
--green-fern: #6da085;
|
--green-fern: #6da085;
|
||||||
--green-mint: #6fa087;
|
--green-mint: #6fa087;
|
||||||
--green-pastel: #6fa188;
|
--green-pastel: #6fa188;
|
||||||
@@ -96,7 +97,6 @@
|
|||||||
--gold-warm: #f2cc8f;
|
--gold-warm: #f2cc8f;
|
||||||
--gold-soft: #e8bf7a;
|
--gold-soft: #e8bf7a;
|
||||||
--gold-warm: #f2cc8f;
|
--gold-warm: #f2cc8f;
|
||||||
--red-instagram: #e4405f;
|
|
||||||
--red-soft: #ffebee;
|
--red-soft: #ffebee;
|
||||||
--lavender-100: #e8e0f5;
|
--lavender-100: #e8e0f5;
|
||||||
--lavender-200: #eeebf4;
|
--lavender-200: #eeebf4;
|
||||||
|
|||||||
66
src/utils/logger.js
Normal file
66
src/utils/logger.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* Production-safe logging utility
|
||||||
|
*
|
||||||
|
* In production (NODE_ENV=production), logs are disabled by default
|
||||||
|
* to prevent exposing sensitive information in browser console.
|
||||||
|
*
|
||||||
|
* In development, all logs are shown for debugging.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* import logger from '../utils/logger';
|
||||||
|
* logger.log('[Component]', 'message', data);
|
||||||
|
* logger.error('[Component]', 'error message', error);
|
||||||
|
* logger.warn('[Component]', 'warning message');
|
||||||
|
*/
|
||||||
|
|
||||||
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
|
// Force enable logs with REACT_APP_DEBUG_LOGS=true in .env
|
||||||
|
const debugEnabled = process.env.REACT_APP_DEBUG_LOGS === 'true';
|
||||||
|
|
||||||
|
const shouldLog = isDevelopment || debugEnabled;
|
||||||
|
|
||||||
|
const logger = {
|
||||||
|
log: (...args) => {
|
||||||
|
if (shouldLog) {
|
||||||
|
console.log(...args);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
error: (...args) => {
|
||||||
|
// Always log errors, but sanitize in production
|
||||||
|
if (shouldLog) {
|
||||||
|
console.error(...args);
|
||||||
|
} else {
|
||||||
|
// In production, only log error type without details
|
||||||
|
console.error('An error occurred. Enable debug logs for details.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
warn: (...args) => {
|
||||||
|
if (shouldLog) {
|
||||||
|
console.warn(...args);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
info: (...args) => {
|
||||||
|
if (shouldLog) {
|
||||||
|
console.info(...args);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
debug: (...args) => {
|
||||||
|
if (shouldLog) {
|
||||||
|
console.debug(...args);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Special method for sensitive data - NEVER logs in production
|
||||||
|
sensitive: (...args) => {
|
||||||
|
if (isDevelopment) {
|
||||||
|
console.log('[SENSITIVE]', ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default logger;
|
||||||
Reference in New Issue
Block a user