Skip to content

Commit

Permalink
add avatar to userModel
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhnyak committed Dec 12, 2023
1 parent bfd3675 commit 79869c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const App = () => {
dispatch(
setCredentials({
name: user.data.name,
email: user.data?.email,
avatarURL: user.data?.avatarURL,
isLoggedIn: true,
isRefreshing: false,
})
Expand Down
5 changes: 3 additions & 2 deletions src/components/AppBar/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { getUser } from "../../redux/selectors";

const UserMenu = () => {
const [anchorElUser, setAnchorElUser] = useState(null);
const { name } = useSelector(getUser);
const { name, avatarURL } = useSelector(getUser);
console.log("avatarURL", useSelector(getUser));

const dispatch = useDispatch();
const [logout] = useLogoutMutation();
Expand Down Expand Up @@ -45,7 +46,7 @@ const UserMenu = () => {
<Box sx={{ flexGrow: 0 }}>
<Tooltip title={name}>
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
<Avatar alt={name} children={name[0]} />
<Avatar alt={name} src={avatarURL} />
</IconButton>
</Tooltip>
<Menu
Expand Down
48 changes: 21 additions & 27 deletions src/components/Contacts/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const Contact: React.FC<Props> = ({
onClick={handleDelete}
title={`Delete ${name}`}
loading={deleteInfo.isLoading}
loadingPosition="end"
// loadingPosition="end"
variant="outlined"
color="success"
>
Expand All @@ -61,39 +61,33 @@ export const Contact: React.FC<Props> = ({
<PersonIcon />
</Avatar>
</ListItemAvatar>
<ListItemText
primary={name}
secondary={
<Stack
direction={{ xs: "column", sm: "row" }}
spacing={{ xs: 0, sm: 2 }}
divider={<Divider orientation="vertical" flexItem />}
>
<Stack>
<ListItemText primary={name}></ListItemText>
<Stack
direction={{ xs: "column", sm: "row" }}
spacing={{ xs: 0, sm: 2 }}
divider={<Divider orientation="vertical" flexItem />}
>
<Link href={"tel:" + phone} underline="hover" sx={{ color: "green" }}>
<Stack direction="row" spacing={1}>
<PhoneIcon fontSize="small" />
<span>{phone}</span>
</Stack>
</Link>
{email && (
<Link
href={"tel:" + phone}
href={"mailto:" + email}
underline="hover"
sx={{ color: "green" }}
>
<Stack direction="row" spacing={1}>
<PhoneIcon fontSize="small" />
<span>{phone}</span>
<MailOutlineIcon fontSize="small" />
<span>{email}</span>
</Stack>
</Link>
{email && (
<Link
href={"mailto:" + email}
underline="hover"
sx={{ color: "green" }}
>
<Stack direction="row" spacing={1}>
<MailOutlineIcon fontSize="small" />
<span>{email}</span>
</Stack>
</Link>
)}
</Stack>
}
/>
)}
</Stack>
</Stack>
</ListItem>
);
};
18 changes: 10 additions & 8 deletions src/redux/authSlice.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { createSlice } from '@reduxjs/toolkit';
import storage from 'redux-persist/lib/storage';
import { persistReducer } from 'redux-persist';
import { createSlice } from "@reduxjs/toolkit";
import storage from "redux-persist/lib/storage";
import { persistReducer } from "redux-persist";

const authInitialState = {
isLoggedIn: false,
isRefreshing: false,
token: '',
name: '',
token: "",
name: "",
avatarURL: "",
};

const persistConfig = {
key: 'root',
key: "root",
storage,
whitelist: ['token'],
whitelist: ["token"],
};

const authSlice = createSlice({
name: 'auth',
name: "auth",
initialState: authInitialState,
reducers: {
setCredentials(state, action) {
console.log(action);
return (state = { ...state, ...action.payload });
},
},
Expand Down

0 comments on commit 79869c6

Please sign in to comment.