Skip to content

Commit

Permalink
Merge pull request #39 from AnWhiteM/nz
Browse files Browse the repository at this point in the history
User info display
  • Loading branch information
AnWhiteM authored Jun 11, 2024
2 parents 7520171 + 0228217 commit b22f2ff
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import css from "../Header/Header.module.css";
import { useState } from "react";
import UserEditModal from "../UserEditModal/UserEditModal";
import ThemeModal from "../ThemeModal/ThemeModal";
import svg from "../../img/icons.svg";
import css from "../Header/Header.module.css";
import { useSelector } from "react-redux";
import { selectUser } from "../../redux/auth/selectror";

export default function Header({ openSideBar, sideBarOpen }) {
const user = useSelector(selectUser);

const [showModal, setShowModal] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);

Expand Down Expand Up @@ -56,7 +60,7 @@ export default function Header({ openSideBar, sideBarOpen }) {
</div>
{showModal && <ThemeModal closeMenuModal={closeMenuModal} />}
<div className={css.layout}>
<p className={css.text}>UserName</p>
<p className={css.text}>{user.name}</p>
<button className={css.button} onClick={() => openModal()}>
<span className={`${css.avatarSmall} ${css.avatar}`} />
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MainDashboard/MainDashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AddColumnBtn } from "../AddColumnBtn/AddColumnBtn";
import { DashboardMessage } from "../DashboardMessage/DashboardMessage";
import { TaskColumn } from "../TaskColumn/TaskColumn";
import css from "./MainDashboard.module.css"
import css from "./MainDashboard.module.css";

export const MainDashboard = () => {
return (
Expand Down
7 changes: 5 additions & 2 deletions src/components/UserEditModal/UserEditModal.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useRef } from "react";
import { useDispatch } from "react-redux";
import { useSelector } from "react-redux";
import { selectUser } from "../../redux/auth/selectror";
import { Field, Form, Formik } from "formik";
import { ErrorMessage } from "formik";
import PasswordField from "../PasswordField/PasswordField";
Expand All @@ -21,6 +23,7 @@ const ValidationSchema = Yup.object().shape({
});

export default function UserEditModal({ onClose }) {
const user = useSelector(selectUser);
const dispatch = useDispatch();

const fileInputRef = useRef(null);
Expand Down Expand Up @@ -84,8 +87,8 @@ export default function UserEditModal({ onClose }) {
<div>
<Formik
initialValues={{
name: "",
email: "",
name: user.name || "",
email: user.email || "",
password: "",
}}
onSubmit={handleSubmit}
Expand Down
2 changes: 1 addition & 1 deletion src/redux/auth/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const register = createAsyncThunk(
"/auth/register",
async (userInfo, thunkAPI) => {
try {

const response = await axios.post("/auth/register", userInfo);
setAuthHeader(response.data.token);
return response.data;
Expand All @@ -31,6 +30,7 @@ export const logIn = createAsyncThunk(
try {
const response = await axios.post("/auth/login", userInfo);
setAuthHeader(response.data.token);
await thunkAPI.dispatch(getUserInfo());
return response.data;
} catch (error) {
return thunkAPI.rejectWithValue(error.message);
Expand Down
6 changes: 5 additions & 1 deletion src/redux/auth/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ const authSlice = createSlice({
})
.addCase(getUserInfo.fulfilled, (state, action) => {
state.loading = false;
state.user = action.payload;
// state.user = action.payload;
state.user.name = action.payload.name;
state.user.email = action.payload.email;
state.user.theme = action.payload.theme;
state.user.avatarURL = action.payload.avatarURL;
state.isLoggedIn = true;
})
.addCase(getUserInfo.rejected, (state, action) => {
Expand Down

0 comments on commit b22f2ff

Please sign in to comment.