import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import apiClient from '../api/client'; import { useBusiness } from '../context/BusinessContext'; import RegisterBusinessModal from '../components/RegisterBusinessModal'; function DeleteConfirmModal({ businessName, onCancel, onConfirm, deleting }) { return (
πŸ—‘

Delete Business?

This will permanently delete {businessName} and all its events, templates, and images. This cannot be undone.

); } export default function Businesses() { const navigate = useNavigate(); const { setActiveBusiness } = useBusiness(); const [businesses, setBusinesses] = useState([]); const [loading, setLoading] = useState(true); const [showModal, setShowModal] = useState(false); const [deleteTarget, setDeleteTarget] = useState(null); const [deleting, setDeleting] = useState(false); const [error, setError] = useState(''); async function load() { setLoading(true); try { const res = await apiClient.get('/api/businesses'); setBusinesses(res.data.businesses || []); } catch { setError('Failed to load businesses'); } finally { setLoading(false); } } useEffect(() => { load(); }, []); function handleSelect(biz) { setActiveBusiness(biz); navigate(`/${biz.businessId}/global-sms`); } async function handleDelete() { if (!deleteTarget) return; setDeleting(true); try { await apiClient.delete(`/api/businesses/${deleteTarget.businessId}`); setDeleteTarget(null); await load(); } catch (err) { setError(err.response?.data?.error || 'Failed to delete business'); setDeleting(false); } } if (loading) { return (
); } // ── NO BUSINESSES YET ────────────────────────────────────────────────────── if (businesses.length === 0 && !showModal) { return (
S

SMS Template Extension

Generate TRAI-compliant SMS templates for your Fynd store. Add your first business to get started.

{showModal && { setShowModal(false); load(); }} />}
); } // ── BUSINESS LIST ────────────────────────────────────────────────────────── return (
{/* Header */}

Your Businesses

Select a business to manage its SMS templates.

{error && (
{error}
)}
{businesses.map(biz => (
Click to manage β†’
))}
{showModal && { setShowModal(false); load(); }} />} {deleteTarget && ( setDeleteTarget(null)} onConfirm={handleDelete} deleting={deleting} /> )}
); }