Skip to content

Commit 01df61b

Browse files
committed
Replace entity slug with entity details object in dashboard navbar
1 parent 97a56d4 commit 01df61b

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

app/[locale]/dashboard/components/dashboard-nav.tsx

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React from 'react';
3+
import { useEffect, useState } from 'react';
44
import Image from 'next/image';
55
import Link from 'next/link';
66
import { usePathname } from 'next/navigation';
@@ -17,11 +17,26 @@ interface DashboardNavProps {
1717
}
1818
export function DashboardNav({
1919
items,
20-
entitySlug,
21-
}: DashboardNavProps & { entitySlug?: string }) {
22-
const [isCollapsed, setIsCollapsed] = React.useState(false);
20+
entityDetails,
21+
}: DashboardNavProps & { entityDetails?: any }) {
22+
const [isCollapsed, setIsCollapsed] = useState(false);
23+
24+
const [isImageValid, setIsImageValid] = useState(() => {
25+
return entityDetails?.logo ? true : false;
26+
});
2327
const path = usePathname();
2428

29+
useEffect(() => {
30+
if (
31+
entityDetails &&
32+
(typeof entityDetails.logo === 'undefined' || entityDetails.logo === null)
33+
) {
34+
setIsImageValid(false);
35+
} else {
36+
setIsImageValid(true);
37+
}
38+
}, [entityDetails]);
39+
2540
useMetaKeyPress('b', () => setIsCollapsed((e) => !e));
2641

2742
if (items && !items.length) {
@@ -39,17 +54,31 @@ export function DashboardNav({
3954
)}
4055
>
4156
<nav className={cn('flex flex-col gap-2')}>
42-
{entitySlug && !isCollapsed ? (
57+
{entityDetails && !isCollapsed ? (
4358
<>
4459
<div className="flex flex-col items-center justify-center px-4 py-8">
45-
<Image
46-
height={140}
47-
width={140}
48-
src={'/obi.jpg'}
49-
alt={'Organisation ID'}
50-
/>
60+
{isImageValid ? (
61+
<Image
62+
height={140}
63+
width={140}
64+
src={`${process.env.NEXT_PUBLIC_BACKEND_URL}${entityDetails?.logo?.url}`}
65+
alt={`${entityDetails?.name} logo`}
66+
onError={() => {
67+
setIsImageValid(false);
68+
}}
69+
className="object-contain"
70+
/>
71+
) : (
72+
<Image
73+
height={140}
74+
width={140}
75+
src={'/fallback.svg'}
76+
alt={'fallback logo'}
77+
className="fill-current bg-baseGraySlateSolid6 object-contain text-baseGraySlateSolid6"
78+
/>
79+
)}
5180
<Text variant="headingMd" fontWeight="medium" className="py-2">
52-
{entitySlug}
81+
{entityDetails?.name}
5382
</Text>
5483
<Link href={'/dashboard'}>
5584
<Text variant="headingXs" color="interactive">

0 commit comments

Comments
 (0)