Skip to content

Commit aa89de5

Browse files
committed
left side bar title issue and user slice addition
1 parent c5554cd commit aa89de5

File tree

6 files changed

+83
-9
lines changed

6 files changed

+83
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This is a free admin dashboard template that uses **Daisy UI** and **Next js** A
99

1010
## Preview
1111

12-
<!-- 🚀 [Live preview](https://tailwind-dashboard-template-dashwind.vercel.app/) -->
12+
🚀 [Live preview](https://admin-dashboard-nextjs-daisyui-template.vercel.app/login)
1313

1414

1515
<!-- ![App Screenshot](https://ik.imagekit.io/vu5t8xb15vzcx/tr:h-600/Screenshot_2023-05-09_at_12.57.37_PM_z94SiShUDS.png?updatedAt=1683617550144) -->

src/containers/left-sidebar.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import SidebarSubmenu from './sidebar-submenu';
66
import routes from '@/helper/sidebar-routes';
77
import { usePathname } from 'next/navigation'
88
import { useEffect } from 'react';
9-
import { useAppDispatch } from '@/lib/hooks';
9+
import { useAppDispatch, useAppSelector } from '@/lib/hooks';
1010
import { setPageTitle } from '@/features/common/headerSlice';
1111
import { UserProfile } from '@/helper/types';
1212
import BookmarkSquareIcon from '@heroicons/react/24/outline/BookmarkSquareIcon'
1313
import ChevronUpIcon from '@heroicons/react/24/outline/ChevronUpIcon'
1414
import ArrowUpOnSquareIcon from '@heroicons/react/24/outline/ArrowUpOnSquareIcon'
15+
import { getUserInfo } from '@/features/common/userSlice';
1516

1617
interface LeftSidebarProps {}
1718

@@ -25,27 +26,42 @@ function LeftSidebar(props: LeftSidebarProps) {
2526
const leftSidebarDrawer = document.getElementById('left-sidebar-drawer');
2627
if (leftSidebarDrawer) leftSidebarDrawer.click();
2728
};
29+
const user = useAppSelector((state) => state.user);
2830

29-
const user : UserProfile = {
30-
name : "Alex",
31-
avatar : "https://reqres.in/img/faces/7-image.jpg",
32-
emailId : ""
33-
}
3431

3532
useEffect(() => {
3633
console.log(pathname)
3734
let routeObj = routes.filter((r) => {return r.path == pathname})[0]
3835
if(routeObj){
3936
dispatch(setPageTitle({title : routeObj.pageTitle}))
37+
}else{
38+
const secondSlashIndex = pathname.indexOf('/', pathname.indexOf('/') + 1)
39+
if (secondSlashIndex !== -1) {
40+
const substringBeforeSecondSlash = pathname.substring(0, secondSlashIndex);
41+
let submenuRouteObj = routes.filter((r) => {return r.path == substringBeforeSecondSlash})[0]
42+
if(submenuRouteObj.submenu){
43+
let submenuObj = submenuRouteObj.submenu.filter((r) => {return r.path == pathname})[0]
44+
console.log("herere", submenuObj)
45+
dispatch(setPageTitle({title : submenuObj.pageTitle}))
46+
47+
}
48+
}
4049
}
4150
}, [pathname])
4251

52+
53+
useEffect(() => {
54+
dispatch(getUserInfo())
55+
}, [])
56+
4357
const logoutUser = async () => {
4458
console.log("here")
4559
localStorage.clear();
4660
window.location.href = '/'
4761
}
4862

63+
64+
4965

5066
return (
5167
<div className="drawer-side z-30 overflow-hidden">

src/features/common/userSlice.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { APIResponse, UserProfile } from '@/helper/types';
2+
import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit';
3+
import axios from 'axios';
4+
5+
6+
7+
export const getUserInfo = createAsyncThunk<UserProfile, void>(
8+
"user/getUserInfo",
9+
async (thunkApi) => {
10+
// const response = await axios.get<APIResponse>("/workspace/home");
11+
// return response.data.payload;
12+
return {name: "Alex", avatar : "https://reqres.in/img/faces/7-image.jpg", emailId : ""}
13+
}
14+
);
15+
16+
const initialState: UserProfile = {
17+
name: "",
18+
avatar: "",
19+
emailId: "",
20+
};
21+
22+
export const userSlice = createSlice({
23+
name: 'user',
24+
initialState,
25+
reducers: {
26+
27+
28+
29+
},
30+
31+
extraReducers: (builder) => {
32+
builder.addCase(getUserInfo.pending, (state) => {
33+
34+
});
35+
builder.addCase(getUserInfo.fulfilled, (state, action) => {
36+
console.log(action.payload)
37+
state.name = action.payload.name
38+
state.avatar = action.payload.avatar
39+
});
40+
builder.addCase(getUserInfo.rejected, (state) => {
41+
42+
});
43+
}
44+
});
45+
46+
export const { } = userSlice.actions;
47+
48+
export default userSlice.reducer;

src/helper/sidebar-routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const routes: SidebarMenuObj[] = [
3030
pageTitle : "Leads"
3131
},
3232
{
33-
path: '',
33+
path: '/settings',
3434
icon: <Cog6ToothIcon className={`${iconClasses} inline`} />,
3535
pageName: 'Settings',
3636
pageTitle : "",

src/helper/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export interface SubmenuItem {
2424

2525
// Routes Interface End ------------------------
2626

27+
/**
28+
* Interface for api response
29+
*/
30+
export interface APIResponse {
31+
payload: any;
32+
message: string;
33+
}
2734

2835
/**
2936
* Interface for UserProfile data.

src/lib/store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import headerSlice from '@/features/common/headerSlice'
22
import modalSlice from '@/features/common/modalSlice'
33
import rightDrawerSlice from '@/features/common/rightDrawerSlice'
4+
import userSlice from '@/features/common/userSlice'
45
import leadSlice from '@/features/leads/leadSlice'
6+
57
import { configureStore } from '@reduxjs/toolkit'
68

79
export const makeStore = () => {
@@ -10,7 +12,8 @@ export const makeStore = () => {
1012
header : headerSlice,
1113
rightDrawer : rightDrawerSlice,
1214
leads : leadSlice,
13-
modal : modalSlice
15+
modal : modalSlice,
16+
user : userSlice
1417
}
1518
})
1619
}

0 commit comments

Comments
 (0)