redirect to events if provider config is completed
This commit is contained in:
parent
82cc095b6e
commit
73d0a08cd9
|
|
@ -17,7 +17,9 @@ export function BusinessProvider({ children }) {
|
|||
const hasProfile = !!activeProfile;
|
||||
setHasGlobalSms(hasProfile);
|
||||
const p = activeProfile?.provider || {};
|
||||
setIsSetupComplete(hasProfile && !!p.providerName && !!p.senderId && !!p.dltEntityId);
|
||||
const nextIsSetupComplete = hasProfile && !!p.providerName && !!p.senderId && !!p.dltEntityId;
|
||||
setIsSetupComplete(nextIsSetupComplete);
|
||||
return nextIsSetupComplete;
|
||||
}, []);
|
||||
|
||||
// On mount: rehydrate from sessionStorage and refresh from API
|
||||
|
|
@ -54,7 +56,7 @@ export function BusinessProvider({ children }) {
|
|||
}
|
||||
}
|
||||
rehydrate();
|
||||
}, []);
|
||||
}, [updateReadyState]);
|
||||
|
||||
const setActiveBusiness = useCallback(async (business) => {
|
||||
setActiveBusinessState(business);
|
||||
|
|
@ -64,12 +66,13 @@ export function BusinessProvider({ children }) {
|
|||
}));
|
||||
try {
|
||||
const smsRes = await apiClient.get(`/api/businesses/${business.businessId}/global-sms/active`);
|
||||
updateReadyState(smsRes.data?.activeProfile);
|
||||
return updateReadyState(smsRes.data?.activeProfile);
|
||||
} catch {
|
||||
setHasGlobalSms(false);
|
||||
setIsSetupComplete(false);
|
||||
return false;
|
||||
}
|
||||
}, []);
|
||||
}, [updateReadyState]);
|
||||
|
||||
const clearBusiness = useCallback(() => {
|
||||
setActiveBusinessState(null);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ export default function Businesses() {
|
|||
const { setActiveBusiness } = useBusiness();
|
||||
const [businesses, setBusinesses] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selectingBusinessId, setSelectingBusinessId] = useState('');
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
const [deleteTarget, setDeleteTarget] = useState(null);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
|
|
@ -60,9 +61,17 @@ export default function Businesses() {
|
|||
|
||||
useEffect(() => { load(); }, []);
|
||||
|
||||
function handleSelect(biz) {
|
||||
setActiveBusiness(biz);
|
||||
navigate(`/${biz.businessId}/global-sms`);
|
||||
async function handleSelect(biz) {
|
||||
setSelectingBusinessId(biz.businessId);
|
||||
setError('');
|
||||
try {
|
||||
const setupComplete = await setActiveBusiness(biz);
|
||||
navigate(`/${biz.businessId}/${setupComplete ? 'events' : 'global-sms'}`);
|
||||
} catch (err) {
|
||||
setError(err.response?.data?.error || 'Failed to open business');
|
||||
} finally {
|
||||
setSelectingBusinessId('');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
|
|
@ -145,6 +154,7 @@ export default function Businesses() {
|
|||
<button
|
||||
className="w-full text-left p-6"
|
||||
onClick={() => handleSelect(biz)}
|
||||
disabled={selectingBusinessId === biz.businessId}
|
||||
>
|
||||
<div className="flex items-center gap-4 mb-3">
|
||||
<div className="w-10 h-10 rounded-lg bg-indigo-600 flex items-center justify-center text-base font-bold text-white shrink-0 shadow-sm">
|
||||
|
|
@ -158,6 +168,12 @@ export default function Businesses() {
|
|||
<p className="text-xs text-gray-400 font-medium">
|
||||
Added {new Date(biz.createdAt).toLocaleDateString('en-IN', { day: 'numeric', month: 'short', year: 'numeric' })}
|
||||
</p>
|
||||
{selectingBusinessId === biz.businessId && (
|
||||
<div className="mt-3 inline-flex items-center gap-2 text-xs text-indigo-600 font-semibold">
|
||||
<span className="w-3.5 h-3.5 border-2 border-indigo-200 border-t-indigo-600 rounded-full animate-spin" />
|
||||
Opening…
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
<div className="px-6 py-3 bg-gray-50 border-t border-gray-100 flex justify-between items-center">
|
||||
<span className="text-xs text-indigo-600 font-semibold group-hover:underline">Click to manage →</span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user