Skip to content

Commit 68808b7

Browse files
committed
Fix TS errors
1 parent e1465df commit 68808b7

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/Dashboard/_common/TheHeader/HeaderProfile.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ import IconAccount from '@material-ui/icons/AccountBalance'
1818
import IconSettings from '@material-ui/icons/Settings'
1919
import IconLogout from '@material-ui/icons/ExitToApp'
2020

21+
import { useDashboardData } from '../../_state'
22+
2123
const HeaderProfile = () => {
2224
const classes = useStyles()
2325
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null)
26+
const { user } = useDashboardData()
27+
28+
if (!user) {
29+
return <div className={clsx('headerProfile', classes.headerProfile)} />
30+
}
2431

2532
function handleClick(event: React.MouseEvent<HTMLButtonElement>) {
2633
setAnchorEl(event.currentTarget)
@@ -43,10 +50,10 @@ const HeaderProfile = () => {
4350
>
4451
<Avatar
4552
className={classes.profileAvatar}
46-
alt="John Doe"
53+
alt={user.firstName}
4754
src="https://avatars3.githubusercontent.com/u/3959008?v=3&s=40"
4855
/>
49-
<span className={classes.profileName}>Gevorg</span>
56+
<span className={classes.profileName}>{user.firstName}</span>
5057
<IconArrowDropDown />
5158
</IconButton>
5259
<Menu

src/Dashboard/_state/dashboard.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ export interface DashboardStateData {
1111
user?: User
1212
}
1313
export interface DashboardState extends DashboardStateStatus {
14-
data?: DashboardStateData
14+
data: DashboardStateData
15+
}
16+
17+
const initialState: DashboardState = {
18+
loading: false,
19+
error: undefined,
20+
data: {},
1521
}
1622

1723
const model = createModel({
18-
state: {
19-
loading: false,
20-
error: null,
21-
data: null,
22-
},
24+
state: initialState,
2325
reducers: {
2426
setStatus: (
2527
state: DashboardState,

src/Dashboard/_state/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { useDispatch, useSelector } from 'react-redux'
22
import { RootState, RootDispatch } from '_store'
33

4-
import dashboard from './dashboard'
4+
import dashboard, { DashboardState, DashboardStateData } from './dashboard'
55

66
export function useDashboardState() {
77
return useSelector((state: RootState) => state.dashboard)
88
}
99

10+
export function useDashboardData(): DashboardStateData {
11+
const { data } = useDashboardState()
12+
13+
return data
14+
}
15+
1016
export function useDashboardEffects() {
1117
const dispatch = useDispatch<RootDispatch>()
1218
return dispatch.dashboard

src/_api/_data/usersData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import organizationsToUsersData from './organizationsToUsersData'
55
const list: User[] = [
66
{
77
id: 1,
8-
firstName: 'John',
9-
lastName: 'Doe',
8+
firstName: 'Gevorg',
9+
lastName: 'H',
1010
username: 'johndoe1',
1111
email: 'john@doe.com',
1212
avatarUrl: 'https://avatars3.githubusercontent.com/u/3959008?v=3&s=40',

0 commit comments

Comments
 (0)