refactor: switch SDK methods to asynchronous
Migrate SDK interactions to asynchronous calls, relax admin setup email constraints, and add event retrieval functionality.
This commit is contained in:
1 parent
81c5e4e2fd
commit
bb938c33c0
36 files changed
+1679
-754
No files matched your search
@@ -1,32 +0,0 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
|
||||
export function useVconMetrics(refreshIntervalMs = 3000) {
|
||||
const [metrics, setMetrics] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const fetchMetrics = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/metrics');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setMetrics(data);
|
||||
setError(null);
|
||||
} else {
|
||||
setError('Failed to fetch metrics');
|
||||
}
|
||||
} catch (err: any) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchMetrics();
|
||||
const timer = setInterval(fetchMetrics, refreshIntervalMs);
|
||||
return () => clearInterval(timer);
|
||||
}, [fetchMetrics, refreshIntervalMs]);
|
||||
|
||||
return { metrics, loading, error, refetch: fetchMetrics };
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
export async function vconApiFetch<T>(endpoint: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(endpoint, {
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options?.headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errorBody = await res.json().catch(() => ({}));
|
||||
throw new Error(errorBody.error || `API error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
Reference in new issue
Block a user