Final fixes before migrating to openrouter key instead of workflows

This commit is contained in:
Ritul Jadhav 2026-04-03 15:54:45 +05:30
parent 93e0b32454
commit c03fef4d95
3 changed files with 593 additions and 127 deletions

View File

@ -59,6 +59,26 @@ function StageMarker({ done, active, enabled }) {
return <span className="inline-block h-3 w-3 rounded-full bg-refresh-active" />; return <span className="inline-block h-3 w-3 rounded-full bg-refresh-active" />;
} }
function normalizeText(value) {
return typeof value === 'string' ? value.trim() : '';
}
function getSidebarBusinessImage(business) {
const brandingLogos = business?.scrapeArtifacts?.json?.branding?.logos;
const primaryLogo = Array.isArray(brandingLogos)
? brandingLogos.find((entry) => normalizeText(entry))
: '';
if (primaryLogo) return primaryLogo;
return (
normalizeText(business?.logoUrl)
|| normalizeText(business?.imageUrl)
|| (Array.isArray(business?.relevantImagePaths)
? business.relevantImagePaths.find((entry) => normalizeText(entry)) || ''
: '')
);
}
export default function Sidebar({ onOpenReview, reviewLoading = false, reviewError = '' }) { export default function Sidebar({ onOpenReview, reviewLoading = false, reviewError = '' }) {
const { const {
activeBusiness, activeBusiness,
@ -70,6 +90,7 @@ export default function Sidebar({ onOpenReview, reviewLoading = false, reviewErr
} = useBusiness(); } = useBusiness();
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const businessImage = getSidebarBusinessImage(activeBusiness);
const globalSmsPath = `/${activeBusinessId}/global-sms`; const globalSmsPath = `/${activeBusinessId}/global-sms`;
const eventsPath = `/${activeBusinessId}/events`; const eventsPath = `/${activeBusinessId}/events`;
@ -132,21 +153,30 @@ export default function Sidebar({ onOpenReview, reviewLoading = false, reviewErr
<span>Switch Business</span> <span>Switch Business</span>
</button> </button>
{activeBusiness && ( {activeBusiness && (
<div className="mt-4"> <div className="mt-5 flex flex-col items-center text-center">
<div className="flex items-center gap-3"> <div className="flex h-16 w-16 rounded-2xl border border-gray-200 bg-white items-center justify-center text-lg font-bold text-white shrink-0 overflow-hidden shadow-sm">
<div className="w-8 h-8 rounded-md bg-primary-blue flex items-center justify-center text-sm font-bold text-white shrink-0 "> {businessImage ? (
<img
src={businessImage}
alt={activeBusiness.brandName || 'Business'}
className="h-full w-full object-contain p-1.5"
/>
) : (
<span className="flex h-full w-full items-center justify-center rounded-2xl bg-primary-blue text-lg">
{activeBusiness.brandName?.[0]?.toUpperCase() || 'B'} {activeBusiness.brandName?.[0]?.toUpperCase() || 'B'}
</span>
)}
</div> </div>
<div className="min-w-0"> <div className="mt-3 min-w-0 w-full">
<p className="text-sm font-semibold text-gray-800 truncate">{activeBusiness.brandName}</p> <p className="text-[15px] font-semibold leading-tight text-gray-800 truncate">{activeBusiness.brandName}</p>
<p className="text-xs text-gray-400 truncate font-medium">{activeBusiness.domain}</p>
{activeBusinessId && ( {activeBusinessId && (
<> <>
<div className="relative mt-2 inline-flex items-center"> <div className="mt-3 flex justify-center">
<div className="relative inline-flex items-center">
<button <button
onClick={onOpenReview} onClick={onOpenReview}
disabled={reviewLoading} disabled={reviewLoading}
className="group inline-flex h-8 w-8 items-center justify-center rounded-md border border-gray-200 bg-white text-gray-500 transition hover:border-gray-300 hover:bg-gray-50 hover:text-primary-blue disabled:cursor-wait disabled:opacity-60" className="group inline-flex h-9 w-9 items-center justify-center rounded-full border border-gray-200 bg-white text-gray-500 shadow-sm transition hover:border-gray-300 hover:bg-gray-50 hover:text-primary-blue disabled:cursor-wait disabled:opacity-60"
title="View brand details" title="View brand details"
aria-label="View brand details" aria-label="View brand details"
> >
@ -158,11 +188,12 @@ export default function Sidebar({ onOpenReview, reviewLoading = false, reviewErr
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 15a3 3 0 100-6 3 3 0 000 6z" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 15a3 3 0 100-6 3 3 0 000 6z" />
</svg> </svg>
)} )}
<span className="pointer-events-none absolute left-full top-1/2 ml-2 hidden -translate-y-1/2 whitespace-nowrap rounded-md border border-gray-200 bg-white px-2.5 py-1 text-xs font-medium text-gray-600 shadow-sm group-hover:block"> <span className="pointer-events-none absolute left-1/2 top-full mt-2 hidden -translate-x-1/2 whitespace-nowrap rounded-md border border-gray-200 bg-white px-2.5 py-1 text-xs font-medium text-gray-600 shadow-sm group-hover:block">
View brand details View brand details
</span> </span>
</button> </button>
</div> </div>
</div>
{reviewError && ( {reviewError && (
<p className="mt-2 text-xs text-red-600">{reviewError}</p> <p className="mt-2 text-xs text-red-600">{reviewError}</p>
)} )}
@ -170,7 +201,6 @@ export default function Sidebar({ onOpenReview, reviewLoading = false, reviewErr
)} )}
</div> </div>
</div> </div>
</div>
)} )}
</div> </div>

View File

@ -1,11 +1,12 @@
import { useState, useEffect, useCallback } from 'react'; import { useState, useEffect, useCallback } from 'react';
import { useParams, useNavigate } from 'react-router-dom'; import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
import apiClient from '../api/client'; import apiClient from '../api/client';
import { useBusiness } from '../context/BusinessContext'; import { useBusiness } from '../context/BusinessContext';
export default function GlobalSms() { export default function GlobalSms() {
const { businessId } = useParams(); const { businessId } = useParams();
const navigate = useNavigate(); const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const { isSetupComplete, setHasGlobalSms, setIsSetupComplete } = useBusiness(); const { isSetupComplete, setHasGlobalSms, setIsSetupComplete } = useBusiness();
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [profiles, setProfiles] = useState([]); const [profiles, setProfiles] = useState([]);
@ -64,6 +65,28 @@ export default function GlobalSms() {
loadProfiles(); loadProfiles();
}, [loadProfiles]); }, [loadProfiles]);
useEffect(() => {
const editProfileId = searchParams.get('editProfile');
if (!editProfileId || profiles.length === 0) return;
const nextParams = new URLSearchParams(searchParams);
nextParams.delete('editProfile');
const matchingProfile = profiles.find((profile) => profile.id === editProfileId);
if (matchingProfile) {
setEditingId(matchingProfile.id);
setFormName(matchingProfile.name);
setFormCurl(matchingProfile.rawCurl);
setFormSetActive(false);
setError('');
setSuccess('');
} else {
setError('The requested profile could not be found.');
}
setSearchParams(nextParams, { replace: true });
}, [profiles, searchParams, setSearchParams]);
const activeProfile = profiles.find(p => p.id === activeProfileId) || null; const activeProfile = profiles.find(p => p.id === activeProfileId) || null;
const hasProfiles = profiles.length > 0; const hasProfiles = profiles.length > 0;
const isCreatingFirstProfile = !hasProfiles && !editingId; const isCreatingFirstProfile = !hasProfiles && !editingId;

View File

@ -1,12 +1,76 @@
import { useState, useEffect } from 'react'; import { useState, useEffect, useCallback, useRef } from 'react';
import { useParams } from 'react-router-dom'; import { useNavigate, useParams } from 'react-router-dom';
import apiClient from '../api/client'; import apiClient from '../api/client';
import { useBusiness } from '../context/BusinessContext';
const DESKTOP_SPLIT_QUERY = '(min-width: 1100px)';
const DEFAULT_LIST_PANE_WIDTH = 340;
const MIN_LIST_PANE_WIDTH = 280;
const MAX_LIST_PANE_WIDTH = 420;
const MIN_DETAIL_PANE_WIDTH = 440;
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
function getMissingProviderFields(profile) {
const provider = profile?.provider || {};
const missing = [];
if (!provider.providerName) missing.push('Provider Name');
if (!provider.senderId) missing.push('Sender ID');
if (!provider.dltEntityId) missing.push('DLT Entity ID');
return missing;
}
function isProviderSetupComplete(profile) {
return getMissingProviderFields(profile).length === 0;
}
function formatUpdatedAt(value) {
if (!value) return 'Not updated yet';
try {
return new Date(value).toLocaleString();
} catch {
return 'Not updated yet';
}
}
function buildProviderSummary(profile) {
const provider = profile?.provider || {};
const parts = [];
if (provider.providerName) parts.push(provider.providerName);
if (provider.senderId) parts.push(`Sender ${provider.senderId}`);
if (provider.dltEntityId) parts.push('DLT added');
return parts.length > 0 ? parts.join(' • ') : 'Provider details not completed yet';
}
function ProfileStatusPill({ complete }) {
return (
<span
className={`rounded-full border px-2.5 py-1 text-[11px] font-semibold uppercase tracking-[0.14em] ${complete
? 'border-emerald-200 bg-emerald-50 text-emerald-700'
: 'border-amber-200 bg-amber-50 text-amber-700'
}`}
>
{complete ? 'Complete' : 'Missing Fields'}
</span>
);
}
export default function Providers() { export default function Providers() {
const { businessId } = useParams(); const { businessId } = useParams();
const navigate = useNavigate();
const { refreshOnboardingState } = useBusiness();
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const [activeProfile, setActiveProfile] = useState(null); const [profiles, setProfiles] = useState([]);
const [activeProfileId, setActiveProfileId] = useState('');
const [selectedProfileId, setSelectedProfileId] = useState('');
const [form, setForm] = useState({ const [form, setForm] = useState({
providerName: '', providerName: '',
senderId: '', senderId: '',
@ -15,54 +79,192 @@ export default function Providers() {
}); });
const [error, setError] = useState(''); const [error, setError] = useState('');
const [success, setSuccess] = useState(''); const [success, setSuccess] = useState('');
const [copiedProfileId, setCopiedProfileId] = useState('');
const [isDesktopSplit, setIsDesktopSplit] = useState(false);
const [listPaneWidth, setListPaneWidth] = useState(DEFAULT_LIST_PANE_WIDTH);
const layoutRef = useRef(null);
const copyTimeoutRef = useRef(null);
useEffect(() => { const globalSmsPath = `/${businessId}/global-sms`;
async function load() {
const loadProfiles = useCallback(async () => {
try { try {
const [activeRes, providerRes] = await Promise.all([ setLoading(true);
apiClient.get(`/api/businesses/${businessId}/global-sms/active`), const res = await apiClient.get(`/api/businesses/${businessId}/global-sms/profiles`);
apiClient.get(`/api/businesses/${businessId}/providers`), const fetchedProfiles = res.data?.profiles || [];
]); const nextActiveProfileId = String(res.data?.activeProfileId || '');
setActiveProfile(activeRes.data?.activeProfile || null); setProfiles(fetchedProfiles);
setForm({ setActiveProfileId(nextActiveProfileId);
providerName: providerRes.data?.providerName || '', setSelectedProfileId((currentSelectedProfileId) => (
senderId: providerRes.data?.senderId || '', fetchedProfiles.some((profile) => profile.id === currentSelectedProfileId)
dltEntityId: providerRes.data?.dltEntityId || '', ? currentSelectedProfileId
authKey: providerRes.data?.authKey || '', : ''
}); ));
} catch (err) { } catch (err) {
setError(err.response?.data?.error || 'Failed to load provider configuration'); setError(err.response?.data?.error || 'Failed to load provider profiles');
} finally { } finally {
setLoading(false); setLoading(false);
} }
}
load();
}, [businessId]); }, [businessId]);
function handleChange(field, value) { useEffect(() => {
setForm(prev => ({ ...prev, [field]: value })); loadProfiles();
}, [loadProfiles]);
useEffect(() => {
const mediaQuery = window.matchMedia(DESKTOP_SPLIT_QUERY);
const syncLayoutMode = (event) => setIsDesktopSplit(event.matches);
setIsDesktopSplit(mediaQuery.matches);
if (typeof mediaQuery.addEventListener === 'function') {
mediaQuery.addEventListener('change', syncLayoutMode);
return () => mediaQuery.removeEventListener('change', syncLayoutMode);
} }
async function handleSave(e) { mediaQuery.addListener(syncLayoutMode);
e.preventDefault(); return () => mediaQuery.removeListener(syncLayoutMode);
}, []);
useEffect(() => () => {
if (copyTimeoutRef.current) {
clearTimeout(copyTimeoutRef.current);
}
}, []);
const selectedProfile = profiles.find((profile) => profile.id === selectedProfileId) || null;
useEffect(() => {
if (!selectedProfile) {
setForm({
providerName: '',
senderId: '',
dltEntityId: '',
authKey: '',
});
return;
}
const provider = selectedProfile.provider || {};
setForm({
providerName: provider.providerName || '',
senderId: provider.senderId || '',
dltEntityId: provider.dltEntityId || '',
authKey: provider.authKey || '',
});
}, [selectedProfile]);
function handleChange(field, value) {
setForm((prev) => ({ ...prev, [field]: value }));
}
function handleSelectProfile(profileId) {
setSelectedProfileId(profileId);
setError('');
setSuccess('');
}
function handleResizeStart(event) {
if (!isDesktopSplit) return;
event.preventDefault();
const containerBounds = layoutRef.current?.getBoundingClientRect();
if (!containerBounds) return;
const maxAllowedWidth = clamp(
containerBounds.width - MIN_DETAIL_PANE_WIDTH,
MIN_LIST_PANE_WIDTH,
MAX_LIST_PANE_WIDTH,
);
function handlePointerMove(moveEvent) {
const nextWidth = clamp(
moveEvent.clientX - containerBounds.left,
MIN_LIST_PANE_WIDTH,
maxAllowedWidth,
);
setListPaneWidth(nextWidth);
}
function handlePointerUp() {
document.body.style.userSelect = '';
window.removeEventListener('mousemove', handlePointerMove);
window.removeEventListener('mouseup', handlePointerUp);
}
document.body.style.userSelect = 'none';
window.addEventListener('mousemove', handlePointerMove);
window.addEventListener('mouseup', handlePointerUp);
}
async function handleActivate(profile) {
if (!profile?.id) return;
try {
setError('');
setSuccess('');
await apiClient.post(`/api/businesses/${businessId}/global-sms/profiles/${profile.id}/activate`);
setSelectedProfileId(profile.id);
await loadProfiles();
await refreshOnboardingState(businessId).catch(() => null);
setSuccess(`${profile.name} is now the active profile.`);
} catch (err) {
setError(err.response?.data?.error || 'Failed to activate profile');
}
}
async function handleCopyCurl(profile) {
if (!profile?.rawCurl) return;
try {
if (!navigator?.clipboard?.writeText) {
throw new Error('Clipboard API unavailable');
}
await navigator.clipboard.writeText(profile.rawCurl);
setCopiedProfileId(profile.id);
if (copyTimeoutRef.current) {
clearTimeout(copyTimeoutRef.current);
}
copyTimeoutRef.current = window.setTimeout(() => {
setCopiedProfileId('');
}, 1800);
} catch {
setError('Failed to copy the cURL command.');
}
}
async function handleSave(event) {
event.preventDefault();
if (!selectedProfile?.id) return;
setSaving(true); setSaving(true);
setError(''); setError('');
setSuccess(''); setSuccess('');
if (form.senderId && !/^[A-Za-z]{6}$/.test(form.senderId)) { if (form.senderId && !/^[A-Za-z]{6}$/.test(form.senderId)) {
setError('DLT Sender ID must be exactly 6 alphabet characters'); setError('DLT Sender ID must be exactly 6 alphabet characters');
setSaving(false); setSaving(false);
return; return;
} }
try { try {
const res = await apiClient.post(`/api/businesses/${businessId}/providers`, form); await apiClient.patch(`/api/businesses/${businessId}/global-sms/profiles/${selectedProfile.id}`, {
setForm({ provider: {
providerName: res.data?.providerName || '', providerName: form.providerName,
senderId: res.data?.senderId || '', senderId: form.senderId.toUpperCase(),
dltEntityId: res.data?.dltEntityId || '', dltEntityId: form.dltEntityId,
authKey: res.data?.authKey || '', authKey: form.authKey,
},
}); });
setSuccess('Provider configuration saved successfully.');
await loadProfiles();
await refreshOnboardingState(businessId).catch(() => null);
setSuccess(`Provider configuration saved for ${selectedProfile.name}.`);
} catch (err) { } catch (err) {
setError(err.response?.data?.error || 'Failed to save configuration'); setError(err.response?.data?.error || 'Failed to save configuration');
} finally { } finally {
@ -79,89 +281,268 @@ export default function Providers() {
} }
return ( return (
<div className="max-w-2xl mx-auto"> <div className="mx-auto max-w-7xl space-y-6 pb-12">
<div className="pb-5 mb-6 border-b border-gray-200"> <div className="flex flex-col gap-4 border-b border-gray-200 pb-5 lg:flex-row lg:items-end lg:justify-between">
<h1 className="text-2xl font-bold text-gray-800 tracking-tight">Provider Configuration</h1> <div>
<p className="text-sm text-gray-500 mt-1 font-medium">Edit the provider details stored on the active cURL profile.</p> <h1 className="text-2xl font-bold tracking-tight text-gray-800">Provider Configuration</h1>
{activeProfile && ( <p className="mt-1 text-sm font-medium text-gray-500">
<p className="text-xs text-gray-500 mt-2 font-semibold uppercase tracking-wide"> Pick a saved profile to review its complete request and manage the provider details stored against it.
Active Profile: {activeProfile.name}
</p> </p>
)} </div>
<button
type="button"
onClick={() => navigate(globalSmsPath)}
className="inline-flex items-center justify-center rounded-lg border border-gray-200 px-4 py-2 text-sm font-semibold text-gray-700 transition hover:border-primary-blue hover:bg-white hover:text-primary-blue"
>
Manage cURLs
</button>
</div> </div>
{error && ( {error && (
<div className="mb-6 px-4 py-2 rounded-md bg-white border border-gray-200 text-gray-700 font-medium text-sm flex items-center justify-between"> <div className="px-4 py-2 rounded-md bg-white border border-gray-200 text-gray-700 font-medium text-sm flex items-center justify-between">
{error} {error}
<button onClick={() => setError('')} className="text-gray-600 hover:text-gray-700 font-bold">&times;</button> <button onClick={() => setError('')} className="text-gray-600 hover:text-gray-700 font-bold">&times;</button>
</div> </div>
)} )}
{success && ( {success && (
<div className="mb-6 px-4 py-2 rounded-md bg-white border border-gray-200 text-gray-700 font-medium text-sm flex items-center justify-between "> <div className="px-4 py-2 rounded-md bg-white border border-gray-200 text-gray-700 font-medium text-sm flex items-center justify-between">
{success} {success}
<button onClick={() => setSuccess('')} className="text-gray-600 hover:text-gray-700 font-bold">&times;</button> <button onClick={() => setSuccess('')} className="text-gray-600 hover:text-gray-700 font-bold">&times;</button>
</div> </div>
)} )}
<form onSubmit={handleSave} className="bg-white border border-gray-200 rounded-lg overflow-hidden"> <div
<div className="p-5 space-y-6"> ref={layoutRef}
className={`grid gap-4 ${isDesktopSplit ? 'items-start' : ''}`}
style={isDesktopSplit ? { gridTemplateColumns: `${listPaneWidth}px 12px minmax(0, 1fr)` } : undefined}
>
<section className="overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm">
<div className="border-b border-gray-200 px-5 py-4">
<div className="flex items-start justify-between gap-4">
<div>
<p className="text-sm font-semibold text-gray-900">Saved Profiles</p>
</div>
<span className="rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-[11px] font-semibold uppercase tracking-[0.14em] text-gray-500">
{profiles.length} total
</span>
</div>
</div>
{profiles.length === 0 ? (
<div className="px-5 py-8 text-center">
<p className="text-sm font-semibold text-gray-900">No saved profiles yet</p>
<p className="mt-2 text-sm text-gray-500">
Add and validate a cURL profile from Omni-channel SMS before configuring provider details here.
</p>
<button
type="button"
onClick={() => navigate(globalSmsPath)}
className="mt-4 inline-flex items-center justify-center rounded-lg bg-primary-blue px-4 py-2 text-sm font-semibold text-white transition hover:bg-primary-dark"
>
Go to Omni-channel SMS
</button>
</div>
) : (
<div className="max-h-[70vh] overflow-y-auto overscroll-contain p-3">
<div className="space-y-3">
{profiles.map((profile) => {
const isActive = profile.id === activeProfileId;
const isSelected = profile.id === selectedProfileId;
const complete = isProviderSetupComplete(profile);
return (
<button
key={profile.id}
type="button"
onClick={() => handleSelectProfile(profile.id)}
className={`w-full rounded-xl border p-4 text-left transition ${isSelected
? 'border-primary-blue bg-indigo-50/40 shadow-sm'
: 'border-gray-200 bg-white hover:border-primary-blue hover:bg-gray-50'
}`}
>
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<p className="truncate text-sm font-semibold text-gray-900">{profile.name}</p>
<p className="mt-1 text-sm text-gray-500">{buildProviderSummary(profile)}</p>
</div>
<div className="flex shrink-0 flex-wrap justify-end gap-2">
{isActive && (
<span className="rounded-full border border-indigo-200 bg-indigo-50 px-2.5 py-1 text-[11px] font-semibold uppercase tracking-[0.14em] text-primary-dark">
Active
</span>
)}
<ProfileStatusPill complete={complete} />
</div>
</div>
<div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-2 text-xs font-medium text-gray-500">
<span>Updated {formatUpdatedAt(profile.updatedAt)}</span>
{profile.provider?.senderId && <span>Sender {profile.provider.senderId}</span>}
{profile.provider?.dltEntityId && <span>DLT ready</span>}
</div>
</button>
);
})}
</div>
</div>
)}
</section>
{isDesktopSplit && (
<div className="hidden self-stretch lg:flex items-stretch justify-center">
<button
type="button"
onMouseDown={handleResizeStart}
className="group relative flex h-full w-3 cursor-col-resize items-stretch justify-center bg-transparent"
aria-label="Resize provider profile list"
>
<span className="pointer-events-none absolute inset-y-2 left-1/2 w-[0.5px] -translate-x-1/2 rounded-full bg-gray-300 transition group-hover:bg-primary-blue" />
</button>
</div>
)}
<section className="min-w-0 overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm">
{!selectedProfile ? (
<div className="flex min-h-[520px] items-center justify-center px-6 py-10 text-center">
<div className="max-w-md">
<p className="text-sm font-semibold uppercase tracking-[0.18em] text-gray-400">Select a profile</p>
<h2 className="mt-3 text-2xl font-semibold tracking-tight text-gray-900">Choose a saved profile to review</h2>
<p className="mt-3 text-sm leading-relaxed text-gray-500">
The selected profile will open here with a complete cURL preview, provider details, and activation controls.
</p>
</div>
</div>
) : (
<>
<div className="border-b border-gray-200 px-6 py-5">
<div className="flex flex-col gap-4 xl:flex-row xl:items-start xl:justify-between">
<div>
<div className="flex flex-wrap items-center gap-2">
<h2 className="text-xl font-semibold tracking-tight text-gray-900">{selectedProfile.name}</h2>
{selectedProfile.id === activeProfileId && (
<span className="rounded-full border border-indigo-200 bg-indigo-50 px-2.5 py-1 text-[11px] font-semibold uppercase tracking-[0.14em] text-primary-dark">
Active profile
</span>
)}
<ProfileStatusPill complete={isProviderSetupComplete(selectedProfile)} />
</div>
<p className="mt-2 text-sm text-gray-500">
Review the exact saved request, then update the provider fields tied to this profile.
</p>
</div>
<div className="flex flex-wrap items-center gap-2">
{selectedProfile.id !== activeProfileId && (
<button
type="button"
onClick={() => handleActivate(selectedProfile)}
className="rounded-lg bg-primary-blue px-4 py-2 text-sm font-semibold text-white transition hover:bg-primary-dark"
>
Set Active
</button>
)}
<button
type="button"
onClick={() => handleCopyCurl(selectedProfile)}
className="rounded-lg border border-gray-200 px-4 py-2 text-sm font-semibold text-gray-700 transition hover:border-primary-blue hover:bg-gray-50 hover:text-primary-blue"
>
{copiedProfileId === selectedProfile.id ? 'Copied' : 'Copy cURL'}
</button>
<button
type="button"
onClick={() => navigate(`${globalSmsPath}?editProfile=${encodeURIComponent(selectedProfile.id)}`)}
className="rounded-lg border border-gray-200 px-4 py-2 text-sm font-semibold text-gray-700 transition hover:border-primary-blue hover:bg-gray-50 hover:text-primary-blue"
>
Edit cURL
</button>
</div>
</div>
</div>
<div className="space-y-6 px-6 py-6">
<div className="rounded-2xl border border-gray-200 bg-gray-950 overflow-hidden">
<div className="flex items-center justify-between gap-4 border-b border-gray-800 px-4 py-3">
<div>
<p className="text-[11px] font-semibold uppercase tracking-[0.18em] text-gray-400">Preview</p>
</div>
<span className="rounded-full border border-gray-700 bg-gray-900 px-2.5 py-1 text-[11px] font-semibold uppercase tracking-[0.14em] text-gray-300">
Updated {formatUpdatedAt(selectedProfile.updatedAt)}
</span>
</div>
<pre className="max-h-72 overflow-y-auto overscroll-contain whitespace-pre-wrap break-all px-4 py-4 text-xs leading-relaxed text-gray-100">
<code>{selectedProfile.rawCurl}</code>
</pre>
</div>
<div className="grid gap-4 xl:grid-cols-[minmax(0,1fr)_260px]">
<form onSubmit={handleSave} className="rounded-2xl border border-gray-200 bg-white overflow-hidden">
<div className="border-b border-gray-200 px-5 py-4">
<p className="text-sm font-semibold text-gray-900">Provider Details</p>
<p className="mt-1 text-sm text-gray-500">
These fields are stored against this profile and are used during template publishing.
</p>
</div>
<div className="space-y-5 px-5 py-5">
<div> <div>
<label className={`block text-sm font-semibold mb-1.5 tracking-wide ${!form.providerName ? 'text-error-text' : 'text-text-primary'}`}> <label className={`block text-sm font-semibold mb-1.5 tracking-wide ${!form.providerName ? 'text-error-text' : 'text-text-primary'}`}>
Provider Name {(!form.providerName) && <span className="text-error-text">*</span>} Provider Name {!form.providerName && <span className="text-error-text">*</span>}
</label> </label>
<input <input
type="text" type="text"
value={form.providerName} value={form.providerName}
onChange={e => handleChange('providerName', e.target.value)} onChange={(event) => handleChange('providerName', event.target.value)}
className={`w-full px-4 py-2 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 `} className={`w-full px-4 py-2 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`}
placeholder="e.g. MSG91, Gupshup" placeholder="e.g. MSG91, Gupshup"
/> />
</div> </div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-5"> <div className="grid gap-5 sm:grid-cols-2">
<div> <div>
<label className={`block text-sm font-semibold mb-1.5 tracking-wide ${!form.senderId ? 'text-error-text' : 'text-text-primary'}`}> <label className={`block text-sm font-semibold mb-1.5 tracking-wide ${!form.senderId ? 'text-error-text' : 'text-text-primary'}`}>
DLT Sender ID {(!form.senderId) && <span className="text-error-text">*</span>} DLT Sender ID {!form.senderId && <span className="text-error-text">*</span>}
</label> </label>
<input <input
type="text" type="text"
value={form.senderId} value={form.senderId}
onChange={e => handleChange('senderId', e.target.value.toUpperCase())} onChange={(event) => handleChange('senderId', event.target.value.toUpperCase())}
maxLength={6} maxLength={6}
className={`w-full px-4 py-2 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 uppercase`} className={`w-full px-4 py-2 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 uppercase`}
placeholder="6 CHARS" placeholder="6 CHARS"
/> />
<p className="text-xs text-gray-500 mt-2 font-medium">Exactly 6 alphabetic characters (e.g. MOKOBA).</p> <p className="mt-2 text-xs font-medium text-gray-500">Exactly 6 alphabetic characters.</p>
</div> </div>
<div> <div>
<label className={`block text-sm font-semibold mb-1.5 tracking-wide ${!form.dltEntityId ? 'text-error-text' : 'text-text-primary'}`}> <label className={`block text-sm font-semibold mb-1.5 tracking-wide ${!form.dltEntityId ? 'text-error-text' : 'text-text-primary'}`}>
DLT Entity ID {(!form.dltEntityId) && <span className="text-error-text">*</span>} DLT Entity ID {!form.dltEntityId && <span className="text-error-text">*</span>}
</label> </label>
<input <input
type="text" type="text"
value={form.dltEntityId} value={form.dltEntityId}
onChange={e => handleChange('dltEntityId', e.target.value)} onChange={(event) => handleChange('dltEntityId', event.target.value)}
className={`w-full px-4 py-2 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 `} className={`w-full px-4 py-2 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`}
placeholder="19-digit DLT PE ID" placeholder="19-digit DLT PE ID"
/> />
</div> </div>
</div> </div>
<div> <div>
<label className="block text-sm font-semibold text-text-primary mb-1.5 tracking-wide">API Auth Key <span className="text-text-muted font-normal text-xs">(Optional)</span></label> <label className="block text-sm font-semibold text-text-primary mb-1.5 tracking-wide">
API Auth Key <span className="text-text-muted font-normal text-xs">(Optional)</span>
</label>
<input <input
type="password" type="password"
value={form.authKey} value={form.authKey}
onChange={e => handleChange('authKey', e.target.value)} onChange={(event) => handleChange('authKey', event.target.value)}
className="w-full px-4 py-2 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 " className="w-full px-4 py-2 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"
placeholder="Authorization key for your SMS provider" placeholder="Authorization key for your SMS provider"
/> />
<p className="text-xs text-gray-500 mt-2 font-medium">Used as the Authorization header in your SMS requests.</p> <p className="mt-2 text-xs font-medium text-gray-500">Used as the Authorization header in your SMS requests.</p>
</div> </div>
</div> </div>
<div className="px-6 py-4 bg-white border-t border-gray-200 flex justify-end"> <div className="flex justify-end border-t border-gray-200 bg-white px-5 py-4">
<button <button
type="submit" type="submit"
disabled={saving} disabled={saving}
@ -171,6 +552,38 @@ export default function Providers() {
</button> </button>
</div> </div>
</form> </form>
<aside className="rounded-2xl border border-gray-200 bg-gray-50 p-5">
<p className="text-sm font-semibold text-gray-900">Current Status</p>
<ul className="mt-4 space-y-3 text-sm">
<li className="rounded-xl border border-gray-200 bg-white px-4 py-3">
<p className="text-xs font-semibold uppercase tracking-[0.14em] text-gray-400">Profile State</p>
<p className="mt-2 font-medium text-gray-900">
{selectedProfile.id === activeProfileId ? 'Currently active for generation' : 'Inactive profile'}
</p>
</li>
<li className="rounded-xl border border-gray-200 bg-white px-4 py-3">
<p className="text-xs font-semibold uppercase tracking-[0.14em] text-gray-400">Provider Setup</p>
<p className="mt-2 font-medium text-gray-900">
{isProviderSetupComplete(selectedProfile)
? 'All mandatory provider fields are complete.'
: getMissingProviderFields(selectedProfile).join(', ')}
</p>
</li>
<li className="rounded-xl border border-gray-200 bg-white px-4 py-3">
<p className="text-xs font-semibold uppercase tracking-[0.14em] text-gray-400">Auth Key</p>
<p className="mt-2 font-medium text-gray-900">
{selectedProfile.provider?.authKey ? 'Saved on this profile' : 'Not added'}
</p>
</li>
</ul>
</aside>
</div>
</div>
</>
)}
</section>
</div>
</div> </div>
); );
} }