diff --git a/src/app/admin/settings/page.tsx b/src/app/admin/settings/page.tsx index d044580..ec2b9fa 100644 --- a/src/app/admin/settings/page.tsx +++ b/src/app/admin/settings/page.tsx @@ -73,10 +73,14 @@ interface CompanySettings { parts: { id: string; name: string; price?: number; minPrice?: number; maxPrice?: number; inStock: number }[]; serviceCenters: { id: string; name: string; address: string; phone: string; rating: number }[]; companyPolicy: { - investor: { title: string; description: string; rules: { name: string; description: string }[] }; - merchant: { title: string; description: string; rules: { name: string; description: string }[] }; - swapStation: { title: string; description: string; rules: { name: string; description: string }[] }; - rentalTypes: { type: string; name: string; title: string; description: string; rules: { name: string; description: string }[]; enabled: boolean }[]; + investor: { title: string; description: string }[]; + merchant: { title: string; description: string }[]; + swapStation: { title: string; description: string }[]; + rentalTypes: { + single: { title: string; description: string }[]; + shared: { title: string; description: string }[]; + renttoown: { title: string; description: string }[]; + }; }; rentalPolicy: { minAge: number; @@ -645,7 +649,8 @@ const initialSettings: CompanySettings = { export default function CompanySettingsPage() { const [settings, setSettings] = useState(initialSettings); const [activeTab, setActiveTab] = useState<'general' | 'branding' | 'social' | 'integration' | 'landing' | 'kyc' | 'parts' | 'companyPolicy' | 'plans' | 'investment' | 'swapstation' | 'riderrequest'>('general'); - const [activeMasterTab, setActiveMasterTab] = useState<'investor' | 'merchant' | 'swapstation' | 'rental' | 'rentalType'>('investor'); + const [activeMasterTab, setActiveMasterTab] = useState<'investor' | 'merchant' | 'swapstation' | 'rentalType'>('investor'); + const [activeRentalTypeTab, setActiveRentalTypeTab] = useState<'single' | 'shared' | 'renttoown'>('single'); const [saved, setSaved] = useState(false); const [activePlanTab, setActivePlanTab] = useState<'singleRent' | 'rentToOwn' | 'shareEv'>('singleRent'); const [addDocType, setAddDocType] = useState<'investor' | 'merchant' | 'swapstation' | 'rental' | null>(null); @@ -784,13 +789,13 @@ export default function CompanySettingsPage() { const addPolicyRule = (tab: 'investor' | 'merchant' | 'swapstation') => { if (!newPolicyName.trim()) return; - const newRule = { name: newPolicyName, description: newPolicyDesc || '

' }; + const newRule = { title: newPolicyName, description: newPolicyDesc || '

' }; if (tab === 'investor') { - setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: { ...settings.companyPolicy.investor, rules: [...settings.companyPolicy.investor.rules, newRule] } } }); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: [...settings.companyPolicy.investor, newRule] } }); } else if (tab === 'merchant') { - setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: { ...settings.companyPolicy.merchant, rules: [...settings.companyPolicy.merchant.rules, newRule] } } }); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: [...settings.companyPolicy.merchant, newRule] } }); } else if (tab === 'swapstation') { - setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: { ...settings.companyPolicy.swapStation, rules: [...settings.companyPolicy.swapStation.rules, newRule] } } }); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: [...settings.companyPolicy.swapStation, newRule] } }); } setNewPolicyName(''); setNewPolicyDesc(''); @@ -799,31 +804,31 @@ export default function CompanySettingsPage() { 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 } } }); + const newRules = settings.companyPolicy.investor.filter((_, i) => i !== index); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: 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 } } }); + const newRules = settings.companyPolicy.merchant.filter((_, i) => i !== index); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: 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 newRules = settings.companyPolicy.swapStation.filter((_, i) => i !== index); + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: newRules } }); } }; const updatePolicyRule = (tab: 'investor' | 'merchant' | 'swapstation', index: number) => { const newDesc = editPolicyDescHtml || editPolicyDesc; if (tab === 'investor') { - const newRules = [...settings.companyPolicy.investor.rules]; - newRules[index] = { name: editPolicyName, description: newDesc }; - setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: { ...settings.companyPolicy.investor, rules: newRules } } }); + const newRules = [...settings.companyPolicy.investor]; + newRules[index] = { title: editPolicyName, description: newDesc }; + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, investor: newRules } }); } else if (tab === 'merchant') { - const newRules = [...settings.companyPolicy.merchant.rules]; - newRules[index] = { name: editPolicyName, description: newDesc }; - setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: { ...settings.companyPolicy.merchant, rules: newRules } } }); + const newRules = [...settings.companyPolicy.merchant]; + newRules[index] = { title: editPolicyName, description: newDesc }; + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, merchant: newRules } }); } else if (tab === 'swapstation') { - const newRules = [...settings.companyPolicy.swapStation.rules]; - newRules[index] = { name: editPolicyName, description: newDesc }; - setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: { ...settings.companyPolicy.swapStation, rules: newRules } } }); + const newRules = [...settings.companyPolicy.swapStation]; + newRules[index] = { title: editPolicyName, description: newDesc }; + setSettings({ ...settings, companyPolicy: { ...settings.companyPolicy, swapStation: newRules } }); } setEditingPolicy(null); }; @@ -1699,7 +1704,7 @@ export default function CompanySettingsPage() { )} - {activeMasterTab === 'rental' && ( + {activeMasterTab === 'rentalType' && (
{settings.masterData.rentalDocuments.map((rental, ri) => (
@@ -1854,7 +1859,6 @@ export default function CompanySettingsPage() { {activeMasterTab === 'investor' && (
-
- {(settings.companyPolicy?.investor?.rules || []).map((policy, i) => ( + {(settings.companyPolicy?.investor || []).map((policy, i) => (
{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" /> + setEditPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm" placeholder="Policy Title" /> setEditPolicyDescHtml(val)} placeholder="Policy Description..." minHeight={100} />
- +
@@ -1877,15 +1887,18 @@ export default function CompanySettingsPage() {
- {policy.name} + {policy.title}
-

{policy.description}

+
- -
@@ -1896,21 +1909,25 @@ export default function CompanySettingsPage() {
{showAddPolicy && (
- setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Name" /> + setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Title" /> setNewPolicyDesc(val)} placeholder="Policy Description..." minHeight={100} />
- +
)} -
)} {activeMasterTab === 'merchant' && (
-
- {(settings.companyPolicy?.merchant?.rules || []).map((policy, i) => ( + {(settings.companyPolicy?.merchant || []).map((policy, i) => (
{editingPolicy?.tab === 'merchant' && 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" /> + setEditPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm" placeholder="Policy Title" /> setEditPolicyDescHtml(val)} placeholder="Policy Description..." minHeight={100} />
- +
@@ -1933,15 +1956,18 @@ export default function CompanySettingsPage() {
- {policy.name} + {policy.title}
-

{policy.description}

+
- -
@@ -1952,21 +1978,25 @@ export default function CompanySettingsPage() {
{showAddPolicy && (
- setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Name" /> + setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Title" /> setNewPolicyDesc(val)} placeholder="Policy Description..." minHeight={100} />
- +
)}
- )} {activeMasterTab === 'swapstation' && (
-
- {(settings.companyPolicy?.swapStation?.rules || []).map((policy, i) => ( + {(settings.companyPolicy?.swapStation || []).map((policy, i) => (
{editingPolicy?.tab === 'swapstation' && 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" /> + setEditPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm" placeholder="Policy Title" /> setEditPolicyDescHtml(val)} placeholder="Policy Description..." minHeight={100} />
- +
@@ -1989,15 +2025,18 @@ export default function CompanySettingsPage() {
- {policy.name} + {policy.title}
-

{policy.description}

+
- -
@@ -2008,336 +2047,331 @@ export default function CompanySettingsPage() {
{showAddPolicy && (
- setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Name" /> + setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Title" /> setNewPolicyDesc(val)} placeholder="Policy Description..." minHeight={100} />
- +
)}
- )} {activeMasterTab === 'rentalType' && ( -
- {(settings.companyPolicy?.rentalTypes || []).map((rtype, idx) => ( -
-
-

{rtype.name}

-
-
+
+
+ + + +
-
- -
-
- {(rtype.rules || []).map((policy, policyIdx) => ( -
- {editingPolicy?.tab === 'rentalType' && editingPolicy?.index === policyIdx ? ( -
- setEditPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm" placeholder="Policy Name" /> - setEditPolicyDescHtml(val)} placeholder="Policy Description..." minHeight={100} /> -
- - -
-
- ) : ( -
-
-
- {policy.name} -
-

{policy.description}

-
-
- - -
-
- )} -
- ))} -
- - {editingPolicy?.tab === 'rentalTypeAdd' && editingPolicy?.index === idx && ( -
- setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Name" /> - setNewPolicyDesc(val)} placeholder="Policy Description..." minHeight={100} /> +
+ + +
+
+ {(settings.companyPolicy?.rentalTypes[activeRentalTypeTab] || []).map((policy, i) => ( +
+ {editingPolicy?.tab === 'rentalType' && editingPolicy?.index === i ? ( +
+ setEditPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm" placeholder="Policy Title" /> + setEditPolicyDescHtml(val)} placeholder="Policy Description..." minHeight={100} />
- + setEditPolicyDescHtml(''); + }} className="px-2 py-1 bg-blue-600 text-white rounded text-xs">Save + +
+
+ ) : ( +
+
+
+ {policy.title} +
+
+
+
+ +
)}
-
- - ))} -
- + ))}
+ {showAddPolicy && ( +
+ setNewPolicyName(e.target.value)} className="w-full px-2 py-1.5 border border-slate-200 rounded text-sm mb-2" placeholder="Policy Title" /> + setNewPolicyDesc(val)} placeholder="Policy Description..." minHeight={100} /> +
+ + +
+
+ )} +
+ )} +
+ )} + + {activeTab === 'plans' && ( +
+
+

Plan Selection

+
+ +
+ + + +
+ + {activePlanTab === 'singleRent' && ( +
+ {settings.plans.singleRent.map((plan, idx) => ( +
+
+
+ {/* {plan.tier === 'Premium' ? '👑' : plan.tier === 'Standard' ? '⚖️' : '💰'} */} +
+

SINGLE RENT - {plan.tier} - ৳{plan.dailyRent}/day

+

{plan.description}

+
+
+ +
+
+
+
+ + { const updated = [...settings.plans.singleRent]; updated[idx].dailyRent = parseInt(e.target.value); setSettings({ ...settings, plans: { ...settings.plans, singleRent: updated } }); }} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm mt-1" /> +
+
+ + { const updated = [...settings.plans.singleRent]; updated[idx].weeklySubscription = parseInt(e.target.value); setSettings({ ...settings, plans: { ...settings.plans, singleRent: updated } }); }} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm mt-1" /> +
+
+ + { const updated = [...settings.plans.singleRent]; updated[idx].monthlySubscription = parseInt(e.target.value); setSettings({ ...settings, plans: { ...settings.plans, singleRent: updated } }); }} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm mt-1" /> +
+
+ + { const updated = [...settings.plans.singleRent]; updated[idx].deposit = parseInt(e.target.value); setSettings({ ...settings, plans: { ...settings.plans, singleRent: updated } }); }} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm mt-1" /> +
+
+ + { const updated = [...settings.plans.singleRent]; updated[idx].ficoSharePercent = parseInt(e.target.value); setSettings({ ...settings, plans: { ...settings.plans, singleRent: updated } }); }} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm mt-1" /> +
+
+ + +
+
+
+
+ FICO + JAIBEN = + {plan.ficoSharePercent + (100 - plan.ficoSharePercent)}% (FICO: {plan.ficoSharePercent}% + JAIBEN: {100 - plan.ficoSharePercent}%) +
+
+
+ +