'use client'; import { useState, useEffect } from 'react'; import { Save } from 'lucide-react'; import { systemConfigApi } from '@/lib/api'; type Tab = 'general' | 'payment' | 'integrations' | 'configurations'; export default function SettingsPage() { const [activeTab, setActiveTab] = useState('general'); const [seatHoldMinutes, setSeatHoldMinutes] = useState('5'); const [holdCutoffHours, setHoldCutoffHours] = useState('2'); const [throttleAuthLimit, setThrottleAuthLimit] = useState('5'); const [throttleStrictLimit, setThrottleStrictLimit] = useState('20'); const [throttleDefaultLimit, setThrottleDefaultLimit] = useState('100'); const [configLoading, setConfigLoading] = useState(false); const [configSaving, setConfigSaving] = useState(false); const [configMessage, setConfigMessage] = useState(''); useEffect(() => { if (activeTab !== 'configurations') return; setConfigLoading(true); systemConfigApi.getAll() .then((data) => { if (data?.seat_hold_duration_minutes) setSeatHoldMinutes(data.seat_hold_duration_minutes); if (data?.hold_cutoff_hours_before_departure) setHoldCutoffHours(data.hold_cutoff_hours_before_departure); if (data?.throttle_auth_limit) setThrottleAuthLimit(data.throttle_auth_limit); if (data?.throttle_strict_limit) setThrottleStrictLimit(data.throttle_strict_limit); if (data?.throttle_default_limit) setThrottleDefaultLimit(data.throttle_default_limit); }) .catch(() => {}) .finally(() => setConfigLoading(false)); }, [activeTab]); const saveConfigurations = async () => { setConfigSaving(true); setConfigMessage(''); try { await systemConfigApi.update({ seat_hold_duration_minutes: seatHoldMinutes, hold_cutoff_hours_before_departure: holdCutoffHours, throttle_auth_limit: throttleAuthLimit, throttle_strict_limit: throttleStrictLimit, throttle_default_limit: throttleDefaultLimit, }); setConfigMessage('Saved successfully.'); } catch { setConfigMessage('Failed to save.'); } finally { setConfigSaving(false); } }; const tabs: { id: Tab; label: string }[] = [ { id: 'general', label: 'General' }, { id: 'payment', label: 'Payment' }, { id: 'integrations', label: 'Integrations' }, { id: 'configurations', label: 'Configurations' }, ]; return (

Settings

Manage system settings and configurations

{activeTab !== 'configurations' && ( )}
{tabs.map((tab) => ( ))}
{activeTab === 'general' && (
)} {activeTab === 'payment' && (

Payment Providers

Telebirr

Mobile payment provider

CBE Birr

Bank payment provider

)} {activeTab === 'integrations' && (

Verifayda 2.0 Integration

Corporate IAM Integration

)} {activeTab === 'configurations' && (

Rate Limiting (requests / minute / IP)

{!configLoading && (
setThrottleAuthLimit(e.target.value)} />

Login, register, OTP. Default: 5.

setThrottleStrictLimit(e.target.value)} />

Sensitive operations. Default: 20.

setThrottleDefaultLimit(e.target.value)} />

All other endpoints including search. Default: 100.

)}

Seat Booking

{configLoading ? (

Loading...

) : ( <>
setSeatHoldMinutes(e.target.value)} />

How long a seat hold remains active before it expires automatically. Default: 5 minutes.

setHoldCutoffHours(e.target.value)} />

Seat holds are rejected when this many hours or fewer remain before departure. Default: 2 hours.

)}
{configMessage && ( {configMessage} )}
)}
); }