Compare commits
20 Commits
a1c68eedc2
...
features
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0ee505339 | ||
|
|
21338f1541 | ||
|
|
da366272b4 | ||
|
|
af27190e29 | ||
|
|
235156a9ee | ||
|
|
68ee22c124 | ||
|
|
5d085153f6 | ||
|
|
01a3c38085 | ||
|
|
7152382dca | ||
|
|
529d3d4697 | ||
|
|
7eef62560e | ||
|
|
f70a133e18 | ||
|
|
d5152609b6 | ||
|
|
de719d9d69 | ||
|
|
27d5c48805 | ||
|
|
64d631d890 | ||
|
|
4423576fa2 | ||
|
|
a77fbc47e3 | ||
|
|
d638afcdb2 | ||
|
|
a247ac5219 |
25
src/App.js
25
src/App.js
@@ -47,6 +47,7 @@ import AdminGallery from './pages/admin/AdminGallery';
|
|||||||
import AdminNewsletters from './pages/admin/AdminNewsletters';
|
import AdminNewsletters from './pages/admin/AdminNewsletters';
|
||||||
import AdminFinancials from './pages/admin/AdminFinancials';
|
import AdminFinancials from './pages/admin/AdminFinancials';
|
||||||
import AdminBylaws from './pages/admin/AdminBylaws';
|
import AdminBylaws from './pages/admin/AdminBylaws';
|
||||||
|
import AdminRegistrationBuilder from './pages/admin/AdminRegistrationBuilder';
|
||||||
import History from './pages/History';
|
import History from './pages/History';
|
||||||
import MissionValues from './pages/MissionValues';
|
import MissionValues from './pages/MissionValues';
|
||||||
import BoardOfDirectors from './pages/BoardOfDirectors';
|
import BoardOfDirectors from './pages/BoardOfDirectors';
|
||||||
@@ -61,19 +62,19 @@ import NotFound from './pages/NotFound';
|
|||||||
|
|
||||||
const PrivateRoute = ({ children, adminOnly = false }) => {
|
const PrivateRoute = ({ children, adminOnly = false }) => {
|
||||||
const { user, loading } = useAuth();
|
const { user, loading } = useAuth();
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <div className="min-h-screen flex items-center justify-center">Loading...</div>;
|
return <div className="min-h-screen flex items-center justify-center">Loading...</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return <Navigate to="/login" />;
|
return <Navigate to="/login" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adminOnly && !['admin', 'superadmin'].includes(user.role)) {
|
if (adminOnly && !['admin', 'superadmin'].includes(user.role)) {
|
||||||
return <Navigate to="/dashboard" />;
|
return <Navigate to="/dashboard" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return children;
|
return children;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -238,6 +239,20 @@ function App() {
|
|||||||
</AdminLayout>
|
</AdminLayout>
|
||||||
</PrivateRoute>
|
</PrivateRoute>
|
||||||
} />
|
} />
|
||||||
|
<Route path="/admin/registration" element={
|
||||||
|
<PrivateRoute adminOnly>
|
||||||
|
<AdminLayout>
|
||||||
|
<AdminRegistrationBuilder />
|
||||||
|
</AdminLayout>
|
||||||
|
</PrivateRoute>
|
||||||
|
} />
|
||||||
|
<Route path="/admin/member-tiers" element={
|
||||||
|
<PrivateRoute adminOnly>
|
||||||
|
<AdminLayout>
|
||||||
|
<AdminMemberTiers />
|
||||||
|
</AdminLayout>
|
||||||
|
</PrivateRoute>
|
||||||
|
} />
|
||||||
<Route path="/admin/plans" element={
|
<Route path="/admin/plans" element={
|
||||||
<PrivateRoute adminOnly>
|
<PrivateRoute adminOnly>
|
||||||
<AdminLayout>
|
<AdminLayout>
|
||||||
@@ -292,6 +307,7 @@ function App() {
|
|||||||
<Navigate to="/admin/settings/permissions" replace />
|
<Navigate to="/admin/settings/permissions" replace />
|
||||||
</PrivateRoute>
|
</PrivateRoute>
|
||||||
} />
|
} />
|
||||||
|
|
||||||
<Route path="/admin/settings" element={
|
<Route path="/admin/settings" element={
|
||||||
<PrivateRoute adminOnly>
|
<PrivateRoute adminOnly>
|
||||||
<AdminLayout>
|
<AdminLayout>
|
||||||
@@ -302,7 +318,6 @@ function App() {
|
|||||||
<Route index element={<Navigate to="stripe" replace />} />
|
<Route index element={<Navigate to="stripe" replace />} />
|
||||||
<Route path="stripe" element={<AdminSettings />} />
|
<Route path="stripe" element={<AdminSettings />} />
|
||||||
<Route path="permissions" element={<AdminRoles />} />
|
<Route path="permissions" element={<AdminRoles />} />
|
||||||
<Route path="member-tiers" element={<AdminMemberTiers />} />
|
|
||||||
<Route path="theme" element={<AdminTheme />} />
|
<Route path="theme" element={<AdminTheme />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
|||||||
222
src/components/AddPaymentMethodDialog.js
Normal file
222
src/components/AddPaymentMethodDialog.js
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { useStripe, useElements, CardElement } from '@stripe/react-stripe-js';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Checkbox } from './ui/checkbox';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { CreditCard, AlertCircle, Loader2 } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import api from '../utils/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddPaymentMethodDialog - Dialog for adding a new payment method using Stripe Elements
|
||||||
|
*
|
||||||
|
* This dialog should be wrapped in an Elements provider with a clientSecret
|
||||||
|
*
|
||||||
|
* @param {string} saveEndpoint - Optional custom API endpoint for saving (default: '/payment-methods')
|
||||||
|
*/
|
||||||
|
const AddPaymentMethodDialog = ({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
onSuccess,
|
||||||
|
clientSecret,
|
||||||
|
saveEndpoint = '/payment-methods',
|
||||||
|
}) => {
|
||||||
|
const stripe = useStripe();
|
||||||
|
const elements = useElements();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [setAsDefault, setSetAsDefault] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const handleSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (!stripe || !elements) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get the CardElement
|
||||||
|
const cardElement = elements.getElement(CardElement);
|
||||||
|
|
||||||
|
if (!cardElement) {
|
||||||
|
setError('Card element not found');
|
||||||
|
toast.error('Card element not found');
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirm the SetupIntent with the card element
|
||||||
|
const { error: stripeError, setupIntent } = await stripe.confirmCardSetup(
|
||||||
|
clientSecret,
|
||||||
|
{
|
||||||
|
payment_method: {
|
||||||
|
card: cardElement,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (stripeError) {
|
||||||
|
setError(stripeError.message);
|
||||||
|
toast.error(stripeError.message);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setupIntent.status === 'succeeded') {
|
||||||
|
// Save the payment method to our backend using the specified endpoint
|
||||||
|
await api.post(saveEndpoint, {
|
||||||
|
stripe_payment_method_id: setupIntent.payment_method,
|
||||||
|
set_as_default: setAsDefault,
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.success('Payment method added successfully');
|
||||||
|
onSuccess?.();
|
||||||
|
onOpenChange(false);
|
||||||
|
} else {
|
||||||
|
setError(`Setup failed with status: ${setupIntent.status}`);
|
||||||
|
toast.error('Failed to set up payment method');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || err.message || 'Failed to save payment method';
|
||||||
|
setError(errorMessage);
|
||||||
|
toast.error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="bg-background rounded-2xl border border-[var(--neutral-800)] p-0 overflow-hidden max-w-md">
|
||||||
|
<DialogHeader className="bg-brand-purple text-white px-6 py-4">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<CreditCard className="h-6 w-6" />
|
||||||
|
<div>
|
||||||
|
<DialogTitle
|
||||||
|
className="text-lg font-semibold text-white"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
Add Payment Method
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription
|
||||||
|
className="text-white/80 text-sm"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Enter your card details securely
|
||||||
|
</DialogDescription>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="p-6 space-y-6">
|
||||||
|
{/* Stripe Card Element */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label
|
||||||
|
className="text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
Card Information
|
||||||
|
</Label>
|
||||||
|
<div className="border border-[var(--neutral-800)] rounded-xl p-4 bg-white">
|
||||||
|
<CardElement
|
||||||
|
options={{
|
||||||
|
style: {
|
||||||
|
base: {
|
||||||
|
fontSize: '16px',
|
||||||
|
color: '#2d2a4a',
|
||||||
|
fontFamily: "'Nunito Sans', sans-serif",
|
||||||
|
'::placeholder': {
|
||||||
|
color: '#9ca3af',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
invalid: {
|
||||||
|
color: '#ef4444',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
hidePostalCode: false,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Set as Default Checkbox */}
|
||||||
|
<div className="flex items-center space-x-3">
|
||||||
|
<Checkbox
|
||||||
|
id="setAsDefault"
|
||||||
|
checked={setAsDefault}
|
||||||
|
onCheckedChange={setSetAsDefault}
|
||||||
|
className="border-brand-purple data-[state=checked]:bg-brand-purple"
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor="setAsDefault"
|
||||||
|
className="text-sm text-brand-purple cursor-pointer"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Set as default payment method for future payments
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Error Message */}
|
||||||
|
{error && (
|
||||||
|
<div className="flex items-start gap-2 p-3 bg-red-50 border border-red-200 rounded-xl">
|
||||||
|
<AlertCircle className="h-5 w-5 text-red-500 flex-shrink-0 mt-0.5" />
|
||||||
|
<p
|
||||||
|
className="text-sm text-red-600"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Security Note */}
|
||||||
|
<p
|
||||||
|
className="text-xs text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Your card information is securely processed by Stripe. We never store your full card number.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<DialogFooter className="flex-row gap-3 justify-end pt-4 border-t border-[var(--neutral-800)]">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
disabled={loading}
|
||||||
|
className="border-2 border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-300)] rounded-full px-6"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={!stripe || loading}
|
||||||
|
className="bg-brand-purple text-white hover:bg-[var(--purple-ink)] rounded-full px-6"
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Saving...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'Add Card'
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddPaymentMethodDialog;
|
||||||
@@ -27,6 +27,8 @@ import {
|
|||||||
Heart,
|
Heart,
|
||||||
Sun,
|
Sun,
|
||||||
Moon,
|
Moon,
|
||||||
|
Star,
|
||||||
|
FileEdit
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
|
||||||
const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
||||||
@@ -104,18 +106,31 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
path: '/admin',
|
path: '/admin',
|
||||||
disabled: false
|
disabled: false
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'Staff',
|
name: 'Staff & Admins',
|
||||||
icon: UserCog,
|
icon: UserCog,
|
||||||
path: '/admin/staff',
|
path: '/admin/staff',
|
||||||
disabled: false
|
disabled: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Members',
|
name: 'Member Roster',
|
||||||
icon: Users,
|
icon: Users,
|
||||||
path: '/admin/members',
|
path: '/admin/members',
|
||||||
disabled: false
|
disabled: false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Member Tiers',
|
||||||
|
icon: Star,
|
||||||
|
path: '/admin/member-tiers',
|
||||||
|
disabled: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Registration',
|
||||||
|
icon: FileEdit,
|
||||||
|
path: '/admin/registration',
|
||||||
|
disabled: false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Validations',
|
name: 'Validations',
|
||||||
icon: CheckCircle,
|
icon: CheckCircle,
|
||||||
@@ -316,6 +331,18 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
{/* Dashboard - Standalone */}
|
{/* Dashboard - Standalone */}
|
||||||
{renderNavItem(filteredNavItems.find(item => item.name === 'Dashboard'))}
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Dashboard'))}
|
||||||
|
|
||||||
|
{/* Onboarding Section */}
|
||||||
|
{isOpen && (
|
||||||
|
<div className="px-4 py-2 mt-6">
|
||||||
|
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||||
|
Onboarding
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="space-y-1">
|
||||||
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Registration'))}
|
||||||
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Validations'))}
|
||||||
|
</div>
|
||||||
{/* MEMBERSHIP Section */}
|
{/* MEMBERSHIP Section */}
|
||||||
{isOpen && (
|
{isOpen && (
|
||||||
<div className="px-4 py-2 mt-6">
|
<div className="px-4 py-2 mt-6">
|
||||||
@@ -325,9 +352,9 @@ const AdminSidebar = ({ isOpen, onToggle, isMobile }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
{renderNavItem(filteredNavItems.find(item => item.name === 'Staff'))}
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Member Roster'))}
|
||||||
{renderNavItem(filteredNavItems.find(item => item.name === 'Members'))}
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Member Tiers'))}
|
||||||
{renderNavItem(filteredNavItems.find(item => item.name === 'Validations'))}
|
{renderNavItem(filteredNavItems.find(item => item.name === 'Staff & Admins'))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* FINANCIALS Section */}
|
{/* FINANCIALS Section */}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ const ChangePasswordDialog = ({ open, onOpenChange }) => {
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => onOpenChange(false)}
|
onClick={() => onOpenChange(false)}
|
||||||
className="btn-outline mr-33"
|
className="btn-outline mr-33 text-white"
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
576
src/components/CreateSubscriptionDialog.js
Normal file
576
src/components/CreateSubscriptionDialog.js
Normal file
@@ -0,0 +1,576 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import api from '../utils/api';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Input } from './ui/input';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { Textarea } from './ui/textarea';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from './ui/select';
|
||||||
|
import { Card } from './ui/card';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { Loader2, Repeat, Search, Calendar, Heart, X, User } from 'lucide-react';
|
||||||
|
|
||||||
|
const CreateSubscriptionDialog = ({ open, onOpenChange, onSuccess }) => {
|
||||||
|
// Search state
|
||||||
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
const [searchResults, setSearchResults] = useState([]);
|
||||||
|
const [selectedUser, setSelectedUser] = useState(null);
|
||||||
|
const [searchLoading, setSearchLoading] = useState(false);
|
||||||
|
const [allUsers, setAllUsers] = useState([]);
|
||||||
|
|
||||||
|
// Plan state
|
||||||
|
const [plans, setPlans] = useState([]);
|
||||||
|
const [selectedPlan, setSelectedPlan] = useState(null);
|
||||||
|
const [useCustomPeriod, setUseCustomPeriod] = useState(false);
|
||||||
|
|
||||||
|
// Form state
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
plan_id: '',
|
||||||
|
amount: '',
|
||||||
|
payment_date: new Date().toISOString().split('T')[0],
|
||||||
|
payment_method: 'cash',
|
||||||
|
custom_period_start: new Date().toISOString().split('T')[0],
|
||||||
|
custom_period_end: '',
|
||||||
|
notes: ''
|
||||||
|
});
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
// Fetch users and plans when dialog opens
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
if (!open) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [usersResponse, plansResponse] = await Promise.all([
|
||||||
|
api.get('/admin/users'),
|
||||||
|
api.get('/admin/subscriptions/plans')
|
||||||
|
]);
|
||||||
|
setAllUsers(usersResponse.data);
|
||||||
|
setPlans(plansResponse.data.filter(p => p.active));
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Failed to load data');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchData();
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
// Filter users based on search query
|
||||||
|
useEffect(() => {
|
||||||
|
if (!searchQuery.trim()) {
|
||||||
|
setSearchResults([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSearchLoading(true);
|
||||||
|
const query = searchQuery.toLowerCase();
|
||||||
|
const filtered = allUsers.filter(user =>
|
||||||
|
user.first_name?.toLowerCase().includes(query) ||
|
||||||
|
user.last_name?.toLowerCase().includes(query) ||
|
||||||
|
user.email?.toLowerCase().includes(query)
|
||||||
|
).slice(0, 10); // Limit to 10 results
|
||||||
|
|
||||||
|
setSearchResults(filtered);
|
||||||
|
setSearchLoading(false);
|
||||||
|
}, [searchQuery, allUsers]);
|
||||||
|
|
||||||
|
// Update amount when plan changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedPlan && !formData.amount) {
|
||||||
|
const suggestedAmount = (selectedPlan.suggested_price_cents || selectedPlan.minimum_price_cents || selectedPlan.price_cents) / 100;
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
amount: suggestedAmount.toFixed(2)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [selectedPlan]);
|
||||||
|
|
||||||
|
// Calculate donation breakdown
|
||||||
|
const getAmountBreakdown = () => {
|
||||||
|
if (!selectedPlan || !formData.amount) return null;
|
||||||
|
|
||||||
|
const totalCents = Math.round(parseFloat(formData.amount) * 100);
|
||||||
|
const minimumCents = selectedPlan.minimum_price_cents || selectedPlan.price_cents || 3000;
|
||||||
|
const donationCents = Math.max(0, totalCents - minimumCents);
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: totalCents,
|
||||||
|
base: minimumCents,
|
||||||
|
donation: donationCents
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatPrice = (cents) => {
|
||||||
|
return `$${(cents / 100).toFixed(2)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const breakdown = getAmountBreakdown();
|
||||||
|
|
||||||
|
const handleSelectUser = (user) => {
|
||||||
|
setSelectedUser(user);
|
||||||
|
setSearchQuery('');
|
||||||
|
setSearchResults([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClearUser = () => {
|
||||||
|
setSelectedUser(null);
|
||||||
|
setFormData({
|
||||||
|
plan_id: '',
|
||||||
|
amount: '',
|
||||||
|
payment_date: new Date().toISOString().split('T')[0],
|
||||||
|
payment_method: 'cash',
|
||||||
|
custom_period_start: new Date().toISOString().split('T')[0],
|
||||||
|
custom_period_end: '',
|
||||||
|
notes: ''
|
||||||
|
});
|
||||||
|
setSelectedPlan(null);
|
||||||
|
setUseCustomPeriod(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (!selectedUser) {
|
||||||
|
toast.error('Please select a user');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formData.plan_id) {
|
||||||
|
toast.error('Please select a subscription plan');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formData.amount || parseFloat(formData.amount) <= 0) {
|
||||||
|
toast.error('Please enter a valid payment amount');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate minimum amount
|
||||||
|
const amountCents = Math.round(parseFloat(formData.amount) * 100);
|
||||||
|
const minimumCents = selectedPlan.minimum_price_cents || selectedPlan.price_cents || 3000;
|
||||||
|
if (amountCents < minimumCents) {
|
||||||
|
toast.error(`Amount must be at least ${formatPrice(minimumCents)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useCustomPeriod && (!formData.custom_period_start || !formData.custom_period_end)) {
|
||||||
|
toast.error('Please specify both start and end dates for custom period');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
plan_id: formData.plan_id,
|
||||||
|
amount_cents: amountCents,
|
||||||
|
payment_date: new Date(formData.payment_date).toISOString(),
|
||||||
|
payment_method: formData.payment_method,
|
||||||
|
override_plan_dates: useCustomPeriod,
|
||||||
|
notes: formData.notes || null
|
||||||
|
};
|
||||||
|
|
||||||
|
if (useCustomPeriod) {
|
||||||
|
payload.custom_period_start = new Date(formData.custom_period_start).toISOString();
|
||||||
|
payload.custom_period_end = new Date(formData.custom_period_end).toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
await api.post(`/admin/users/${selectedUser.id}/activate-payment`, payload);
|
||||||
|
toast.success(`Subscription created for ${selectedUser.first_name} ${selectedUser.last_name}!`);
|
||||||
|
|
||||||
|
// Reset form
|
||||||
|
handleClearUser();
|
||||||
|
onOpenChange(false);
|
||||||
|
if (onSuccess) onSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = error.response?.data?.detail || 'Failed to create subscription';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
handleClearUser();
|
||||||
|
setSearchQuery('');
|
||||||
|
setSearchResults([]);
|
||||||
|
onOpenChange(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleClose}>
|
||||||
|
<DialogContent className="sm:max-w-[700px] rounded-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<Repeat className="h-6 w-6" />
|
||||||
|
Create Subscription
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription className="text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
Search for an existing member and create a subscription with manual payment processing.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="grid gap-6 py-4">
|
||||||
|
{/* User Search Section */}
|
||||||
|
{!selectedUser ? (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Label className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Search Member
|
||||||
|
</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-5 w-5 text-brand-purple" />
|
||||||
|
<Input
|
||||||
|
placeholder="Search by name or email..."
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
className="pl-10 rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
/>
|
||||||
|
{searchLoading && (
|
||||||
|
<Loader2 className="absolute right-3 top-1/2 transform -translate-y-1/2 h-4 w-4 animate-spin text-brand-purple" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Search Results */}
|
||||||
|
{searchResults.length > 0 && (
|
||||||
|
<Card className="border-2 border-[var(--neutral-800)] rounded-xl overflow-hidden">
|
||||||
|
<div className="max-h-60 overflow-y-auto">
|
||||||
|
{searchResults.map((user) => (
|
||||||
|
<button
|
||||||
|
key={user.id}
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleSelectUser(user)}
|
||||||
|
className="w-full p-3 text-left hover:bg-[var(--lavender-400)] transition-colors border-b border-[var(--neutral-800)] last:border-b-0"
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="h-10 w-10 rounded-full bg-[var(--neutral-800)]/20 flex items-center justify-center">
|
||||||
|
<User className="h-5 w-5 text-brand-purple" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{user.first_name} {user.last_name}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{user.email}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{searchQuery && !searchLoading && searchResults.length === 0 && (
|
||||||
|
<p className="text-sm text-brand-purple text-center py-4" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
No members found matching "{searchQuery}"
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
/* Selected User Card */
|
||||||
|
<Card className="p-4 bg-[var(--lavender-400)] border-2 border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="h-12 w-12 rounded-full bg-[var(--neutral-800)]/20 flex items-center justify-center">
|
||||||
|
<User className="h-6 w-6 text-brand-purple" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{selectedUser.first_name} {selectedUser.last_name}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{selectedUser.email}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleClearUser}
|
||||||
|
className="text-brand-purple hover:bg-[var(--neutral-800)]/20"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Payment Form - Only show when user is selected */}
|
||||||
|
{selectedUser && (
|
||||||
|
<>
|
||||||
|
{/* Plan Selection */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="plan_id" className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Subscription Plan
|
||||||
|
</Label>
|
||||||
|
<Select
|
||||||
|
value={formData.plan_id}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
const plan = plans.find(p => p.id === value);
|
||||||
|
setSelectedPlan(plan);
|
||||||
|
const suggestedAmount = plan ? (plan.suggested_price_cents || plan.minimum_price_cents || plan.price_cents) / 100 : '';
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
plan_id: value,
|
||||||
|
amount: suggestedAmount ? suggestedAmount.toFixed(2) : ''
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="rounded-xl border-2 border-[var(--neutral-800)]">
|
||||||
|
<SelectValue placeholder="Select subscription plan" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{plans.map(plan => {
|
||||||
|
const minPrice = (plan.minimum_price_cents || plan.price_cents) / 100;
|
||||||
|
const sugPrice = plan.suggested_price_cents ? (plan.suggested_price_cents / 100) : null;
|
||||||
|
return (
|
||||||
|
<SelectItem key={plan.id} value={plan.id}>
|
||||||
|
{plan.name} - ${minPrice.toFixed(2)}{sugPrice && sugPrice > minPrice ? ` (Suggested: $${sugPrice.toFixed(2)})` : ''}/{plan.billing_cycle}
|
||||||
|
</SelectItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
{selectedPlan && (
|
||||||
|
<p className="text-xs text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{selectedPlan.description || `${selectedPlan.billing_cycle} subscription`}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Payment Amount */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="amount" className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Payment Amount ($)
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="amount"
|
||||||
|
type="number"
|
||||||
|
step="0.01"
|
||||||
|
min="0"
|
||||||
|
placeholder="Enter amount"
|
||||||
|
value={formData.amount}
|
||||||
|
onChange={(e) => setFormData({ ...formData, amount: e.target.value })}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
{selectedPlan && (
|
||||||
|
<p className="text-xs text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
Minimum: {formatPrice(selectedPlan.minimum_price_cents || selectedPlan.price_cents || 3000)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Amount Breakdown */}
|
||||||
|
{breakdown && breakdown.total >= breakdown.base && (
|
||||||
|
<Card className="p-4 bg-[var(--lavender-400)] border border-[var(--neutral-800)]">
|
||||||
|
<div className="space-y-2 text-sm" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
<div className="flex justify-between text-[var(--purple-ink)]">
|
||||||
|
<span>Membership Fee:</span>
|
||||||
|
<span className="font-semibold">{formatPrice(breakdown.base)}</span>
|
||||||
|
</div>
|
||||||
|
{breakdown.donation > 0 && (
|
||||||
|
<div className="flex justify-between text-[var(--orange-light)]">
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
<Heart className="h-4 w-4" />
|
||||||
|
Additional Donation:
|
||||||
|
</span>
|
||||||
|
<span className="font-semibold">{formatPrice(breakdown.donation)}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex justify-between text-[var(--purple-ink)] font-bold text-base pt-2 border-t border-[var(--neutral-800)]">
|
||||||
|
<span>Total:</span>
|
||||||
|
<span>{formatPrice(breakdown.total)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Payment Date */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="payment_date" className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Payment Date
|
||||||
|
</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Calendar className="absolute left-4 top-1/2 transform -translate-y-1/2 h-5 w-5 text-brand-purple" />
|
||||||
|
<Input
|
||||||
|
id="payment_date"
|
||||||
|
type="date"
|
||||||
|
value={formData.payment_date}
|
||||||
|
onChange={(e) => setFormData({ ...formData, payment_date: e.target.value })}
|
||||||
|
className="pl-12 rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Payment Method */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="payment_method" className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Payment Method
|
||||||
|
</Label>
|
||||||
|
<Select
|
||||||
|
value={formData.payment_method}
|
||||||
|
onValueChange={(value) => setFormData({ ...formData, payment_method: value })}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="rounded-xl border-2 border-[var(--neutral-800)]">
|
||||||
|
<SelectValue placeholder="Select payment method" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="cash">Cash</SelectItem>
|
||||||
|
<SelectItem value="bank_transfer">Bank Transfer</SelectItem>
|
||||||
|
<SelectItem value="check">Check</SelectItem>
|
||||||
|
<SelectItem value="other">Other</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Subscription Period */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Label className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Subscription Period
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="use_custom_period"
|
||||||
|
checked={useCustomPeriod}
|
||||||
|
onChange={(e) => setUseCustomPeriod(e.target.checked)}
|
||||||
|
className="rounded border-[var(--neutral-800)]"
|
||||||
|
/>
|
||||||
|
<Label htmlFor="use_custom_period" className="text-sm text-brand-purple font-normal cursor-pointer" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
Use custom dates instead of plan's billing cycle
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{useCustomPeriod ? (
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="custom_period_start" className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Start Date
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="custom_period_start"
|
||||||
|
type="date"
|
||||||
|
value={formData.custom_period_start}
|
||||||
|
onChange={(e) => setFormData({ ...formData, custom_period_start: e.target.value })}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
required={useCustomPeriod}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="custom_period_end" className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
End Date
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="custom_period_end"
|
||||||
|
type="date"
|
||||||
|
value={formData.custom_period_end}
|
||||||
|
onChange={(e) => setFormData({ ...formData, custom_period_end: e.target.value })}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
required={useCustomPeriod}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
selectedPlan && (
|
||||||
|
<div className="text-sm text-brand-purple bg-[var(--lavender-300)] p-3 rounded-lg space-y-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{selectedPlan.custom_cycle_enabled ? (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
<span className="font-medium text-[var(--purple-ink)]">Plan uses custom billing cycle:</span>
|
||||||
|
<br />
|
||||||
|
{(() => {
|
||||||
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||||
|
const startMonth = months[(selectedPlan.custom_cycle_start_month || 1) - 1];
|
||||||
|
const endMonth = months[(selectedPlan.custom_cycle_end_month || 12) - 1];
|
||||||
|
return `${startMonth} ${selectedPlan.custom_cycle_start_day} - ${endMonth} ${selectedPlan.custom_cycle_end_day} (recurring annually)`;
|
||||||
|
})()}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs">
|
||||||
|
Subscription will end on the upcoming cycle end date based on today's date.
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p>
|
||||||
|
Will use plan's billing cycle: <span className="font-medium">{selectedPlan.billing_cycle}</span>
|
||||||
|
<br />
|
||||||
|
Starts today, ends {selectedPlan.billing_cycle === 'monthly' ? '30 days' :
|
||||||
|
selectedPlan.billing_cycle === 'quarterly' ? '90 days' :
|
||||||
|
selectedPlan.billing_cycle === 'yearly' ? '1 year' :
|
||||||
|
selectedPlan.billing_cycle === 'lifetime' ? 'lifetime' : '1 year'} from now
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Notes */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="notes" className="text-[var(--purple-ink)] font-medium" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Notes (Optional)
|
||||||
|
</Label>
|
||||||
|
<Textarea
|
||||||
|
id="notes"
|
||||||
|
placeholder="Additional notes about the payment..."
|
||||||
|
value={formData.notes}
|
||||||
|
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple min-h-[100px]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleClose}
|
||||||
|
className="rounded-xl"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
className="rounded-xl bg-[var(--green-light)] hover:bg-[var(--green-fern)] text-white"
|
||||||
|
disabled={loading || !selectedUser}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Creating...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Repeat className="h-4 w-4 mr-2" />
|
||||||
|
Create Subscription
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CreateSubscriptionDialog;
|
||||||
281
src/components/InviteMemberDialog.js
Normal file
281
src/components/InviteMemberDialog.js
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import api from '../utils/api';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Input } from './ui/input';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { Loader2, Mail, Copy, Check } from 'lucide-react';
|
||||||
|
|
||||||
|
const InviteMemberDialog = ({ open, onOpenChange, onSuccess }) => {
|
||||||
|
const [formData, setFormData] = useState({
|
||||||
|
email: '',
|
||||||
|
first_name: '',
|
||||||
|
last_name: '',
|
||||||
|
phone: '',
|
||||||
|
role: 'admin'
|
||||||
|
});
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
const [invitationUrl, setInvitationUrl] = useState(null);
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
const [roles, setRoles] = useState([]);
|
||||||
|
const [loadingRoles, setLoadingRoles] = useState(false);
|
||||||
|
|
||||||
|
// Fetch roles when dialog opens
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
fetchRoles();
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const fetchRoles = async () => {
|
||||||
|
setLoadingRoles(true);
|
||||||
|
try {
|
||||||
|
// New endpoint returns roles based on user's permission level
|
||||||
|
// Superadmin: all roles
|
||||||
|
// Admin: admin, finance, and non-elevated custom roles
|
||||||
|
const response = await api.get('/admin/roles/assignable');
|
||||||
|
setRoles(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch assignable roles:', error);
|
||||||
|
toast.error('Failed to load roles. Please try again.');
|
||||||
|
} finally {
|
||||||
|
setLoadingRoles(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (field, value) => {
|
||||||
|
setFormData(prev => ({ ...prev, [field]: value }));
|
||||||
|
// Clear error when user starts typing
|
||||||
|
if (errors[field]) {
|
||||||
|
setErrors(prev => ({ ...prev, [field]: null }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const validate = () => {
|
||||||
|
const newErrors = {};
|
||||||
|
|
||||||
|
if (!formData.email) {
|
||||||
|
newErrors.email = 'Email is required';
|
||||||
|
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
|
||||||
|
newErrors.email = 'Invalid email format';
|
||||||
|
}
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return Object.keys(newErrors).length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (!validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await api.post('/admin/users/invite', formData);
|
||||||
|
toast.success('Invitation sent successfully');
|
||||||
|
|
||||||
|
// Show invitation URL
|
||||||
|
setInvitationUrl(response.data.invitation_url);
|
||||||
|
|
||||||
|
// Don't close dialog yet - show invitation URL first
|
||||||
|
if (onSuccess) onSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = error.response?.data?.detail || 'Failed to send invitation';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = () => {
|
||||||
|
navigator.clipboard.writeText(invitationUrl);
|
||||||
|
setCopied(true);
|
||||||
|
toast.success('Invitation link copied to clipboard');
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
// Reset form
|
||||||
|
setFormData({
|
||||||
|
email: '',
|
||||||
|
first_name: '',
|
||||||
|
last_name: '',
|
||||||
|
phone: '',
|
||||||
|
role: 'admin'
|
||||||
|
});
|
||||||
|
setInvitationUrl(null);
|
||||||
|
setCopied(false);
|
||||||
|
onOpenChange(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleClose}>
|
||||||
|
<DialogContent className="sm:max-w-[600px] rounded-2xl overflow-y-auto max-h-[90vh]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<Mail className="h-6 w-6" />
|
||||||
|
{invitationUrl ? 'Invitation Sent' : 'Invite Member'}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{invitationUrl
|
||||||
|
? 'The invitation has been sent via email. You can also copy the link below.'
|
||||||
|
: 'Send an email invitation to join as member. They will set their own password.'}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
{invitationUrl ? (
|
||||||
|
// Show invitation URL after successful send
|
||||||
|
<div className="py-4">
|
||||||
|
<Label className="text-[var(--purple-ink)] mb-2 block">Invitation Link (expires in 7 days)</Label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Input
|
||||||
|
value={invitationUrl}
|
||||||
|
readOnly
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] bg-gray-50"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={copyToClipboard}
|
||||||
|
className="rounded-xl bg-brand-purple hover:bg-[var(--purple-ink)] text-white flex-shrink-0"
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
<>
|
||||||
|
<Check className="h-4 w-4 mr-2" />
|
||||||
|
Copied
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Copy className="h-4 w-4 mr-2" />
|
||||||
|
Copy
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
// Show invitation form
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="grid gap-6 py-4">
|
||||||
|
{/* Email */}
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="email" className="text-[var(--purple-ink)]">
|
||||||
|
Email <span className="text-red-500">*</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={formData.email}
|
||||||
|
onChange={(e) => handleChange('email', e.target.value)}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple "
|
||||||
|
placeholder="member@example.com"
|
||||||
|
/>
|
||||||
|
{errors.email && (
|
||||||
|
<p className="text-sm text-red-500">{errors.email}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* First Name (Optional) */}
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="first_name" className="text-[var(--purple-ink)]">
|
||||||
|
First Name <span className="text-gray-400">(Optional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="first_name"
|
||||||
|
value={formData.first_name}
|
||||||
|
onChange={(e) => handleChange('first_name', e.target.value)}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple "
|
||||||
|
placeholder="Jane"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Last Name (Optional) */}
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="last_name" className="text-[var(--purple-ink)]">
|
||||||
|
Last Name <span className="text-gray-400">(Optional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="last_name"
|
||||||
|
value={formData.last_name}
|
||||||
|
onChange={(e) => handleChange('last_name', e.target.value)}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple "
|
||||||
|
placeholder="Doe"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Phone (Optional) */}
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="phone" className="text-[var(--purple-ink)]">
|
||||||
|
Phone <span className="text-gray-400">(Optional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="phone"
|
||||||
|
type="tel"
|
||||||
|
value={formData.phone}
|
||||||
|
onChange={(e) => handleChange('phone', e.target.value)}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple "
|
||||||
|
placeholder="(555) 123-4567"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleClose}
|
||||||
|
className="rounded-xl"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
className="rounded-xl bg-[var(--green-light)] hover:bg-[var(--green-fern)] text-white"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Sending...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Mail className="h-4 w-4 mr-2" />
|
||||||
|
Send Invitation
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{invitationUrl && (
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
onClick={handleClose}
|
||||||
|
className="rounded-xl bg-[var(--green-light)] hover:bg-[var(--green-fern)] text-white"
|
||||||
|
>
|
||||||
|
Done
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
)}
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InviteMemberDialog;
|
||||||
151
src/components/PasswordConfirmDialog.js
Normal file
151
src/components/PasswordConfirmDialog.js
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Input } from './ui/input';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { Shield, Eye, EyeOff, Loader2 } from 'lucide-react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PasswordConfirmDialog - Dialog requiring admin password re-entry for sensitive actions
|
||||||
|
*/
|
||||||
|
const PasswordConfirmDialog = ({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
onConfirm,
|
||||||
|
title = 'Confirm Your Identity',
|
||||||
|
description = 'Please enter your password to proceed with this action.',
|
||||||
|
loading = false,
|
||||||
|
}) => {
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const handleSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
if (!password.trim()) {
|
||||||
|
setError('Password is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await onConfirm(password);
|
||||||
|
setPassword('');
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message || 'Invalid password');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOpenChange = (isOpen) => {
|
||||||
|
if (!isOpen) {
|
||||||
|
setPassword('');
|
||||||
|
setError(null);
|
||||||
|
}
|
||||||
|
onOpenChange(isOpen);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent className="bg-background rounded-2xl border border-[var(--neutral-800)] p-0 overflow-hidden max-w-md">
|
||||||
|
<DialogHeader className="bg-brand-purple text-white px-6 py-4">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Shield className="h-6 w-6" />
|
||||||
|
<div>
|
||||||
|
<DialogTitle
|
||||||
|
className="text-lg font-semibold text-white"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription
|
||||||
|
className="text-white/80 text-sm"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</DialogDescription>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="p-6 space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label
|
||||||
|
htmlFor="password"
|
||||||
|
className="text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
Your Password
|
||||||
|
</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type={showPassword ? 'text' : 'password'}
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
placeholder="Enter your password"
|
||||||
|
className="border-[var(--neutral-800)] pr-10"
|
||||||
|
autoComplete="current-password"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowPassword(!showPassword)}
|
||||||
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-brand-purple hover:text-[var(--purple-ink)]"
|
||||||
|
>
|
||||||
|
{showPassword ? (
|
||||||
|
<EyeOff className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<Eye className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p
|
||||||
|
className="text-sm text-red-500"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DialogFooter className="flex-row gap-3 justify-end pt-4 border-t border-[var(--neutral-800)]">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => handleOpenChange(false)}
|
||||||
|
disabled={loading}
|
||||||
|
className="border-2 border-[var(--neutral-800)] text-brand-purple hover:bg-[var(--lavender-300)] rounded-full px-6"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={loading || !password.trim()}
|
||||||
|
className="bg-brand-purple text-white hover:bg-[var(--purple-ink)] rounded-full px-6"
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Verifying...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'Confirm'
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PasswordConfirmDialog;
|
||||||
186
src/components/PaymentMethodCard.js
Normal file
186
src/components/PaymentMethodCard.js
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { CreditCard, Trash2, Star, Banknote, Building2, FileCheck } from 'lucide-react';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card brand icon mapping
|
||||||
|
*/
|
||||||
|
const getBrandIcon = (brand) => {
|
||||||
|
const brandLower = brand?.toLowerCase();
|
||||||
|
// Return text abbreviation for known brands
|
||||||
|
switch (brandLower) {
|
||||||
|
case 'visa':
|
||||||
|
return 'VISA';
|
||||||
|
case 'mastercard':
|
||||||
|
return 'MC';
|
||||||
|
case 'amex':
|
||||||
|
case 'american_express':
|
||||||
|
return 'AMEX';
|
||||||
|
case 'discover':
|
||||||
|
return 'DISC';
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get icon for payment method type
|
||||||
|
*/
|
||||||
|
const getPaymentTypeIcon = (paymentType) => {
|
||||||
|
switch (paymentType) {
|
||||||
|
case 'cash':
|
||||||
|
return Banknote;
|
||||||
|
case 'bank_transfer':
|
||||||
|
return Building2;
|
||||||
|
case 'check':
|
||||||
|
return FileCheck;
|
||||||
|
default:
|
||||||
|
return CreditCard;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format payment type for display
|
||||||
|
*/
|
||||||
|
const formatPaymentType = (paymentType) => {
|
||||||
|
switch (paymentType) {
|
||||||
|
case 'cash':
|
||||||
|
return 'Cash';
|
||||||
|
case 'bank_transfer':
|
||||||
|
return 'Bank Transfer';
|
||||||
|
case 'check':
|
||||||
|
return 'Check';
|
||||||
|
case 'card':
|
||||||
|
return 'Card';
|
||||||
|
default:
|
||||||
|
return paymentType;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PaymentMethodCard - Displays a single payment method
|
||||||
|
*/
|
||||||
|
const PaymentMethodCard = ({
|
||||||
|
method,
|
||||||
|
onSetDefault,
|
||||||
|
onDelete,
|
||||||
|
loading = false,
|
||||||
|
showActions = true,
|
||||||
|
}) => {
|
||||||
|
const PaymentIcon = getPaymentTypeIcon(method.payment_type);
|
||||||
|
const brandAbbr = method.card_brand ? getBrandIcon(method.card_brand) : null;
|
||||||
|
const isExpired = method.card_exp_year && method.card_exp_month &&
|
||||||
|
new Date(method.card_exp_year, method.card_exp_month) < new Date();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`flex items-center justify-between p-4 border rounded-xl ${
|
||||||
|
method.is_default
|
||||||
|
? 'border-brand-purple bg-[var(--lavender-500)]'
|
||||||
|
: 'border-[var(--neutral-800)] bg-white'
|
||||||
|
} ${isExpired ? 'opacity-70' : ''}`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
{/* Payment Method Icon */}
|
||||||
|
<div className={`p-3 rounded-full ${
|
||||||
|
method.is_default
|
||||||
|
? 'bg-brand-purple text-white'
|
||||||
|
: 'bg-[var(--lavender-300)] text-brand-purple'
|
||||||
|
}`}>
|
||||||
|
<PaymentIcon className="h-5 w-5" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Payment Method Details */}
|
||||||
|
<div>
|
||||||
|
{method.payment_type === 'card' ? (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{brandAbbr && (
|
||||||
|
<span className="text-xs font-bold text-[var(--purple-ink)] bg-[var(--lavender-300)] px-2 py-0.5 rounded">
|
||||||
|
{brandAbbr}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
className="font-medium text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{method.card_brand ? method.card_brand.charAt(0).toUpperCase() + method.card_brand.slice(1) : 'Card'} •••• {method.card_last4 || '****'}
|
||||||
|
</span>
|
||||||
|
{method.is_default && (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-brand-purple font-medium">
|
||||||
|
<Star className="h-3 w-3 fill-current" />
|
||||||
|
Default
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
className={`text-sm ${isExpired ? 'text-red-500' : 'text-brand-purple'}`}
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{isExpired ? 'Expired' : 'Expires'} {method.card_exp_month?.toString().padStart(2, '0')}/{method.card_exp_year?.toString().slice(-2)}
|
||||||
|
{method.card_funding && (
|
||||||
|
<span className="ml-2 text-xs capitalize">({method.card_funding})</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className="font-medium text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{formatPaymentType(method.payment_type)}
|
||||||
|
</span>
|
||||||
|
{method.is_default && (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-brand-purple font-medium">
|
||||||
|
<Star className="h-3 w-3 fill-current" />
|
||||||
|
Default
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{method.manual_notes && (
|
||||||
|
<p
|
||||||
|
className="text-sm text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{method.manual_notes}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
{showActions && (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{!method.is_default && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onSetDefault?.(method.id)}
|
||||||
|
disabled={loading}
|
||||||
|
className="border border-brand-purple text-brand-purple hover:bg-[var(--lavender-300)] rounded-lg text-xs px-3"
|
||||||
|
>
|
||||||
|
Set Default
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onDelete?.(method.id)}
|
||||||
|
disabled={loading}
|
||||||
|
className="border border-red-500 text-red-500 hover:bg-red-50 rounded-lg p-2"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaymentMethodCard;
|
||||||
309
src/components/PaymentMethodsSection.js
Normal file
309
src/components/PaymentMethodsSection.js
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
|
import { loadStripe } from '@stripe/stripe-js';
|
||||||
|
import { Elements } from '@stripe/react-stripe-js';
|
||||||
|
import { Card } from './ui/card';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { CreditCard, Plus, Loader2, AlertCircle } from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import api from '../utils/api';
|
||||||
|
import PaymentMethodCard from './PaymentMethodCard';
|
||||||
|
import AddPaymentMethodDialog from './AddPaymentMethodDialog';
|
||||||
|
import ConfirmationDialog from './ConfirmationDialog';
|
||||||
|
|
||||||
|
// Initialize Stripe with publishable key from environment
|
||||||
|
const stripePromise = loadStripe(process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PaymentMethodsSection - Manages user payment methods
|
||||||
|
*
|
||||||
|
* Features:
|
||||||
|
* - List saved payment methods
|
||||||
|
* - Add new payment method via Stripe SetupIntent
|
||||||
|
* - Set default payment method
|
||||||
|
* - Delete payment methods
|
||||||
|
*/
|
||||||
|
const PaymentMethodsSection = () => {
|
||||||
|
const [paymentMethods, setPaymentMethods] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [actionLoading, setActionLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
// Dialog states
|
||||||
|
const [addDialogOpen, setAddDialogOpen] = useState(false);
|
||||||
|
const [clientSecret, setClientSecret] = useState(null);
|
||||||
|
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
|
||||||
|
const [methodToDelete, setMethodToDelete] = useState(null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch payment methods from API
|
||||||
|
*/
|
||||||
|
const fetchPaymentMethods = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
const response = await api.get('/payment-methods');
|
||||||
|
setPaymentMethods(response.data);
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to load payment methods';
|
||||||
|
setError(errorMessage);
|
||||||
|
console.error('Failed to fetch payment methods:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchPaymentMethods();
|
||||||
|
}, [fetchPaymentMethods]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create SetupIntent and open add dialog
|
||||||
|
*/
|
||||||
|
const handleAddNew = async () => {
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
const response = await api.post('/payment-methods/setup-intent');
|
||||||
|
setClientSecret(response.data.client_secret);
|
||||||
|
setAddDialogOpen(true);
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to initialize payment setup';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
console.error('Failed to create setup intent:', err);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle successful payment method addition
|
||||||
|
*/
|
||||||
|
const handleAddSuccess = () => {
|
||||||
|
setAddDialogOpen(false);
|
||||||
|
setClientSecret(null);
|
||||||
|
fetchPaymentMethods();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a payment method as default
|
||||||
|
*/
|
||||||
|
const handleSetDefault = async (methodId) => {
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
await api.put(`/payment-methods/${methodId}/default`);
|
||||||
|
toast.success('Default payment method updated');
|
||||||
|
fetchPaymentMethods();
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to update default payment method';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
console.error('Failed to set default:', err);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open delete confirmation dialog
|
||||||
|
*/
|
||||||
|
const handleDeleteClick = (methodId) => {
|
||||||
|
setMethodToDelete(methodId);
|
||||||
|
setDeleteConfirmOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirm and delete payment method
|
||||||
|
*/
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (!methodToDelete) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
await api.delete(`/payment-methods/${methodToDelete}`);
|
||||||
|
toast.success('Payment method removed');
|
||||||
|
setDeleteConfirmOpen(false);
|
||||||
|
setMethodToDelete(null);
|
||||||
|
fetchPaymentMethods();
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to remove payment method';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
console.error('Failed to delete payment method:', err);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stripe Elements options - simplified for CardElement
|
||||||
|
const elementsOptions = {
|
||||||
|
appearance: {
|
||||||
|
theme: 'stripe',
|
||||||
|
variables: {
|
||||||
|
colorPrimary: '#6b5b95',
|
||||||
|
colorBackground: '#ffffff',
|
||||||
|
colorText: '#2d2a4a',
|
||||||
|
colorDanger: '#ef4444',
|
||||||
|
fontFamily: "'Nunito Sans', sans-serif",
|
||||||
|
borderRadius: '12px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card className="space-y-4 px-6 pb-6">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="bg-brand-purple text-white px-4 py-3 rounded-t-lg -mx-6 -mt-0 flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<CreditCard className="h-5 w-5" />
|
||||||
|
<h3
|
||||||
|
className="font-semibold"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
Payment Methods
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleAddNew}
|
||||||
|
disabled={actionLoading}
|
||||||
|
size="sm"
|
||||||
|
className="bg-white text-brand-purple hover:bg-[var(--lavender-300)] rounded-lg px-3 py-1"
|
||||||
|
>
|
||||||
|
{actionLoading ? (
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Plus className="h-4 w-4 mr-1" />
|
||||||
|
Add
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Loading State */}
|
||||||
|
{loading && (
|
||||||
|
<div className="flex items-center justify-center py-8">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-brand-purple" />
|
||||||
|
<span
|
||||||
|
className="ml-2 text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Loading payment methods...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error State */}
|
||||||
|
{error && !loading && (
|
||||||
|
<div className="flex items-center gap-2 p-4 bg-red-50 border border-red-200 rounded-xl">
|
||||||
|
<AlertCircle className="h-5 w-5 text-red-500 flex-shrink-0" />
|
||||||
|
<p
|
||||||
|
className="text-sm text-red-600"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={fetchPaymentMethods}
|
||||||
|
className="ml-auto border-red-500 text-red-500 hover:bg-red-50 rounded-lg"
|
||||||
|
>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Payment Methods List */}
|
||||||
|
{!loading && !error && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{paymentMethods.length === 0 ? (
|
||||||
|
<div className="text-center py-8">
|
||||||
|
<CreditCard className="h-12 w-12 text-[var(--lavender-500)] mx-auto mb-3" />
|
||||||
|
<p
|
||||||
|
className="text-brand-purple mb-2"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
No payment methods saved
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
className="text-sm text-brand-purple/70 mb-4"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Add a card to make payments easier
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleAddNew}
|
||||||
|
disabled={actionLoading}
|
||||||
|
className="bg-brand-purple text-white hover:bg-[var(--purple-ink)] rounded-full px-6"
|
||||||
|
>
|
||||||
|
{actionLoading ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||||
|
Setting up...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Plus className="h-4 w-4 mr-2" />
|
||||||
|
Add Payment Method
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
paymentMethods.map((method) => (
|
||||||
|
<PaymentMethodCard
|
||||||
|
key={method.id}
|
||||||
|
method={method}
|
||||||
|
onSetDefault={handleSetDefault}
|
||||||
|
onDelete={handleDeleteClick}
|
||||||
|
loading={actionLoading}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Info Text */}
|
||||||
|
{!loading && paymentMethods.length > 0 && (
|
||||||
|
<p
|
||||||
|
className="text-xs text-brand-purple/70 pt-2 border-t border-[var(--neutral-800)]"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Your default payment method will be used for subscription renewals and donations.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Add Payment Method Dialog */}
|
||||||
|
{clientSecret && stripePromise && (
|
||||||
|
<Elements stripe={stripePromise} options={elementsOptions}>
|
||||||
|
<AddPaymentMethodDialog
|
||||||
|
open={addDialogOpen}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
setAddDialogOpen(open);
|
||||||
|
if (!open) setClientSecret(null);
|
||||||
|
}}
|
||||||
|
onSuccess={handleAddSuccess}
|
||||||
|
clientSecret={clientSecret}
|
||||||
|
/>
|
||||||
|
</Elements>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Delete Confirmation Dialog */}
|
||||||
|
<ConfirmationDialog
|
||||||
|
open={deleteConfirmOpen}
|
||||||
|
onOpenChange={setDeleteConfirmOpen}
|
||||||
|
onConfirm={handleDeleteConfirm}
|
||||||
|
title="Remove Payment Method"
|
||||||
|
description="Are you sure you want to remove this payment method? This action cannot be undone."
|
||||||
|
confirmText="Remove"
|
||||||
|
cancelText="Cancel"
|
||||||
|
variant="danger"
|
||||||
|
loading={actionLoading}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaymentMethodsSection;
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { NavLink, useLocation } from 'react-router-dom';
|
import { NavLink, useLocation } from 'react-router-dom';
|
||||||
import { CreditCard, Shield, Star, Palette } from 'lucide-react';
|
import { CreditCard, Shield, Star, Palette, FileEdit } from 'lucide-react';
|
||||||
|
|
||||||
const settingsItems = [
|
const settingsItems = [
|
||||||
{ label: 'Stripe', path: '/admin/settings/stripe', icon: CreditCard },
|
{ label: 'Stripe', path: '/admin/settings/stripe', icon: CreditCard },
|
||||||
{ label: 'Permissions', path: '/admin/settings/permissions', icon: Shield },
|
{ label: 'Permissions', path: '/admin/settings/permissions', icon: Shield },
|
||||||
{ label: 'Member Tiers', path: '/admin/settings/member-tiers', icon: Star },
|
|
||||||
{ label: 'Theme', path: '/admin/settings/theme', icon: Palette },
|
{ label: 'Theme', path: '/admin/settings/theme', icon: Palette },
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const SettingsTabs = () => {
|
const SettingsTabs = () => {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const STATUS_BADGE_CONFIG = {
|
|||||||
//status-based badges
|
//status-based badges
|
||||||
pending_email: { label: 'Pending Email', variant: 'orange2' },
|
pending_email: { label: 'Pending Email', variant: 'orange2' },
|
||||||
pending_validation: { label: 'Pending Validation', variant: 'gray' },
|
pending_validation: { label: 'Pending Validation', variant: 'gray' },
|
||||||
pre_validated: { label: 'Pre-Validated', variant: 'green' },
|
|
||||||
payment_pending: { label: 'Payment Pending', variant: 'orange' },
|
payment_pending: { label: 'Payment Pending', variant: 'orange' },
|
||||||
active: { label: 'Active', variant: 'green' },
|
active: { label: 'Active', variant: 'green' },
|
||||||
inactive: { label: 'Inactive', variant: 'gray2' },
|
inactive: { label: 'Inactive', variant: 'gray2' },
|
||||||
@@ -23,7 +22,12 @@ const STATUS_BADGE_CONFIG = {
|
|||||||
admin: { label: 'Admin', variant: 'purple' },
|
admin: { label: 'Admin', variant: 'purple' },
|
||||||
moderator: { label: 'Moderator', variant: 'bg-[var(--neutral-800)] text-[var(--purple-ink)]' },
|
moderator: { label: 'Moderator', variant: 'bg-[var(--neutral-800)] text-[var(--purple-ink)]' },
|
||||||
staff: { label: 'Staff', variant: 'gray' },
|
staff: { label: 'Staff', variant: 'gray' },
|
||||||
media: { label: 'Media', variant: 'gray2' }
|
media: { label: 'Media', variant: 'gray2' },
|
||||||
|
|
||||||
|
//donation badges
|
||||||
|
pending: { label: 'Payment Pending', variant: 'orange' },
|
||||||
|
completed: { label: 'Completed', variant: 'green' },
|
||||||
|
failed: { label: 'Failed', className: 'bg-red-100 text-red-700' }
|
||||||
};
|
};
|
||||||
|
|
||||||
//todo: make shield icon dynamic based on status
|
//todo: make shield icon dynamic based on status
|
||||||
|
|||||||
539
src/components/ViewRegistrationDialog.js
Normal file
539
src/components/ViewRegistrationDialog.js
Normal file
@@ -0,0 +1,539 @@
|
|||||||
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from './ui/dialog';
|
||||||
|
import { Button } from './ui/button';
|
||||||
|
import { Card } from './ui/card';
|
||||||
|
import { Checkbox } from './ui/checkbox';
|
||||||
|
import { Input } from './ui/input';
|
||||||
|
import { Label } from './ui/label';
|
||||||
|
import { Textarea } from './ui/textarea';
|
||||||
|
import { User, Mail, Phone, Calendar, UserCheck, Clock, FileText } from 'lucide-react';
|
||||||
|
import StatusBadge from './StatusBadge';
|
||||||
|
import api from '../utils/api';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
const ViewRegistrationDialog = ({ open, onOpenChange, user }) => {
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
|
const [formData, setFormData] = useState(null);
|
||||||
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
|
||||||
|
const autoSaveTimeoutRef = useRef(null);
|
||||||
|
const pendingSaveRef = useRef(false);
|
||||||
|
|
||||||
|
const leadSourceOptions = [
|
||||||
|
'Current member',
|
||||||
|
'Friend',
|
||||||
|
'OutSmart Magazine',
|
||||||
|
'Search engine (Google etc.)',
|
||||||
|
"I've known about LOAF for a long time",
|
||||||
|
'Other'
|
||||||
|
];
|
||||||
|
|
||||||
|
const volunteerOptions = [
|
||||||
|
'Welcoming new members at events',
|
||||||
|
'Sending out birthday cards',
|
||||||
|
'Care Team Calls',
|
||||||
|
'Sharing ideas for events',
|
||||||
|
'Researching grants',
|
||||||
|
'Applying for grants',
|
||||||
|
'Assisting with TeatherLOAFers',
|
||||||
|
'Assisting with ActiveLOAFers',
|
||||||
|
'Assisting with weekday Lunch Bunch',
|
||||||
|
'Uploading Photos to the Website',
|
||||||
|
'Assisting with eNewsletter',
|
||||||
|
'Other administrative task'
|
||||||
|
];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !user) return;
|
||||||
|
const nextFormData = {
|
||||||
|
lead_sources: Array.isArray(user.lead_sources) ? user.lead_sources : [],
|
||||||
|
partner_first_name: user.partner_first_name || '',
|
||||||
|
partner_last_name: user.partner_last_name || '',
|
||||||
|
partner_is_member: Boolean(user.partner_is_member),
|
||||||
|
partner_plan_to_become_member: Boolean(user.partner_plan_to_become_member),
|
||||||
|
newsletter_publish_name: Boolean(user.newsletter_publish_name),
|
||||||
|
newsletter_publish_photo: Boolean(user.newsletter_publish_photo),
|
||||||
|
newsletter_publish_birthday: Boolean(user.newsletter_publish_birthday),
|
||||||
|
newsletter_publish_none: Boolean(user.newsletter_publish_none),
|
||||||
|
referred_by_member_name: user.referred_by_member_name || '',
|
||||||
|
volunteer_interests: Array.isArray(user.volunteer_interests) ? user.volunteer_interests : [],
|
||||||
|
scholarship_requested: Boolean(user.scholarship_requested),
|
||||||
|
scholarship_reason: user.scholarship_reason || ''
|
||||||
|
};
|
||||||
|
setFormData(nextFormData);
|
||||||
|
setHasUnsavedChanges(false);
|
||||||
|
}, [open, user]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (autoSaveTimeoutRef.current) {
|
||||||
|
clearTimeout(autoSaveTimeoutRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const formatDate = (dateString) => {
|
||||||
|
if (!dateString) return '—';
|
||||||
|
return new Date(dateString).toLocaleDateString('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDateTime = (dateString) => {
|
||||||
|
if (!dateString) return '—';
|
||||||
|
return new Date(dateString).toLocaleString('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatPhoneNumber = (phone) => {
|
||||||
|
if (!phone) return '—';
|
||||||
|
const cleaned = phone.replace(/\D/g, '');
|
||||||
|
if (cleaned.length === 10) {
|
||||||
|
return `(${cleaned.slice(0, 3)}) ${cleaned.slice(3, 6)}-${cleaned.slice(6)}`;
|
||||||
|
}
|
||||||
|
return phone;
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveProfile = async (showToast = true) => {
|
||||||
|
if (!formData) return;
|
||||||
|
if (isSaving) {
|
||||||
|
pendingSaveRef.current = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSaving(true);
|
||||||
|
try {
|
||||||
|
await api.put('/users/profile', {
|
||||||
|
lead_sources: formData.lead_sources,
|
||||||
|
partner_first_name: formData.partner_first_name,
|
||||||
|
partner_last_name: formData.partner_last_name,
|
||||||
|
partner_is_member: formData.partner_is_member,
|
||||||
|
partner_plan_to_become_member: formData.partner_plan_to_become_member,
|
||||||
|
newsletter_publish_name: formData.newsletter_publish_name,
|
||||||
|
newsletter_publish_photo: formData.newsletter_publish_photo,
|
||||||
|
newsletter_publish_birthday: formData.newsletter_publish_birthday,
|
||||||
|
newsletter_publish_none: formData.newsletter_publish_none,
|
||||||
|
referred_by_member_name: formData.referred_by_member_name,
|
||||||
|
volunteer_interests: formData.volunteer_interests,
|
||||||
|
scholarship_requested: formData.scholarship_requested,
|
||||||
|
scholarship_reason: formData.scholarship_reason
|
||||||
|
});
|
||||||
|
setHasUnsavedChanges(false);
|
||||||
|
if (showToast) {
|
||||||
|
toast.success('Registration details saved');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (showToast) {
|
||||||
|
toast.error(error.response?.data?.detail || 'Failed to save registration details');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setIsSaving(false);
|
||||||
|
if (pendingSaveRef.current) {
|
||||||
|
pendingSaveRef.current = false;
|
||||||
|
saveProfile(showToast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const scheduleAutoSave = () => {
|
||||||
|
setHasUnsavedChanges(true);
|
||||||
|
if (autoSaveTimeoutRef.current) {
|
||||||
|
clearTimeout(autoSaveTimeoutRef.current);
|
||||||
|
}
|
||||||
|
autoSaveTimeoutRef.current = setTimeout(() => {
|
||||||
|
saveProfile(false);
|
||||||
|
}, 800);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputChange = (e) => {
|
||||||
|
const { name, value } = e.target;
|
||||||
|
setFormData(prev => {
|
||||||
|
const next = { ...prev, [name]: value };
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
scheduleAutoSave();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCheckboxChange = (name, checked) => {
|
||||||
|
setFormData(prev => ({ ...prev, [name]: checked }));
|
||||||
|
scheduleAutoSave();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLeadSourceChange = (source) => {
|
||||||
|
setFormData(prev => {
|
||||||
|
const sources = prev.lead_sources.includes(source)
|
||||||
|
? prev.lead_sources.filter((item) => item !== source)
|
||||||
|
: [...prev.lead_sources, source];
|
||||||
|
return { ...prev, lead_sources: sources };
|
||||||
|
});
|
||||||
|
scheduleAutoSave();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVolunteerChange = (option) => {
|
||||||
|
setFormData(prev => {
|
||||||
|
const interests = prev.volunteer_interests.includes(option)
|
||||||
|
? prev.volunteer_interests.filter((item) => item !== option)
|
||||||
|
: [...prev.volunteer_interests, option];
|
||||||
|
return { ...prev, volunteer_interests: interests };
|
||||||
|
});
|
||||||
|
scheduleAutoSave();
|
||||||
|
};
|
||||||
|
|
||||||
|
const InfoRow = ({ icon: Icon, label, value }) => (
|
||||||
|
<div className="flex items-start gap-3 py-3 border-b border-[var(--neutral-800)] last:border-b-0">
|
||||||
|
<div className="h-10 w-10 rounded-lg bg-[var(--lavender-400)] flex items-center justify-center flex-shrink-0">
|
||||||
|
<Icon className="h-5 w-5 text-brand-purple" />
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{label}
|
||||||
|
</p>
|
||||||
|
<p className="font-medium text-[var(--purple-ink)] break-words" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{value || '—'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[600px] rounded-2xl max-h-[90vh] overflow-y-auto scrollbar-dashboard">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="text-2xl text-[var(--purple-ink)] flex items-center gap-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
<FileText className="h-6 w-6" />
|
||||||
|
Registration Details
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription className="text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
View the registration information for this member application.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="py-4 space-y-4">
|
||||||
|
{/* User Header Card */}
|
||||||
|
<Card className="p-4 bg-[var(--lavender-400)] border-2 border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<div className="h-16 w-16 rounded-full bg-[var(--neutral-800)]/20 flex items-center justify-center">
|
||||||
|
<User className="h-8 w-8 text-brand-purple" />
|
||||||
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<p className="text-xl font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{user.first_name} {user.last_name}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{user.email}
|
||||||
|
</p>
|
||||||
|
<div className="mt-2">
|
||||||
|
<StatusBadge status={user.status} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Contact Information */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Contact Information
|
||||||
|
</h3>
|
||||||
|
<InfoRow icon={Mail} label="Email Address" value={user.email} />
|
||||||
|
<InfoRow icon={Phone} label="Phone Number" value={formatPhoneNumber(user.phone)} />
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Registration Details */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Registration Details
|
||||||
|
</h3>
|
||||||
|
<InfoRow icon={Calendar} label="Registration Date" value={formatDate(user.created_at)} />
|
||||||
|
<InfoRow icon={UserCheck} label="Referred By" value={formData?.referred_by_member_name} />
|
||||||
|
<InfoRow icon={Clock} label="Email Verification Expires" value={formatDateTime(user.email_verification_expires_at)} />
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{formData && (
|
||||||
|
<>
|
||||||
|
{/* How Did You Hear About Us */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
How Did You Hear About Us? *
|
||||||
|
</h3>
|
||||||
|
<div className="space-y-3">
|
||||||
|
{leadSourceOptions.map((source) => (
|
||||||
|
<div key={source} className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id={`lead_${source}`}
|
||||||
|
checked={formData.lead_sources.includes(source)}
|
||||||
|
onCheckedChange={() => handleLeadSourceChange(source)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor={`lead_${source}`} className="text-base cursor-pointer">
|
||||||
|
{source}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Partner Information */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Partner Information (Optional)
|
||||||
|
</h3>
|
||||||
|
<div className="grid md:grid-cols-2 gap-4 mb-4">
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="partner_first_name">Partner First Name</Label>
|
||||||
|
<Input
|
||||||
|
id="partner_first_name"
|
||||||
|
name="partner_first_name"
|
||||||
|
value={formData.partner_first_name}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
className="h-12 rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="partner_last_name">Partner Last Name</Label>
|
||||||
|
<Input
|
||||||
|
id="partner_last_name"
|
||||||
|
name="partner_last_name"
|
||||||
|
value={formData.partner_last_name}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
className="h-12 rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="partner_is_member"
|
||||||
|
checked={formData.partner_is_member}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('partner_is_member', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="partner_is_member" className="text-base cursor-pointer">
|
||||||
|
Is your partner already a member?
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="partner_plan_to_become_member"
|
||||||
|
checked={formData.partner_plan_to_become_member}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('partner_plan_to_become_member', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="partner_plan_to_become_member" className="text-base cursor-pointer">
|
||||||
|
Does your partner plan to become a member?
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Newsletter Preferences */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Newsletter Publication Preferences *
|
||||||
|
</h3>
|
||||||
|
<p className="text-brand-purple mb-4" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
Please check what information may be published in LOAF Newsletter
|
||||||
|
</p>
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="newsletter_publish_name"
|
||||||
|
checked={formData.newsletter_publish_name}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('newsletter_publish_name', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="newsletter_publish_name" className="text-base cursor-pointer">
|
||||||
|
Name
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="newsletter_publish_photo"
|
||||||
|
checked={formData.newsletter_publish_photo}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('newsletter_publish_photo', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="newsletter_publish_photo" className="text-base cursor-pointer">
|
||||||
|
Photo (added later in profile)
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="newsletter_publish_birthday"
|
||||||
|
checked={formData.newsletter_publish_birthday}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('newsletter_publish_birthday', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="newsletter_publish_birthday" className="text-base cursor-pointer">
|
||||||
|
Birthday
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="newsletter_publish_none"
|
||||||
|
checked={formData.newsletter_publish_none}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('newsletter_publish_none', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="newsletter_publish_none" className="text-base cursor-pointer">
|
||||||
|
Do not publish any of my information
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Referral */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Referral
|
||||||
|
</h3>
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="referred_by_member_name">Name of a LOAF Member who already knows you</Label>
|
||||||
|
<Input
|
||||||
|
id="referred_by_member_name"
|
||||||
|
name="referred_by_member_name"
|
||||||
|
value={formData.referred_by_member_name}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
placeholder="Enter member name or email"
|
||||||
|
className="h-12 rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
/>
|
||||||
|
<p className="text-sm text-brand-purple mt-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
If referred by a current member, you may skip the event attendance requirement.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Volunteer Interests */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-2" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Volunteer Interests (Optional)
|
||||||
|
</h3>
|
||||||
|
<p className="text-brand-purple mb-4" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
I may at some time be interested in volunteering with LOAF in the following ways (training is provided)
|
||||||
|
</p>
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||||
|
{volunteerOptions.map((option) => (
|
||||||
|
<div key={option} className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id={`volunteer_${option}`}
|
||||||
|
checked={formData.volunteer_interests.includes(option)}
|
||||||
|
onCheckedChange={() => handleVolunteerChange(option)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor={`volunteer_${option}`} className="text-base cursor-pointer">
|
||||||
|
{option}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Scholarship Request */}
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id="scholarship_requested"
|
||||||
|
checked={formData.scholarship_requested}
|
||||||
|
onCheckedChange={(checked) => handleCheckboxChange('scholarship_requested', checked)}
|
||||||
|
/>
|
||||||
|
<Label htmlFor="scholarship_requested" className="text-base cursor-pointer font-semibold">
|
||||||
|
I am requesting for scholarship
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-brand-purple mt-2" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
Scholarship information is kept confidential
|
||||||
|
</p>
|
||||||
|
{formData.scholarship_requested && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<Label htmlFor="scholarship_reason">Please explain your situation *</Label>
|
||||||
|
<Textarea
|
||||||
|
id="scholarship_reason"
|
||||||
|
name="scholarship_reason"
|
||||||
|
value={formData.scholarship_reason}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
placeholder="Tell us why you're requesting a scholarship..."
|
||||||
|
rows={4}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] focus:border-brand-purple"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Additional Information (if available) */}
|
||||||
|
{(user.address || user.city || user.state || user.zip_code) && (
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Address
|
||||||
|
</h3>
|
||||||
|
<div className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{user.address && <p>{user.address}</p>}
|
||||||
|
{(user.city || user.state || user.zip_code) && (
|
||||||
|
<p>
|
||||||
|
{[user.city, user.state, user.zip_code].filter(Boolean).join(', ')}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Notes (if available) */}
|
||||||
|
{user.notes && (
|
||||||
|
<Card className="p-4 border border-[var(--neutral-800)] rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-[var(--purple-ink)] mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Notes
|
||||||
|
</h3>
|
||||||
|
<p className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{user.notes}
|
||||||
|
</p>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Rejection Reason (if rejected) */}
|
||||||
|
{user.status === 'rejected' && user.rejection_reason && (
|
||||||
|
<Card className="p-4 border border-red-300 bg-red-50 dark:bg-red-500/10 rounded-xl">
|
||||||
|
<h3 className="text-lg font-semibold text-red-600 mb-3" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Rejection Reason
|
||||||
|
</h3>
|
||||||
|
<p className="text-red-600" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{user.rejection_reason}
|
||||||
|
</p>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<div className="flex-1 text-sm text-brand-purple" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{isSaving && 'Saving changes...'}
|
||||||
|
{!isSaving && hasUnsavedChanges && 'Unsaved changes'}
|
||||||
|
{!isSaving && !hasUnsavedChanges && 'All changes saved'}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => saveProfile(true)}
|
||||||
|
disabled={!hasUnsavedChanges || isSaving}
|
||||||
|
className="rounded-xl border-2 border-[var(--neutral-800)] bg-white text-[var(--purple-ink)] hover:bg-[var(--lavender-300)]"
|
||||||
|
>
|
||||||
|
Save All
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
className="rounded-xl bg-[var(--purple-ink)] hover:bg-[var(--purple-ink)]/90 text-white"
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ViewRegistrationDialog;
|
||||||
531
src/components/admin/AdminPaymentMethodsPanel.js
Normal file
531
src/components/admin/AdminPaymentMethodsPanel.js
Normal file
@@ -0,0 +1,531 @@
|
|||||||
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
|
import { loadStripe } from '@stripe/stripe-js';
|
||||||
|
import { Elements } from '@stripe/react-stripe-js';
|
||||||
|
import { Card } from '../ui/card';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '../ui/select';
|
||||||
|
import { Textarea } from '../ui/textarea';
|
||||||
|
import { Label } from '../ui/label';
|
||||||
|
import {
|
||||||
|
CreditCard,
|
||||||
|
Plus,
|
||||||
|
Loader2,
|
||||||
|
AlertCircle,
|
||||||
|
Eye,
|
||||||
|
Banknote,
|
||||||
|
Building2,
|
||||||
|
FileCheck,
|
||||||
|
Trash2,
|
||||||
|
Star,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import api from '../../utils/api';
|
||||||
|
import ConfirmationDialog from '../ConfirmationDialog';
|
||||||
|
import PasswordConfirmDialog from '../PasswordConfirmDialog';
|
||||||
|
import AddPaymentMethodDialog from '../AddPaymentMethodDialog';
|
||||||
|
|
||||||
|
// Initialize Stripe with publishable key from environment
|
||||||
|
const stripePromise = loadStripe(process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get icon for payment method type
|
||||||
|
*/
|
||||||
|
const getPaymentTypeIcon = (paymentType) => {
|
||||||
|
switch (paymentType) {
|
||||||
|
case 'cash':
|
||||||
|
return Banknote;
|
||||||
|
case 'bank_transfer':
|
||||||
|
return Building2;
|
||||||
|
case 'check':
|
||||||
|
return FileCheck;
|
||||||
|
default:
|
||||||
|
return CreditCard;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format payment type for display
|
||||||
|
*/
|
||||||
|
const formatPaymentType = (paymentType) => {
|
||||||
|
switch (paymentType) {
|
||||||
|
case 'cash':
|
||||||
|
return 'Cash';
|
||||||
|
case 'bank_transfer':
|
||||||
|
return 'Bank Transfer';
|
||||||
|
case 'check':
|
||||||
|
return 'Check';
|
||||||
|
case 'card':
|
||||||
|
return 'Card';
|
||||||
|
default:
|
||||||
|
return paymentType;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AdminPaymentMethodsPanel - Admin panel for managing user payment methods
|
||||||
|
*/
|
||||||
|
const AdminPaymentMethodsPanel = ({ userId, userName }) => {
|
||||||
|
const [paymentMethods, setPaymentMethods] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [actionLoading, setActionLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
// Dialog states
|
||||||
|
const [addCardDialogOpen, setAddCardDialogOpen] = useState(false);
|
||||||
|
const [addManualDialogOpen, setAddManualDialogOpen] = useState(false);
|
||||||
|
const [clientSecret, setClientSecret] = useState(null);
|
||||||
|
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
|
||||||
|
const [methodToDelete, setMethodToDelete] = useState(null);
|
||||||
|
const [revealDialogOpen, setRevealDialogOpen] = useState(false);
|
||||||
|
const [revealedData, setRevealedData] = useState(null);
|
||||||
|
|
||||||
|
// Manual payment form state
|
||||||
|
const [manualPaymentType, setManualPaymentType] = useState('cash');
|
||||||
|
const [manualNotes, setManualNotes] = useState('');
|
||||||
|
const [manualSetDefault, setManualSetDefault] = useState(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch payment methods from API
|
||||||
|
*/
|
||||||
|
const fetchPaymentMethods = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
const response = await api.get(`/admin/users/${userId}/payment-methods`);
|
||||||
|
setPaymentMethods(response.data);
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to load payment methods';
|
||||||
|
setError(errorMessage);
|
||||||
|
console.error('Failed to fetch payment methods:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (userId) {
|
||||||
|
fetchPaymentMethods();
|
||||||
|
}
|
||||||
|
}, [userId, fetchPaymentMethods]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create SetupIntent for adding a card
|
||||||
|
*/
|
||||||
|
const handleAddCard = async () => {
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
const response = await api.post(`/admin/users/${userId}/payment-methods/setup-intent`);
|
||||||
|
setClientSecret(response.data.client_secret);
|
||||||
|
setAddCardDialogOpen(true);
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to initialize payment setup';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
console.error('Failed to create setup intent:', err);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle successful card addition
|
||||||
|
*/
|
||||||
|
const handleCardAddSuccess = () => {
|
||||||
|
setAddCardDialogOpen(false);
|
||||||
|
setClientSecret(null);
|
||||||
|
fetchPaymentMethods();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save manual payment method
|
||||||
|
*/
|
||||||
|
const handleSaveManualPayment = async () => {
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
await api.post(`/admin/users/${userId}/payment-methods/manual`, {
|
||||||
|
payment_type: manualPaymentType,
|
||||||
|
manual_notes: manualNotes || null,
|
||||||
|
set_as_default: manualSetDefault,
|
||||||
|
});
|
||||||
|
toast.success('Manual payment method recorded');
|
||||||
|
setAddManualDialogOpen(false);
|
||||||
|
setManualPaymentType('cash');
|
||||||
|
setManualNotes('');
|
||||||
|
setManualSetDefault(false);
|
||||||
|
fetchPaymentMethods();
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to record payment method';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
console.error('Failed to save manual payment:', err);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a payment method as default
|
||||||
|
*/
|
||||||
|
const handleSetDefault = async (methodId) => {
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
await api.put(`/admin/users/${userId}/payment-methods/${methodId}/default`);
|
||||||
|
toast.success('Default payment method updated');
|
||||||
|
fetchPaymentMethods();
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to update default';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirm and delete payment method
|
||||||
|
*/
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (!methodToDelete) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
await api.delete(`/admin/users/${userId}/payment-methods/${methodToDelete}`);
|
||||||
|
toast.success('Payment method removed');
|
||||||
|
setDeleteConfirmOpen(false);
|
||||||
|
setMethodToDelete(null);
|
||||||
|
fetchPaymentMethods();
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to remove payment method';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reveal sensitive payment details with password confirmation
|
||||||
|
*/
|
||||||
|
const handleRevealDetails = async (password) => {
|
||||||
|
try {
|
||||||
|
setActionLoading(true);
|
||||||
|
const response = await api.post(`/admin/users/${userId}/payment-methods/reveal`, {
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
setRevealedData(response.data);
|
||||||
|
setRevealDialogOpen(false);
|
||||||
|
toast.success('Sensitive details revealed');
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err.response?.data?.detail || 'Failed to reveal details';
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setActionLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stripe Elements options - simplified for CardElement
|
||||||
|
const elementsOptions = {
|
||||||
|
appearance: {
|
||||||
|
theme: 'stripe',
|
||||||
|
variables: {
|
||||||
|
colorPrimary: '#6b5b95',
|
||||||
|
colorBackground: '#ffffff',
|
||||||
|
colorText: '#2d2a4a',
|
||||||
|
fontFamily: "'Nunito Sans', sans-serif",
|
||||||
|
borderRadius: '12px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card className="p-6 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<CreditCard className="h-5 w-5 text-brand-purple" />
|
||||||
|
<h2
|
||||||
|
className="text-lg font-semibold text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
Payment Methods
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setRevealDialogOpen(true)}
|
||||||
|
disabled={actionLoading || paymentMethods.length === 0}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="border-brand-purple text-brand-purple hover:bg-[var(--lavender-300)] rounded-lg"
|
||||||
|
>
|
||||||
|
<Eye className="h-4 w-4 mr-1" />
|
||||||
|
Reveal Details
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setAddManualDialogOpen(true)}
|
||||||
|
disabled={actionLoading}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="border-brand-purple text-brand-purple hover:bg-[var(--lavender-300)] rounded-lg"
|
||||||
|
>
|
||||||
|
<Banknote className="h-4 w-4 mr-1" />
|
||||||
|
Add Manual
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleAddCard}
|
||||||
|
disabled={actionLoading}
|
||||||
|
size="sm"
|
||||||
|
className="bg-brand-purple text-white hover:bg-[var(--purple-ink)] rounded-lg"
|
||||||
|
>
|
||||||
|
{actionLoading ? (
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Plus className="h-4 w-4 mr-1" />
|
||||||
|
Add Card
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Loading State */}
|
||||||
|
{loading && (
|
||||||
|
<div className="flex items-center justify-center py-8">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-brand-purple" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error State */}
|
||||||
|
{error && !loading && (
|
||||||
|
<div className="flex items-center gap-2 p-4 bg-red-50 border border-red-200 rounded-xl">
|
||||||
|
<AlertCircle className="h-5 w-5 text-red-500 flex-shrink-0" />
|
||||||
|
<p className="text-sm text-red-600">{error}</p>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={fetchPaymentMethods}
|
||||||
|
className="ml-auto"
|
||||||
|
>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Payment Methods List */}
|
||||||
|
{!loading && !error && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{paymentMethods.length === 0 ? (
|
||||||
|
<p
|
||||||
|
className="text-center py-6 text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
No payment methods on file for this user.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
(revealedData || paymentMethods).map((method) => {
|
||||||
|
const PaymentIcon = getPaymentTypeIcon(method.payment_type);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={method.id}
|
||||||
|
className={`flex items-center justify-between p-4 border rounded-xl ${
|
||||||
|
method.is_default
|
||||||
|
? 'border-brand-purple bg-[var(--lavender-500)]'
|
||||||
|
: 'border-[var(--neutral-800)] bg-white'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div
|
||||||
|
className={`p-2 rounded-full ${
|
||||||
|
method.is_default
|
||||||
|
? 'bg-brand-purple text-white'
|
||||||
|
: 'bg-[var(--lavender-300)] text-brand-purple'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<PaymentIcon className="h-4 w-4" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{method.payment_type === 'card' ? (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className="font-medium text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{method.card_brand
|
||||||
|
? method.card_brand.charAt(0).toUpperCase() +
|
||||||
|
method.card_brand.slice(1)
|
||||||
|
: 'Card'}{' '}
|
||||||
|
•••• {method.card_last4 || '****'}
|
||||||
|
</span>
|
||||||
|
{method.is_default && (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-brand-purple font-medium">
|
||||||
|
<Star className="h-3 w-3 fill-current" />
|
||||||
|
Default
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
className="text-sm text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
Expires {method.card_exp_month?.toString().padStart(2, '0')}/
|
||||||
|
{method.card_exp_year?.toString().slice(-2)}
|
||||||
|
{revealedData && method.stripe_payment_method_id && (
|
||||||
|
<span className="ml-2 text-xs font-mono bg-[var(--lavender-300)] px-2 py-0.5 rounded">
|
||||||
|
{method.stripe_payment_method_id}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className="font-medium text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{formatPaymentType(method.payment_type)}
|
||||||
|
</span>
|
||||||
|
{method.is_default && (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-brand-purple font-medium">
|
||||||
|
<Star className="h-3 w-3 fill-current" />
|
||||||
|
Default
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{method.manual_notes && (
|
||||||
|
<p
|
||||||
|
className="text-sm text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{method.manual_notes}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{!method.is_default && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleSetDefault(method.id)}
|
||||||
|
disabled={actionLoading}
|
||||||
|
className="text-xs"
|
||||||
|
>
|
||||||
|
Set Default
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setMethodToDelete(method.id);
|
||||||
|
setDeleteConfirmOpen(true);
|
||||||
|
}}
|
||||||
|
disabled={actionLoading}
|
||||||
|
className="border-red-500 text-red-500 hover:bg-red-50 p-2"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Add Card Dialog */}
|
||||||
|
{clientSecret && stripePromise && (
|
||||||
|
<Elements stripe={stripePromise} options={elementsOptions}>
|
||||||
|
<AddPaymentMethodDialog
|
||||||
|
open={addCardDialogOpen}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
setAddCardDialogOpen(open);
|
||||||
|
if (!open) setClientSecret(null);
|
||||||
|
}}
|
||||||
|
onSuccess={handleCardAddSuccess}
|
||||||
|
clientSecret={clientSecret}
|
||||||
|
saveEndpoint={`/admin/users/${userId}/payment-methods`}
|
||||||
|
/>
|
||||||
|
</Elements>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Add Manual Payment Method Dialog */}
|
||||||
|
<ConfirmationDialog
|
||||||
|
open={addManualDialogOpen}
|
||||||
|
onOpenChange={setAddManualDialogOpen}
|
||||||
|
onConfirm={handleSaveManualPayment}
|
||||||
|
title="Record Manual Payment Method"
|
||||||
|
description={
|
||||||
|
<div className="space-y-4 mt-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Payment Type</Label>
|
||||||
|
<Select value={manualPaymentType} onValueChange={setManualPaymentType}>
|
||||||
|
<SelectTrigger className="w-full">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="cash">Cash</SelectItem>
|
||||||
|
<SelectItem value="check">Check</SelectItem>
|
||||||
|
<SelectItem value="bank_transfer">Bank Transfer</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Notes (optional)</Label>
|
||||||
|
<Textarea
|
||||||
|
value={manualNotes}
|
||||||
|
onChange={(e) => setManualNotes(e.target.value)}
|
||||||
|
placeholder="e.g., Check #1234, received 01/15/2026"
|
||||||
|
className="min-h-[80px]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
confirmText="Save"
|
||||||
|
variant="info"
|
||||||
|
loading={actionLoading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Delete Confirmation Dialog */}
|
||||||
|
<ConfirmationDialog
|
||||||
|
open={deleteConfirmOpen}
|
||||||
|
onOpenChange={setDeleteConfirmOpen}
|
||||||
|
onConfirm={handleDeleteConfirm}
|
||||||
|
title="Remove Payment Method"
|
||||||
|
description="Are you sure you want to remove this payment method? This action cannot be undone."
|
||||||
|
confirmText="Remove"
|
||||||
|
variant="danger"
|
||||||
|
loading={actionLoading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Password Confirm Dialog for Reveal */}
|
||||||
|
<PasswordConfirmDialog
|
||||||
|
open={revealDialogOpen}
|
||||||
|
onOpenChange={setRevealDialogOpen}
|
||||||
|
onConfirm={handleRevealDetails}
|
||||||
|
title="Reveal Sensitive Details"
|
||||||
|
description="Enter your password to view Stripe payment method IDs. This action will be logged."
|
||||||
|
loading={actionLoading}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AdminPaymentMethodsPanel;
|
||||||
347
src/components/admin/SubscriptionsTable.jsx
Normal file
347
src/components/admin/SubscriptionsTable.jsx
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Button } from '../ui/button';
|
||||||
|
import StatusBadge from '../StatusBadge';
|
||||||
|
import {
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
Edit,
|
||||||
|
XCircle,
|
||||||
|
CreditCard,
|
||||||
|
Info,
|
||||||
|
ExternalLink,
|
||||||
|
Copy
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
const HEADER_CELLS = [
|
||||||
|
{ label: 'Member', align: 'text-left' },
|
||||||
|
{ label: 'Plan', align: 'text-left' },
|
||||||
|
{ label: 'Status', align: 'text-left' },
|
||||||
|
{ label: 'Period', align: 'text-left' },
|
||||||
|
{ label: 'Base Fee', align: 'text-right' },
|
||||||
|
{ label: 'Donation', align: 'text-right' },
|
||||||
|
{ label: 'Total', align: 'text-right' },
|
||||||
|
{ label: 'Details', align: 'text-center' },
|
||||||
|
{ label: 'Actions', align: 'text-center' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const HeaderCell = ({ align, children }) => (
|
||||||
|
<th
|
||||||
|
className={`p-4 text-[var(--purple-ink)] font-semibold ${align}`}
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
|
||||||
|
const TableCell = ({ align = 'text-left', className = '', style, children, ...props }) => (
|
||||||
|
<td
|
||||||
|
className={`p-4 ${align} ${className}`.trim()}
|
||||||
|
style={style}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const SubscriptionRow = ({
|
||||||
|
sub,
|
||||||
|
isExpanded,
|
||||||
|
onToggle,
|
||||||
|
onEdit,
|
||||||
|
onCancel,
|
||||||
|
hasPermission,
|
||||||
|
formatDate,
|
||||||
|
formatDateTime,
|
||||||
|
formatPrice,
|
||||||
|
copyToClipboard
|
||||||
|
}) => (
|
||||||
|
<>
|
||||||
|
<tr className="border-b border-[var(--neutral-800)] hover:bg-[var(--lavender-400)] transition-colors">
|
||||||
|
<TableCell>
|
||||||
|
<div className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
{sub.user.first_name} {sub.user.last_name}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{sub.user.email}
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
{sub.plan.name}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-brand-purple ">
|
||||||
|
{sub.plan.billing_cycle}
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge status={sub.status} />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="text-sm text-[var(--purple-ink)]" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
|
<div>{formatDate(sub.start_date)}</div>
|
||||||
|
<div className="text-xs text-brand-purple ">to {formatDate(sub.end_date)}</div>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell
|
||||||
|
align="text-right"
|
||||||
|
className="text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{formatPrice(sub.base_subscription_cents || 0)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell
|
||||||
|
align="text-right"
|
||||||
|
className="text-[var(--orange-light)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{formatPrice(sub.donation_cents || 0)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell
|
||||||
|
align="text-right"
|
||||||
|
className="font-semibold text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{formatPrice(sub.amount_paid_cents || 0)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={onToggle}
|
||||||
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
|
>
|
||||||
|
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||||||
|
</Button>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex items-center justify-center gap-2">
|
||||||
|
{hasPermission('subscriptions.edit') && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onEdit(sub)}
|
||||||
|
className="text-brand-purple hover:bg-[var(--neutral-800)]"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{sub.status === 'active' && hasPermission('subscriptions.cancel') && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline-destructive"
|
||||||
|
onClick={() => onCancel(sub.id)}
|
||||||
|
>
|
||||||
|
<XCircle className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{isExpanded && (
|
||||||
|
<tr className="bg-[var(--lavender-400)]/30">
|
||||||
|
<TableCell 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">
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</TableCell>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const SubscriptionsTable = ({
|
||||||
|
subscriptions,
|
||||||
|
expandedRows,
|
||||||
|
onToggleRowExpansion,
|
||||||
|
onEdit,
|
||||||
|
onCancel,
|
||||||
|
hasPermission,
|
||||||
|
formatDate,
|
||||||
|
formatDateTime,
|
||||||
|
formatPrice,
|
||||||
|
copyToClipboard
|
||||||
|
}) => (
|
||||||
|
<table className="w-full">
|
||||||
|
<thead>
|
||||||
|
<tr className="bg-[var(--neutral-800)]/20 border-b border-[var(--neutral-800)]">
|
||||||
|
{HEADER_CELLS.map((cell) => (
|
||||||
|
<HeaderCell key={cell.label} align={cell.align}>
|
||||||
|
{cell.label}
|
||||||
|
</HeaderCell>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{subscriptions.length > 0 ? (
|
||||||
|
subscriptions.map((sub) => (
|
||||||
|
<SubscriptionRow
|
||||||
|
key={sub.id}
|
||||||
|
sub={sub}
|
||||||
|
isExpanded={expandedRows.has(sub.id)}
|
||||||
|
onToggle={() => onToggleRowExpansion(sub.id)}
|
||||||
|
onEdit={onEdit}
|
||||||
|
onCancel={onCancel}
|
||||||
|
hasPermission={hasPermission}
|
||||||
|
formatDate={formatDate}
|
||||||
|
formatDateTime={formatDateTime}
|
||||||
|
formatPrice={formatPrice}
|
||||||
|
copyToClipboard={copyToClipboard}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<TableCell
|
||||||
|
align="text-center"
|
||||||
|
className="p-12 text-brand-purple "
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
colSpan={9}
|
||||||
|
>
|
||||||
|
No subscriptions found
|
||||||
|
</TableCell>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default SubscriptionsTable;
|
||||||
427
src/components/registration/DynamicFormField.js
Normal file
427
src/components/registration/DynamicFormField.js
Normal file
@@ -0,0 +1,427 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Label } from '../ui/label';
|
||||||
|
import { Input } from '../ui/input';
|
||||||
|
import { Textarea } from '../ui/textarea';
|
||||||
|
import { Checkbox } from '../ui/checkbox';
|
||||||
|
import { RadioGroup, RadioGroupItem } from '../ui/radio-group';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '../ui/select';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DynamicFormField - Renders form fields based on schema configuration
|
||||||
|
*
|
||||||
|
* Supports field types:
|
||||||
|
* - text, email, phone, password: Input fields
|
||||||
|
* - date: Date picker input
|
||||||
|
* - textarea: Multi-line text input
|
||||||
|
* - checkbox: Single checkbox
|
||||||
|
* - radio: Radio button group
|
||||||
|
* - dropdown: Select dropdown
|
||||||
|
* - multiselect: Checkbox group for multiple selections
|
||||||
|
* - address_group: Group of address-related fields
|
||||||
|
* - file_upload: File upload input
|
||||||
|
*/
|
||||||
|
const DynamicFormField = ({
|
||||||
|
field,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
errors = [],
|
||||||
|
formData = {},
|
||||||
|
}) => {
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
type,
|
||||||
|
label,
|
||||||
|
required,
|
||||||
|
placeholder,
|
||||||
|
options = [],
|
||||||
|
rows = 4,
|
||||||
|
validation = {},
|
||||||
|
} = field;
|
||||||
|
|
||||||
|
const hasError = errors.length > 0;
|
||||||
|
const errorMessage = errors[0];
|
||||||
|
|
||||||
|
const formatPhoneNumber = (rawValue) => {
|
||||||
|
const digits = String(rawValue || '').replace(/\D/g, '').slice(0, 10);
|
||||||
|
if (digits.length <= 3) return digits;
|
||||||
|
if (digits.length <= 6) {
|
||||||
|
return `(${digits.slice(0, 3)}) ${digits.slice(3)}`;
|
||||||
|
}
|
||||||
|
return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Common input className
|
||||||
|
const inputClassName = `h-14 rounded-xl border-2 ${
|
||||||
|
hasError
|
||||||
|
? 'border-red-500 focus:border-red-500'
|
||||||
|
: 'border-[var(--neutral-800)] focus:border-brand-purple'
|
||||||
|
}`;
|
||||||
|
|
||||||
|
// Handle change for different field types
|
||||||
|
const handleInputChange = (e) => {
|
||||||
|
const { value: newValue, type: inputType, checked } = e.target;
|
||||||
|
if (inputType === 'checkbox') {
|
||||||
|
onChange(id, checked);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === 'phone') {
|
||||||
|
onChange(id, formatPhoneNumber(newValue));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
onChange(id, newValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectChange = (newValue) => {
|
||||||
|
onChange(id, newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCheckboxChange = (checked) => {
|
||||||
|
onChange(id, checked);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMultiselectChange = (optionValue) => {
|
||||||
|
const currentValues = Array.isArray(value) ? value : [];
|
||||||
|
const newValues = currentValues.includes(optionValue)
|
||||||
|
? currentValues.filter((v) => v !== optionValue)
|
||||||
|
: [...currentValues, optionValue];
|
||||||
|
onChange(id, newValues);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render error message
|
||||||
|
const renderError = () => {
|
||||||
|
if (!hasError) return null;
|
||||||
|
return (
|
||||||
|
<p className="text-sm text-red-500 mt-1">{errorMessage}</p>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render label
|
||||||
|
const renderLabel = () => (
|
||||||
|
<Label htmlFor={id} className={hasError ? 'text-red-500' : ''}>
|
||||||
|
{label} {required && '*'}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Render based on field type
|
||||||
|
switch (type) {
|
||||||
|
case 'text':
|
||||||
|
case 'email':
|
||||||
|
case 'phone':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Input
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
type={type === 'phone' ? 'tel' : type}
|
||||||
|
required={required}
|
||||||
|
value={value || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
placeholder={placeholder}
|
||||||
|
inputMode={type === 'phone' ? 'numeric' : undefined}
|
||||||
|
maxLength={type === 'phone' ? 14 : undefined}
|
||||||
|
className={inputClassName}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'password':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Input
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
type="password"
|
||||||
|
required={required}
|
||||||
|
value={value || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
placeholder={placeholder}
|
||||||
|
minLength={validation.minLength}
|
||||||
|
className={inputClassName}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'date':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Input
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
type="date"
|
||||||
|
required={required}
|
||||||
|
value={value || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
className={inputClassName}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'textarea':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Textarea
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
required={required}
|
||||||
|
value={value || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
placeholder={placeholder}
|
||||||
|
rows={rows}
|
||||||
|
className={`rounded-xl border-2 ${
|
||||||
|
hasError
|
||||||
|
? 'border-red-500 focus:border-red-500'
|
||||||
|
: 'border-[var(--neutral-800)] focus:border-brand-purple'
|
||||||
|
}`}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'checkbox':
|
||||||
|
return (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
checked={value || false}
|
||||||
|
onCheckedChange={handleCheckboxChange}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={id}
|
||||||
|
className={`text-base cursor-pointer ${hasError ? 'text-red-500' : ''}`}
|
||||||
|
>
|
||||||
|
{label} {required && '*'}
|
||||||
|
</Label>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'radio':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<RadioGroup
|
||||||
|
value={value || ''}
|
||||||
|
onValueChange={handleSelectChange}
|
||||||
|
className="space-y-2"
|
||||||
|
>
|
||||||
|
{options.map((option) => (
|
||||||
|
<div key={option.value} className="flex items-center space-x-2">
|
||||||
|
<RadioGroupItem
|
||||||
|
value={option.value}
|
||||||
|
id={`${id}-${option.value}`}
|
||||||
|
data-testid={`field-${id}-${option.value}`}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${id}-${option.value}`}
|
||||||
|
className="text-base cursor-pointer"
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</RadioGroup>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'dropdown':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Select value={value || ''} onValueChange={handleSelectChange}>
|
||||||
|
<SelectTrigger
|
||||||
|
className={`h-14 rounded-xl border-2 ${
|
||||||
|
hasError
|
||||||
|
? 'border-red-500'
|
||||||
|
: 'border-[var(--neutral-800)] focus:border-brand-purple'
|
||||||
|
}`}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
>
|
||||||
|
<SelectValue placeholder={placeholder || 'Select an option'} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{options.map((option) => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'multiselect':
|
||||||
|
const selectedValues = Array.isArray(value) ? value : [];
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<div className="space-y-3">
|
||||||
|
{options.map((option) => (
|
||||||
|
<div key={option.value} className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
id={`${id}-${option.value}`}
|
||||||
|
checked={selectedValues.includes(option.value)}
|
||||||
|
onCheckedChange={() => handleMultiselectChange(option.value)}
|
||||||
|
data-testid={`field-${id}-${option.value}`}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${id}-${option.value}`}
|
||||||
|
className="text-base cursor-pointer"
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'address_group':
|
||||||
|
// Address group renders multiple related fields
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{renderLabel()}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Input
|
||||||
|
id={`${id}_address`}
|
||||||
|
name={`${id}_address`}
|
||||||
|
placeholder="Street Address"
|
||||||
|
value={formData[`${id}_address`] || ''}
|
||||||
|
onChange={(e) => onChange(`${id}_address`, e.target.value)}
|
||||||
|
className={inputClassName}
|
||||||
|
required={required}
|
||||||
|
/>
|
||||||
|
<div className="grid md:grid-cols-3 gap-4">
|
||||||
|
<Input
|
||||||
|
id={`${id}_city`}
|
||||||
|
name={`${id}_city`}
|
||||||
|
placeholder="City"
|
||||||
|
value={formData[`${id}_city`] || ''}
|
||||||
|
onChange={(e) => onChange(`${id}_city`, e.target.value)}
|
||||||
|
className={inputClassName}
|
||||||
|
required={required}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
id={`${id}_state`}
|
||||||
|
name={`${id}_state`}
|
||||||
|
placeholder="State"
|
||||||
|
value={formData[`${id}_state`] || ''}
|
||||||
|
onChange={(e) => onChange(`${id}_state`, e.target.value)}
|
||||||
|
className={inputClassName}
|
||||||
|
required={required}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
id={`${id}_zipcode`}
|
||||||
|
name={`${id}_zipcode`}
|
||||||
|
placeholder="Zipcode"
|
||||||
|
value={formData[`${id}_zipcode`] || ''}
|
||||||
|
onChange={(e) => onChange(`${id}_zipcode`, e.target.value)}
|
||||||
|
className={inputClassName}
|
||||||
|
required={required}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
case 'file_upload':
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Input
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
type="file"
|
||||||
|
accept={field.allowed_types?.join(',')}
|
||||||
|
onChange={(e) => {
|
||||||
|
const file = e.target.files?.[0];
|
||||||
|
onChange(id, file);
|
||||||
|
}}
|
||||||
|
className={`h-14 rounded-xl border-2 pt-3 ${
|
||||||
|
hasError
|
||||||
|
? 'border-red-500'
|
||||||
|
: 'border-[var(--neutral-800)] focus:border-brand-purple'
|
||||||
|
}`}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
{field.max_size_mb && (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Max file size: {field.max_size_mb}MB
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.warn(`Unknown field type: ${type}`);
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{renderLabel()}
|
||||||
|
<Input
|
||||||
|
id={id}
|
||||||
|
name={id}
|
||||||
|
value={value || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
placeholder={placeholder}
|
||||||
|
className={inputClassName}
|
||||||
|
data-testid={`field-${id}`}
|
||||||
|
/>
|
||||||
|
{renderError()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get width class based on field width configuration
|
||||||
|
*/
|
||||||
|
export const getWidthClass = (width) => {
|
||||||
|
switch (width) {
|
||||||
|
case 'half':
|
||||||
|
return 'md:col-span-1';
|
||||||
|
case 'third':
|
||||||
|
return 'md:col-span-1';
|
||||||
|
case 'two-thirds':
|
||||||
|
return 'md:col-span-2';
|
||||||
|
case 'full':
|
||||||
|
default:
|
||||||
|
return 'md:col-span-2';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get grid columns class based on field widths in a row
|
||||||
|
*/
|
||||||
|
export const getGridClass = (fields) => {
|
||||||
|
const hasThird = fields.some((f) => f.width === 'third');
|
||||||
|
if (hasThird) {
|
||||||
|
return 'grid md:grid-cols-3 gap-4';
|
||||||
|
}
|
||||||
|
return 'grid md:grid-cols-2 gap-4';
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DynamicFormField;
|
||||||
482
src/components/registration/DynamicRegistrationForm.js
Normal file
482
src/components/registration/DynamicRegistrationForm.js
Normal file
@@ -0,0 +1,482 @@
|
|||||||
|
import React, { useMemo, useCallback } from 'react';
|
||||||
|
import DynamicFormField, { getWidthClass } from './DynamicFormField';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DynamicRegistrationForm - Renders the entire registration form from schema
|
||||||
|
*
|
||||||
|
* Features:
|
||||||
|
* - Renders steps and sections based on schema
|
||||||
|
* - Handles conditional field visibility
|
||||||
|
* - Supports step navigation
|
||||||
|
* - Validates fields per step
|
||||||
|
*/
|
||||||
|
const DynamicRegistrationForm = ({
|
||||||
|
schema,
|
||||||
|
formData,
|
||||||
|
onFormDataChange,
|
||||||
|
currentStep,
|
||||||
|
errors = {},
|
||||||
|
}) => {
|
||||||
|
// Get current step data
|
||||||
|
const stepData = useMemo(() => {
|
||||||
|
const steps = schema?.steps || [];
|
||||||
|
const sortedSteps = [...steps].sort((a, b) => a.order - b.order);
|
||||||
|
return sortedSteps[currentStep - 1] || null;
|
||||||
|
}, [schema, currentStep]);
|
||||||
|
|
||||||
|
// Evaluate conditional rules to determine which fields are visible
|
||||||
|
const hiddenFields = useMemo(() => {
|
||||||
|
const rules = schema?.conditional_rules || [];
|
||||||
|
const hidden = new Set();
|
||||||
|
|
||||||
|
// First pass: collect fields that have "show" rules (hidden by default)
|
||||||
|
for (const rule of rules) {
|
||||||
|
if (rule.action === 'show') {
|
||||||
|
rule.target_fields?.forEach((fieldId) => hidden.add(fieldId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second pass: evaluate rules and show/hide fields
|
||||||
|
for (const rule of rules) {
|
||||||
|
const {
|
||||||
|
trigger_field,
|
||||||
|
trigger_operator = 'equals',
|
||||||
|
trigger_value,
|
||||||
|
action,
|
||||||
|
target_fields = [],
|
||||||
|
} = rule;
|
||||||
|
|
||||||
|
const fieldValue = formData[trigger_field];
|
||||||
|
let conditionMet = false;
|
||||||
|
|
||||||
|
switch (trigger_operator) {
|
||||||
|
case 'equals':
|
||||||
|
conditionMet = fieldValue === trigger_value;
|
||||||
|
break;
|
||||||
|
case 'not_equals':
|
||||||
|
conditionMet = fieldValue !== trigger_value;
|
||||||
|
break;
|
||||||
|
case 'contains':
|
||||||
|
conditionMet = Array.isArray(fieldValue)
|
||||||
|
? fieldValue.includes(trigger_value)
|
||||||
|
: String(fieldValue || '').includes(trigger_value);
|
||||||
|
break;
|
||||||
|
case 'not_empty':
|
||||||
|
conditionMet = Boolean(fieldValue);
|
||||||
|
break;
|
||||||
|
case 'empty':
|
||||||
|
conditionMet = !Boolean(fieldValue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
conditionMet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conditionMet) {
|
||||||
|
if (action === 'show') {
|
||||||
|
target_fields.forEach((fieldId) => hidden.delete(fieldId));
|
||||||
|
} else if (action === 'hide') {
|
||||||
|
target_fields.forEach((fieldId) => hidden.add(fieldId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hidden;
|
||||||
|
}, [schema, formData]);
|
||||||
|
|
||||||
|
// Handle field change
|
||||||
|
const handleFieldChange = useCallback(
|
||||||
|
(fieldId, value) => {
|
||||||
|
onFormDataChange((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[fieldId]: value,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
[onFormDataChange]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if a field is visible
|
||||||
|
const isFieldVisible = useCallback(
|
||||||
|
(fieldId) => {
|
||||||
|
return !hiddenFields.has(fieldId);
|
||||||
|
},
|
||||||
|
[hiddenFields]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get errors for a specific field
|
||||||
|
const getFieldErrors = useCallback(
|
||||||
|
(fieldId) => {
|
||||||
|
return errors[fieldId] || [];
|
||||||
|
},
|
||||||
|
[errors]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Group fields by their width for rendering
|
||||||
|
const groupFieldsByRow = (fields) => {
|
||||||
|
const rows = [];
|
||||||
|
let currentRow = [];
|
||||||
|
let currentRowWidth = 0;
|
||||||
|
|
||||||
|
const visibleFields = fields.filter((f) => isFieldVisible(f.id));
|
||||||
|
|
||||||
|
for (const field of visibleFields) {
|
||||||
|
const width = field.width || 'full';
|
||||||
|
let widthValue = 1;
|
||||||
|
|
||||||
|
if (width === 'half') widthValue = 0.5;
|
||||||
|
else if (width === 'third') widthValue = 0.33;
|
||||||
|
else if (width === 'two-thirds') widthValue = 0.67;
|
||||||
|
|
||||||
|
if (currentRowWidth + widthValue > 1) {
|
||||||
|
if (currentRow.length > 0) {
|
||||||
|
rows.push(currentRow);
|
||||||
|
}
|
||||||
|
currentRow = [field];
|
||||||
|
currentRowWidth = widthValue;
|
||||||
|
} else {
|
||||||
|
currentRow.push(field);
|
||||||
|
currentRowWidth += widthValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentRow.length > 0) {
|
||||||
|
rows.push(currentRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!stepData) {
|
||||||
|
return (
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
No step data available
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
{/* Step Header */}
|
||||||
|
{stepData.description && (
|
||||||
|
<p
|
||||||
|
className="text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
|
{stepData.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Sections */}
|
||||||
|
{stepData.sections
|
||||||
|
?.sort((a, b) => a.order - b.order)
|
||||||
|
.map((section) => {
|
||||||
|
const visibleFields = section.fields?.filter((f) =>
|
||||||
|
isFieldVisible(f.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Skip empty sections
|
||||||
|
if (!visibleFields || visibleFields.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldRows = groupFieldsByRow(
|
||||||
|
section.fields?.sort((a, b) => a.order - b.order) || []
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={section.id} className="space-y-4">
|
||||||
|
{/* Section Title */}
|
||||||
|
{section.title && (
|
||||||
|
<h2
|
||||||
|
className="text-2xl font-semibold text-[var(--purple-ink)]"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
|
{section.title}
|
||||||
|
</h2>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Section Description */}
|
||||||
|
{section.description && (
|
||||||
|
<p className="text-muted-foreground">{section.description}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Fields */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
{fieldRows.map((row, rowIndex) => {
|
||||||
|
// Determine grid class based on field widths
|
||||||
|
const hasThird = row.some((f) => f.width === 'third');
|
||||||
|
const hasHalf = row.some((f) => f.width === 'half');
|
||||||
|
const gridCols = hasThird
|
||||||
|
? 'grid md:grid-cols-3 gap-4'
|
||||||
|
: hasHalf
|
||||||
|
? 'grid md:grid-cols-2 gap-4'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
if (row.length === 1 && !hasHalf && !hasThird) {
|
||||||
|
// Single full-width field
|
||||||
|
const field = row[0];
|
||||||
|
return (
|
||||||
|
<DynamicFormField
|
||||||
|
key={field.id}
|
||||||
|
field={field}
|
||||||
|
value={formData[field.id]}
|
||||||
|
onChange={handleFieldChange}
|
||||||
|
errors={getFieldErrors(field.id)}
|
||||||
|
formData={formData}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={`row-${rowIndex}`} className={gridCols}>
|
||||||
|
{row.map((field) => (
|
||||||
|
<div
|
||||||
|
key={field.id}
|
||||||
|
className={getWidthClass(field.width)}
|
||||||
|
>
|
||||||
|
<DynamicFormField
|
||||||
|
field={field}
|
||||||
|
value={formData[field.id]}
|
||||||
|
onChange={handleFieldChange}
|
||||||
|
errors={getFieldErrors(field.id)}
|
||||||
|
formData={formData}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DynamicStepIndicator - Renders step progress indicator
|
||||||
|
*/
|
||||||
|
export const DynamicStepIndicator = ({ steps, currentStep }) => {
|
||||||
|
const sortedSteps = [...steps].sort((a, b) => a.order - b.order);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mb-8">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
{sortedSteps.map((step, index) => {
|
||||||
|
const stepNumber = index + 1;
|
||||||
|
const isActive = stepNumber === currentStep;
|
||||||
|
const isCompleted = stepNumber < currentStep;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={step.id} className="flex items-center flex-1">
|
||||||
|
{/* Step Circle */}
|
||||||
|
<div className="flex flex-col items-center">
|
||||||
|
<div
|
||||||
|
className={`w-10 h-10 rounded-full flex items-center justify-center text-lg font-medium transition-colors ${
|
||||||
|
isActive
|
||||||
|
? 'bg-brand-purple text-white'
|
||||||
|
: isCompleted
|
||||||
|
? 'bg-green-500 text-white'
|
||||||
|
: 'bg-[var(--neutral-800)] text-[var(--purple-ink)]'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isCompleted ? '✓' : stepNumber}
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className={`mt-2 text-sm text-center hidden md:block ${
|
||||||
|
isActive ? 'text-brand-purple font-medium' : 'text-muted-foreground'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{step.title}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Connector Line */}
|
||||||
|
{index < sortedSteps.length - 1 && (
|
||||||
|
<div
|
||||||
|
className={`flex-1 h-1 mx-4 rounded ${
|
||||||
|
isCompleted
|
||||||
|
? 'bg-green-500'
|
||||||
|
: 'bg-[var(--neutral-800)]'
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a single step based on schema
|
||||||
|
*/
|
||||||
|
export const validateStep = (stepData, formData, hiddenFields) => {
|
||||||
|
const errors = {};
|
||||||
|
|
||||||
|
if (!stepData?.sections) return { isValid: true, errors };
|
||||||
|
|
||||||
|
for (const section of stepData.sections) {
|
||||||
|
// Check section-level validation (e.g., atLeastOne)
|
||||||
|
const sectionValidation = section.validation || {};
|
||||||
|
if (sectionValidation.atLeastOne) {
|
||||||
|
const fieldIds = (section.fields || []).map((f) => f.id);
|
||||||
|
const hasValue = fieldIds.some((id) => {
|
||||||
|
if (hiddenFields.has(id)) return true; // Skip hidden fields
|
||||||
|
const value = formData[id];
|
||||||
|
return Boolean(value);
|
||||||
|
});
|
||||||
|
if (!hasValue) {
|
||||||
|
// Add error to first field in section
|
||||||
|
const firstFieldId = fieldIds[0];
|
||||||
|
if (firstFieldId) {
|
||||||
|
errors[firstFieldId] = [
|
||||||
|
sectionValidation.message ||
|
||||||
|
`At least one field in ${section.title || 'this section'} is required`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check field-level validation
|
||||||
|
for (const field of section.fields || []) {
|
||||||
|
const { id, required, validation = {}, type, label } = field;
|
||||||
|
|
||||||
|
// Skip hidden fields
|
||||||
|
if (hiddenFields.has(id)) continue;
|
||||||
|
|
||||||
|
// Skip client-only fields for server validation
|
||||||
|
if (field.client_only && field.id !== 'confirmPassword') continue;
|
||||||
|
|
||||||
|
const value = formData[id];
|
||||||
|
|
||||||
|
// Required check
|
||||||
|
if (required) {
|
||||||
|
const isEmpty =
|
||||||
|
value === undefined ||
|
||||||
|
value === null ||
|
||||||
|
value === '' ||
|
||||||
|
(Array.isArray(value) && value.length === 0);
|
||||||
|
|
||||||
|
if (isEmpty) {
|
||||||
|
errors[id] = [`${label || id} is required`];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip further validation if value is empty
|
||||||
|
if (!value && value !== false) continue;
|
||||||
|
|
||||||
|
// Type-specific validation
|
||||||
|
const fieldErrors = [];
|
||||||
|
|
||||||
|
if (type === 'email') {
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(value)) {
|
||||||
|
fieldErrors.push('Please enter a valid email address');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'password') {
|
||||||
|
if (validation.minLength && value.length < validation.minLength) {
|
||||||
|
fieldErrors.push(
|
||||||
|
`Password must be at least ${validation.minLength} characters`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'text' || type === 'textarea') {
|
||||||
|
if (validation.minLength && value.length < validation.minLength) {
|
||||||
|
fieldErrors.push(
|
||||||
|
`${label || id} must be at least ${validation.minLength} characters`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (validation.maxLength && value.length > validation.maxLength) {
|
||||||
|
fieldErrors.push(
|
||||||
|
`${label || id} must be at most ${validation.maxLength} characters`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match field validation (for confirmPassword)
|
||||||
|
if (validation.matchField) {
|
||||||
|
if (value !== formData[validation.matchField]) {
|
||||||
|
fieldErrors.push('Passwords do not match');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldErrors.length > 0) {
|
||||||
|
errors[id] = fieldErrors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isValid: Object.keys(errors).length === 0,
|
||||||
|
errors,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate conditional rules to get hidden fields set
|
||||||
|
*/
|
||||||
|
export const evaluateConditionalRules = (schema, formData) => {
|
||||||
|
const rules = schema?.conditional_rules || [];
|
||||||
|
const hidden = new Set();
|
||||||
|
|
||||||
|
// First pass: collect fields that have "show" rules (hidden by default)
|
||||||
|
for (const rule of rules) {
|
||||||
|
if (rule.action === 'show') {
|
||||||
|
rule.target_fields?.forEach((fieldId) => hidden.add(fieldId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second pass: evaluate rules and show/hide fields
|
||||||
|
for (const rule of rules) {
|
||||||
|
const {
|
||||||
|
trigger_field,
|
||||||
|
trigger_operator = 'equals',
|
||||||
|
trigger_value,
|
||||||
|
action,
|
||||||
|
target_fields = [],
|
||||||
|
} = rule;
|
||||||
|
|
||||||
|
const fieldValue = formData[trigger_field];
|
||||||
|
let conditionMet = false;
|
||||||
|
|
||||||
|
switch (trigger_operator) {
|
||||||
|
case 'equals':
|
||||||
|
conditionMet = fieldValue === trigger_value;
|
||||||
|
break;
|
||||||
|
case 'not_equals':
|
||||||
|
conditionMet = fieldValue !== trigger_value;
|
||||||
|
break;
|
||||||
|
case 'contains':
|
||||||
|
conditionMet = Array.isArray(fieldValue)
|
||||||
|
? fieldValue.includes(trigger_value)
|
||||||
|
: String(fieldValue || '').includes(trigger_value);
|
||||||
|
break;
|
||||||
|
case 'not_empty':
|
||||||
|
conditionMet = Boolean(fieldValue);
|
||||||
|
break;
|
||||||
|
case 'empty':
|
||||||
|
conditionMet = !Boolean(fieldValue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
conditionMet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conditionMet) {
|
||||||
|
if (action === 'show') {
|
||||||
|
target_fields.forEach((fieldId) => hidden.delete(fieldId));
|
||||||
|
} else if (action === 'hide') {
|
||||||
|
target_fields.forEach((fieldId) => hidden.add(fieldId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hidden;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DynamicRegistrationForm;
|
||||||
@@ -83,16 +83,16 @@ const SelectItem = React.forwardRef(({ className, children, ...props }, ref) =>
|
|||||||
<SelectPrimitive.Item
|
<SelectPrimitive.Item
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:text-white focus:text-white",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}>
|
{...props}>
|
||||||
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
|
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center ">
|
||||||
<SelectPrimitive.ItemIndicator>
|
<SelectPrimitive.ItemIndicator>
|
||||||
<Check className="h-4 w-4" />
|
<Check className="h-4 w-4" />
|
||||||
</SelectPrimitive.ItemIndicator>
|
</SelectPrimitive.ItemIndicator>
|
||||||
</span>
|
</span>
|
||||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
<SelectPrimitive.ItemText className="">{children}</SelectPrimitive.ItemText>
|
||||||
</SelectPrimitive.Item>
|
</SelectPrimitive.Item>
|
||||||
))
|
))
|
||||||
SelectItem.displayName = SelectPrimitive.Item.displayName
|
SelectItem.displayName = SelectPrimitive.Item.displayName
|
||||||
|
|||||||
@@ -1,78 +1,91 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Table = React.forwardRef(({ className, ...props }, ref) => (
|
const Table = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<div className="relative w-full overflow-auto">
|
<div className="relative w-full overflow-auto">
|
||||||
<table
|
<table ref={ref} className={cn("w-full", className)} {...props} />
|
||||||
ref={ref}
|
|
||||||
className={cn("w-full caption-bottom text-sm", className)}
|
|
||||||
{...props} />
|
|
||||||
</div>
|
</div>
|
||||||
))
|
));
|
||||||
Table.displayName = "Table"
|
Table.displayName = "Table";
|
||||||
|
|
||||||
const TableHeader = React.forwardRef(({ className, ...props }, ref) => (
|
const TableHeader = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
<thead
|
||||||
))
|
ref={ref}
|
||||||
TableHeader.displayName = "TableHeader"
|
className={cn(
|
||||||
|
"bg-[var(--lavender-300)] border-b border-[var(--neutral-800)]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableHeader.displayName = "TableHeader";
|
||||||
|
|
||||||
const TableBody = React.forwardRef(({ className, ...props }, ref) => (
|
const TableBody = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<tbody
|
<tbody
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("[&_tr:last-child]:border-0", className)}
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
TableBody.displayName = "TableBody"
|
));
|
||||||
|
TableBody.displayName = "TableBody";
|
||||||
|
|
||||||
const TableFooter = React.forwardRef(({ className, ...props }, ref) => (
|
const TableFooter = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<tfoot
|
<tfoot
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)}
|
className={cn(
|
||||||
{...props} />
|
"border-t border-[var(--neutral-800)] font-medium [&>tr]:last:border-b-0",
|
||||||
))
|
className,
|
||||||
TableFooter.displayName = "TableFooter"
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableFooter.displayName = "TableFooter";
|
||||||
|
|
||||||
const TableRow = React.forwardRef(({ className, ...props }, ref) => (
|
const TableRow = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<tr
|
<tr
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
"border-b border-[var(--neutral-800)] transition-colors hover:bg-[var(--lavender-400)]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
TableRow.displayName = "TableRow"
|
));
|
||||||
|
TableRow.displayName = "TableRow";
|
||||||
|
|
||||||
const TableHead = React.forwardRef(({ className, ...props }, ref) => (
|
const TableHead = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<th
|
<th
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
"p-4 text-left align-middle font-semibold text-[var(--purple-ink)] [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
TableHead.displayName = "TableHead"
|
));
|
||||||
|
TableHead.displayName = "TableHead";
|
||||||
|
|
||||||
const TableCell = React.forwardRef(({ className, ...props }, ref) => (
|
const TableCell = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<td
|
<td
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
"p-4 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px] ",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
TableCell.displayName = "TableCell"
|
));
|
||||||
|
TableCell.displayName = "TableCell";
|
||||||
|
|
||||||
const TableCaption = React.forwardRef(({ className, ...props }, ref) => (
|
const TableCaption = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
<caption
|
<caption
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||||
{...props} />
|
{...props}
|
||||||
))
|
/>
|
||||||
TableCaption.displayName = "TableCaption"
|
));
|
||||||
|
TableCaption.displayName = "TableCaption";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Table,
|
Table,
|
||||||
@@ -83,4 +96,4 @@ export {
|
|||||||
TableRow,
|
TableRow,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableCaption,
|
TableCaption,
|
||||||
}
|
};
|
||||||
|
|||||||
1032
src/pages/Profile.js
1032
src/pages/Profile.js
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect, useMemo, useCallback } from 'react';
|
||||||
import { useNavigate, Link } from 'react-router-dom';
|
import { useNavigate, Link } from 'react-router-dom';
|
||||||
import { useAuth } from '../context/AuthContext';
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { Button } from '../components/ui/button';
|
import { Button } from '../components/ui/button';
|
||||||
@@ -6,189 +6,221 @@ import { Card } from '../components/ui/card';
|
|||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import PublicNavbar from '../components/PublicNavbar';
|
import PublicNavbar from '../components/PublicNavbar';
|
||||||
import PublicFooter from '../components/PublicFooter';
|
import PublicFooter from '../components/PublicFooter';
|
||||||
import { ArrowRight, ArrowLeft } from 'lucide-react';
|
import { ArrowRight, ArrowLeft, Loader2 } from 'lucide-react';
|
||||||
import RegistrationStepIndicator from '../components/registration/RegistrationStepIndicator';
|
import DynamicRegistrationForm, {
|
||||||
import RegistrationStep1 from '../components/registration/RegistrationStep1';
|
DynamicStepIndicator,
|
||||||
import RegistrationStep2 from '../components/registration/RegistrationStep2';
|
validateStep,
|
||||||
import RegistrationStep3 from '../components/registration/RegistrationStep3';
|
evaluateConditionalRules,
|
||||||
import RegistrationStep4 from '../components/registration/RegistrationStep4';
|
} from '../components/registration/DynamicRegistrationForm';
|
||||||
|
import api from '../utils/api';
|
||||||
|
|
||||||
|
// Fallback schema for when API is unavailable
|
||||||
|
const FALLBACK_SCHEMA = {
|
||||||
|
version: '1.0',
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
id: 'step_account',
|
||||||
|
title: 'Account Setup',
|
||||||
|
description: 'Create your account credentials.',
|
||||||
|
order: 1,
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
id: 'section_credentials',
|
||||||
|
title: 'Account Credentials',
|
||||||
|
order: 1,
|
||||||
|
fields: [
|
||||||
|
{ id: 'first_name', type: 'text', label: 'First Name', required: true, is_fixed: true, mapping: 'first_name', width: 'half', order: 1 },
|
||||||
|
{ id: 'last_name', type: 'text', label: 'Last Name', required: true, is_fixed: true, mapping: 'last_name', width: 'half', order: 2 },
|
||||||
|
{ id: 'email', type: 'email', label: 'Email Address', required: true, is_fixed: true, mapping: 'email', width: 'full', order: 3 },
|
||||||
|
{ id: 'password', type: 'password', label: 'Password', required: true, is_fixed: true, mapping: 'password', validation: { minLength: 6 }, width: 'half', order: 4 },
|
||||||
|
{ id: 'confirmPassword', type: 'password', label: 'Confirm Password', required: true, is_fixed: true, client_only: true, width: 'half', order: 5, validation: { matchField: 'password' } },
|
||||||
|
{ id: 'accepts_tos', type: 'checkbox', label: 'I accept the Terms of Service and Privacy Policy', required: true, is_fixed: true, mapping: 'accepts_tos', width: 'full', order: 6 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
conditional_rules: [],
|
||||||
|
fixed_fields: ['email', 'password', 'first_name', 'last_name', 'accepts_tos'],
|
||||||
|
};
|
||||||
|
|
||||||
const Register = () => {
|
const Register = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { register } = useAuth();
|
const { register } = useAuth();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [schemaLoading, setSchemaLoading] = useState(true);
|
||||||
|
const [schema, setSchema] = useState(null);
|
||||||
const [currentStep, setCurrentStep] = useState(1);
|
const [currentStep, setCurrentStep] = useState(1);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({});
|
||||||
// Step 1: Personal & Partner Information
|
const [errors, setErrors] = useState({});
|
||||||
first_name: '',
|
|
||||||
last_name: '',
|
|
||||||
phone: '',
|
|
||||||
date_of_birth: '',
|
|
||||||
address: '',
|
|
||||||
city: '',
|
|
||||||
state: '',
|
|
||||||
zipcode: '',
|
|
||||||
lead_sources: [],
|
|
||||||
partner_first_name: '',
|
|
||||||
partner_last_name: '',
|
|
||||||
partner_is_member: false,
|
|
||||||
partner_plan_to_become_member: false,
|
|
||||||
|
|
||||||
// Step 2: Newsletter, Volunteer & Scholarship
|
// Fetch registration schema on mount
|
||||||
referred_by_member_name: '',
|
useEffect(() => {
|
||||||
newsletter_publish_name: false,
|
const fetchSchema = async () => {
|
||||||
newsletter_publish_photo: false,
|
try {
|
||||||
newsletter_publish_birthday: false,
|
const response = await api.get('/registration/schema');
|
||||||
newsletter_publish_none: false,
|
setSchema(response.data);
|
||||||
volunteer_interests: [],
|
} catch (error) {
|
||||||
scholarship_requested: false,
|
console.error('Failed to load registration schema:', error);
|
||||||
scholarship_reason: '',
|
toast.error('Failed to load registration form. Using default form.');
|
||||||
|
setSchema(FALLBACK_SCHEMA);
|
||||||
// Step 3: Directory Settings
|
} finally {
|
||||||
show_in_directory: false,
|
setSchemaLoading(false);
|
||||||
directory_email: '',
|
|
||||||
directory_bio: '',
|
|
||||||
directory_address: '',
|
|
||||||
directory_phone: '',
|
|
||||||
directory_dob: '',
|
|
||||||
directory_partner_name: '',
|
|
||||||
|
|
||||||
// Step 4: Account Credentials
|
|
||||||
email: '',
|
|
||||||
password: '',
|
|
||||||
confirmPassword: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleInputChange = (e) => {
|
|
||||||
const { name, value, type, checked } = e.target;
|
|
||||||
setFormData(prev => ({
|
|
||||||
...prev,
|
|
||||||
[name]: type === 'checkbox' ? checked : value
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateStep1 = () => {
|
|
||||||
const required = ['first_name', 'last_name', 'phone', 'date_of_birth',
|
|
||||||
'address', 'city', 'state', 'zipcode'];
|
|
||||||
for (const field of required) {
|
|
||||||
if (!formData[field]?.trim()) {
|
|
||||||
toast.error('Please fill in all required fields');
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
if (formData.lead_sources.length === 0) {
|
|
||||||
toast.error('Please select at least one option for how you heard about us');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateStep2 = () => {
|
fetchSchema();
|
||||||
const { newsletter_publish_name, newsletter_publish_photo,
|
}, []);
|
||||||
newsletter_publish_birthday, newsletter_publish_none } = formData;
|
|
||||||
|
|
||||||
if (!newsletter_publish_name && !newsletter_publish_photo &&
|
// Get sorted steps
|
||||||
!newsletter_publish_birthday && !newsletter_publish_none) {
|
const sortedSteps = useMemo(() => {
|
||||||
toast.error('Please select at least one newsletter publication preference');
|
if (!schema?.steps) return [];
|
||||||
return false;
|
return [...schema.steps].sort((a, b) => a.order - b.order);
|
||||||
}
|
}, [schema]);
|
||||||
|
|
||||||
if (formData.scholarship_requested && !formData.scholarship_reason?.trim()) {
|
// Get current step data
|
||||||
toast.error('Please explain your scholarship request');
|
const currentStepData = useMemo(() => {
|
||||||
return false;
|
return sortedSteps[currentStep - 1] || null;
|
||||||
}
|
}, [sortedSteps, currentStep]);
|
||||||
|
|
||||||
return true;
|
// Get hidden fields based on conditional rules
|
||||||
};
|
const hiddenFields = useMemo(() => {
|
||||||
|
return evaluateConditionalRules(schema, formData);
|
||||||
|
}, [schema, formData]);
|
||||||
|
|
||||||
const validateStep3 = () => {
|
// Validate current step
|
||||||
return true; // No required fields
|
const validateCurrentStep = useCallback(() => {
|
||||||
};
|
if (!currentStepData) return { isValid: true, errors: {} };
|
||||||
|
return validateStep(currentStepData, formData, hiddenFields);
|
||||||
const validateStep4 = () => {
|
}, [currentStepData, formData, hiddenFields]);
|
||||||
if (!formData.email || !formData.password || !formData.confirmPassword) {
|
|
||||||
toast.error('Please fill in all account fields');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(formData.email)) {
|
|
||||||
toast.error('Please enter a valid email address');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formData.password.length < 6) {
|
|
||||||
toast.error('Password must be at least 6 characters');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formData.password !== formData.confirmPassword) {
|
|
||||||
toast.error('Passwords do not match');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Handle next step
|
||||||
const handleNext = () => {
|
const handleNext = () => {
|
||||||
let isValid = false;
|
const { isValid, errors: stepErrors } = validateCurrentStep();
|
||||||
|
|
||||||
switch (currentStep) {
|
if (!isValid) {
|
||||||
case 1: isValid = validateStep1(); break;
|
setErrors(stepErrors);
|
||||||
case 2: isValid = validateStep2(); break;
|
const firstErrorField = Object.keys(stepErrors)[0];
|
||||||
case 3: isValid = validateStep3(); break;
|
if (firstErrorField) {
|
||||||
default: isValid = false;
|
toast.error(stepErrors[firstErrorField][0]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValid) {
|
setErrors({});
|
||||||
setCurrentStep(prev => Math.min(prev + 1, 4));
|
setCurrentStep((prev) => Math.min(prev + 1, sortedSteps.length));
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBack = () => {
|
|
||||||
setCurrentStep(prev => Math.max(prev - 1, 1));
|
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle previous step
|
||||||
|
const handleBack = () => {
|
||||||
|
setErrors({});
|
||||||
|
setCurrentStep((prev) => Math.max(prev - 1, 1));
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle form submission
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Final validation
|
// Validate final step
|
||||||
if (!validateStep4()) return;
|
const { isValid, errors: stepErrors } = validateCurrentStep();
|
||||||
|
if (!isValid) {
|
||||||
|
setErrors(stepErrors);
|
||||||
|
const firstErrorField = Object.keys(stepErrors)[0];
|
||||||
|
if (firstErrorField) {
|
||||||
|
toast.error(stepErrors[firstErrorField][0]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Remove confirmPassword (client-side only)
|
// Prepare submission data
|
||||||
const { confirmPassword, ...dataToSubmit } = formData;
|
const submitData = { ...formData };
|
||||||
|
|
||||||
|
// Remove client-only fields
|
||||||
|
delete submitData.confirmPassword;
|
||||||
|
|
||||||
// Convert date fields to ISO format
|
// Convert date fields to ISO format
|
||||||
const submitData = {
|
if (submitData.date_of_birth) {
|
||||||
...dataToSubmit,
|
submitData.date_of_birth = new Date(submitData.date_of_birth).toISOString();
|
||||||
date_of_birth: new Date(dataToSubmit.date_of_birth).toISOString(),
|
}
|
||||||
directory_dob: dataToSubmit.directory_dob
|
if (submitData.directory_dob) {
|
||||||
? new Date(dataToSubmit.directory_dob).toISOString()
|
submitData.directory_dob = new Date(submitData.directory_dob).toISOString();
|
||||||
: null
|
}
|
||||||
};
|
|
||||||
|
// Ensure boolean fields are actually booleans
|
||||||
|
const booleanFields = [
|
||||||
|
'partner_is_member',
|
||||||
|
'partner_plan_to_become_member',
|
||||||
|
'newsletter_publish_name',
|
||||||
|
'newsletter_publish_photo',
|
||||||
|
'newsletter_publish_birthday',
|
||||||
|
'newsletter_publish_none',
|
||||||
|
'scholarship_requested',
|
||||||
|
'show_in_directory',
|
||||||
|
'accepts_tos',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const field of booleanFields) {
|
||||||
|
if (field in submitData) {
|
||||||
|
submitData[field] = Boolean(submitData[field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure array fields are arrays
|
||||||
|
const arrayFields = ['lead_sources', 'volunteer_interests'];
|
||||||
|
for (const field of arrayFields) {
|
||||||
|
if (field in submitData && !Array.isArray(submitData[field])) {
|
||||||
|
submitData[field] = submitData[field] ? [submitData[field]] : [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await register(submitData);
|
await register(submitData);
|
||||||
toast.success('Please check your email for a confirmation email.');
|
toast.success('Please check your email for a confirmation email.');
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(error.response?.data?.detail || 'Registration failed. Please try again.');
|
const errorMessage = error.response?.data?.detail;
|
||||||
|
if (typeof errorMessage === 'object' && errorMessage.errors) {
|
||||||
|
// Handle structured validation errors
|
||||||
|
const errorList = errorMessage.errors;
|
||||||
|
toast.error(errorList[0] || 'Registration failed');
|
||||||
|
} else {
|
||||||
|
toast.error(errorMessage || 'Registration failed. Please try again.');
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Show loading state while fetching schema
|
||||||
|
if (schemaLoading) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-background">
|
||||||
|
<PublicNavbar />
|
||||||
|
<div className="max-w-4xl mx-auto px-6 py-12 flex items-center justify-center min-h-[60vh]">
|
||||||
|
<div className="text-center">
|
||||||
|
<Loader2 className="h-8 w-8 animate-spin mx-auto mb-4 text-brand-purple" />
|
||||||
|
<p className="text-muted-foreground">Loading registration form...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<PublicFooter />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-background">
|
<div className="min-h-screen bg-background">
|
||||||
<PublicNavbar />
|
<PublicNavbar />
|
||||||
|
|
||||||
<div className="max-w-4xl mx-auto px-6 py-12">
|
<div className="max-w-4xl mx-auto px-6 py-12">
|
||||||
<div className="mb-8">
|
<div className="mb-8">
|
||||||
<Link to="/" className="inline-flex items-center text-brand-purple hover:text-[var(--orange-light)] transition-colors">
|
<Link
|
||||||
|
to="/"
|
||||||
|
className="inline-flex items-center text-brand-purple hover:text-[var(--orange-light)] transition-colors"
|
||||||
|
>
|
||||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||||
Back to Home
|
Back to Home
|
||||||
</Link>
|
</Link>
|
||||||
@@ -196,47 +228,34 @@ const Register = () => {
|
|||||||
|
|
||||||
<Card className="p-8 md:p-12 bg-background rounded-2xl border border-[var(--neutral-800)] shadow-lg">
|
<Card className="p-8 md:p-12 bg-background rounded-2xl border border-[var(--neutral-800)] shadow-lg">
|
||||||
<div className="mb-8">
|
<div className="mb-8">
|
||||||
<h1 className="text-4xl md:text-5xl font-semibold text-[var(--purple-ink)] mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<h1
|
||||||
|
className="text-4xl md:text-5xl font-semibold text-[var(--purple-ink)] mb-4"
|
||||||
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
|
>
|
||||||
Join Our Community
|
Join Our Community
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-lg text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p
|
||||||
|
className="text-lg text-brand-purple"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
Fill out the form below to start your membership journey.
|
Fill out the form below to start your membership journey.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-8" data-testid="register-form">
|
<form onSubmit={handleSubmit} className="space-y-8" data-testid="register-form">
|
||||||
<RegistrationStepIndicator currentStep={currentStep} />
|
{/* Step Indicator */}
|
||||||
|
{sortedSteps.length > 1 && (
|
||||||
{currentStep === 1 && (
|
<DynamicStepIndicator steps={sortedSteps} currentStep={currentStep} />
|
||||||
<RegistrationStep1
|
|
||||||
formData={formData}
|
|
||||||
setFormData={setFormData}
|
|
||||||
handleInputChange={handleInputChange}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{currentStep === 2 && (
|
{/* Dynamic Form Content */}
|
||||||
<RegistrationStep2
|
<DynamicRegistrationForm
|
||||||
formData={formData}
|
schema={schema}
|
||||||
setFormData={setFormData}
|
formData={formData}
|
||||||
handleInputChange={handleInputChange}
|
onFormDataChange={setFormData}
|
||||||
/>
|
currentStep={currentStep}
|
||||||
)}
|
errors={errors}
|
||||||
|
/>
|
||||||
{currentStep === 3 && (
|
|
||||||
<RegistrationStep3
|
|
||||||
formData={formData}
|
|
||||||
setFormData={setFormData}
|
|
||||||
handleInputChange={handleInputChange}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{currentStep === 4 && (
|
|
||||||
<RegistrationStep4
|
|
||||||
formData={formData}
|
|
||||||
handleInputChange={handleInputChange}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Navigation Buttons */}
|
{/* Navigation Buttons */}
|
||||||
<div className="flex justify-between items-center pt-6">
|
<div className="flex justify-between items-center pt-6">
|
||||||
@@ -245,7 +264,7 @@ const Register = () => {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={handleBack}
|
onClick={handleBack}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="rounded-full px-6 py-6 text-lg border-2 border-[var(--neutral-800)] hover:border-brand-purple text-[var(--purple-ink)]"
|
className="rounded-full px-6 py-6 text-lg border-2 border-[var(--neutral-800)] hover:border-brand-purple text-[var(--purple-ink)]"
|
||||||
>
|
>
|
||||||
<ArrowLeft className="mr-2 h-5 w-5" />
|
<ArrowLeft className="mr-2 h-5 w-5" />
|
||||||
Back
|
Back
|
||||||
@@ -254,7 +273,7 @@ const Register = () => {
|
|||||||
<div></div>
|
<div></div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{currentStep < 4 ? (
|
{currentStep < sortedSteps.length ? (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleNext}
|
onClick={handleNext}
|
||||||
@@ -267,16 +286,28 @@ const Register = () => {
|
|||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
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"
|
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 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
data-testid="submit-register-button"
|
data-testid="submit-register-button"
|
||||||
>
|
>
|
||||||
{loading ? 'Creating Account...' : 'Create Account'}
|
{loading ? (
|
||||||
<ArrowRight className="ml-2 h-5 w-5" />
|
<>
|
||||||
|
<Loader2 className="mr-2 h-5 w-5 animate-spin" />
|
||||||
|
Creating Account...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
Create Account
|
||||||
|
<ArrowRight className="ml-2 h-5 w-5" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-center text-brand-purple mt-4" style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p
|
||||||
|
className="text-center text-brand-purple mt-4"
|
||||||
|
style={{ fontFamily: "'Nunito Sans', sans-serif" }}
|
||||||
|
>
|
||||||
Already have an account?{' '}
|
Already have an account?{' '}
|
||||||
<Link to="/login" className="text-[var(--orange-light)] hover:underline font-medium">
|
<Link to="/login" className="text-[var(--orange-light)] hover:underline font-medium">
|
||||||
Login here
|
Login here
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ const AdminDashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
<Link to={'/'} className=''>
|
<Link to={'/'} className=''>
|
||||||
<Button
|
<Button
|
||||||
className="btn-lavender mb-8 md:mb-0 "
|
className="btn-lavender mb-8 md:mb-0 mr-4 "
|
||||||
>
|
>
|
||||||
<Globe />
|
<Globe />
|
||||||
View Public Site
|
View Public Site
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useAuth } from '../../context/AuthContext';
|
|||||||
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 { Input } from '../../components/ui/input';
|
import { Input } from '../../components/ui/input';
|
||||||
|
import StatusBadge from '@/components/StatusBadge';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -17,6 +18,14 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '../../components/ui/dropdown-menu';
|
} from '../../components/ui/dropdown-menu';
|
||||||
import { Badge } from '../../components/ui/badge';
|
import { Badge } from '../../components/ui/badge';
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from '../../components/ui/table';
|
||||||
import api from '../../utils/api';
|
import api from '../../utils/api';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import {
|
import {
|
||||||
@@ -184,15 +193,8 @@ const AdminDonations = () => {
|
|||||||
toast.error('Failed to copy to clipboard');
|
toast.error('Failed to copy to clipboard');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
const getStatusBadgeVariant = (status) => {
|
*/
|
||||||
const variants = {
|
|
||||||
completed: 'default',
|
|
||||||
pending: 'secondary',
|
|
||||||
failed: 'destructive'
|
|
||||||
};
|
|
||||||
return variants[status] || 'outline';
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTypeBadgeColor = (type) => {
|
const getTypeBadgeColor = (type) => {
|
||||||
return type === 'member' ? 'bg-[var(--green-light)]' : 'bg-brand-purple ';
|
return type === 'member' ? 'bg-[var(--green-light)]' : 'bg-brand-purple ';
|
||||||
@@ -392,51 +394,37 @@ const AdminDonations = () => {
|
|||||||
{/* Donations Table */}
|
{/* Donations Table */}
|
||||||
<Card className="bg-background rounded-2xl border-2 border-[var(--neutral-800)] overflow-hidden">
|
<Card className="bg-background rounded-2xl border-2 border-[var(--neutral-800)] overflow-hidden">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full">
|
<Table>
|
||||||
<thead className="bg-[var(--lavender-300)] border-b-2 border-[var(--neutral-800)]">
|
<TableHeader>
|
||||||
<tr>
|
<TableRow>
|
||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<TableHead>Donor</TableHead>
|
||||||
Donor
|
<TableHead>Type</TableHead>
|
||||||
</th>
|
<TableHead>Amount</TableHead>
|
||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<TableHead>Status</TableHead>
|
||||||
Type
|
<TableHead>Date</TableHead>
|
||||||
</th>
|
<TableHead>Payment Method</TableHead>
|
||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<TableHead className="text-center">Details</TableHead>
|
||||||
Amount
|
</TableRow>
|
||||||
</th>
|
</TableHeader>
|
||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<TableBody>
|
||||||
Status
|
|
||||||
</th>
|
|
||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
|
||||||
Date
|
|
||||||
</th>
|
|
||||||
<th className="px-6 py-4 text-left text-sm font-semibold text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
|
||||||
Payment Method
|
|
||||||
</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>
|
|
||||||
</thead>
|
|
||||||
<tbody className="divide-y divide-[var(--neutral-800)]">
|
|
||||||
{filteredDonations.length === 0 ? (
|
{filteredDonations.length === 0 ? (
|
||||||
<tr>
|
<TableRow>
|
||||||
<td colSpan="7" className="px-6 py-12 text-center">
|
<TableCell colSpan={7} className="p-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" }}>
|
||||||
{donations.length === 0 ? 'No donations yet' : 'No donations match your filters'}
|
{donations.length === 0 ? 'No donations yet' : 'No donations match your filters'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</TableCell>
|
||||||
</tr>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
filteredDonations.map((donation) => {
|
filteredDonations.map((donation) => {
|
||||||
const isExpanded = expandedRows.has(donation.id);
|
const isExpanded = expandedRows.has(donation.id);
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={donation.id}>
|
<React.Fragment key={donation.id}>
|
||||||
<tr className="hover:bg-[var(--lavender-400)] transition-colors">
|
<TableRow>
|
||||||
<td className="px-6 py-4">
|
<TableCell>
|
||||||
<div>
|
<div>
|
||||||
<p className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<p className="font-medium text-[var(--purple-ink)]" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{donation.donor_name || 'Anonymous'}
|
{donation.donor_name || 'Anonymous'}
|
||||||
@@ -445,39 +433,37 @@ const AdminDonations = () => {
|
|||||||
{donation.donor_email || 'No email'}
|
{donation.donor_email || 'No email'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</TableCell>
|
||||||
<td className="px-6 py-4">
|
<TableCell>
|
||||||
<Badge
|
<Badge
|
||||||
className={`${getTypeBadgeColor(donation.donation_type)} text-white border-none rounded-full px-3 py-1`}
|
className={`${getTypeBadgeColor(donation.donation_type)} text-white border-none px-3 py-1`}
|
||||||
style={{ fontFamily: "'Inter', sans-serif" }}
|
style={{ fontFamily: "'Inter', sans-serif" }}
|
||||||
>
|
>
|
||||||
{donation.donation_type === 'member' ? 'Member' : 'Public'}
|
{donation.donation_type === 'member' ? 'Member' : 'Public'}
|
||||||
</Badge>
|
</Badge>
|
||||||
</td>
|
</TableCell>
|
||||||
<td className="px-6 py-4">
|
<TableCell>
|
||||||
<p className="font-semibold text-[var(--purple-ink)] text-lg" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<p className="font-semibold text-[var(--purple-ink)] text-lg" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
{donation.amount}
|
{donation.amount}
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</TableCell>
|
||||||
<td className="px-6 py-4">
|
<TableCell>
|
||||||
<Badge variant={getStatusBadgeVariant(donation.status)} className="rounded-full">
|
<StatusBadge status={donation.status} />
|
||||||
{donation.status.charAt(0).toUpperCase() + donation.status.slice(1)}
|
</TableCell>
|
||||||
</Badge>
|
<TableCell>
|
||||||
</td>
|
|
||||||
<td className="px-6 py-4">
|
|
||||||
<div className="flex items-center gap-2 text-brand-purple ">
|
<div className="flex items-center gap-2 text-brand-purple ">
|
||||||
<Calendar className="h-4 w-4" />
|
<Calendar className="h-4 w-4" />
|
||||||
<span style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<span style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
{formatDate(donation.created_at)}
|
{formatDate(donation.created_at)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</TableCell>
|
||||||
<td className="px-6 py-4">
|
<TableCell>
|
||||||
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif capitalize" }}>
|
||||||
{donation.payment_method || 'N/A'}
|
{donation.payment_method || 'N/A'}
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</TableCell>
|
||||||
<td className="px-6 py-4 text-center">
|
<TableCell className="text-center">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -486,12 +472,11 @@ const AdminDonations = () => {
|
|||||||
>
|
>
|
||||||
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
{isExpanded ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||||||
</Button>
|
</Button>
|
||||||
</td>
|
</TableCell>
|
||||||
</tr>
|
</TableRow>
|
||||||
{/* Expandable Details Row */}
|
|
||||||
{isExpanded && (
|
{isExpanded && (
|
||||||
<tr className="bg-[var(--lavender-400)]/30">
|
<TableRow className="bg-[var(--lavender-400)]/30">
|
||||||
<td colSpan="7" className="px-6 py-6">
|
<TableCell colSpan={7} className="p-6">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h4 className="font-semibold text-[var(--purple-ink)] text-lg mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<h4 className="font-semibold text-[var(--purple-ink)] text-lg mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
Transaction Details
|
Transaction Details
|
||||||
@@ -601,15 +586,15 @@ const AdminDonations = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</TableCell>
|
||||||
</tr>
|
</TableRow>
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</TableBody>
|
||||||
</table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|||||||
@@ -150,9 +150,15 @@ const AdminMemberTiers = () => {
|
|||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{/* Header and Actions */}
|
{/* Header and Actions */}
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||||
<p className="text-muted-foreground">
|
<div>
|
||||||
Configure tier names, time ranges, and badges displayed in the members directory.
|
|
||||||
</p>
|
<h1 className="text-4xl md:text-5xl font-semibold text-[var(--purple-ink)] mb-4" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
Members Tiers
|
||||||
|
</h1>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Configure tier names, time ranges, and badges displayed in the members directory.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{hasChanges && (
|
{hasChanges && (
|
||||||
<Button variant="outline" onClick={handleDiscardChanges}>
|
<Button variant="outline" onClick={handleDiscardChanges}>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { Users, Search, User, CreditCard, Eye, CheckCircle, Calendar, AlertCircl
|
|||||||
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 InviteMemberDialog from '../../components/InviteMemberDialog';
|
||||||
import WordPressImportWizard from '../../components/WordPressImportWizard';
|
import WordPressImportWizard from '../../components/WordPressImportWizard';
|
||||||
import StatusBadge from '../../components/StatusBadge';
|
import StatusBadge from '../../components/StatusBadge';
|
||||||
import { StatCard } from '@/components/StatCard';
|
import { StatCard } from '@/components/StatCard';
|
||||||
@@ -323,11 +323,9 @@ const AdminMembers = () => {
|
|||||||
<SelectItem value="active">Active</SelectItem>
|
<SelectItem value="active">Active</SelectItem>
|
||||||
<SelectItem value="payment_pending">Payment Pending</SelectItem>
|
<SelectItem value="payment_pending">Payment Pending</SelectItem>
|
||||||
<SelectItem value="pending_validation">Pending Validation</SelectItem>
|
<SelectItem value="pending_validation">Pending Validation</SelectItem>
|
||||||
<SelectItem value="pre_validated">Pre-Validated</SelectItem>
|
|
||||||
<SelectItem value="inactive">Inactive</SelectItem>
|
<SelectItem value="inactive">Inactive</SelectItem>
|
||||||
<SelectItem value="canceled">Canceled</SelectItem>
|
<SelectItem value="canceled">Canceled</SelectItem>
|
||||||
<SelectItem value="expired">Expired</SelectItem>
|
<SelectItem value="expired">Expired</SelectItem>
|
||||||
<SelectItem value="abandoned">Abandoned</SelectItem>
|
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
@@ -523,7 +521,7 @@ const AdminMembers = () => {
|
|||||||
onSuccess={refetch}
|
onSuccess={refetch}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InviteStaffDialog
|
<InviteMemberDialog
|
||||||
open={inviteDialogOpen}
|
open={inviteDialogOpen}
|
||||||
onOpenChange={setInviteDialogOpen}
|
onOpenChange={setInviteDialogOpen}
|
||||||
onSuccess={refetch}
|
onSuccess={refetch}
|
||||||
|
|||||||
1136
src/pages/admin/AdminRegistrationBuilder.js
Normal file
1136
src/pages/admin/AdminRegistrationBuilder.js
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,7 @@ import ConfirmationDialog from '../../components/ConfirmationDialog';
|
|||||||
import ChangeRoleDialog from '../../components/ChangeRoleDialog';
|
import ChangeRoleDialog from '../../components/ChangeRoleDialog';
|
||||||
import StatusBadge from '../../components/StatusBadge';
|
import StatusBadge from '../../components/StatusBadge';
|
||||||
import TransactionHistory from '../../components/TransactionHistory';
|
import TransactionHistory from '../../components/TransactionHistory';
|
||||||
|
import AdminPaymentMethodsPanel from '../../components/admin/AdminPaymentMethodsPanel';
|
||||||
|
|
||||||
const AdminUserView = () => {
|
const AdminUserView = () => {
|
||||||
const { userId } = useParams();
|
const { userId } = useParams();
|
||||||
@@ -417,6 +418,14 @@ const AdminUserView = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{/* Payment Methods Panel */}
|
||||||
|
<div className="mb-8">
|
||||||
|
<AdminPaymentMethodsPanel
|
||||||
|
userId={userId}
|
||||||
|
userName={`${user.first_name} ${user.last_name}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Additional Details */}
|
{/* Additional Details */}
|
||||||
<Card className="p-8 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
<Card className="p-8 bg-background rounded-2xl border border-[var(--neutral-800)]">
|
||||||
<h2 className="text-2xl font-semibold text-[var(--purple-ink)] mb-6" style={{ fontFamily: "'Inter', sans-serif" }}>
|
<h2 className="text-2xl font-semibold text-[var(--purple-ink)] mb-6" style={{ fontFamily: "'Inter', sans-serif" }}>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { useAuth } from '../../context/AuthContext';
|
import { useAuth } from '../../context/AuthContext';
|
||||||
import api from '../../utils/api';
|
import api from '../../utils/api';
|
||||||
import { Card } from '../../components/ui/card';
|
import { Card } from '../../components/ui/card';
|
||||||
import { Button } from '../../components/ui/button';
|
|
||||||
import { Input } from '../../components/ui/input';
|
import { Input } from '../../components/ui/input';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
@@ -19,6 +18,12 @@ import {
|
|||||||
TableRow,
|
TableRow,
|
||||||
TableCell,
|
TableCell,
|
||||||
} from '../../components/ui/table';
|
} from '../../components/ui/table';
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from '../../components/ui/tooltip';
|
||||||
import {
|
import {
|
||||||
Pagination,
|
Pagination,
|
||||||
PaginationContent,
|
PaginationContent,
|
||||||
@@ -29,12 +34,27 @@ import {
|
|||||||
PaginationEllipsis,
|
PaginationEllipsis,
|
||||||
} from '../../components/ui/pagination';
|
} from '../../components/ui/pagination';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { CheckCircle, Clock, Search, ArrowUp, ArrowDown, X, XCircle } from 'lucide-react';
|
import {
|
||||||
|
CheckCircle,
|
||||||
|
Clock,
|
||||||
|
Search,
|
||||||
|
ArrowUp,
|
||||||
|
ArrowDown,
|
||||||
|
X,
|
||||||
|
FileText,
|
||||||
|
XCircle,
|
||||||
|
Users,
|
||||||
|
Mail,
|
||||||
|
ShieldCheck,
|
||||||
|
CreditCard
|
||||||
|
} from 'lucide-react';
|
||||||
import PaymentActivationDialog from '../../components/PaymentActivationDialog';
|
import PaymentActivationDialog from '../../components/PaymentActivationDialog';
|
||||||
import ConfirmationDialog from '../../components/ConfirmationDialog';
|
import ConfirmationDialog from '../../components/ConfirmationDialog';
|
||||||
import RejectionDialog from '../../components/RejectionDialog';
|
import RejectionDialog from '../../components/RejectionDialog';
|
||||||
import StatusBadge from '@/components/StatusBadge';
|
import StatusBadge from '@/components/StatusBadge';
|
||||||
import { StatCard } from '@/components/StatCard';
|
import { StatCard } from '@/components/StatCard';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import ViewRegistrationDialog from '@/components/ViewRegistrationDialog';
|
||||||
|
|
||||||
const AdminValidations = () => {
|
const AdminValidations = () => {
|
||||||
const { hasPermission } = useAuth();
|
const { hasPermission } = useAuth();
|
||||||
@@ -48,6 +68,8 @@ const AdminValidations = () => {
|
|||||||
const [pendingAction, setPendingAction] = useState(null);
|
const [pendingAction, setPendingAction] = useState(null);
|
||||||
const [rejectionDialogOpen, setRejectionDialogOpen] = useState(false);
|
const [rejectionDialogOpen, setRejectionDialogOpen] = useState(false);
|
||||||
const [userToReject, setUserToReject] = useState(null);
|
const [userToReject, setUserToReject] = useState(null);
|
||||||
|
const [viewRegistrationDialogOpen, setViewRegistrationDialogOpen] = useState(false);
|
||||||
|
const [selectedUserForView, setSelectedUserForView] = useState(null);
|
||||||
|
|
||||||
// Filtering state
|
// Filtering state
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
@@ -61,6 +83,9 @@ const AdminValidations = () => {
|
|||||||
const [sortBy, setSortBy] = useState('created_at');
|
const [sortBy, setSortBy] = useState('created_at');
|
||||||
const [sortOrder, setSortOrder] = useState('desc');
|
const [sortOrder, setSortOrder] = useState('desc');
|
||||||
|
|
||||||
|
// Resend email state
|
||||||
|
const [resendLoading, setResendLoading] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchPendingUsers();
|
fetchPendingUsers();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -236,6 +261,24 @@ const AdminValidations = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRegistrationDialog = (user) => {
|
||||||
|
setSelectedUserForView(user);
|
||||||
|
setViewRegistrationDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Resend Email Handler
|
||||||
|
const handleResendVerification = async (user) => {
|
||||||
|
setResendLoading(user.id);
|
||||||
|
try {
|
||||||
|
await api.post(`/admin/users/${user.id}/resend-verification`);
|
||||||
|
toast.success(`Verification email sent to ${user.email}`);
|
||||||
|
fetchPendingUsers();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(error.response?.data?.detail || 'Failed to send verification email');
|
||||||
|
} finally {
|
||||||
|
setResendLoading(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleSort = (column) => {
|
const handleSort = (column) => {
|
||||||
@@ -261,6 +304,37 @@ const AdminValidations = () => {
|
|||||||
<ArrowDown className="h-4 w-4 inline ml-1" />;
|
<ArrowDown className="h-4 w-4 inline ml-1" />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const formatPhoneNumber = (phone) => {
|
||||||
|
if (!phone) return '-';
|
||||||
|
const cleaned = phone.replace(/\D/g, '');
|
||||||
|
if (cleaned.length === 10) {
|
||||||
|
return `(${cleaned.slice(0, 3)}) ${cleaned.slice(3, 6)} - ${cleaned.slice(6)}`;
|
||||||
|
}
|
||||||
|
return phone;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleActionSelect = (user, action) => {
|
||||||
|
switch (action) {
|
||||||
|
case 'validate':
|
||||||
|
handleValidateRequest(user);
|
||||||
|
break;
|
||||||
|
case 'bypass_validate':
|
||||||
|
handleBypassAndValidateRequest(user);
|
||||||
|
break;
|
||||||
|
case 'resend_email':
|
||||||
|
handleResendVerification(user);
|
||||||
|
break;
|
||||||
|
case 'activate_payment':
|
||||||
|
handleActivatePayment(user);
|
||||||
|
break;
|
||||||
|
case 'reactivate':
|
||||||
|
handleReactivateUser(user);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
@@ -279,44 +353,30 @@ const AdminValidations = () => {
|
|||||||
<div className=' text-2xl text-[var(--purple-ink)] pb-8 font-semibold'>
|
<div className=' text-2xl text-[var(--purple-ink)] pb-8 font-semibold'>
|
||||||
Quick Overview
|
Quick Overview
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-2 md:grid-cols-6 gap-4">
|
<div className="grid grid-cols-2 md:grid-cols-5 gap-4">
|
||||||
<StatCard
|
|
||||||
title="Total Pending"
|
|
||||||
value={loading ? '-' : pendingUsers.length}
|
|
||||||
icon={CheckCircle}
|
|
||||||
iconBgClass="text-brand-purple"
|
|
||||||
dataTestId="stat-total-users"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<StatCard
|
<StatCard
|
||||||
title="Awaiting Email"
|
title="Awaiting Email"
|
||||||
value={loading ? '-' : pendingUsers.filter(u => u.status === 'pending_email').length}
|
value={loading ? '-' : pendingUsers.filter(u => u.status === 'pending_email').length}
|
||||||
icon={CheckCircle}
|
icon={Mail}
|
||||||
iconBgClass="text-brand-purple"
|
iconBgClass="text-brand-pink"
|
||||||
dataTestId="stat-total-users"
|
dataTestId="stat-total-users"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<StatCard
|
<StatCard
|
||||||
title="Pending Validation"
|
title="Pending Validation"
|
||||||
value={loading ? '-' : pendingUsers.filter(u => u.status === 'pending_validation').length}
|
value={loading ? '-' : pendingUsers.filter(u => u.status === 'pending_validation').length}
|
||||||
icon={CheckCircle}
|
icon={ShieldCheck}
|
||||||
iconBgClass="text-brand-purple"
|
iconBgClass="text-success"
|
||||||
dataTestId="stat-pending-validation"
|
dataTestId="stat-pending-validation"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<StatCard
|
|
||||||
title="Pre-Validated"
|
|
||||||
value={loading ? '-' : pendingUsers.filter(u => u.status === 'pre_validated').length}
|
|
||||||
icon={CheckCircle}
|
|
||||||
iconBgClass="text-brand-purple"
|
|
||||||
dataTestId="stat-pre-validated"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<StatCard
|
<StatCard
|
||||||
title="Payment Pending"
|
title="Payment Pending"
|
||||||
value={loading ? '-' : pendingUsers.filter(u => u.status === 'payment_pending').length}
|
value={loading ? '-' : pendingUsers.filter(u => u.status === 'payment_pending').length}
|
||||||
icon={CheckCircle}
|
icon={CreditCard}
|
||||||
iconBgClass="text-brand-purple"
|
iconBgClass="text-accent"
|
||||||
dataTestId="stat-payment-pending"
|
dataTestId="stat-payment-pending"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -328,7 +388,13 @@ const AdminValidations = () => {
|
|||||||
dataTestId="stat-rejected"
|
dataTestId="stat-rejected"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<StatCard
|
||||||
|
title="Total Pending"
|
||||||
|
value={loading ? '-' : pendingUsers.filter(user => ['pending_email', 'pending_validation', 'pre_validated', 'payment_pending',].includes(user.status)).length}
|
||||||
|
icon={Users}
|
||||||
|
iconBgClass="text-brand-purple"
|
||||||
|
dataTestId="stat-total-users"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@@ -349,13 +415,12 @@ const AdminValidations = () => {
|
|||||||
<SelectTrigger className="h-14 rounded-xl border-2 border-[var(--neutral-800)]">
|
<SelectTrigger className="h-14 rounded-xl border-2 border-[var(--neutral-800)]">
|
||||||
<SelectValue placeholder="Filter by status" />
|
<SelectValue placeholder="Filter by status" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent className="">
|
||||||
<SelectItem value="all">All Statuses</SelectItem>
|
<SelectItem value="all">All Statuses</SelectItem>
|
||||||
<SelectItem value="pending_email">Awaiting Email</SelectItem>
|
<SelectItem value="pending_email" >Awaiting Email</SelectItem>
|
||||||
<SelectItem value="pending_validation">Pending Validation</SelectItem>
|
<SelectItem value="pending_validation" >Pending Validation</SelectItem>
|
||||||
<SelectItem value="pre_validated">Pre-Validated</SelectItem>
|
<SelectItem value="payment_pending" >Payment Pending</SelectItem>
|
||||||
<SelectItem value="payment_pending">Payment Pending</SelectItem>
|
<SelectItem value="rejected" >Rejected</SelectItem>
|
||||||
<SelectItem value="rejected">Rejected</SelectItem>
|
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
@@ -371,14 +436,13 @@ const AdminValidations = () => {
|
|||||||
<Card className="bg-background rounded-2xl border border-[var(--neutral-800)] overflow-hidden">
|
<Card className="bg-background rounded-2xl border border-[var(--neutral-800)] overflow-hidden">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow className="text-md">
|
||||||
<TableHead
|
<TableHead
|
||||||
className="cursor-pointer hover:bg-[var(--neutral-800)]/20"
|
className="cursor-pointer hover:bg-[var(--neutral-800)]/20"
|
||||||
onClick={() => handleSort('first_name')}
|
onClick={() => handleSort('first_name')}
|
||||||
>
|
>
|
||||||
Name {renderSortIcon('first_name')}
|
Member {renderSortIcon('first_name')}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead>Email</TableHead>
|
|
||||||
<TableHead>Phone</TableHead>
|
<TableHead>Phone</TableHead>
|
||||||
<TableHead
|
<TableHead
|
||||||
className="cursor-pointer hover:bg-[var(--neutral-800)]/20"
|
className="cursor-pointer hover:bg-[var(--neutral-800)]/20"
|
||||||
@@ -392,6 +456,13 @@ const AdminValidations = () => {
|
|||||||
>
|
>
|
||||||
Registered {renderSortIcon('created_at')}
|
Registered {renderSortIcon('created_at')}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
|
<TableHead
|
||||||
|
className="cursor-pointer hover:bg-[var(--neutral-800)]/20"
|
||||||
|
onClick={() => handleSort('email_verification_expires_at')}
|
||||||
|
>
|
||||||
|
{/* TODO: change ' ' */}
|
||||||
|
Validation Expiry {renderSortIcon('email_verification_expires_at')}
|
||||||
|
</TableHead>
|
||||||
<TableHead>Referred By</TableHead>
|
<TableHead>Referred By</TableHead>
|
||||||
<TableHead>Actions</TableHead>
|
<TableHead>Actions</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -399,105 +470,116 @@ const AdminValidations = () => {
|
|||||||
<TableBody>
|
<TableBody>
|
||||||
{paginatedUsers.map((user) => (
|
{paginatedUsers.map((user) => (
|
||||||
<TableRow key={user.id}>
|
<TableRow key={user.id}>
|
||||||
<TableCell className="font-medium">
|
<TableCell className=" ">
|
||||||
{user.first_name} {user.last_name}
|
<div className='font-semibold'>
|
||||||
|
|
||||||
|
{user.first_name} {user.last_name}
|
||||||
|
</div>
|
||||||
|
<div className='text-brand-purple'>
|
||||||
|
{user.email}
|
||||||
|
</div>
|
||||||
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{user.email}</TableCell>
|
<TableCell>{formatPhoneNumber(user.phone)}</TableCell>
|
||||||
<TableCell>{user.phone}</TableCell>
|
|
||||||
<TableCell><StatusBadge status={user.status} /></TableCell>
|
<TableCell><StatusBadge status={user.status} /></TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{new Date(user.created_at).toLocaleDateString()}
|
{new Date(user.created_at).toLocaleDateString()}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{user.email_verification_expires_at
|
||||||
|
? new Date(user.email_verification_expires_at).toLocaleString()
|
||||||
|
: '—'}
|
||||||
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{user.referred_by_member_name || '-'}
|
{user.referred_by_member_name || '-'}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="flex gap-2">
|
<div className='flex gap-2 justify-between'>
|
||||||
{user.status === 'rejected' ? (
|
|
||||||
<Button
|
<Select
|
||||||
onClick={() => handleReactivateUser(user)}
|
value=""
|
||||||
disabled={actionLoading === user.id}
|
onValueChange={(action) => handleActionSelect(user, action)}
|
||||||
size="sm"
|
disabled={actionLoading === user.id || resendLoading === user.id}
|
||||||
className="bg-[var(--green-light)] text-white hover:bg-[var(--green-mint)]"
|
>
|
||||||
>
|
<SelectTrigger className="w-[100px] h-9 border-[var(--neutral-800)]">
|
||||||
{actionLoading === user.id ? 'Reactivating...' : 'Reactivate'}
|
<SelectValue placeholder={actionLoading === user.id || resendLoading === user.id ? 'Processing...' : 'Action'} />
|
||||||
</Button>
|
</SelectTrigger>
|
||||||
) : user.status === 'pending_email' ? (
|
<SelectContent>
|
||||||
<>
|
{user.status === 'rejected' ? (
|
||||||
{hasPermission('users.approve') && (
|
<SelectItem value="reactivate">Reactivate</SelectItem>
|
||||||
<Button
|
) : user.status === 'pending_email' ? (
|
||||||
onClick={() => handleBypassAndValidateRequest(user)}
|
<>
|
||||||
disabled={actionLoading === user.id}
|
{hasPermission('users.approve') && (
|
||||||
size="sm"
|
<SelectItem value="bypass_validate">Bypass & Validate</SelectItem>
|
||||||
className="bg-[var(--neutral-800)] text-[var(--purple-ink)] hover:bg-background"
|
)}
|
||||||
>
|
{hasPermission('users.approve') && (
|
||||||
{actionLoading === user.id ? 'Validating...' : 'Bypass & Validate'}
|
<SelectItem value="resend_email">Resend Email</SelectItem>
|
||||||
</Button>
|
)}
|
||||||
|
{/* {hasPermission('users.approve') && (
|
||||||
|
<SelectItem value="reject">Reject</SelectItem>
|
||||||
|
)} */}
|
||||||
|
</>
|
||||||
|
) : user.status === 'payment_pending' ? (
|
||||||
|
<>
|
||||||
|
{hasPermission('subscriptions.activate') && (
|
||||||
|
<SelectItem value="activate_payment">Activate Payment</SelectItem>
|
||||||
|
)}
|
||||||
|
{/* {hasPermission('users.approve') && (
|
||||||
|
<SelectItem value="reject">Reject</SelectItem>
|
||||||
|
)} */}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{hasPermission('users.approve') && (
|
||||||
|
<SelectItem value="validate">Validate</SelectItem>
|
||||||
|
)}
|
||||||
|
{/* {hasPermission('users.approve') && (
|
||||||
|
<SelectItem value="reject">Reject</SelectItem>
|
||||||
|
)} */}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{hasPermission('users.approve') && (
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<TooltipProvider>
|
||||||
|
{/* view registration */}
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleRejectUser(user)}
|
onClick={() => handleRegistrationDialog(user)}
|
||||||
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 dark:hover:bg-red-500/10"
|
className="border-2 border-primary text-primary hover:bg-red-50 dark:hover:bg-red-500/10"
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4 mr-1" />
|
<FileText className="size-4" />
|
||||||
Reject
|
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
</TooltipTrigger>
|
||||||
</>
|
<TooltipContent>
|
||||||
) : user.status === 'payment_pending' ? (
|
View registration
|
||||||
<>
|
</TooltipContent>
|
||||||
{hasPermission('subscriptions.activate') && (
|
</Tooltip>
|
||||||
<Button
|
|
||||||
onClick={() => handleActivatePayment(user)}
|
{/* reject */}
|
||||||
size="sm"
|
{hasPermission('users.approve') && (
|
||||||
className="btn-light-lavender"
|
<Tooltip>
|
||||||
>
|
<TooltipTrigger asChild>
|
||||||
<CheckCircle className="h-4 w-4 mr-1" />
|
<Button
|
||||||
Activate Payment
|
onClick={() => handleRejectUser(user)}
|
||||||
</Button>
|
disabled={actionLoading === user.id}
|
||||||
)}
|
size="sm"
|
||||||
{hasPermission('users.approve') && (
|
variant="outline"
|
||||||
<Button
|
className="border-2 mr-2 border-red-500 text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10"
|
||||||
onClick={() => handleRejectUser(user)}
|
>
|
||||||
disabled={actionLoading === user.id}
|
X
|
||||||
size="sm"
|
</Button>
|
||||||
variant="outline"
|
</TooltipTrigger>
|
||||||
className="border-2 border-red-500 text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10"
|
<TooltipContent>
|
||||||
>
|
Reject user
|
||||||
<X className="h-4 w-4 mr-1" />
|
</TooltipContent>
|
||||||
Reject
|
</Tooltip>
|
||||||
</Button>
|
)}
|
||||||
)}
|
</TooltipProvider>
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{hasPermission('users.approve') && (
|
|
||||||
<Button
|
|
||||||
onClick={() => handleValidateRequest(user)}
|
|
||||||
disabled={actionLoading === user.id}
|
|
||||||
size="sm"
|
|
||||||
className="bg-[var(--green-light)] text-white hover:bg-[var(--green-mint)]"
|
|
||||||
>
|
|
||||||
{actionLoading === user.id ? 'Validating...' : 'Validate'}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{hasPermission('users.approve') && (
|
|
||||||
<Button
|
|
||||||
onClick={() => handleRejectUser(user)}
|
|
||||||
disabled={actionLoading === user.id}
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
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" />
|
|
||||||
Reject
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -622,6 +704,13 @@ const AdminValidations = () => {
|
|||||||
user={userToReject}
|
user={userToReject}
|
||||||
loading={actionLoading !== null}
|
loading={actionLoading !== null}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* View Registration Dialog */}
|
||||||
|
<ViewRegistrationDialog
|
||||||
|
open={viewRegistrationDialogOpen}
|
||||||
|
onOpenChange={setViewRegistrationDialogOpen}
|
||||||
|
user={selectedUserForView}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useMemo, useCallback } from 'react';
|
|||||||
import api from '../../utils/api';
|
import api from '../../utils/api';
|
||||||
import Navbar from '../../components/Navbar';
|
import Navbar from '../../components/Navbar';
|
||||||
import MemberFooter from '../../components/MemberFooter';
|
import MemberFooter from '../../components/MemberFooter';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import { Card } from '../../components/ui/card';
|
import { Card } from '../../components/ui/card';
|
||||||
import { Input } from '../../components/ui/input';
|
import { Input } from '../../components/ui/input';
|
||||||
import { Badge } from '../../components/ui/badge';
|
import { Badge } from '../../components/ui/badge';
|
||||||
@@ -135,7 +136,7 @@ const MembersDirectory = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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-white to-muted">
|
||||||
<Navbar />
|
<Navbar />
|
||||||
|
|
||||||
<div className="max-w-7xl mx-auto py-12">
|
<div className="max-w-7xl mx-auto py-12">
|
||||||
@@ -154,7 +155,7 @@ const MembersDirectory = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Search Bar */}
|
{/* Search Bar */}
|
||||||
<div className="mb-24 mx-10">
|
<div className="mb-24 w-full">
|
||||||
<div className="relative w-full ">
|
<div className="relative w-full ">
|
||||||
<Search className="absolute left-4 top-1/2 transform -translate-y-1/2 h-5 w-5 text-brand-purple " />
|
<Search className="absolute left-4 top-1/2 transform -translate-y-1/2 h-5 w-5 text-brand-purple " />
|
||||||
<Input
|
<Input
|
||||||
@@ -221,9 +222,10 @@ const MembersDirectory = () => {
|
|||||||
</h3>
|
</h3>
|
||||||
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
<p className="text-brand-purple " style={{ fontFamily: "'Nunito Sans', sans-serif" }}>
|
||||||
Update your profile settings to show in the directory and add your photo, bio, and contact information.{' '}
|
Update your profile settings to show in the directory and add your photo, bio, and contact information.{' '}
|
||||||
<a href="/members/profile" className="text-[var(--orange-light)] hover:underline font-medium">
|
|
||||||
|
<Link to="/profile" className="text-[var(--orange-light)] hover:underline font-medium">
|
||||||
Edit your profile →
|
Edit your profile →
|
||||||
</a>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,32 +2,6 @@
|
|||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
--background: 0 0% 100%;
|
|
||||||
--foreground: 280 47% 27%;
|
|
||||||
--card: 0 0% 100%;
|
|
||||||
--card-foreground: 280 47% 27%;
|
|
||||||
--popover: 0 0% 100%;
|
|
||||||
--popover-foreground: 280 47% 27%;
|
|
||||||
--primary: 280 47% 27%;
|
|
||||||
--primary-foreground: 0 0% 100%;
|
|
||||||
--secondary: 268 33% 89%;
|
|
||||||
--secondary-foreground: 280 47% 27%;
|
|
||||||
--muted: 268 43% 95%;
|
|
||||||
--muted-foreground: 268 35% 47%;
|
|
||||||
--accent: var(--brand-orange);
|
|
||||||
--accent-foreground: 280 47% 27%;
|
|
||||||
--destructive: 0 84.2% 60.2%;
|
|
||||||
--destructive-foreground: 0 0% 98%;
|
|
||||||
--border: 268 33% 89%;
|
|
||||||
--input: 268 33% 89%;
|
|
||||||
--ring: 268 35% 47%;
|
|
||||||
--chart-1: 268 36% 46%;
|
|
||||||
--chart-2: 17 100% 73%;
|
|
||||||
--chart-3: 268 33% 89%;
|
|
||||||
--chart-4: 280 44% 29%;
|
|
||||||
--chart-5: 268 35% 47%;
|
|
||||||
--radius: 0.5rem;
|
|
||||||
|
|
||||||
/* =========================
|
/* =========================
|
||||||
Brand Colors
|
Brand Colors
|
||||||
========================= */
|
========================= */
|
||||||
@@ -47,7 +21,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
==========================
|
==========================
|
||||||
Color Patch
|
Social Media Colors
|
||||||
==========================
|
==========================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -55,6 +29,50 @@
|
|||||||
--blue-facebook: #1877f2;
|
--blue-facebook: #1877f2;
|
||||||
--blue-twitter: #1da1f2;
|
--blue-twitter: #1da1f2;
|
||||||
--red-instagram: #e4405f;
|
--red-instagram: #e4405f;
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Theme Colors
|
||||||
|
========================= */
|
||||||
|
--background: 0 0% 100%;
|
||||||
|
--foreground: 280 47% 27%;
|
||||||
|
|
||||||
|
--card: 0 0% 100%;
|
||||||
|
--card-foreground: 280 47% 27%;
|
||||||
|
|
||||||
|
--popover: 0 0% 100%;
|
||||||
|
--popover-foreground: 280 47% 27%;
|
||||||
|
|
||||||
|
--primary: 280 47% 27%;
|
||||||
|
--primary-foreground: 0 0% 100%;
|
||||||
|
|
||||||
|
--secondary: var(--brand-lavender);
|
||||||
|
--secondary-foreground: 280 47% 27%;
|
||||||
|
|
||||||
|
--muted: 268 43% 95%;
|
||||||
|
--muted-foreground: 268 35% 47%;
|
||||||
|
|
||||||
|
--accent: var(--brand-orange);
|
||||||
|
--accent-foreground: 280 47% 27%;
|
||||||
|
|
||||||
|
--destructive: 0 84.2% 60.2%;
|
||||||
|
--destructive-foreground: 0 0% 98%;
|
||||||
|
|
||||||
|
--success: 147 23% 46%;
|
||||||
|
--success-foreground: 0 0% 98%;
|
||||||
|
|
||||||
|
--warning: var(--brand-orange);
|
||||||
|
--warning-foreground: 0 0% 10%;
|
||||||
|
|
||||||
|
--border: 268 33% 89%;
|
||||||
|
--input: 268 33% 89%;
|
||||||
|
--ring: 268 35% 47%;
|
||||||
|
--chart-1: 268 36% 46%;
|
||||||
|
--chart-2: 17 100% 73%;
|
||||||
|
--chart-3: 268 33% 89%;
|
||||||
|
--chart-4: 280 44% 29%;
|
||||||
|
--chart-5: 268 35% 47%;
|
||||||
|
--radius: 0.5rem;
|
||||||
|
|
||||||
--purple-ink: #422268;
|
--purple-ink: #422268;
|
||||||
--purple-ink-2: #422268;
|
--purple-ink-2: #422268;
|
||||||
--purple-deep: #48286e;
|
--purple-deep: #48286e;
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ module.exports = {
|
|||||||
DEFAULT: 'hsl(var(--success))',
|
DEFAULT: 'hsl(var(--success))',
|
||||||
foreground: 'hsl(var(--success-foreground))'
|
foreground: 'hsl(var(--success-foreground))'
|
||||||
},
|
},
|
||||||
|
warning: {
|
||||||
|
DEFAULT: 'hsl(var(--warning))',
|
||||||
|
foreground: 'hsl(var(--warning-foreground))'
|
||||||
|
},
|
||||||
border: 'hsl(var(--border))',
|
border: 'hsl(var(--border))',
|
||||||
input: 'hsl(var(--input))',
|
input: 'hsl(var(--input))',
|
||||||
ring: 'hsl(var(--ring))',
|
ring: 'hsl(var(--ring))',
|
||||||
|
|||||||
Reference in New Issue
Block a user