import { useState, useEffect } from 'react'; import { useParams } from 'react-router-dom'; import apiClient from '../api/client'; export default function Providers() { const { businessId } = useParams(); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [form, setForm] = useState({ providerName: 'MSG91', senderId: '', dltEntityId: '', authKey: '', }); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); useEffect(() => { async function load() { try { const res = await apiClient.get(`/api/businesses/${businessId}/providers`); if (res.data && res.data.providerName) { setForm({ providerName: res.data.providerName || 'MSG91', senderId: res.data.senderId || '', dltEntityId: res.data.dltEntityId || '', authKey: res.data.authKey || '', }); } } catch { // no providers yet — keep defaults } finally { setLoading(false); } } load(); }, [businessId]); function handleChange(field, value) { setForm(prev => ({ ...prev, [field]: value })); } async function handleSave(e) { e.preventDefault(); setSaving(true); setError(''); setSuccess(''); if (form.senderId && !/^[A-Za-z]{6}$/.test(form.senderId)) { setError('DLT Sender ID must be exactly 6 alphabet characters'); setSaving(false); return; } try { await apiClient.post(`/api/businesses/${businessId}/providers`, form); setSuccess('Provider configuration saved successfully.'); } catch (err) { setError(err.response?.data?.error || 'Failed to save configuration'); } finally { setSaving(false); } } if (loading) { return (
); } return (

Provider Configuration

Save your DLT-approved sender details so the extension can dispatch SMS via your vendor.

{error && (
{error}
)} {success && (
{success}
)}
handleChange('providerName', e.target.value)} className={`w-full px-4 py-2.5 rounded-lg bg-surface-white border ${!form.providerName ? 'border-error-text focus:ring-error-text' : 'border-border-main focus:ring-primary-blue'} text-text-primary placeholder-placeholder-bg font-medium focus:outline-none focus:ring-2 focus:border-transparent transition text-sm shadow-sm`} placeholder="e.g. MSG91, Gupshup" />
handleChange('senderId', e.target.value.toUpperCase())} maxLength={6} className={`w-full px-4 py-2.5 rounded-lg bg-surface-white border ${!form.senderId ? 'border-error-text focus:ring-error-text' : 'border-border-main focus:ring-primary-blue'} text-text-primary font-mono tracking-widest placeholder-placeholder-bg focus:outline-none focus:ring-2 focus:border-transparent transition text-sm shadow-sm uppercase`} placeholder="6 CHARS" />

Exactly 6 alphabetic characters (e.g. MOKOBA).

handleChange('dltEntityId', e.target.value)} className={`w-full px-4 py-2.5 rounded-lg bg-surface-white border ${!form.dltEntityId ? 'border-error-text focus:ring-error-text' : 'border-border-main focus:ring-primary-blue'} text-text-primary font-mono placeholder-placeholder-bg focus:outline-none focus:ring-2 focus:border-transparent transition text-sm shadow-sm`} placeholder="19-digit DLT PE ID" />
handleChange('authKey', e.target.value)} className="w-full px-4 py-2.5 rounded-lg bg-surface-white border border-border-main text-text-primary font-mono placeholder-placeholder-bg focus:outline-none focus:ring-2 focus:ring-primary-blue focus:border-transparent transition text-sm shadow-sm" placeholder="Authorization key for your SMS provider" />

Used as the Authorization header in your SMS requests.

); }