Skip to content

Commit 31458fd

Browse files
committed
refactor(DashboardNav): improve image validation logic and enhance image rendering
1 parent 6523e68 commit 31458fd

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,28 @@ export function DashboardNav({
2424
const [isCollapsed, setIsCollapsed] = useState(false);
2525

2626
const [isImageValid, setIsImageValid] = useState(() => {
27-
return type === 'organization' && entityDetails?.logo ? true : type === 'self' && entityDetails?.profilePicture ? true : false;
27+
if (type === 'organization') {
28+
return !!entityDetails?.logo?.url;
29+
} else if (type === 'self') {
30+
return !!entityDetails?.profilePicture?.url;
31+
}
32+
return false;
2833
});
34+
2935
const path = usePathname();
3036

3137
useEffect(() => {
32-
if (
33-
entityDetails &&
34-
(typeof entityDetails.logo === 'undefined' || entityDetails.logo === null)
35-
) {
38+
if (!entityDetails) {
3639
setIsImageValid(false);
37-
} else {
38-
setIsImageValid(true);
40+
return;
41+
}
42+
43+
if (type === 'organization') {
44+
setIsImageValid(!!entityDetails.logo?.url);
45+
} else if (type === 'self') {
46+
setIsImageValid(!!entityDetails.profilePicture?.url);
3947
}
40-
}, [entityDetails]);
48+
}, [entityDetails, type]);
4149

4250
useMetaKeyPress('b', () => setIsCollapsed((e) => !e));
4351

@@ -47,7 +55,6 @@ export function DashboardNav({
4755

4856
const sidebarIcon = isCollapsed ? Icons.expand : Icons.collapse;
4957

50-
5158
return (
5259
<aside
5360
className={cn(
@@ -65,12 +72,16 @@ export function DashboardNav({
6572
<Image
6673
height={140}
6774
width={140}
68-
src={ type === 'organization' ? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${entityDetails?.logo?.url}` : `${process.env.NEXT_PUBLIC_BACKEND_URL}/${entityDetails?.profilePicture?.url}` }
75+
src={
76+
type === 'organization'
77+
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${entityDetails?.logo?.url}`
78+
: `${process.env.NEXT_PUBLIC_BACKEND_URL}/${entityDetails?.profilePicture?.url}`
79+
}
6980
alt={`${entityDetails?.name} logo`}
7081
onError={() => {
7182
setIsImageValid(false);
7283
}}
73-
className="object-contain"
84+
className={`${type === 'organization' ? 'object-contain' : 'object-cover rounded-full'}`}
7485
/>
7586
) : (
7687
<Image

0 commit comments

Comments
 (0)