Skip to content

Commit b30dd1a

Browse files
committed
fix bug on link in menu and sidebar
1 parent b7ab1ff commit b30dd1a

2 files changed

Lines changed: 93 additions & 44 deletions

File tree

src/app/components/SafeLLM/Menu.tsx

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const Menu = ({ currentPath, setShowInnerComponent }: { currentPath: string, set
2828
if (!userProfileState) {
2929
getUserProfileService(false).then((res: any) => {
3030
setUserProfile(res);
31-
console.log("User Profile:", userProfile);
3231
}).catch((error) => {
3332
console.error("Error fetching user profile:", error);
3433
});
@@ -44,15 +43,12 @@ const Menu = ({ currentPath, setShowInnerComponent }: { currentPath: string, set
4443
dispatch(fetchChatHistoryListRequest());
4544
}, [dispatch]);
4645

46+
4747
function handleClick(path: string) {
48-
if (currentPath as any === path)
49-
setShowInnerComponent(true);
50-
else
51-
setShowInnerComponent(true);
48+
setShowInnerComponent(true);
5249
Router.push(path);
5350
}
5451

55-
5652
const logoutFuc = async () => {
5753
await logout();
5854
dispatch(resetLoginOtpState());
@@ -87,10 +83,19 @@ const Menu = ({ currentPath, setShowInnerComponent }: { currentPath: string, set
8783
<div className={'w-full h-3 bg-secondary-02'} />
8884
<ul>
8985
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
90-
<a className={'flex flex-1'} onClick={() => handleClick('/chat')}>
91-
<Icons name={'profile-faq'} />
92-
<p className={'ml-3'}>chat</p>
93-
</a>
86+
{currentPath === '/chat' ?
87+
<a className={'flex flex-1'} onClick={() => handleClick('/chat')}>
88+
<Icons name={'profile-faq'} />
89+
<p className={'ml-3'}>Chat</p>
90+
</a>
91+
:
92+
<Link href="/chat">
93+
<span className={'flex flex-1'}>
94+
<Icons name={'profile-faq'} />
95+
<p className={'ml-3'}>Chat</p>
96+
</span>
97+
</Link>
98+
}
9499
<Icons name={'direction-left-gray'} />
95100
</li>
96101

@@ -108,52 +113,94 @@ const Menu = ({ currentPath, setShowInnerComponent }: { currentPath: string, set
108113
<ul className="pl-8 space-y-1 max-h-40 overflow-y-auto" onScroll={handleScroll}>
109114
{chatHistory.map((chat: any) => (
110115
<li key={chat.id}>
116+
111117
<a
112118
href={`/chat/history/${chat.id}`}
113119
className={`block px-4 py-2 hover:bg-primary-02 hover:text-primary ${currentPath.includes(chat.id) ? 'bg-primary-01 text-primary' : ''}`}
114120
>
115121
{chat.title} - {new Date(chat.date).toLocaleDateString()}
116122
</a>
123+
117124
</li>
118125
))}
119126
</ul>
120127
)}
121128

122-
{allowedRolesManagement.includes(role) ?
123-
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
124-
<a className={'flex flex-1'} onClick={() => handleClick('/management')}>
125-
<Icons name={'management'} />
126-
<p className={'ml-3'}>Management</p>
127-
</a>
128-
<Icons name={'direction-left-gray'} />
129-
</li>
130-
: ''
131-
}
132-
{allowedRolesManagement.includes(role) ?
133-
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
134-
<a className={'flex flex-1'} onClick={() => handleClick('/alerts')}>
135-
<Icons name={'chart-live'} />
136-
<p className={'ml-3'}>Alerts</p>
137-
</a>
138-
<Icons name={'direction-left-gray'} />
139-
</li>
140-
: ''
141-
}
129+
{allowedRolesManagement.includes(role) && (
130+
<>
131+
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
132+
{currentPath === '/management' ?
133+
<a className={'flex flex-1'} onClick={() => handleClick('/management')}>
134+
<Icons name={'management'} />
135+
<p className={'ml-3'}>Management</p>
136+
</a>
137+
:
138+
<Link href="/management">
139+
<span className={'flex flex-1'}>
140+
<Icons name={'management'} />
141+
<p className={'ml-3'}>Management</p>
142+
</span>
143+
</Link>
144+
}
145+
146+
<Icons name={'direction-left-gray'} />
147+
</li>
148+
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
149+
150+
{currentPath === '/alerts' ?
151+
<a className={'flex flex-1'} onClick={() => handleClick('/alerts')}>
152+
<Icons name={'chart-live'} />
153+
<p className={'ml-3'}>Alerts</p>
154+
</a>
155+
:
156+
<Link href="/alerts">
157+
<span className={'flex flex-1'}>
158+
<Icons name={'chart-live'} />
159+
<p className={'ml-3'}>Alerts</p>
160+
</span>
161+
</Link>
162+
}
163+
<Icons name={'direction-left-gray'} />
164+
</li>
165+
</>
166+
)}
142167
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
143-
<a className={'flex flex-1'} onClick={() => handleClick('/profile')}>
144-
<Icons name={'profile-account'} />
145-
<p className={'ml-3'}>Profle</p>
146-
</a>
168+
169+
170+
{currentPath === '/profile' ?
171+
<a className={'flex flex-1'} onClick={() => handleClick('/profile')}>
172+
<Icons name={'profile-account'} />
173+
<p className={'ml-3'}>Profle</p>
174+
</a>
175+
:
176+
<Link href="/profile">
177+
<span className={'flex flex-1'}>
178+
<Icons name={'profile-account'} />
179+
<p className={'ml-3'}>Profile</p>
180+
</span>
181+
</Link>
182+
}
147183
<Icons name={'direction-left-gray'} />
148184
</li>
149185
<li className={'flex justify-between p-4 border-b-2 border-secondary-02 cursor-pointer'}>
150-
<a className={'flex flex-1'} onClick={() => handleClick('/security')}>
151-
<Icons name={'profile-security'} />
152-
<p className={'ml-3'}>Security</p>
153-
</a>
186+
187+
188+
{currentPath === '/security' ?
189+
<a className={'flex flex-1'} onClick={() => handleClick('/security')}>
190+
<Icons name={'profile-security'} />
191+
<p className={'ml-3'}>Security</p>
192+
</a>
193+
:
194+
<Link href="/security">
195+
<span className={'flex flex-1'}>
196+
<Icons name={'profile-security'} />
197+
<p className={'ml-3'}>Security</p>
198+
</span>
199+
</Link>
200+
}
154201
<Icons name={'direction-left-gray'} />
155202
</li>
156-
203+
157204
<li className={'flex p-4 cursor-pointer'} onClick={logoutFuc}>
158205
<Icons name={'profile-logout'} />
159206
<p className={'ml-3'}>Logout</p>

src/app/components/Sidebar/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import { useParams } from "next/navigation";
1313
import toast, { Toaster } from "react-hot-toast";
1414
import { resetLoginOtpState } from "@/store/auth/login/otp/slice";
1515
import { loginReset } from "@/store/auth/login/form/slice";
16+
import Link from 'next/link';
1617
const allowedRolesManagement = ['admin', 'developer', 'management'];
1718

1819

20+
1921
export default function Sidebar(props: SidebarInterface) {
2022

2123
const [userProfile, setUserProfile] = useState<UserProfileResponseInterface>()
@@ -193,7 +195,7 @@ export default function Sidebar(props: SidebarInterface) {
193195
<li className={`relative group ${item.hasDivider ? borderBottomStyle : ''}`}
194196
key={item.label}>
195197
{item.path ?
196-
<a href={`${item.path}`}
198+
<Link href={`${item.path}`}
197199
className={itemsStyle + ' ' +
198200
` ${pathname === item.path ? 'bg-primary-01 text-primary border-r-2 border-primary ' : ''}`}>
199201
<div className={'group-hover:hidden'}>
@@ -206,8 +208,8 @@ export default function Sidebar(props: SidebarInterface) {
206208
{item.badge && (
207209
<span className="absolute top-4 right-3 inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-red-100 bg-red-600 rounded-full">{item.badge}</span>
208210
)}
209-
</a> :
210-
<a onClick={() => { setIsHistoryOpen(!isHistoryOpen) }}
211+
</Link > :
212+
<a onClick={() => { setIsHistoryOpen(!isHistoryOpen) }}
211213
className={itemsStyle + ' ' +
212214
` ${pathname === item.path ? 'relative bg-primary-01 text-primary border-r-2 border-primary ' : 'relative cursor-pointer'}`}>
213215
<div className={'group-hover:hidden'}>
@@ -231,13 +233,13 @@ export default function Sidebar(props: SidebarInterface) {
231233
<ul className="pl-8 space-y-1 max-h-40 overflow-y-auto" onScroll={handleScroll}>
232234
{(item as any).subItems && (item as any).subItems.map((subItem: any) => (
233235
<li key={subItem.label} >
234-
<a href={subItem.path} className={`block px-4 py-2 hover:bg-primary-02 hover:text-primary ${id && id == subItem.chatId ? 'bg-primary-01 text-primary' : ''
236+
<Link href={subItem.path} className={`block px-4 py-2 hover:bg-primary-02 hover:text-primary ${id && id == subItem.chatId ? 'bg-primary-01 text-primary' : ''
235237
}`}>
236238
{subItem.label}
237239
{item.badge && (
238240
<span className="absolute top-4 right-3 inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-red-100 bg-red-600 rounded-full">{item.badge}</span>
239241
)}
240-
</a>
242+
</Link >
241243
</li>
242244
))}
243245
</ul>

0 commit comments

Comments
 (0)