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) => {
|
const loadBackoffice = async (silent = false) => {
|
||||||
try {
|
try {
|
||||||
if (!silent) setLoading(true)
|
|
||||||
const { adminAccessApi, adminAuditApi, adminCompaniesApi, adminJobsApi, adminTagsApi, backofficeApi, plansApi } = await import("@/lib/api")
|
const { adminAccessApi, adminAuditApi, adminCompaniesApi, adminJobsApi, adminTagsApi, backofficeApi, plansApi } = await import("@/lib/api")
|
||||||
const [rolesData, auditData, companiesData, jobsData, tagsData, statsData, plansData] = await Promise.all([
|
const [rolesData, auditData, companiesData, jobsData, tagsData, statsData, plansData] = await Promise.all([
|
||||||
adminAccessApi.listRoles(),
|
adminAccessApi.listRoles().catch(() => []),
|
||||||
adminAuditApi.listLogins(20),
|
adminAuditApi.listLogins(20).catch(() => []),
|
||||||
adminCompaniesApi.list(false),
|
adminCompaniesApi.list(false).catch(() => ({ data: [] })),
|
||||||
adminJobsApi.list({ status: "review", limit: 10 }),
|
adminJobsApi.list({ status: "review", limit: 10 }).catch(() => ({ data: [] })),
|
||||||
adminTagsApi.list(),
|
adminTagsApi.list().catch(() => []),
|
||||||
backofficeApi.admin.getStats().catch(() => null),
|
backofficeApi.admin.getStats().catch(() => null),
|
||||||
plansApi.getAll().catch(() => [])
|
plansApi.getAll().catch(() => [])
|
||||||
])
|
])
|
||||||
|
|
@ -300,9 +299,6 @@ export default function SettingsPage() {
|
||||||
setPlans(plansData)
|
setPlans(plansData)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading backoffice:", 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(() => {
|
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 (
|
return (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue