fix: resolve infinite loading on settings page
- Remove duplicate setLoading calls in loadBackoffice - Add proper error handling with catch for all API calls - Wrap useEffect initialization in try/catch/finally
This commit is contained in:
parent
754acd9d3c
commit
1b35b8dd70
1 changed files with 15 additions and 10 deletions
|
|
@ -280,14 +280,13 @@ export default function SettingsPage() {
|
|||
|
||||
const loadBackoffice = async (silent = false) => {
|
||||
try {
|
||||
if (!silent) setLoading(true)
|
||||
const { adminAccessApi, adminAuditApi, adminCompaniesApi, adminJobsApi, adminTagsApi, backofficeApi, plansApi } = await import("@/lib/api")
|
||||
const [rolesData, auditData, companiesData, jobsData, tagsData, statsData, plansData] = await Promise.all([
|
||||
adminAccessApi.listRoles(),
|
||||
adminAuditApi.listLogins(20),
|
||||
adminCompaniesApi.list(false),
|
||||
adminJobsApi.list({ status: "review", limit: 10 }),
|
||||
adminTagsApi.list(),
|
||||
adminAccessApi.listRoles().catch(() => []),
|
||||
adminAuditApi.listLogins(20).catch(() => []),
|
||||
adminCompaniesApi.list(false).catch(() => ({ data: [] })),
|
||||
adminJobsApi.list({ status: "review", limit: 10 }).catch(() => ({ data: [] })),
|
||||
adminTagsApi.list().catch(() => []),
|
||||
backofficeApi.admin.getStats().catch(() => null),
|
||||
plansApi.getAll().catch(() => [])
|
||||
])
|
||||
|
|
@ -300,9 +299,6 @@ export default function SettingsPage() {
|
|||
setPlans(plansData)
|
||||
} catch (error) {
|
||||
console.error("Error loading backoffice:", error)
|
||||
toast.error("Failed to load backoffice data")
|
||||
} finally {
|
||||
if (!silent) setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -405,7 +401,16 @@ export default function SettingsPage() {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([fetchSettings(), fetchCredentials(), loadBackoffice()]).finally(() => setLoading(false))
|
||||
const init = async () => {
|
||||
try {
|
||||
await Promise.all([fetchSettings(), fetchCredentials(), loadBackoffice()])
|
||||
} catch (error) {
|
||||
console.error("Error loading settings:", error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
init()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in a new issue