diff --git a/src/app/admin/settings/page.tsx b/src/app/admin/settings/page.tsx index 39b73db..942f587 100644 --- a/src/app/admin/settings/page.tsx +++ b/src/app/admin/settings/page.tsx @@ -1,7 +1,7 @@ 'use client'; import { useState } from 'react'; -import { Settings, Upload, Image, Globe, Mail, MessageSquare, Phone, MapPin, Link2, Clock, Save, FileText, Camera, Palette, Ruler, Sun, Moon, Monitor, Smartphone, Tablet, Package, Wrench, FileCheck, BadgeDollarSign, CreditCard, Plus, X, DollarSign, Zap, Users, Check, Pencil } from 'lucide-react'; +import { Settings, Upload, Image, Globe, Mail, MessageSquare, Phone, MapPin, Link2, Clock, Save, FileText, Camera, Palette, Ruler, Sun, Moon, Monitor, Smartphone, Tablet, Package, Wrench, FileCheck, BadgeDollarSign, CreditCard, Plus, X, DollarSign, Zap, Users, Check, Pencil, Trash2 } from 'lucide-react'; import RichTextEditor from '@/components/RichTextEditor'; interface CompanySettings { @@ -679,6 +679,10 @@ export default function CompanySettingsPage() { const [editingPolicy, setEditingPolicy] = useState<{tab: string; index: number} | null>(null); const [editPolicyName, setEditPolicyName] = useState(''); const [editPolicyDesc, setEditPolicyDesc] = useState(''); + const [editPolicyDescHtml, setEditPolicyDescHtml] = useState(''); + const [showAddPolicy, setShowAddPolicy] = useState(false); + const [newPolicyName, setNewPolicyName] = useState(''); + const [newPolicyDesc, setNewPolicyDesc] = useState(''); const [addInvestPlan, setAddInvestPlan] = useState(false); const [newInvestName, setNewInvestName] = useState(''); const [newInvestTier, setNewInvestTier] = useState('Standard'); @@ -802,6 +806,51 @@ setNewSwapName(''); setTimeout(() => setSaved(false), 2000); }; + const addPolicyRule = (tab: 'investor' | 'merchant' | 'swapstation') => { + if (!newPolicyName.trim()) return; + const newRule = { name: newPolicyName, description: newPolicyDesc }; + if (tab === 'investor') { + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: { ...settings.companyPolicy.investor, rules: [...settings.companyPolicy.investor.rules, newRule] } } }); + } else if (tab === 'merchant') { + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: { ...settings.companyPolicy.merchant, rules: [...settings.companyPolicy.merchant.rules, newRule] } } }); + } else if (tab === 'swapstation') { + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: { ...settings.companyPolicy.swapStation, rules: [...settings.companyPolicy.swapStation.rules, newRule] } } }); + } + setNewPolicyName(''); + setNewPolicyDesc(''); + setShowAddPolicy(false); + }; + + const deletePolicyRule = (tab: 'investor' | 'merchant' | 'swapstation', index: number) => { + if (tab === 'investor') { + const newRules = settings.companyPolicy.investor.rules.filter((_, i) => i !== index); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: { ...settings.companyPolicy.investor, rules: newRules } } }); + } else if (tab === 'merchant') { + const newRules = settings.companyPolicy.merchant.rules.filter((_, i) => i !== index); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: { ...settings.companyPolicy.merchant, rules: newRules } } }); + } else if (tab === 'swapstation') { + const newRules = settings.companyPolicy.swapStation.rules.filter((_, i) => i !== index); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: { ...settings.companyPolicy.swapStation, rules: newRules } } }); + } + }; + + const updatePolicyRule = (tab: 'investor' | 'merchant' | 'swapstation', index: number) => { + if (tab === 'investor') { + const newRules = [...settings.companyPolicy.investor.rules]; + newRules[index] = { name: editPolicyName, description: editPolicyDesc }; + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: { ...settings.companyPolicy.investor, rules: newRules } } }); + } else if (tab === 'merchant') { + const newRules = [...settings.companyPolicy.merchant.rules]; + newRules[index] = { name: editPolicyName, description: editPolicyDesc }; + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: { ...settings.companyPolicy.merchant, rules: newRules } } }); + } else if (tab === 'swapstation') { + const newRules = [...settings.companyPolicy.swapStation.rules]; + newRules[index] = { name: editPolicyName, description: editPolicyDesc }; + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: { ...settings.companyPolicy.swapStation, rules: newRules } } }); + } + setEditingPolicy(null); + }; + const tabs = [ { id: 'general', label: 'General', icon: Settings }, { id: 'branding', label: 'Branding', icon: Palette }, @@ -1842,21 +1891,53 @@ setNewSwapName('');
+
{(settings.companyPolicy?.investor?.rules || []).map((policy, i) => (
-
-
-
- {policy.name} + {editingPolicy?.tab === 'investor' && editingPolicy?.index === i ? ( +
+ setEditPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm" placeholder="Policy Name" /> +