import React, { useState, useEffect } from 'react'; import { SettingsLayout } from './components/SettingsLayout'; import { SettingsCard } from './components/SettingsCard'; import { SettingsSection } from './components/SettingsSection'; import { Input } from '@/components/ui/input'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { toast } from 'sonner'; interface StoreSettings { storeName: string; contactEmail: string; supportEmail: string; phone: string; country: string; address: string; city: string; state: string; postcode: string; currency: string; currencyPosition: 'left' | 'right' | 'left_space' | 'right_space'; thousandSep: string; decimalSep: string; decimals: number; timezone: string; weightUnit: string; dimensionUnit: string; } export default function StoreDetailsPage() { const [isLoading, setIsLoading] = useState(true); const [settings, setSettings] = useState({ storeName: '', contactEmail: '', supportEmail: '', phone: '', country: 'ID', address: '', city: '', state: '', postcode: '', currency: 'IDR', currencyPosition: 'left', thousandSep: ',', decimalSep: '.', decimals: 0, timezone: 'Asia/Jakarta', weightUnit: 'kg', dimensionUnit: 'cm', }); useEffect(() => { // TODO: Load settings from API setTimeout(() => { setSettings({ storeName: 'WooNooW Store', contactEmail: 'contact@example.com', supportEmail: 'support@example.com', phone: '+62 812 3456 7890', country: 'ID', address: 'Jl. Example No. 123', city: 'Jakarta', state: 'DKI Jakarta', postcode: '12345', currency: 'IDR', currencyPosition: 'left', thousandSep: '.', decimalSep: ',', decimals: 0, timezone: 'Asia/Jakarta', weightUnit: 'kg', dimensionUnit: 'cm', }); setIsLoading(false); }, 500); }, []); const handleSave = async () => { // TODO: Save to API await new Promise((resolve) => setTimeout(resolve, 1000)); toast.success('Your store details have been updated successfully.'); }; const updateSetting = ( key: K, value: StoreSettings[K] ) => { setSettings((prev) => ({ ...prev, [key]: value })); }; // Currency preview const formatCurrency = (amount: number) => { const formatted = amount.toFixed(settings.decimals) .replace('.', settings.decimalSep) .replace(/\B(?=(\d{3})+(?!\d))/g, settings.thousandSep); const symbol = settings.currency === 'IDR' ? 'Rp' : settings.currency === 'USD' ? '$' : '€'; switch (settings.currencyPosition) { case 'left': return `${symbol}${formatted}`; case 'right': return `${formatted}${symbol}`; case 'left_space': return `${symbol} ${formatted}`; case 'right_space': return `${formatted} ${symbol}`; default: return `${symbol}${formatted}`; } }; return ( {/* Store Identity */} updateSetting('storeName', e.target.value)} placeholder="My Awesome Store" /> updateSetting('contactEmail', e.target.value)} placeholder="contact@example.com" /> updateSetting('supportEmail', e.target.value)} placeholder="support@example.com" /> updateSetting('phone', e.target.value)} placeholder="+62 812 3456 7890" /> {/* Store Address */} updateSetting('address', e.target.value)} placeholder="Jl. Example No. 123" />
updateSetting('city', e.target.value)} placeholder="Jakarta" /> updateSetting('state', e.target.value)} placeholder="DKI Jakarta" /> updateSetting('postcode', e.target.value)} placeholder="12345" />
{/* Currency & Formatting */}
updateSetting('thousandSep', e.target.value)} maxLength={1} placeholder="," /> updateSetting('decimalSep', e.target.value)} maxLength={1} placeholder="." />
{/* Live Preview */}

Preview:

{formatCurrency(1234567.89)}

{/* Standards & Formats */}
{/* Summary Card */}

🇮🇩 Your store is located in {settings.country === 'ID' ? 'Indonesia' : settings.country}

Prices will be displayed in {settings.currency} • Timezone: {settings.timezone}

); }