Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/pages/SuperAdminPanel.jsx
Browse files
frontend/src/pages/SuperAdminPanel.jsx
CHANGED
|
@@ -97,7 +97,27 @@ const BillingTierCard = ({ tier, onSave }) => {
|
|
| 97 |
};
|
| 98 |
|
| 99 |
const SuperAdminPanel = () => {
|
| 100 |
-
const { user } = useAuth();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
const [organizations, setOrganizations] = useState([]);
|
| 102 |
const [recentPayments, setRecentPayments] = useState([]);
|
| 103 |
const [trends, setTrends] = useState([]);
|
|
@@ -210,11 +230,10 @@ const SuperAdminPanel = () => {
|
|
| 210 |
const fetchStats = async () => {
|
| 211 |
setLoading(true);
|
| 212 |
try {
|
| 213 |
-
const token = localStorage.getItem('wss_token');
|
| 214 |
const [globalRes, bookingsRes, emailLogsRes] = await Promise.all([
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
]);
|
| 219 |
if (globalRes.ok) {
|
| 220 |
const data = await globalRes.json();
|
|
|
|
| 97 |
};
|
| 98 |
|
| 99 |
const SuperAdminPanel = () => {
|
| 100 |
+
const { user, refreshAccessToken } = useAuth();
|
| 101 |
+
|
| 102 |
+
const authFetch = async (url, options = {}) => {
|
| 103 |
+
let activeToken = localStorage.getItem('wss_token');
|
| 104 |
+
const headers = {
|
| 105 |
+
'Authorization': `Bearer ${activeToken}`,
|
| 106 |
+
...(options.headers || {})
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
let res = await fetch(url, { ...options, headers });
|
| 110 |
+
|
| 111 |
+
if (res.status === 401 && refreshAccessToken) {
|
| 112 |
+
const newToken = await refreshAccessToken();
|
| 113 |
+
if (newToken) {
|
| 114 |
+
headers['Authorization'] = `Bearer ${newToken}`;
|
| 115 |
+
res = await fetch(url, { ...options, headers });
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
return res;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
const [organizations, setOrganizations] = useState([]);
|
| 122 |
const [recentPayments, setRecentPayments] = useState([]);
|
| 123 |
const [trends, setTrends] = useState([]);
|
|
|
|
| 230 |
const fetchStats = async () => {
|
| 231 |
setLoading(true);
|
| 232 |
try {
|
|
|
|
| 233 |
const [globalRes, bookingsRes, emailLogsRes] = await Promise.all([
|
| 234 |
+
authFetch('/api/auth/global-stats'),
|
| 235 |
+
authFetch('/api/demo/bookings'),
|
| 236 |
+
authFetch('/api/auth/email-logs')
|
| 237 |
]);
|
| 238 |
if (globalRes.ok) {
|
| 239 |
const data = await globalRes.json();
|