fix: ensure safe handling of organizations and notifications data in LayoutContent and NotificationCenter components
This commit is contained in:
@@ -22,7 +22,7 @@ export default function LayoutContent({ children }: { children: React.ReactNode
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (auth.user) {
|
if (auth.user) {
|
||||||
getUserOrganizations()
|
getUserOrganizations()
|
||||||
.then((organizations) => setOrgs(organizations))
|
.then((organizations) => setOrgs(Array.isArray(organizations) ? organizations : []))
|
||||||
.catch(err => console.error('Failed to fetch orgs for header', err))
|
.catch(err => console.error('Failed to fetch orgs for header', err))
|
||||||
}
|
}
|
||||||
}, [auth.user])
|
}, [auth.user])
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ export default function NotificationCenter() {
|
|||||||
setError(null)
|
setError(null)
|
||||||
try {
|
try {
|
||||||
const res = await listNotifications()
|
const res = await listNotifications()
|
||||||
setNotifications(res.notifications)
|
setNotifications(Array.isArray(res?.notifications) ? res.notifications : [])
|
||||||
setUnreadCount(res.unread_count)
|
setUnreadCount(typeof res?.unread_count === 'number' ? res.unread_count : 0)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(getAuthErrorMessage(err as Error) || 'Failed to load notifications')
|
setError(getAuthErrorMessage(err as Error) || 'Failed to load notifications')
|
||||||
setNotifications([])
|
setNotifications([])
|
||||||
@@ -160,14 +160,14 @@ export default function NotificationCenter() {
|
|||||||
{error && (
|
{error && (
|
||||||
<div className="p-6 text-center text-red-500 text-sm">{error}</div>
|
<div className="p-6 text-center text-red-500 text-sm">{error}</div>
|
||||||
)}
|
)}
|
||||||
{!loading && !error && notifications.length === 0 && (
|
{!loading && !error && (notifications?.length ?? 0) === 0 && (
|
||||||
<div className="p-6 text-center text-neutral-500 dark:text-neutral-400 text-sm">
|
<div className="p-6 text-center text-neutral-500 dark:text-neutral-400 text-sm">
|
||||||
No notifications yet
|
No notifications yet
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!loading && !error && notifications.length > 0 && (
|
{!loading && !error && (notifications?.length ?? 0) > 0 && (
|
||||||
<ul className="divide-y divide-neutral-200 dark:divide-neutral-700">
|
<ul className="divide-y divide-neutral-200 dark:divide-neutral-700">
|
||||||
{notifications.map((n) => (
|
{(notifications ?? []).map((n) => (
|
||||||
<li key={n.id}>
|
<li key={n.id}>
|
||||||
{n.link_url ? (
|
{n.link_url ? (
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
759
package-lock.json
generated
759
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user