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;
|
const hasProfile = !!activeProfile;
|
||||||
setHasGlobalSms(hasProfile);
|
setHasGlobalSms(hasProfile);
|
||||||
const p = activeProfile?.provider || {};
|
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
|
// On mount: rehydrate from sessionStorage and refresh from API
|
||||||
|
|
@ -54,7 +56,7 @@ export function BusinessProvider({ children }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rehydrate();
|
rehydrate();
|
||||||
}, []);
|
}, [updateReadyState]);
|
||||||
|
|
||||||
const setActiveBusiness = useCallback(async (business) => {
|
const setActiveBusiness = useCallback(async (business) => {
|
||||||
setActiveBusinessState(business);
|
setActiveBusinessState(business);
|
||||||
|
|
@ -64,12 +66,13 @@ export function BusinessProvider({ children }) {
|
||||||
}));
|
}));
|
||||||
try {
|
try {
|
||||||
const smsRes = await apiClient.get(`/api/businesses/${business.businessId}/global-sms/active`);
|
const smsRes = await apiClient.get(`/api/businesses/${business.businessId}/global-sms/active`);
|
||||||
updateReadyState(smsRes.data?.activeProfile);
|
return updateReadyState(smsRes.data?.activeProfile);
|
||||||
} catch {
|
} catch {
|
||||||
setHasGlobalSms(false);
|
setHasGlobalSms(false);
|
||||||
setIsSetupComplete(false);
|
setIsSetupComplete(false);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}, []);
|
}, [updateReadyState]);
|
||||||
|
|
||||||
const clearBusiness = useCallback(() => {
|
const clearBusiness = useCallback(() => {
|
||||||
setActiveBusinessState(null);
|
setActiveBusinessState(null);
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ export default function Businesses() {
|
||||||
const { setActiveBusiness } = useBusiness();
|
const { setActiveBusiness } = useBusiness();
|
||||||
const [businesses, setBusinesses] = useState([]);
|
const [businesses, setBusinesses] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [selectingBusinessId, setSelectingBusinessId] = useState('');
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [deleteTarget, setDeleteTarget] = useState(null);
|
const [deleteTarget, setDeleteTarget] = useState(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
|
|
@ -60,9 +61,17 @@ export default function Businesses() {
|
||||||
|
|
||||||
useEffect(() => { load(); }, []);
|
useEffect(() => { load(); }, []);
|
||||||
|
|
||||||
function handleSelect(biz) {
|
async function handleSelect(biz) {
|
||||||
setActiveBusiness(biz);
|
setSelectingBusinessId(biz.businessId);
|
||||||
navigate(`/${biz.businessId}/global-sms`);
|
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() {
|
async function handleDelete() {
|
||||||
|
|
@ -145,6 +154,7 @@ export default function Businesses() {
|
||||||
<button
|
<button
|
||||||
className="w-full text-left p-6"
|
className="w-full text-left p-6"
|
||||||
onClick={() => handleSelect(biz)}
|
onClick={() => handleSelect(biz)}
|
||||||
|
disabled={selectingBusinessId === biz.businessId}
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-4 mb-3">
|
<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">
|
<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">
|
<p className="text-xs text-gray-400 font-medium">
|
||||||
Added {new Date(biz.createdAt).toLocaleDateString('en-IN', { day: 'numeric', month: 'short', year: 'numeric' })}
|
Added {new Date(biz.createdAt).toLocaleDateString('en-IN', { day: 'numeric', month: 'short', year: 'numeric' })}
|
||||||
</p>
|
</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>
|
</button>
|
||||||
<div className="px-6 py-3 bg-gray-50 border-t border-gray-100 flex justify-between items-center">
|
<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>
|
<span className="text-xs text-indigo-600 font-semibold group-hover:underline">Click to manage →</span>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user